Skip to content

Commit

Permalink
Merge pull request #2 from angryelectron/development
Browse files Browse the repository at this point in the history
Improve tests
  • Loading branch information
abythell committed Nov 7, 2014
2 parents 335a68b + a5c80f4 commit e731bec
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 142 deletions.
48 changes: 30 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
ThingSpeak Java Client
===
A Java client for the [ThingSpeak](http://thingspeak.com) Internet of
Things. Implements all aspects of the ThingSpeak API and can be used to
update channel data, retrieve and examine feeds, and query public channels.
It supports the hosted ThingSpeak server at api.thingspeak.com as well
as self-hosted open-source servers ([GitHub Source](https://github.com/iobridge/thingspeak)).
A Java client for the [ThingSpeak](http://thingspeak.com) Internet of Things.
Implements all aspects of the ThingSpeak API and can be used to update channel
data, retrieve and examine feeds, and query public channels. It supports the
hosted ThingSpeak server at api.thingspeak.com as well as self-hosted
open-source servers ([GitHub Source](https://github.com/iobridge/thingspeak)).

Also included: An appender for log4j - post data to ThingSpeak channels using Logger
framework.
Also included: An appender for log4j - post data to ThingSpeak channels using
Logger framework.

How To Install
---
Get the source by [downloading a zip file](https://github.com/angryelectron/thingspeak-java/archive/master.zip)
or by cloning the git repository https://github.com/angryelectron/thingspeak-java.git .
Building the source requires the Java 7 SDK and Apache Ant, or use the [Netbeans IDE](http://netbeans.org).
Get the source by [downloading a zip
file](https://github.com/angryelectron/thingspeak-java/archive/master.zip) or
by cloning the git repository
https://github.com/angryelectron/thingspeak-java.git . Building the source
requires the Java 7 SDK and Apache Ant, or use the [Netbeans
IDE](http://netbeans.org).

Here is an example of how to install the client from the command line in Ubuntu/Debian/Raspbian with a minimal build environment:
Here is an example of how to install the client from the command line in
Ubuntu/Debian/Raspbian with a minimal build environment:

```
sudo apt-get update
Expand All @@ -25,7 +29,9 @@ cd thingspeak-java
ant
```

After building, the jars, docs, and dependencies can be found in thingspeak/dist.
To run optional tests, run 'ant test'. Due to the rate limit of the public
Thingspeak server (15sec), tests can take a long time to run. After building,
the jars, docs, and dependencies can be found in thingspeak/dist.

How To Use
---
Expand All @@ -34,10 +40,14 @@ Add thingspeak-x.y.jar to your project and the following dependencies:
* [Unirest](http://unirest.io)
* [GSON](http://code.google.com/p/google-gson/)

Dependencies can be found in thingspeak/dist/lib after building the source. Refer to the included javadocs for more details. The [ThingSpeak API Documentation](http://community.thingspeak.com/documentation/api/#thingspeak_api)
Dependencies can be found in thingspeak/dist/lib after building the source.
Refer to the included javadocs for more details. The [ThingSpeak API
Documentation](http://community.thingspeak.com/documentation/api/#thingspeak_api)
is also a good source of additional information about using the API.

If you encounter any issues with the ThingSpeak Java Client, please use the [GitHub issue tracker](https://github.com/angryelectron/thingspeak-java/issues).
If you encounter any issues with the ThingSpeak Java Client, please use the
[GitHub issue
tracker](https://github.com/angryelectron/thingspeak-java/issues).

Examples
---
Expand All @@ -60,13 +70,15 @@ Entry entry = channel.getLastChannelEntry();
System.out.println(entry.getField(1);
```

Please refer to thingspeak/dist/javadoc for more information about customzing channel feeds, searching public channels, using open-source servers, and all the other operations supported by the ThingSpeak API.
Please refer to thingspeak/dist/javadoc for more information about customzing
channel feeds, searching public channels, using open-source servers, and all
the other operations supported by the ThingSpeak API.

log4j Appender
---
Use log4j to update ThingSpeak channels. Date, Level, and Message are 'fields',
written as an 'entry'. Setup a new ThingSpeak channel with these three fields, then
pass the channel number and API write-key to the appender.
Use log4j to update ThingSpeak channels. Date, Level, and Message are
'fields', written as an 'entry'. Setup a new ThingSpeak channel with these
three fields, then pass the channel number and API write-key to the appender.

Here's how to configure the appender and send a test
message (just add your own channelNumber and apiWriteKey):
Expand Down
4 changes: 3 additions & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<!-- the Compile on Save feature is turned off for the project. -->
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
<!-- in the project's Project Properties dialog box.-->
<project name="ThingSpeak" default="default" basedir=".">
<project name="ThingSpeak" default="default-notest" basedir=".">
<description>Builds, tests, and runs the project ThingSpeak.</description>
<import file="nbproject/build-impl.xml"/>
<!--
Expand Down Expand Up @@ -70,6 +70,8 @@
nbproject/build-impl.xml file.
-->

<target depends="jar,javadoc" description="Build and test whole project without tests." name="default-notest"/>

<target name="-post-jar" description="bundle sources and javadoc in a jar" depends="javadoc">
<jar compress="${jar.compress}" basedir="${src.dir}" jarfile="${dist.dir}/${application.title}-sources.jar"/>
Expand Down
2 changes: 1 addition & 1 deletion src/com/angryelectron/thingspeak/Feed.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public Map<Integer, Entry> getEntryMap() {
*/
public Entry getEntry(Integer id) throws ThingSpeakException {
for (Entry entry : this.feeds) {
if (entry.getEntryId() == id) {
if (entry.getEntryId().equals(id)) {
return entry;
}
}
Expand Down
21 changes: 20 additions & 1 deletion test/com/angryelectron/thingspeak/FeedTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.junit.AfterClass;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
Expand All @@ -38,6 +41,9 @@ public class FeedTest {
*/
@BeforeClass
public static void setUpClass() throws Exception {
BasicConfigurator.resetConfiguration();
BasicConfigurator.configure();
Logger.getLogger("org.apache.http").setLevel(Level.OFF);
Entry entry = new Entry();
entry.setElevation(0.0);
entry.setField(1, "nonsense-data1");
Expand Down Expand Up @@ -76,6 +82,7 @@ public static void tearDownClass() throws Exception {

@Test
public void testGetChannelFeedPublic() throws Exception {
System.out.println("testGetChannelFeedPublic");
Channel publicChannel = new Channel(TestChannelSettings.publicChannelID, TestChannelSettings.publicChannelWriteKey);
publicChannel.setUrl(TestChannelSettings.server);
Feed publicFeed = publicChannel.getChannelFeed();
Expand All @@ -92,6 +99,7 @@ public void testGetChannelFeedPublic() throws Exception {

@Test
public void testGetChannelFeedPrivate() throws Exception {
System.out.println("testGetChannelFeedPrivate");
Channel publicChannel = new Channel(TestChannelSettings.privateChannelID, TestChannelSettings.privateChannelWriteKey, TestChannelSettings.privateChannelReadKey);
publicChannel.setUrl(TestChannelSettings.server);
Feed publicFeed = publicChannel.getChannelFeed();
Expand Down Expand Up @@ -124,12 +132,13 @@ public void testGetChannelFeedPrivate() throws Exception {

@Test
public void testGetChannelFeedWithOptions() throws Exception {
System.out.println("testGetChannelFeedWithOptions");
Channel publicChannel = new Channel(TestChannelSettings.publicChannelID, TestChannelSettings.publicChannelWriteKey);
publicChannel.setUrl(TestChannelSettings.server);
FeedParameters options = new FeedParameters();
options.location(true);
options.status(true);
Feed publicFeed = publicChannel.getChannelFeed(options);
Feed publicFeed = publicChannel.getChannelFeed(options);
Entry entry = publicFeed.getChannelLastEntry();
assertNotNull(entry.getStatus());
assertNotNull(entry.getElevation());
Expand All @@ -139,6 +148,7 @@ public void testGetChannelFeedWithOptions() throws Exception {

@Test
public void testGetLastEntry() throws Exception {
System.out.println("testGetLastEntry");
Channel publicChannel = new Channel(TestChannelSettings.publicChannelID, TestChannelSettings.publicChannelWriteKey);
publicChannel.setUrl(TestChannelSettings.server);
Entry entry = publicChannel.getLastChannelEntry();
Expand All @@ -159,6 +169,7 @@ public void testGetLastEntry() throws Exception {

@Test
public void testGetLastEntryWithOptions() throws Exception {
System.out.println("testGetLastEntryWithOptions");
Channel publicChannel = new Channel(TestChannelSettings.publicChannelID, TestChannelSettings.publicChannelWriteKey);
publicChannel.setUrl(TestChannelSettings.server);
FeedParameters options = new FeedParameters();
Expand All @@ -173,6 +184,7 @@ public void testGetLastEntryWithOptions() throws Exception {

@Test
public void testGetLastEntryWithTimezoneOffset() throws Exception {
System.out.println("testGetLastEntryWithTimezoneOffset");
Channel channel = new Channel(TestChannelSettings.publicChannelID);
channel.setUrl(TestChannelSettings.server);
FeedParameters options = new FeedParameters();
Expand All @@ -184,6 +196,7 @@ public void testGetLastEntryWithTimezoneOffset() throws Exception {

@Test
public void testGetFieldFeed() throws Exception {
System.out.println("testGetFieldFeed");
Channel publicChannel = new Channel(TestChannelSettings.publicChannelID);
publicChannel.setUrl(TestChannelSettings.server);
Feed feed = publicChannel.getFieldFeed(1);
Expand All @@ -206,6 +219,7 @@ public void testGetFieldFeed() throws Exception {

@Test
public void testGetFieldFeedWithOptions() throws Exception {
System.out.println("testGetFieldFeedWithOptions");
Channel publicChannel = new Channel(TestChannelSettings.publicChannelID);
publicChannel.setUrl(TestChannelSettings.server);
FeedParameters options = new FeedParameters();
Expand All @@ -224,6 +238,7 @@ public void testGetFieldFeedWithOptions() throws Exception {

@Test
public void testGetFieldFeedLastEntry() throws Exception {
System.out.println("testGetFieldFeedLastEntry");
Channel publicChannel = new Channel(TestChannelSettings.publicChannelID);
publicChannel.setUrl(TestChannelSettings.server);
Entry entry = publicChannel.getLastFieldEntry(1);
Expand All @@ -233,6 +248,7 @@ public void testGetFieldFeedLastEntry() throws Exception {

@Test
public void testGetFieldFeedLastEntryWithOptions() throws Exception {
System.out.println("testGetFieldFeedLastEntryWithOptions");
Channel publicChannel = new Channel(TestChannelSettings.publicChannelID);
publicChannel.setUrl(TestChannelSettings.server);
FeedParameters options = new FeedParameters();
Expand All @@ -249,6 +265,7 @@ public void testGetFieldFeedLastEntryWithOptions() throws Exception {

@Test
public void testGetStatus() throws Exception {
System.out.println("testGetStatus");
Channel channel = new Channel(TestChannelSettings.publicChannelID);
channel.setUrl(TestChannelSettings.server);
Feed feed = channel.getStatusFeed();
Expand All @@ -259,6 +276,7 @@ public void testGetStatus() throws Exception {

@Test
public void testGetStatusWithOptions() throws Exception {
System.out.println("testGetStatusWithOptions");
Channel channel = new Channel(TestChannelSettings.publicChannelID);
channel.setUrl(TestChannelSettings.server);
FeedParameters options = new FeedParameters();
Expand All @@ -273,6 +291,7 @@ public void testGetStatusWithOptions() throws Exception {

@Test
public void testGetStatus_emptyFields() throws Exception {
System.out.println("testGetStatusEmptyFields");
Channel channel = new Channel(TestChannelSettings.publicChannelID);
channel.setUrl(TestChannelSettings.server);
Feed statusFeed = channel.getStatusFeed();
Expand Down
72 changes: 0 additions & 72 deletions test/com/angryelectron/thingspeak/TestPublicChannels.java

This file was deleted.

Loading

0 comments on commit e731bec

Please sign in to comment.