StateSensor extends Sensor { public void setStrictStateMapping(boolean strictStateMapping) { this.hasStrictStateMapping = strictStateMapping; } StateSensor(String name, int sensorID, StatusCache cache, EventProducer producer, int commandID, DistinctStates states); protected  StateSensor(String name, int sensorID, StatusCache cache, EnumSensorType type, EventProducer producer,
                        int commandID, DistinctStates states, boolean includeStatesAsProperties); @Override Event processEvent(String value); void setStrictStateMapping(boolean strictStateMapping); @Override String toString(); final static boolean DEFAULT_STRICT_STATE_MAPPING; }
@Test public void testArbitraryStringPassThrough() throws Exception { final int SENSOR_ID = 21; MixedStateReadCommand readCommand = new MixedStateReadCommand("foo", "bar", "acme"); StateSensor s1 = new StateSensor("arbitrary string", SENSOR_ID, cache, readCommand, 1, null); s1.setStrictStateMapping(false); cache.registerSensor(s1); s1.start(); Assert.assertTrue( "Expected 'foo', got " + getSensorValueFromCache(SENSOR_ID), getSensorValueFromCache(SENSOR_ID).equals("foo") ); Assert.assertTrue(s1.getSensorID() == SENSOR_ID); Assert.assertTrue(s1.isPolling()); Assert.assertFalse(s1.isEventListener()); Assert.assertTrue(s1.getName().equals("arbitrary string")); Assert.assertTrue(s1.getProperties().size() == 0); readCommand.nextValue(); Assert.assertTrue(getSensorValueFromCache(SENSOR_ID).equals("bar")); readCommand.nextValue(); Assert.assertTrue(getSensorValueFromCache(SENSOR_ID).equals("acme")); }
@Test public void testArbitraryStringPassThroughWithMixedMapping() throws Exception { final int SENSOR_ID = 21; MixedStateReadCommand readCommand = new MixedStateReadCommand("foo", "bar", "acme"); StateSensor.DistinctStates states = new StateSensor.DistinctStates(); states.addState("bar"); states.addStateMapping("acme", "emca"); StateSensor s1 = new StateSensor("arbitrary string", SENSOR_ID, cache, readCommand, 1, states); s1.setStrictStateMapping(false); cache.registerSensor(s1); s1.start(); Assert.assertTrue( "Expected 'foo', got " + getSensorValueFromCache(SENSOR_ID), getSensorValueFromCache(SENSOR_ID).equals("foo") ); Assert.assertTrue(s1.getSensorID() == SENSOR_ID); Assert.assertTrue(s1.isPolling()); Assert.assertFalse(s1.isEventListener()); Assert.assertTrue(s1.getName().equals("arbitrary string")); Assert.assertTrue(s1.getProperties().size() == 2); Assert.assertTrue(s1.getProperties().keySet().contains("state-1")); Assert.assertTrue(s1.getProperties().keySet().contains("state-2")); Assert.assertTrue(s1.getProperties().values().contains("bar")); Assert.assertTrue(s1.getProperties().values().contains("acme")); readCommand.nextValue(); Assert.assertTrue(getSensorValueFromCache(SENSOR_ID).equals("bar")); readCommand.nextValue(); Assert.assertTrue(getSensorValueFromCache(SENSOR_ID).equals("emca")); }