This is an automated email from the ASF dual-hosted git repository. heneveld pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/brooklyn-server.git
commit 394d939169fa71e0b9563575b334367f07a8947d Author: Alex Heneveld <[email protected]> AuthorDate: Wed Feb 13 21:10:12 2019 +0000 tidy YAML test fixture, make extensible so subtests can do post-processing on specs --- .../brooklyn/camp/brooklyn/AbstractYamlTest.java | 35 +++++++++++----------- .../brooklyn/core/mgmt/EntityManagementUtils.java | 7 +++-- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/AbstractYamlTest.java b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/AbstractYamlTest.java index 76b0f5d..cc98510 100644 --- a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/AbstractYamlTest.java +++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/AbstractYamlTest.java @@ -50,7 +50,6 @@ import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests; import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests.Builder; import org.apache.brooklyn.core.typereg.BasicBrooklynTypeRegistry; import org.apache.brooklyn.core.typereg.BasicManagedBundle; -import org.apache.brooklyn.core.typereg.RegisteredTypeLoadingContexts; import org.apache.brooklyn.core.typereg.RegisteredTypePredicates; import org.apache.brooklyn.util.collections.MutableMap; import org.apache.brooklyn.util.core.ResourceUtils; @@ -174,51 +173,50 @@ public abstract class AbstractYamlTest { return builder.toString(); } - protected Entity createAndStartApplication(String... multiLineYaml) throws Exception { + protected Application createAndStartApplication(String... multiLineYaml) throws Exception { return createAndStartApplication(joinLines(multiLineYaml)); } /** @deprecated since 0.10.0, use {@link #createAndStartApplication(String)} instead */ @Deprecated - protected Entity createAndStartApplication(Reader input) throws Exception { + protected Application createAndStartApplication(Reader input) throws Exception { return createAndStartApplication(Streams.readFully(input)); } - protected Entity createAndStartApplication(String input) throws Exception { + protected Application createAndStartApplication(String input) throws Exception { return createAndStartApplication(input, MutableMap.<String,String>of()); } - protected Entity createAndStartApplication(String input, Map<String,?> startParameters) throws Exception { - final Entity app = createApplicationUnstarted(input); + protected Application createAndStartApplication(String input, Map<String,?> startParameters) throws Exception { + final Application app = createApplicationUnstarted(input); app.invoke(Startable.START, startParameters).get(); return app; } - protected Entity createAndStartApplicationAsync(String... multiLineYaml) throws Exception { + protected Application createAndStartApplicationAsync(String... multiLineYaml) throws Exception { return createAndStartApplicationAsync(joinLines(multiLineYaml)); } - protected Entity createAndStartApplicationAsync(String yaml) throws Exception { + protected Application createAndStartApplicationAsync(String yaml) throws Exception { return createAndStartApplicationAsync(yaml, MutableMap.<String,String>of()); } - protected Entity createAndStartApplicationAsync(String yaml, Map<String,?> startParameters) throws Exception { - final Entity app = createApplicationUnstarted(yaml); + protected Application createAndStartApplicationAsync(String yaml, Map<String,?> startParameters) throws Exception { + final Application app = createApplicationUnstarted(yaml); // Not calling .get() on task, so this is non-blocking. app.invoke(Startable.START, startParameters); return app; } - protected Entity createApplicationUnstarted(String... multiLineYaml) throws Exception { + protected Application createApplicationUnstarted(String... multiLineYaml) throws Exception { return createApplicationUnstarted(joinLines(multiLineYaml)); } - protected Entity createApplicationUnstarted(String yaml) throws Exception { + protected Application createApplicationUnstarted(String yaml) throws Exception { // not starting the app (would have happened automatically if we use camp to instantiate, // but not if we use create spec approach). - EntitySpec<?> spec = - mgmt().getTypeRegistry().createSpecFromPlan(CampTypePlanTransformer.FORMAT, yaml, RegisteredTypeLoadingContexts.spec(Application.class), EntitySpec.class); + EntitySpec<Application> spec = createAppEntitySpec(yaml); final Entity app = brooklynMgmt.getEntityManager().createEntity(spec); - return app; + return (Application) app; } /** @deprecated since 0.10.0, use {@link #createStartWaitAndLogApplication(String)} instead */ @@ -238,10 +236,11 @@ public abstract class AbstractYamlTest { return app; } - protected EntitySpec<?> createAppEntitySpec(String... yaml) { - return EntityManagementUtils.createEntitySpecForApplication(mgmt(), joinLines(yaml)); + @SuppressWarnings("unchecked") + protected <T extends Application> EntitySpec<T> createAppEntitySpec(String... yaml) { + return (EntitySpec<T>) EntityManagementUtils.createEntitySpecForApplication(mgmt(), CampTypePlanTransformer.FORMAT, joinLines(yaml)); } - + protected void addCatalogItems(Iterable<String> catalogYaml) { addCatalogItems(joinLines(catalogYaml)); } diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/EntityManagementUtils.java b/core/src/main/java/org/apache/brooklyn/core/mgmt/EntityManagementUtils.java index 218a24a..da5466a 100644 --- a/core/src/main/java/org/apache/brooklyn/core/mgmt/EntityManagementUtils.java +++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/EntityManagementUtils.java @@ -99,9 +99,12 @@ public class EntityManagementUtils { return createUnstarted(mgmt, spec); } + public static EntitySpec<? extends Application> createEntitySpecForApplication(ManagementContext mgmt, String plan) { + return createEntitySpecForApplication(mgmt, null, plan); + } @SuppressWarnings("unchecked") - public static EntitySpec<? extends Application> createEntitySpecForApplication(ManagementContext mgmt, final String plan) { - return mgmt.getTypeRegistry().createSpecFromPlan(null, plan, RegisteredTypeLoadingContexts.spec(Application.class), EntitySpec.class); + public static EntitySpec<? extends Application> createEntitySpecForApplication(ManagementContext mgmt, String format, String plan) { + return mgmt.getTypeRegistry().createSpecFromPlan(format, plan, RegisteredTypeLoadingContexts.spec(Application.class), EntitySpec.class); } /** container for operation which creates something and which wants to return both
