support effector parameters which are maps (@sjcorbett just did this also; now this commit simply adds a test for this)
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/cefcda3b Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/cefcda3b Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/cefcda3b Branch: refs/heads/master Commit: cefcda3b862fbbc0ff0008daadf988f8c361522a Parents: 8569120 Author: Alex Heneveld <alex.henev...@cloudsoftcorp.com> Authored: Fri Jul 18 00:39:24 2014 -0400 Committer: Alex Heneveld <alex.henev...@cloudsoftcorp.com> Committed: Fri Jul 18 12:26:20 2014 -0400 ---------------------------------------------------------------------- .../brooklynnode/BrooklynNodeRestTest.java | 55 +++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/cefcda3b/usage/launcher/src/test/java/brooklyn/entity/brooklynnode/BrooklynNodeRestTest.java ---------------------------------------------------------------------- diff --git a/usage/launcher/src/test/java/brooklyn/entity/brooklynnode/BrooklynNodeRestTest.java b/usage/launcher/src/test/java/brooklyn/entity/brooklynnode/BrooklynNodeRestTest.java index 2cd97f0..2a3816b 100644 --- a/usage/launcher/src/test/java/brooklyn/entity/brooklynnode/BrooklynNodeRestTest.java +++ b/usage/launcher/src/test/java/brooklyn/entity/brooklynnode/BrooklynNodeRestTest.java @@ -1,7 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package brooklyn.entity.brooklynnode; import java.net.URI; +import java.util.concurrent.Callable; +import org.apache.http.client.HttpClient; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.testng.Assert; @@ -19,12 +39,17 @@ import brooklyn.launcher.camp.SimpleYamlLauncher; import brooklyn.location.Location; import brooklyn.management.Task; import brooklyn.test.EntityTestUtils; +import brooklyn.test.HttpTestUtils; import brooklyn.test.entity.TestApplication; import brooklyn.test.entity.TestEntity; +import brooklyn.util.collections.Jsonya; import brooklyn.util.collections.MutableMap; import brooklyn.util.collections.MutableSet; import brooklyn.util.config.ConfigBag; +import brooklyn.util.http.HttpTool; +import brooklyn.util.http.HttpToolResponse; import brooklyn.util.net.Urls; +import brooklyn.util.repeat.Repeater; import brooklyn.util.time.Duration; import com.google.common.collect.Iterables; @@ -40,7 +65,7 @@ public class BrooklynNodeRestTest { // so feels worth it to have as a unit test @Test public void testBrooklynNodeRestDeployAndMirror() { - SimpleYamlLauncher l = new SimpleYamlLauncherForTests(); + final SimpleYamlLauncher l = new SimpleYamlLauncherForTests(); try { TestApplication app = ApplicationBuilder.newManagedApp(TestApplication.class, l.getManagementContext()); @@ -84,6 +109,34 @@ public class BrooklynNodeRestTest { EntityTestUtils.assertAttributeEqualsEventually(mirror, TestEntity.NAME, "foo"); log.info("Mirror successfully validated"); + // also try deploying by invoking deploy through json + // (catch issues when effector params are map) + HttpClient client = HttpTool.httpClientBuilder().build(); + HttpToolResponse result = HttpTool.httpPost(client, URI.create(Urls.mergePaths(uri.toString(), "/v1/applications/"+app.getId()+"/entities/"+bn.getId() + +"/effectors/deployBlueprint")), + MutableMap.of(com.google.common.net.HttpHeaders.CONTENT_TYPE, "application/json"), + Jsonya.newInstance() + .put("blueprintType", TestApplication.class.getName()) + .put("blueprintConfig", MutableMap.of(TestEntity.CONF_NAME.getName(), "foo")) + .toString().getBytes()); + log.info("Deploy effector invoked, result: "+result); + HttpTestUtils.assertHealthyStatusCode( result.getResponseCode() ); + + Repeater.create().every(Duration.millis(10)).until(new Callable<Boolean>() { + @Override + public Boolean call() throws Exception { + return l.getManagementContext().getApplications().size() == 3; + } + }).limitTimeTo(Duration.TEN_SECONDS); + + apps = MutableSet.copyOf( l.getManagementContext().getApplications() ); + apps.removeAll( MutableSet.of(app, newApp) ); + Application newApp2 = Iterables.getOnlyElement(apps); + Entities.dumpInfo(newApp2); + + EntityTestUtils.assertAttributeEqualsEventually(newApp2, Attributes.SERVICE_UP, true); + Assert.assertEquals(newApp2.getConfig(TestEntity.CONF_NAME), "foo"); + } finally { l.destroyAll(); }