use of org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homie300.Property in project smarthome by eclipse.
the class HomieImplementationTests method createSpyProperty.
// Inject a spy'ed property
public Property createSpyProperty(InvocationOnMock invocation) {
final Node node = (Node) invocation.getMock();
final String id = (String) invocation.getArguments()[0];
Property property = spy(node.createProperty(id, spy(new PropertyAttributes())));
return property;
}
use of org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homie300.Property in project smarthome by eclipse.
the class HomieImplementationTests method createSpyNode.
// Inject a spy'ed node
public Node createSpyNode(InvocationOnMock invocation) {
final Device device = (Device) invocation.getMock();
final String id = (String) invocation.getArguments()[0];
// Create the node
Node node = spy(device.createNode(id, spy(new NodeAttributes())));
// Intercept creating a property in the next call and inject a spy'ed property.
doAnswer(this::createSpyProperty).when(node).createProperty(any());
return node;
}
use of org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homie300.Property in project smarthome by eclipse.
the class HomieThingHandlerTests method handleCommandUpdate.
@SuppressWarnings("null")
@Test
public void handleCommandUpdate() {
// Create mocked homie device tree with one node and one writable property
Node node = thingHandler.device.createNode("node", spy(new NodeAttributes()));
doReturn(future).when(node.attributes).subscribeAndReceive(any(), any(), anyString(), any(), anyInt());
doReturn(future).when(node.attributes).unsubscribe();
node.attributes.name = "testnode";
Property property = node.createProperty("property", spy(new PropertyAttributes()));
doReturn(future).when(property.attributes).subscribeAndReceive(any(), any(), anyString(), any(), anyInt());
doReturn(future).when(property.attributes).unsubscribe();
property.attributes.name = "testprop";
property.attributes.datatype = DataTypeEnum.string_;
property.attributes.settable = true;
property.attributesReceived();
node.properties.put(property.propertyID, property);
thingHandler.device.nodes.put(node.nodeID, node);
ChannelState channelState = property.getChannelState();
assertNotNull(channelState);
// Pretend we called start()
ChannelStateHelper.setConnection(channelState, connection);
thingHandler.connection = connection;
StringType updateValue = new StringType("UPDATE");
thingHandler.handleCommand(property.channelUID, updateValue);
assertThat(property.getChannelState().getCache().getChannelState().toString(), is("UPDATE"));
verify(connection, times(1)).publish(any(), any(), anyInt(), anyBoolean());
// Check non writable property
property.attributes.settable = false;
property.attributesReceived();
// Assign old value
Value value = property.getChannelState().getCache();
Command command = TypeParser.parseCommand(value.getSupportedCommandTypes(), "OLDVALUE");
property.getChannelState().getCache().update(command);
// Try to update with new value
updateValue = new StringType("SOMETHINGNEW");
thingHandler.handleCommand(property.channelUID, updateValue);
// Expect old value and no MQTT publish
assertThat(property.getChannelState().getCache().getChannelState().toString(), is("OLDVALUE"));
verify(connection, times(1)).publish(any(), any(), anyInt(), anyBoolean());
}
use of org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homie300.Property in project smarthome by eclipse.
the class HomieThingHandlerTests method createSpyNode.
public Node createSpyNode(String propertyID, Device device) {
// Create the node
Node node = spy(device.createNode("node", spy(new NodeAttributes())));
doReturn(future).when(node.attributes).subscribeAndReceive(any(), any(), anyString(), any(), anyInt());
doReturn(future).when(node.attributes).unsubscribe();
node.attributes.name = "testnode";
node.attributes.properties = new String[] { "property" };
doAnswer(this::createSubscriberAnswer).when(node.attributes).createSubscriber(any(), any(), any(), anyBoolean());
// Intercept creating a property in the next call and inject a spy'ed property.
doAnswer(i -> createSpyProperty("property", node)).when(node).createProperty(any());
return node;
}
Aggregations