@Test public void testGetSensors() throws Exception{ assertEquals(entity.getEntityType().getSensors(), DEFAULT_SENSORS); }
@Test public void testGetConfigKeys() throws Exception{ assertEquals(entity.getEntityType().getConfigKeys(), DEFAULT_CONFIG_KEYS); }
@Test public void testHasSensor() throws Exception { assertTrue(entity.getEntityType().hasSensor("entity.sensor.added")); assertFalse(entity.getEntityType().hasSensor("does.not.exist")); }
private boolean isEffectorRedefined(String effectorName) { return entity().getEntityType().getEffectorByName(effectorName).isPresent(); }
@Test public void testGetSensor() throws Exception { Sensor<?> sensor = entity.getEntityType().getSensor("entity.sensor.added"); assertEquals(sensor.getDescription(), "Sensor dynamically added to entity"); assertEquals(sensor.getName(), "entity.sensor.added"); assertNull(entity.getEntityType().getSensor("does.not.exist")); }
@Test public void testAddConfigKeyThroughEntity() throws Exception{ Entities.deproxy(entity).configure(ImmutableList.<ConfigKey<?>>of(NEW_CONFIG)); assertEquals(entity.getEntityType().getConfigKeys(), ImmutableSet.builder().addAll(DEFAULT_CONFIG_KEYS).add(NEW_CONFIG).build()); assertEventuallyListenerEventsEqual(ImmutableList.of(BasicSensorEvent.ofUnchecked(AbstractEntity.CONFIG_KEY_ADDED, entity, NEW_CONFIG))); }
@Test public void testAddSensors() throws Exception{ entity.getMutableEntityType().addSensor(TEST_SENSOR); assertEquals(entity.getEntityType().getSensors(), ImmutableSet.builder().addAll(DEFAULT_SENSORS).add(TEST_SENSOR).build()); assertEventuallyListenerEventsEqual(ImmutableList.of(BasicSensorEvent.ofUnchecked(SENSOR_ADDED, entity, TEST_SENSOR))); }
private Object invokeEffectorNamed(String effectorName, ConfigBag params) { LOG.info("{} invoking effector on {}, effector={}, parameters={}", new Object[]{this, entity(), effectorName, params}); Maybe<Effector<?>> effector = entity().getEntityType().getEffectorByName(effectorName); if (effector.isAbsent()) { throw new IllegalStateException("Cannot find effector " + effectorName); } return entity().invoke(effector.get(), params.getAllConfig()).getUnchecked(); }
@Test public void testAddSensorValueThroughEntity() throws Exception{ entity.sensors().set(TEST_SENSOR, "abc"); assertEquals(entity.getEntityType().getSensors(), ImmutableSet.builder().addAll(DEFAULT_SENSORS).add(TEST_SENSOR).build()); assertEventuallyListenerEventsEqual(ImmutableList.of(BasicSensorEvent.ofUnchecked(SENSOR_ADDED, entity, TEST_SENSOR))); }
@Test public void testAddConfigKey() throws Exception{ entity.getMutableEntityType().addConfigKey(NEW_CONFIG); assertEquals(entity.getEntityType().getConfigKeys(), ImmutableSet.builder().addAll(DEFAULT_CONFIG_KEYS).add(NEW_CONFIG).build()); assertEventuallyListenerEventsEqual(ImmutableList.of(BasicSensorEvent.ofUnchecked(AbstractEntity.CONFIG_KEY_ADDED, entity, NEW_CONFIG))); }
@Test public void testGetConfigKey() throws Exception { ConfigKey<?> expected = ConfigEntityForTesting.INSTALL_UNIQUE_LABEL; ConfigKey<?> configKey = entity.getEntityType().getConfigKey(expected.getName()); assertEquals(configKey.getDescription(), expected.getDescription()); assertEquals(configKey.getName(), expected.getName()); assertNull(entity.getEntityType().getConfigKey("does.not.exist")); }
@Test public void testRemoveSensorThroughEntity() throws Exception{ entity.sensors().set(TEST_SENSOR, "abc"); entity.removeAttribute(TEST_SENSOR); assertFalse(entity.getEntityType().getSensors().contains(TEST_SENSOR), "sensors="+entity.getEntityType().getSensors()); assertEquals(entity.getAttribute(TEST_SENSOR), null); assertEventuallyListenerEventsEqual(ImmutableList.of(BasicSensorEvent.ofUnchecked(SENSOR_ADDED, entity, TEST_SENSOR), BasicSensorEvent.ofUnchecked(SENSOR_REMOVED, entity, TEST_SENSOR))); }
builder.effectors.addAll(entity.getEntityType().getEffectors()); builder.effectors.removeAll(definedType.getEffectors().values()); builder.configKeys.addAll(entity.getEntityType().getConfigKeys());
@Test public void testRemoveConfigKey() throws Exception { entity.getMutableEntityType().removeConfigKey(ConfigEntityForTesting.INSTALL_UNIQUE_LABEL); assertEquals(entity.getEntityType().getConfigKeys(), MutableSet.builder().addAll(DEFAULT_CONFIG_KEYS).remove(ConfigEntityForTesting.INSTALL_UNIQUE_LABEL).build().asUnmodifiable()); assertEventuallyListenerEventsEqual(ImmutableList.of( BasicSensorEvent.ofUnchecked(AbstractEntity.CONFIG_KEY_REMOVED, entity, ConfigEntityForTesting.INSTALL_UNIQUE_LABEL))); }
@Test public void testRemoveSensor() throws Exception { entity.getMutableEntityType().removeSensor(SENSOR_ADDED); assertEquals(entity.getEntityType().getSensors(), MutableSet.builder().addAll(DEFAULT_SENSORS).remove(SENSOR_ADDED).build().asUnmodifiable()); assertEventuallyListenerEventsEqual(ImmutableList.of( BasicSensorEvent.ofUnchecked(SENSOR_REMOVED, entity, SENSOR_ADDED))); }
@Test public void testRemoveSensors() throws Exception { entity.getMutableEntityType().removeSensor(SENSOR_ADDED.getName()); entity.getMutableEntityType().removeSensor(POLICY_ADDED.getName()); assertEquals(entity.getEntityType().getSensors(), MutableSet.builder().addAll(DEFAULT_SENSORS).remove(SENSOR_ADDED).remove(POLICY_ADDED).build().asUnmodifiable()); final RecordingSensorEventListener<?> listener = this.listener; Asserts.succeedsEventually(new Runnable() { @Override public void run() { assertEquals(Iterables.size(listener.getEvents()), 2); } }); assertEventuallyListenerEventsEqual(ImmutableList.of( BasicSensorEvent.ofUnchecked(SENSOR_REMOVED, entity, SENSOR_ADDED), BasicSensorEvent.ofUnchecked(SENSOR_REMOVED, entity, POLICY_ADDED))); }
"apps/"+entity().getApplicationId()+"/chef/entities/"+entity().getEntityType().getSimpleName()+"_"+entity().getId());
"apps/"+entity().getApplicationId()+"/chef/entities/"+entity().getEntityType().getSimpleName()+"_"+entity().getId());