SensorResource extends AbstractBrooklynRestResource implements SensorApi { @Override public Map<String, Object> batchSensorRead(final String application, final String entityToken, final Boolean raw) { final Entity entity = brooklyn().getEntity(application, entityToken); if (!Entitlements.isEntitled(mgmt().getEntitlementManager(), Entitlements.SEE_ENTITY, entity)) { throw WebResourceUtils.forbidden("User '%s' is not authorized to see entity '%s'", Entitlements.getEntitlementContext().user(), entity); } Map<String, Object> sensorMap = Maps.newHashMap(); @SuppressWarnings("rawtypes") Iterable<AttributeSensor> sensors = filter(entity.getEntityType().getSensors(), AttributeSensor.class); for (AttributeSensor<?> sensor : sensors) { if (!Entitlements.isEntitled(mgmt().getEntitlementManager(), Entitlements.SEE_SENSOR, new EntityAndItem<String>(entity, sensor.getName()))) { log.trace("User {} not authorized to see sensor {} of entity {}; excluding from current-state results", new Object[] {Entitlements.getEntitlementContext().user(), sensor.getName(), entity}); continue; } Object value = entity.getAttribute(findSensor(entity, sensor.getName())); sensorMap.put(sensor.getName(), resolving(value).preferJson(true).asJerseyOutermostReturnValue(false).raw(raw).context(entity).timeout(Duration.ZERO).renderAs(sensor).resolve()); } return sensorMap; }  @Override List<SensorSummary> list(final String application, final String entityToken); @Override Map<String, Object> batchSensorRead(final String application, final String entityToken, final Boolean raw); @Override String getPlain(String application, String entityToken, String sensorName, final Boolean raw); @Override Object get(final String application, final String entityToken, String sensorName, final Boolean raw); @SuppressWarnings({ "rawtypes", "unchecked" }) @Override void setFromMap(String application, String entityToken, Map newValues); @SuppressWarnings({ "rawtypes", "unchecked" }) @Override void set(String application, String entityToken, String sensorName, Object newValue); @Override void delete(String application, String entityToken, String sensorName);  }
@Test public void testBatchSensorRead() throws Exception { Response response = client().path(SENSORS_ENDPOINT + "/current-state") .accept(MediaType.APPLICATION_JSON) .get(); Map<String, ?> currentState = response.readEntity(new GenericType<Map<String,?>>(Map.class) {}); for (String sensor : currentState.keySet()) { if (sensor.equals(SENSOR_NAME)) { assertEquals(currentState.get(sensor), "12345 frogs"); } } }