Moved find device to its own utility method, and added a specific equals method and reworked some test.
This commit is contained in:
parent
7e8938c38c
commit
c7e286f51e
166 changed files with 618 additions and 374 deletions
|
|
@ -3,44 +3,45 @@ package se.hal.plugin.tellstick;
|
|||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import se.hal.intf.*;
|
||||
import se.hal.struct.devicedata.DimmerEventData;
|
||||
import zutil.converter.Converter;
|
||||
import se.hal.plugin.tellstick.test.TestEventDevice;
|
||||
import se.hal.plugin.tellstick.test.TestProtocol;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Created by Ziver on 2015-11-19.
|
||||
*/
|
||||
public class TelstickSerialCommEventTest {
|
||||
public class TellstickSerialCommEventTest {
|
||||
|
||||
@Before
|
||||
public void init(){
|
||||
TellstickParser.registerProtocol(TestEvent.class);
|
||||
public void init() {
|
||||
TellstickParser.registerProtocol(TestProtocol.class);
|
||||
}
|
||||
|
||||
|
||||
//############# Non crashing TC
|
||||
// ----------------------------------------------------
|
||||
// Non crashing TC
|
||||
// ----------------------------------------------------
|
||||
|
||||
@Test
|
||||
public void startup(){
|
||||
public void startup() {
|
||||
TellstickSerialComm tellstick = new TellstickSerialComm();
|
||||
tellstick.handleLine("+V2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unregisteredListener(){
|
||||
public void unregisteredListener() {
|
||||
TellstickSerialComm tellstick = new TellstickSerialComm();
|
||||
tellstick.handleLine("+Wclass:sensor;protocol:test-prot;model:test-model;data:1234;");
|
||||
}
|
||||
|
||||
|
||||
//############ Normal TCs
|
||||
// ----------------------------------------------------
|
||||
// Normal TCs
|
||||
// ----------------------------------------------------
|
||||
|
||||
@Test
|
||||
public void receiveUnregisteredEvent(){
|
||||
public void receiveUnregisteredEvent() {
|
||||
// Setup
|
||||
TellstickSerialComm tellstick = new TellstickSerialComm();
|
||||
final ArrayList<HalEventConfig> list = new ArrayList<>();
|
||||
|
|
@ -51,14 +52,14 @@ public class TelstickSerialCommEventTest {
|
|||
}
|
||||
});
|
||||
// Execution
|
||||
tellstick.handleLine("+Wclass:sensor;protocol:test-prot;model:test-model;data:2345;");
|
||||
tellstick.handleLine("+Wclass:sensor;protocol:test-prot;model:test-model;data:6345;");
|
||||
assertEquals("Events first transmission", 0, list.size());
|
||||
tellstick.handleLine("+Wclass:sensor;protocol:test-prot;model:test-model;data:2345;");
|
||||
tellstick.handleLine("+Wclass:sensor;protocol:test-prot;model:test-model;data:6345;");
|
||||
assertEquals("Events Second transmission", 1, list.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void receiveEvent(){
|
||||
public void receiveEvent() {
|
||||
// Setup
|
||||
TellstickSerialComm tellstick = new TellstickSerialComm();
|
||||
final ArrayList<HalEventConfig> list = new ArrayList<>();
|
||||
|
|
@ -69,45 +70,13 @@ public class TelstickSerialCommEventTest {
|
|||
}
|
||||
});
|
||||
// Execution
|
||||
TestEvent event = new TestEvent();
|
||||
TestEventDevice event = new TestEventDevice();
|
||||
event.testData = 0xAAAA;
|
||||
tellstick.register(event);
|
||||
tellstick.handleLine("+Wclass:sensor;protocol:test-prot;model:test-model;data:AAAA;");
|
||||
// Verification
|
||||
assertEquals("Nr of received events", 1, list.size());
|
||||
assertEquals("Data", event.testData, ((TestEvent)list.get(0)).testData);
|
||||
assertEquals("Data", event.testData, ((TestEventDevice)list.get(0)).testData);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private static class TestEvent extends TellstickProtocol implements HalEventConfig,TellstickDevice {
|
||||
public int testData;
|
||||
|
||||
public TestEvent(){
|
||||
super("test-prot", "test-model");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TellstickDecodedEntry> decode(byte[] data) {
|
||||
testData = Converter.toInt(data);
|
||||
|
||||
ArrayList<TellstickDecodedEntry> list = new ArrayList<>();
|
||||
list.add(new TellstickDecodedEntry(
|
||||
this, new DimmerEventData(testData, System.currentTimeMillis())
|
||||
));
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Class<? extends HalEventController> getDeviceControllerClass() { return null; }
|
||||
@Override
|
||||
public Class<? extends HalEventData> getDeviceDataClass() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {return testData == ((TestEvent)obj).testData;}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
package se.hal.plugin.tellstick;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import se.hal.intf.*;
|
||||
import se.hal.plugin.tellstick.test.TestProtocol;
|
||||
import se.hal.plugin.tellstick.test.TestSensorDevice;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Created by Ziver on 2015-11-19.
|
||||
*/
|
||||
public class TellstickSerialCommSensorTest {
|
||||
|
||||
@Before
|
||||
public void init(){
|
||||
TellstickParser.registerProtocol(TestProtocol.class);
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------------------
|
||||
// Normal TCs
|
||||
// ----------------------------------------------------
|
||||
|
||||
@Test
|
||||
public void receiveUnregisteredSensor() {
|
||||
// Setup
|
||||
TellstickSerialComm tellstick = new TellstickSerialComm();
|
||||
final ArrayList<HalSensorConfig> list = new ArrayList<>();
|
||||
tellstick.setListener(new HalDeviceReportListener<HalSensorConfig,HalSensorData>() {
|
||||
@Override
|
||||
public void reportReceived(HalSensorConfig e, HalSensorData d) {
|
||||
list.add(e);
|
||||
}
|
||||
});
|
||||
// Execution
|
||||
tellstick.handleLine("+Wclass:sensor;protocol:test-prot;model:test-model;data:15;");
|
||||
assertEquals("Sensors first transmission", 0, list.size());
|
||||
tellstick.handleLine("+Wclass:sensor;protocol:test-prot;model:test-model;data:15;");
|
||||
assertEquals("Sensors Second transmission", 1, list.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void receiveSensor() {
|
||||
// Setup
|
||||
TellstickSerialComm tellstick = new TellstickSerialComm();
|
||||
final ArrayList<HalSensorConfig> list = new ArrayList<>();
|
||||
tellstick.setListener(new HalDeviceReportListener<HalSensorConfig,HalSensorData>() {
|
||||
@Override
|
||||
public void reportReceived(HalSensorConfig e, HalSensorData d) {
|
||||
list.add(e);
|
||||
}
|
||||
});
|
||||
// Execution
|
||||
TestSensorDevice sensor = new TestSensorDevice();
|
||||
sensor.testData = 0xAA;
|
||||
tellstick.register(sensor);
|
||||
tellstick.handleLine("+Wclass:sensor;protocol:test-prot;model:test-model;data:AA;");
|
||||
// Verification
|
||||
assertEquals("Nr of received sensors", 1, list.size());
|
||||
assertEquals("Data", sensor.testData, ((TestSensorDevice)list.get(0)).testData);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,103 +0,0 @@
|
|||
package se.hal.plugin.tellstick;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import se.hal.intf.*;
|
||||
import se.hal.struct.devicedata.TemperatureSensorData;
|
||||
import zutil.converter.Converter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Created by Ziver on 2015-11-19.
|
||||
*/
|
||||
public class TelstickSerialCommSensorTest {
|
||||
|
||||
@Before
|
||||
public void init(){
|
||||
TellstickParser.registerProtocol(TestSensor.class);
|
||||
}
|
||||
|
||||
|
||||
//############ Normal TCs
|
||||
|
||||
@Test
|
||||
public void receiveUnregisteredSensor(){
|
||||
// Setup
|
||||
TellstickSerialComm tellstick = new TellstickSerialComm();
|
||||
final ArrayList<HalSensorConfig> list = new ArrayList<>();
|
||||
tellstick.setListener(new HalDeviceReportListener<HalSensorConfig,HalSensorData>() {
|
||||
@Override
|
||||
public void reportReceived(HalSensorConfig e, HalSensorData d) {
|
||||
list.add(e);
|
||||
}
|
||||
});
|
||||
// Execution
|
||||
tellstick.handleLine("+Wclass:sensor;protocol:test-prot;model:test-model;data:2345;");
|
||||
assertEquals("Sensors first transmission", 0, list.size());
|
||||
tellstick.handleLine("+Wclass:sensor;protocol:test-prot;model:test-model;data:2345;");
|
||||
assertEquals("Sensors Second transmission", 1, list.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void receiveSensor(){
|
||||
// Setup
|
||||
TellstickSerialComm tellstick = new TellstickSerialComm();
|
||||
final ArrayList<HalSensorConfig> list = new ArrayList<>();
|
||||
tellstick.setListener(new HalDeviceReportListener<HalSensorConfig,HalSensorData>() {
|
||||
@Override
|
||||
public void reportReceived(HalSensorConfig e, HalSensorData d) {
|
||||
list.add(e);
|
||||
}
|
||||
});
|
||||
// Execution
|
||||
TestSensor sensor = new TestSensor();
|
||||
sensor.testData = 0xAAAA;
|
||||
tellstick.register(sensor);
|
||||
tellstick.handleLine("+Wclass:sensor;protocol:test-prot;model:test-model;data:AAAA;");
|
||||
// Verification
|
||||
assertEquals("Nr of received sensors", 1, list.size());
|
||||
assertEquals("Data", sensor.testData, ((TestSensor)list.get(0)).testData);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private static class TestSensor extends TellstickProtocol implements HalSensorConfig,TellstickDevice {
|
||||
public int testData;
|
||||
|
||||
public TestSensor(){
|
||||
super("test-prot", "test-model");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TellstickDecodedEntry> decode(byte[] data) {
|
||||
testData = Converter.toInt(data);
|
||||
|
||||
ArrayList<TellstickDecodedEntry> list = new ArrayList<>();
|
||||
list.add(new TellstickDecodedEntry(
|
||||
this, new TemperatureSensorData(testData, 0)
|
||||
));
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {return testData == ((TestSensor)obj).testData;}
|
||||
|
||||
|
||||
@Override
|
||||
public long getDataInterval() { return 0; }
|
||||
@Override
|
||||
public AggregationMethod getAggregationMethod() { return null; }
|
||||
@Override
|
||||
public Class<? extends HalSensorController> getDeviceControllerClass() { return null; }
|
||||
@Override
|
||||
public Class<? extends HalSensorData> getDeviceDataClass() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
package se.hal.plugin.tellstick.test;
|
||||
|
||||
import se.hal.intf.HalDeviceConfig;
|
||||
import se.hal.intf.HalEventConfig;
|
||||
import se.hal.intf.HalEventController;
|
||||
import se.hal.intf.HalEventData;
|
||||
import se.hal.plugin.tellstick.TellstickDevice;
|
||||
import se.hal.plugin.tellstick.TellstickSerialCommEventTest;
|
||||
|
||||
public class TestEventDevice implements TellstickDevice, HalEventConfig {
|
||||
public int testData;
|
||||
|
||||
|
||||
@Override
|
||||
public String getProtocolName() {
|
||||
return "test-prot";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getModelName() {
|
||||
return "test-model";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Class<? extends HalEventController> getDeviceControllerClass() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends HalEventData> getDeviceDataClass() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return testData == ((TestEventDevice) obj).testData;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
package se.hal.plugin.tellstick.test;
|
||||
|
||||
import se.hal.plugin.tellstick.TellstickProtocol;
|
||||
import se.hal.struct.devicedata.DimmerEventData;
|
||||
import se.hal.struct.devicedata.TemperatureSensorData;
|
||||
import zutil.converter.Converter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TestProtocol extends TellstickProtocol {
|
||||
|
||||
public TestProtocol() {
|
||||
super("test-prot", "test-model");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TellstickDecodedEntry> decode(byte[] data) {
|
||||
ArrayList<TellstickDecodedEntry> list = new ArrayList<>();
|
||||
int parsedData = Converter.toInt(data);
|
||||
|
||||
if (parsedData > 5000) {
|
||||
TestEventDevice device = new TestEventDevice();
|
||||
device.testData = Converter.toInt(data);
|
||||
|
||||
list.add(new TellstickDecodedEntry(
|
||||
device, new DimmerEventData(device.testData, System.currentTimeMillis())
|
||||
));
|
||||
} else {
|
||||
TestSensorDevice device = new TestSensorDevice();
|
||||
device.testData = Converter.toInt(data);
|
||||
|
||||
list.add(new TellstickDecodedEntry(
|
||||
device, new TemperatureSensorData(device.testData, System.currentTimeMillis())
|
||||
));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
package se.hal.plugin.tellstick.test;
|
||||
|
||||
import se.hal.intf.HalDeviceConfig;
|
||||
import se.hal.intf.HalSensorConfig;
|
||||
import se.hal.intf.HalSensorController;
|
||||
import se.hal.intf.HalSensorData;
|
||||
import se.hal.plugin.tellstick.TellstickDevice;
|
||||
import se.hal.plugin.tellstick.TellstickSerialCommSensorTest;
|
||||
|
||||
public class TestSensorDevice implements HalSensorConfig, TellstickDevice {
|
||||
public int testData;
|
||||
|
||||
@Override
|
||||
public String getProtocolName() {
|
||||
return "test-prot";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getModelName() {
|
||||
return "test-model";
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getDataInterval() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AggregationMethod getAggregationMethod() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends HalSensorController> getDeviceControllerClass() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends HalSensorData> getDeviceDataClass() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return testData == ((TestSensorDevice) obj).testData;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue