use of io.envoyproxy.envoy.config.core.v3.Node 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 io.envoyproxy.envoy.config.core.v3.Node 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 io.envoyproxy.envoy.config.core.v3.Node 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;
}
use of io.envoyproxy.envoy.config.core.v3.Node in project smarthome by eclipse.
the class ChildMapTests method testArrayToSubtopicCreateAndRemove.
@Test
public void testArrayToSubtopicCreateAndRemove() {
AddedAction addedAction = spy(new AddedAction());
// Assign "abc,def" to the
subject.apply(new String[] { "abc", "def" }, addedAction, this::createNode, this::removedNode);
assertThat(future.isDone(), is(true));
assertThat(subject.get("abc").nodeID, is("abc"));
assertThat(subject.get("def").nodeID, is("def"));
verify(addedAction, times(2)).apply(any());
Node soonToBeRemoved = subject.get("def");
subject.apply(new String[] { "abc" }, addedAction, this::createNode, this::removedNode);
verify(callback).nodeRemoved(eq(soonToBeRemoved));
}
Aggregations