This repository has been archived by the owner on Dec 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(InfluxDBManager,InfluxDBTest,TestUtility) : Improuve Tests
Add TestUtility to manage InfluxDB server URL. Refactor InfluxDBUnitTest to InfluxDBTest. Improuve InfluxDBManger.
- Loading branch information
1 parent
ac9d8f2
commit f9643ac
Showing
4 changed files
with
136 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package science.apolline; | ||
|
||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonParser; | ||
|
||
import org.influxdb.InfluxDB; | ||
import org.junit.Assert; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.ExpectedException; | ||
|
||
import java.io.IOException; | ||
|
||
|
||
/** | ||
* Created by sparow on 10/1/17. | ||
*/ | ||
|
||
public class InfluxDBTest { | ||
|
||
public static String JSONTOSEND = "{\"device\":\"Arduino\",\"sensorId\":\"MQ135\",\"gasId\":{\"CO2\":1,\"SMOKE\":2,\"CH4\":3,\"O3\":4},\"unit\":\"PPM\",\"time\":\"WedSep2614:23:28EST2017\"}"; | ||
JsonParser parser = new JsonParser(); | ||
private InfluxDBManager influxDBManager = new InfluxDBManager(); | ||
|
||
@Rule | ||
public final ExpectedException exception = ExpectedException.none(); | ||
|
||
|
||
|
||
/** | ||
* Test for a ping. | ||
*/ | ||
@Test | ||
public void setupInfluxDBTest() throws Exception { | ||
InfluxDB influxDB = this.influxDBManager.setup("http://" + TestUtility.getInfluxDBIP() + ":" + TestUtility.getInfluxDBPORT(true),"toto", "root"); | ||
Assert.assertNotNull(influxDB); | ||
} | ||
|
||
/** | ||
* Test for input JSON parsing. | ||
*/ | ||
@Test | ||
public void testJsonParsing() throws Exception { | ||
|
||
JsonElement jsonElement = this.parser.parse(JSONTOSEND); | ||
Assert.assertNotNull(jsonElement); | ||
Assert.assertEquals(this.parser.parse(JSONTOSEND).toString(),JSONTOSEND); | ||
|
||
} | ||
|
||
/** | ||
* Test for writing points to remote InfluxDB server. | ||
*/ | ||
@Test | ||
public void testWriteToInfluxDB() throws Exception { | ||
InfluxDB influxDB = this.influxDBManager.setup("http://" + TestUtility.getInfluxDBIP() + ":" + TestUtility.getInfluxDBPORT(true), "toto", "root"); | ||
Assert.assertNotNull(influxDB); | ||
Assert.assertTrue(this.influxDBManager.write(influxDB, "test0", JSONTOSEND)); | ||
} | ||
|
||
|
||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package science.apolline; | ||
|
||
/** | ||
* Created by sparow on 10/9/17. | ||
*/ | ||
|
||
import java.util.Map; | ||
|
||
public class TestUtility { | ||
|
||
|
||
public static String getInfluxDBIP() { | ||
String ip = "127.0.0.1"; | ||
|
||
Map<String, String> getenv = System.getenv(); | ||
if (getenv.containsKey("INFLUXDB_IP")) { | ||
ip = getenv.get("INFLUXDB_IP"); | ||
} | ||
|
||
return ip; | ||
} | ||
|
||
|
||
|
||
public static String getInfluxDBPORT(boolean apiPort) { | ||
String port = "8086"; | ||
|
||
Map<String, String> getenv = System.getenv(); | ||
if(apiPort) { | ||
if (getenv.containsKey("INFLUXDB_PORT_API")) | ||
port = getenv.get("INFLUXDB_PORT_API"); | ||
} | ||
return port; | ||
} | ||
} |