Search in sources :

Example 16 with Node

use of io.opencensus.proto.agent.common.v1.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;
}
Also used : Device(org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homie300.Device) Node(org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homie300.Node) NodeAttributes(org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homie300.NodeAttributes)

Example 17 with Node

use of io.opencensus.proto.agent.common.v1.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());
}
Also used : ChannelState(org.eclipse.smarthome.binding.mqtt.generic.internal.generic.ChannelState) PropertyAttributes(org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homie300.PropertyAttributes) StringType(org.eclipse.smarthome.core.library.types.StringType) Command(org.eclipse.smarthome.core.types.Command) Node(org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homie300.Node) NodeAttributes(org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homie300.NodeAttributes) Value(org.eclipse.smarthome.binding.mqtt.generic.internal.values.Value) Property(org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homie300.Property) Test(org.junit.Test)

Example 18 with Node

use of io.opencensus.proto.agent.common.v1.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;
}
Also used : Node(org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homie300.Node) NodeAttributes(org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homie300.NodeAttributes)

Example 19 with Node

use of io.opencensus.proto.agent.common.v1.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));
}
Also used : Node(org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homie300.Node) Test(org.junit.Test)

Aggregations

Node (org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homie300.Node)9 Test (org.junit.Test)8 NodeAttributes (org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homie300.NodeAttributes)6 Node (org.openstreetmap.osmosis.core.domain.v0_6.Node)6 Property (org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homie300.Property)5 PropertyAttributes (org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homie300.PropertyAttributes)4 Way (org.openstreetmap.osmosis.core.domain.v0_6.Way)4 ArrayList (java.util.ArrayList)3 ChannelState (org.eclipse.smarthome.binding.mqtt.generic.internal.generic.ChannelState)3 WayNode (org.openstreetmap.osmosis.core.domain.v0_6.WayNode)3 Function (com.google.common.base.Function)2 Optional (com.google.common.base.Optional)2 Node (io.opencensus.proto.agent.common.v1.Node)2 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)2 Nullable (javax.annotation.Nullable)2 Device (org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homie300.Device)2 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)2 SimpleFeature (org.opengis.feature.simple.SimpleFeature)2