### Question:
HttpRequestSensor extends AddSensor<T> { @Override public void apply(final EntityLocal entity) { super.apply(entity); if (LOG.isDebugEnabled()) { LOG.debug("Adding HTTP JSON sensor {} to {}", name, entity); } HttpPollConfig<T> pollConfig = new HttpPollConfig<T>(sensor) .checkSuccess(HttpValueFunctions.responseCodeEquals(200)) .onFailureOrException(Functions.constant((T) null)) .onSuccess(HttpValueFunctions.<T>jsonContentsFromPath(jsonPath)) .period(period); HttpFeed.builder().entity(entity) .baseUri(uri) .credentialsIfNotNull(username, password) .poll(pollConfig) .build(); } HttpRequestSensor(final ConfigBag params); @Override void apply(final EntityLocal entity); static final ConfigKey<String> SENSOR_URI; static final ConfigKey<String> JSON_PATH; static final ConfigKey<String> USERNAME; static final ConfigKey<String> PASSWORD; }### Answer:
@Test public void testHttpSensor() throws Exception { HttpRequestSensor<Integer> sensor = new HttpRequestSensor<Integer>(ConfigBag.newInstance() .configure(HttpRequestSensor.SENSOR_PERIOD, Duration.millis(100)) .configure(HttpRequestSensor.SENSOR_NAME, SENSOR_STRING.getName()) .configure(HttpRequestSensor.SENSOR_TYPE, TARGET_TYPE) .configure(HttpRequestSensor.JSON_PATH, "$.myKey") .configure(HttpRequestSensor.SENSOR_URI, serverUrl + "/myKey/myValue")); sensor.apply(entity); entity.sensors().set(Attributes.SERVICE_UP, true); EntityTestUtils.assertAttributeEqualsEventually(entity, SENSOR_STRING, "myValue"); }