Deployer { protected Sensor getSensor(int id) { Sensor sensor = deviceStateCache.getSensor(id); if (sensor == null) { log.error( "Attempted to access sensor with id ''{0}'' which did not exist in device " + "state cache.", id ); } return sensor; } Deployer(String serviceName, StatusCache deviceStateCache,
                  ControllerConfiguration controllerConfig,
                  Map<String, ModelBuilder> builders); synchronized void startController(); boolean isPaused(); void softRestart(); void deployFromZip(InputStream inputStream); void deployFromOnline(String username, String credentials); Element queryElementById(int id); Map<String, String> getConfigurationProperties(); Sensor getSensorFromComponentInclude(Element componentIncludeElement); void announceDiscoveredDevices(List<DiscoveredDeviceDTO> list); String getLinkedAccountId(); void unlinkController();  }
@Test public void testGetSensor() throws Exception { StatusCache cache = new StatusCache(); Deployer d = createDeployer(deployerName, cache); Sensor s1 = new SwitchSensor("Sensor 1", 1, cache, new TestEventListener(), 1); Sensor s2 = new RangeSensor("Sensor 2", 2, cache, new TestEventListener(), 1, 0, 10); Sensor s3 = new LevelSensor("Sensor 3", 3, cache, new TestEventListener(), 1); Sensor s4 = new StateSensor("Sensor 4", 4, cache, new TestEventListener(), 1, new StateSensor.DistinctStates()); cache.registerSensor(s1); cache.registerSensor(s2); cache.registerSensor(s3); cache.registerSensor(s4); Sensor sensor1 = d.getSensor(1); Assert.assertNotNull(sensor1); Assert.assertNotNull(sensor1.equals(s1)); Assert.assertNotNull(s1.equals(sensor1)); Assert.assertTrue(s1.getName().equals(sensor1.getName())); Assert.assertTrue(s1.getSensorID() == sensor1.getSensorID()); Assert.assertTrue(sensor1.getSensorID() == 1); Sensor sensor2 = d.getSensor(2); Assert.assertNotNull(sensor2); Assert.assertNotNull(sensor2.equals(s2)); Assert.assertNotNull(s2.equals(sensor2)); Assert.assertTrue(s2.getName().equals(sensor2.getName())); Assert.assertTrue(s2.getSensorID() == sensor2.getSensorID()); Assert.assertTrue(sensor2.getSensorID() == 2); Sensor sensor3 = d.getSensor(3); Assert.assertNotNull(sensor3); Assert.assertNotNull(sensor3.equals(s3)); Assert.assertNotNull(s3.equals(sensor3)); Assert.assertTrue(s3.getName().equals(sensor3.getName())); Assert.assertTrue(s3.getSensorID() == sensor3.getSensorID()); Assert.assertTrue(sensor3.getSensorID() == 3); Sensor sensor4 = d.getSensor(4); Assert.assertNotNull(sensor4); Assert.assertNotNull(sensor4.equals(s4)); Assert.assertNotNull(s4.equals(sensor4)); Assert.assertTrue(s4.getName().equals(sensor4.getName())); Assert.assertTrue(s4.getSensorID() == sensor4.getSensorID()); Assert.assertTrue(sensor4.getSensorID() == 4); }
@Test public void testGetSensorUnknownID() throws Exception { Deployer d = createDeployer(deployerName); Sensor s = d.getSensor(0); Assert.assertTrue(s == null); }