kopia lustrzana https://github.com/bertrik/ttnhabbridge
Add unit test for MQTT data.
rodzic
29671c1b37
commit
e30bb2d887
|
@ -0,0 +1,59 @@
|
|||
package nl.sikken.bertrik.hab.ttn;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
/**
|
||||
* Representation of a message received from the TTN MQTT stream.
|
||||
*/
|
||||
public final class MqttData {
|
||||
|
||||
@JsonProperty("app_id")
|
||||
private String appId;
|
||||
|
||||
@JsonProperty("dev_id")
|
||||
private String devId;
|
||||
|
||||
@JsonProperty("hardware_serial")
|
||||
private String hardwareSerial;
|
||||
|
||||
@JsonProperty("port")
|
||||
private int port;
|
||||
|
||||
@JsonProperty("counter")
|
||||
private int counter;
|
||||
|
||||
@JsonProperty("payload_raw")
|
||||
private byte[] payload;
|
||||
|
||||
@JsonProperty("metadata")
|
||||
private MqttMetaData metaData;
|
||||
|
||||
private MqttData() {
|
||||
// jackson constructor
|
||||
}
|
||||
|
||||
public String getAppId() {
|
||||
return appId;
|
||||
}
|
||||
|
||||
public String getDevId() {
|
||||
return devId;
|
||||
}
|
||||
|
||||
public String getHardwareSerial() {
|
||||
return hardwareSerial;
|
||||
}
|
||||
|
||||
public int getCounter() {
|
||||
return counter;
|
||||
}
|
||||
|
||||
public byte[] getPayload() {
|
||||
return payload;
|
||||
}
|
||||
|
||||
public MqttMetaData getMetaData() {
|
||||
return metaData;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package nl.sikken.bertrik.hab.ttn;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
/**
|
||||
* Representation of meta-data part of MQTT message.
|
||||
*/
|
||||
public final class MqttMetaData {
|
||||
|
||||
@JsonProperty("time")
|
||||
private String time;
|
||||
|
||||
private MqttMetaData() {
|
||||
// jackson constructor
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package nl.sikken.bertrik.hab.ttn;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParseException;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
/**
|
||||
* Unit tests for MqttData.
|
||||
*/
|
||||
public final class MqttDataTest {
|
||||
|
||||
@Test
|
||||
public void testDeserialization() throws JsonParseException, JsonMappingException, IOException {
|
||||
final String s = "{\"app_id\":\"ttnmapper\",\"dev_id\":\"mapper2\","
|
||||
+ "\"hardware_serial\":\"0004A30B001ADBC5\",\"port\":1,\"counter\":0,"
|
||||
+ "\"payload_raw\":\"AA==\",\"metadata\":{\"time\":\"2017-08-19T15:23:39.288816687Z\"}}";
|
||||
|
||||
final ObjectMapper mapper = new ObjectMapper();
|
||||
final MqttData mqttData = mapper.readValue(s, MqttData.class);
|
||||
|
||||
Assert.assertEquals(0, mqttData.getCounter());
|
||||
}
|
||||
|
||||
}
|
Ładowanie…
Reference in New Issue