Set the TARGET sensor with resolved test entity
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/fad2435d Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/fad2435d Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/fad2435d Branch: refs/heads/master Commit: fad2435d4d4f2ca7b6d41bd723e1738dc0b4e13f Parents: b87c20b Author: Andrew Donald Kennedy <[email protected]> Authored: Mon Jul 18 13:28:34 2016 +0100 Committer: Andrew Donald Kennedy <[email protected]> Committed: Thu Jul 21 10:52:12 2016 +0100 ---------------------------------------------------------------------- .../test/framework/TargetableTestComponent.java | 16 ++++++++++------ .../test/framework/TargetableTestComponentImpl.java | 15 ++++++++++----- 2 files changed, 20 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/fad2435d/test-framework/src/main/java/org/apache/brooklyn/test/framework/TargetableTestComponent.java ---------------------------------------------------------------------- diff --git a/test-framework/src/main/java/org/apache/brooklyn/test/framework/TargetableTestComponent.java b/test-framework/src/main/java/org/apache/brooklyn/test/framework/TargetableTestComponent.java index 5ea28cb..7280ef1 100644 --- a/test-framework/src/main/java/org/apache/brooklyn/test/framework/TargetableTestComponent.java +++ b/test-framework/src/main/java/org/apache/brooklyn/test/framework/TargetableTestComponent.java @@ -27,20 +27,24 @@ import org.apache.brooklyn.core.sensor.AttributeSensorAndConfigKey; import org.apache.brooklyn.util.time.Duration; /** - * Entity that can target another entity for the purpouse of testing + * Entity that can target another entity for the purpose of testing */ @ImplementedBy(value = TargetableTestComponentImpl.class) public interface TargetableTestComponent extends Entity, Startable { /** - * The target entity to test (optional, use either this or targetId). + * The target entity to test. Optional, use either this or + * {@link #TARGET_ID targetId}. If both are set then this + * will take precedence. */ AttributeSensorAndConfigKey<Entity, Entity> TARGET_ENTITY = ConfigKeys.newSensorAndConfigKey(Entity.class, "target", "Entity under test"); /** - * Id of the target entity to test (optional, use either this or target). + * Id of the target entity to test. + * + * @see {@link #TARGET_ENTITY target}. */ - AttributeSensorAndConfigKey<String, String> TARGET_ID = ConfigKeys.newStringSensorAndConfigKey("targetId", "Id of the entity under test"); + ConfigKey<String> TARGET_ID = ConfigKeys.newStringConfigKey("targetId", "Id of the entity under test"); /** * The duration to wait for an entity with the given targetId to exist, before throwing an exception. @@ -54,8 +58,8 @@ public interface TargetableTestComponent extends Entity, Startable { /** * Get the target of the test. * - * @return The target. - * @throws IllegalArgumentException if the target cannot be found. + * @return The target entity + * @throws {@link IllegalArgumentException} if the target cannot be found */ Entity resolveTarget(); http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/fad2435d/test-framework/src/main/java/org/apache/brooklyn/test/framework/TargetableTestComponentImpl.java ---------------------------------------------------------------------- diff --git a/test-framework/src/main/java/org/apache/brooklyn/test/framework/TargetableTestComponentImpl.java b/test-framework/src/main/java/org/apache/brooklyn/test/framework/TargetableTestComponentImpl.java index 4750b4d..0d59507 100644 --- a/test-framework/src/main/java/org/apache/brooklyn/test/framework/TargetableTestComponentImpl.java +++ b/test-framework/src/main/java/org/apache/brooklyn/test/framework/TargetableTestComponentImpl.java @@ -44,14 +44,19 @@ public abstract class TargetableTestComponentImpl extends AbstractEntity impleme private static final Logger LOG = LoggerFactory.getLogger(TargetableTestComponentImpl.class); /** - * Find the target entity using "target" config key, if entity provided directly in config, or by doing an implicit - * lookup using DSL ($brooklyn:component("myNginX")), if id of entity provided as "targetId" config key. + * Find the target entity using the {@link #TARGET target} config key value, + * or by doing an implicit lookup using the equivalent of the DSL code + * {@code $brooklyn:entity("targetId")} if the id of an entity was + * provided as the {@link #TARGET_ID targetId} config key value. * - * @return The target entity. - * @throws @RuntimeException if no target can be determined. + * @return The target entity + * @throws {@link RuntimeException} if no target can be determined */ + @Override public Entity resolveTarget() { - return resolveTarget(getExecutionContext(), this); + Entity target = resolveTarget(getExecutionContext(), this); + sensors().set(TARGET_ENTITY, target); + return target; } /**
