/** * Parse the following sensor when deployed through a complete controller.xml document. * * <pre>{@code * <sensor id="1013" name="s1013" type="switch"> * <include type="command" ref="962" /> * <state name="on" value="open" /> * <state name="off" value="close" /> * </sensor> * * }</pre> * * @throws Exception if test fails */ @Test public void testMappedSwitchSensorBuildWithListener() throws Exception { Sensor s = buildSensor(1013); Assert.assertTrue(s instanceof SwitchSensor); Assert.assertTrue(s.getName().equals("s1013")); Assert.assertTrue(s.getProperties().size() == 0); Assert.assertTrue(s.getSensorID() == 1013); Assert.assertFalse(s.isRunning()); Assert.assertFalse(s.isPolling()); Assert.assertTrue(s.isEventListener()); Assert.assertFalse(s.equals(null)); Assert.assertTrue(s.equals(s)); Assert.assertFalse(s.equals(buildSensor(SensorType.SWITCH))); Assert.assertFalse(s.equals(buildSensor(SensorType.RANGE))); }
/** * Same as {@link #testSwitchStateMappingWithNoValue} above, just uses an event listener instead * of polling sensor command. * * <p>See http://jira.openremote.org/browse/ORCJAVA-73 * * @throws Exception if test fails */ @Test public void testSwitchStateMappingWithNoValueAndListener() throws Exception { Sensor s = buildSensorWithID(727); s.start(); Assert.assertTrue(s.getName().equals("se2")); Assert.assertTrue(s.getSensorID() == 727); // switch sensor states should not show up as properties, even if mapped... Assert.assertTrue(s.getProperties().size() == 0); // should get either one depending what the state of the listener is String val = cache.queryStatus(727); Assert.assertTrue( "Expected either 'on' or 'off', got " + val, val.equals("off") || val.equals("on")); Assert.assertTrue(s instanceof SwitchSensor); StateSensor state = (StateSensor) s; // check that states are in place despite funky XML model... Assert.assertTrue(state.processEvent("on").getValue().equals("on")); Assert.assertTrue(state.processEvent("off").getValue().equals("off")); Assert.assertTrue(state.processEvent("foo").getValue().equals(Sensor.UNKNOWN_STATUS)); String status = cache.queryStatus(727); // should have something since its a listener... Assert.assertFalse(status.equals(Sensor.UNKNOWN_STATUS)); Assert.assertTrue(s.isEventListener()); Assert.assertFalse(s.isPolling()); }
/** * Test against what could be qualified as a bug that has now become a feature and we need to make * sure we don't regress on it unintentionally should we try to fix the bug again. * * <p>Current tooling generates a style of switch sensors in XML that makes very little sense: * * <pre>{@code * <sensor id = "717" name = "se" type = "switch"> * <include type = "command" ref = "96" /> * <state name = "on" /> * <state name = "off" /> * </sensor> * }</pre> * * It makes no sense because switch can only ever return on/off as states and no mapping is * provided, making the state declarations redundant. But because tooling does generate this, we * need to make sure we correctly parse it. * * <p>See http://jira.openremote.org/browse/ORCJAVA-73 * * @throws Exception if test fails */ @Test public void testSwitchStateMappingWithNoValue() throws Exception { Sensor s = buildSensorWithID(717); Assert.assertTrue(s.getName().equals("se")); Assert.assertTrue(s.getSensorID() == 717); // switch sensor states should not show up as properties, even if mapped... Assert.assertTrue(s.getProperties().size() == 0); commandService.trigger("666", "click"); String offValue = getSensorValueFromCache(717); Assert.assertTrue("Expected 'off', got '" + offValue + "'", offValue.equals("off")); commandService.trigger("555", "click"); String onValue = getSensorValueFromCache(717); Assert.assertTrue("Expected 'on', got '" + onValue + "'", onValue.equals("on")); Assert.assertTrue(s instanceof SwitchSensor); StateSensor state = (StateSensor) s; // check that states are in place despite funky XML model... Assert.assertTrue(state.processEvent("on").getValue().equals("on")); Assert.assertTrue(state.processEvent("off").getValue().equals("off")); Assert.assertTrue(state.processEvent("foo").getValue().equals(Sensor.UNKNOWN_STATUS)); Assert.assertTrue(s.isPolling()); Assert.assertFalse(s.isEventListener()); }