http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d03f254b/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/LocationsYamlTest.java ---------------------------------------------------------------------- diff --git a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/LocationsYamlTest.java b/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/LocationsYamlTest.java deleted file mode 100644 index 371a477..0000000 --- a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/LocationsYamlTest.java +++ /dev/null @@ -1,285 +0,0 @@ -/* - * 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 org.apache.brooklyn.camp.brooklyn; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertTrue; - -import java.io.StringReader; -import java.util.List; - -import org.apache.brooklyn.api.entity.Entity; -import org.apache.brooklyn.api.location.Location; -import org.apache.brooklyn.api.location.MachineLocation; -import org.apache.brooklyn.core.entity.Entities; -import org.apache.brooklyn.location.byon.FixedListMachineProvisioningLocation; -import org.apache.brooklyn.location.localhost.LocalhostMachineProvisioningLocation; -import org.apache.brooklyn.location.multi.MultiLocation; -import org.apache.brooklyn.location.ssh.SshMachineLocation; -import org.apache.brooklyn.util.text.Strings; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testng.Assert; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Iterables; - -public class LocationsYamlTest extends AbstractYamlTest { - private static final Logger log = LoggerFactory.getLogger(LocationsYamlTest.class); - - @Test - public void testLocationString() throws Exception { - String yaml = - "location: localhost\n"+ - "services:\n"+ - "- type: org.apache.brooklyn.core.test.entity.TestEntity\n"; - - Entity app = createStartWaitAndLogApplication(new StringReader(yaml)); - LocalhostMachineProvisioningLocation loc = (LocalhostMachineProvisioningLocation) Iterables.getOnlyElement(app.getLocations()); - assertNotNull(loc); - } - - @Test - public void testLocationComplexString() throws Exception { - String yaml = - "location: localhost:(name=myname)\n"+ - "services:\n"+ - "- type: org.apache.brooklyn.core.test.entity.TestEntity\n"; - - Entity app = createStartWaitAndLogApplication(new StringReader(yaml)); - LocalhostMachineProvisioningLocation loc = (LocalhostMachineProvisioningLocation) Iterables.getOnlyElement(app.getLocations()); - assertEquals(loc.getDisplayName(), "myname"); - } - - @Test - public void testLocationSplitLineWithNoConfig() throws Exception { - String yaml = - "location:\n"+ - " localhost\n"+ - "services:\n"+ - "- type: org.apache.brooklyn.core.test.entity.TestEntity\n"; - - Entity app = createStartWaitAndLogApplication(new StringReader(yaml)); - LocalhostMachineProvisioningLocation loc = (LocalhostMachineProvisioningLocation) Iterables.getOnlyElement(app.getLocations()); - assertNotNull(loc); - } - - @Test - public void testMultiLocations() throws Exception { - String yaml = - "locations:\n"+ - "- localhost:(name=loc1)\n"+ - "- localhost:(name=loc2)\n"+ - "services:\n"+ - "- type: org.apache.brooklyn.core.test.entity.TestEntity\n"; - - Entity app = createStartWaitAndLogApplication(new StringReader(yaml)); - List<Location> locs = ImmutableList.copyOf(app.getLocations()); - assertEquals(locs.size(), 2, "locs="+locs); - LocalhostMachineProvisioningLocation loc1 = (LocalhostMachineProvisioningLocation) locs.get(0); - LocalhostMachineProvisioningLocation loc2 = (LocalhostMachineProvisioningLocation) locs.get(1); - assertEquals(loc1.getDisplayName(), "loc1"); - assertEquals(loc2.getDisplayName(), "loc2"); - } - - @Test - public void testLocationConfig() throws Exception { - String yaml = - "location:\n"+ - " localhost:\n"+ - " displayName: myname\n"+ - " myconfkey: myconfval\n"+ - "services:\n"+ - "- type: org.apache.brooklyn.core.test.entity.TestEntity\n"; - - Entity app = createStartWaitAndLogApplication(new StringReader(yaml)); - LocalhostMachineProvisioningLocation loc = (LocalhostMachineProvisioningLocation) Iterables.getOnlyElement(app.getLocations()); - assertEquals(loc.getDisplayName(), "myname"); - assertEquals(loc.config().getLocalBag().getStringKey("myconfkey"), "myconfval"); - } - - @Test - public void testMultiLocationConfig() throws Exception { - String yaml = - "locations:\n"+ - "- localhost:\n"+ - " displayName: myname1\n"+ - " myconfkey: myconfval1\n"+ - "- localhost:\n"+ - " displayName: myname2\n"+ - " myconfkey: myconfval2\n"+ - "services:\n"+ - "- type: org.apache.brooklyn.core.test.entity.TestEntity\n"; - - Entity app = createStartWaitAndLogApplication(new StringReader(yaml)); - List<Location> locs = ImmutableList.copyOf(app.getLocations()); - assertEquals(locs.size(), 2, "locs="+locs); - LocalhostMachineProvisioningLocation loc1 = (LocalhostMachineProvisioningLocation) locs.get(0); - LocalhostMachineProvisioningLocation loc2 = (LocalhostMachineProvisioningLocation) locs.get(1); - assertEquals(loc1.getDisplayName(), "myname1"); - assertEquals(loc1.config().getLocalBag().getStringKey("myconfkey"), "myconfval1"); - assertEquals(loc2.getDisplayName(), "myname2"); - assertEquals(loc2.config().getLocalBag().getStringKey("myconfkey"), "myconfval2"); - } - - // TODO Fails because PlanInterpretationContext constructor throws NPE on location's value (using ImmutableMap). - @Test(groups="WIP") - public void testLocationBlank() throws Exception { - String yaml = - "location: \n"+ - "services:\n"+ - "- type: org.apache.brooklyn.core.test.entity.TestEntity\n"; - - Entity app = createStartWaitAndLogApplication(new StringReader(yaml)); - assertTrue(app.getLocations().isEmpty(), "locs="+app.getLocations()); - } - - @Test - public void testInvalidLocationAndLocations() throws Exception { - String yaml = - "location: localhost\n"+ - "locations:\n"+ - "- localhost\n"+ - "services:\n"+ - "- type: org.apache.brooklyn.core.test.entity.TestEntity\n"; - - try { - createStartWaitAndLogApplication(new StringReader(yaml)); - } catch (Exception e) { - if (!e.toString().contains("Conflicting 'location' and 'locations'")) throw e; - } - } - - @Test - public void testInvalidLocationList() throws Exception { - // should have used "locations:" instead of "location:" - String yaml = - "location:\n"+ - "- localhost\n"+ - "services:\n"+ - "- type: org.apache.brooklyn.core.test.entity.TestEntity\n"; - - try { - createStartWaitAndLogApplication(new StringReader(yaml)); - } catch (Exception e) { - if (!e.toString().contains("must be a string or map")) throw e; - } - } - - @Test - public void testRootLocationPassedToChild() throws Exception { - String yaml = - "locations:\n"+ - "- localhost:(name=loc1)\n"+ - "services:\n"+ - "- type: org.apache.brooklyn.core.test.entity.TestEntity\n"; - - Entity app = createStartWaitAndLogApplication(new StringReader(yaml)); - Entity child = Iterables.getOnlyElement(app.getChildren()); - LocalhostMachineProvisioningLocation loc = (LocalhostMachineProvisioningLocation) Iterables.getOnlyElement(Entities.getAllInheritedLocations(child)); - assertEquals(loc.getDisplayName(), "loc1"); - } - - @Test - public void testByonYamlHosts() throws Exception { - String yaml = - "locations:\n"+ - "- byon:\n"+ - " user: root\n"+ - " privateKeyFile: /tmp/key_file\n"+ - " hosts: \n"+ - " - 127.0.0.1\n"+ - " - [email protected]\n"+ - "services:\n"+ - "- type: org.apache.brooklyn.core.test.entity.TestEntity\n"; - - Entity app = createStartWaitAndLogApplication(new StringReader(yaml)); - Entity child = Iterables.getOnlyElement(app.getChildren()); - FixedListMachineProvisioningLocation<?> loc = (FixedListMachineProvisioningLocation<?>) Iterables.getOnlyElement(Entities.getAllInheritedLocations(child)); - Assert.assertEquals(loc.getChildren().size(), 2); - - SshMachineLocation l1 = (SshMachineLocation)loc.obtain(); - assertUserAddress(l1, "root", "127.0.0.1"); - assertUserAddress((SshMachineLocation)loc.obtain(), "brooklyn", "127.0.0.2"); - Assert.assertEquals(l1.getConfig(SshMachineLocation.PRIVATE_KEY_FILE), "/tmp/key_file"); - } - - @Test - public void testByonYamlHostsString() throws Exception { - String yaml = - "locations:\n"+ - "- byon:\n"+ - " user: root\n"+ - " hosts: \"{127.0.{0,127}.{1-2},[email protected]}\"\n"+ - "services:\n"+ - "- type: org.apache.brooklyn.core.test.entity.TestEntity\n"; - - Entity app = createStartWaitAndLogApplication(new StringReader(yaml)); - Entity child = Iterables.getOnlyElement(app.getChildren()); - FixedListMachineProvisioningLocation<?> loc = (FixedListMachineProvisioningLocation<?>) Iterables.getOnlyElement(Entities.getAllInheritedLocations(child)); - Assert.assertEquals(loc.getChildren().size(), 5); - - assertUserAddress((SshMachineLocation)loc.obtain(), "root", "127.0.0.1"); - assertUserAddress((SshMachineLocation)loc.obtain(), "root", "127.0.0.2"); - assertUserAddress((SshMachineLocation)loc.obtain(), "root", "127.0.127.1"); - assertUserAddress((SshMachineLocation)loc.obtain(), "root", "127.0.127.2"); - assertUserAddress((SshMachineLocation)loc.obtain(), "brooklyn", "127.0.0.127"); - } - - @Test - public void testMultiByonYaml() throws Exception { - String yaml = - "locations:\n"+ - "- multi:\n"+ - " targets:\n"+ - " - byon:\n"+ - " user: root\n"+ - " hosts: 127.0.{0,127}.{1-2}\n"+ - " - byon:\n"+ - " user: brooklyn\n"+ - " hosts:\n"+ - " - 127.0.0.127\n"+ - "services:\n"+ - "- type: org.apache.brooklyn.core.test.entity.TestEntity\n"; - - Entity app = createStartWaitAndLogApplication(new StringReader(yaml)); - Entity child = Iterables.getOnlyElement(app.getChildren()); - MultiLocation<?> loc = (MultiLocation<?>) Iterables.getOnlyElement(Entities.getAllInheritedLocations(child)); - Assert.assertEquals(loc.getSubLocations().size(), 2); - - assertUserAddress((SshMachineLocation)loc.obtain(), "root", "127.0.0.1"); - assertUserAddress((SshMachineLocation)loc.obtain(), "root", "127.0.0.2"); - assertUserAddress((SshMachineLocation)loc.obtain(), "root", "127.0.127.1"); - assertUserAddress((SshMachineLocation)loc.obtain(), "root", "127.0.127.2"); - assertUserAddress((SshMachineLocation)loc.obtain(), "brooklyn", "127.0.0.127"); - } - - public static void assertUserAddress(MachineLocation l, String user, String address) { - Assert.assertEquals(l.getAddress().getHostAddress(), address); - if (!Strings.isBlank(user)) Assert.assertEquals(((SshMachineLocation)l).getUser(), user); - } - - @Override - protected Logger getLogger() { - return log; - } - -}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d03f254b/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/MapReferenceYamlTest.java ---------------------------------------------------------------------- diff --git a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/MapReferenceYamlTest.java b/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/MapReferenceYamlTest.java deleted file mode 100644 index 176245d..0000000 --- a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/MapReferenceYamlTest.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * 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 org.apache.brooklyn.camp.brooklyn; - -import java.util.Map; -import java.util.concurrent.Callable; - -import org.apache.brooklyn.api.entity.Entity; -import org.apache.brooklyn.core.entity.Entities; -import org.apache.brooklyn.core.test.entity.TestEntity; -import org.apache.brooklyn.entity.stock.BasicEntity; -import org.apache.brooklyn.util.core.task.Tasks; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testng.Assert; -import org.testng.annotations.Test; - -import com.google.common.collect.Iterables; - -@Test -public class MapReferenceYamlTest extends AbstractYamlTest { - private static final Logger log = LoggerFactory.getLogger(MapReferenceYamlTest.class); - - protected Entity setupAndCheckTestEntityInBasicYamlWith(String ...extras) throws Exception { - Entity app = createAndStartApplication(loadYaml("test-entity-reference-map-template.yaml", extras)); - waitForApplicationTasks(app); - - Assert.assertEquals(app.getDisplayName(), "test-entity-reference-map-template"); - - log.info("App started:"); - Entities.dumpInfo(app); - - Assert.assertEquals(Iterables.size(app.getChildren()), 3, "Expected app to have child entity"); - Iterable<BasicEntity> basicEntities = Iterables.filter(app.getChildren(), BasicEntity.class); - Iterable<TestEntity> testEntities = Iterables.filter(app.getChildren(), TestEntity.class); - Assert.assertEquals(Iterables.size(basicEntities), 2, "Expected app to have two basic entities"); - Assert.assertEquals(Iterables.size(testEntities), 1, "Expected app to have one test entity"); - - return Iterables.getOnlyElement(testEntities); - } - - @Test - public void testSingleEntity() throws Exception { - setupAndCheckTestEntityInBasicYamlWith(); - } - - @Test - public void testBrooklynConfigWithMapFunction() throws Exception { - final Entity testEntity = setupAndCheckTestEntityInBasicYamlWith( - " brooklyn.config:", - " test.confMapThing.obj:", - " frog: $brooklyn:formatString(\"%s\", \"frog\")", - " object:", - " $brooklyn:object:", - " type: org.apache.brooklyn.camp.brooklyn.SimpleTestPojo", - " one: $brooklyn:entity(\"one\")", - " two: $brooklyn:entity(\"two\")"); - - Map<?,?> testMap = (Map<?,?>) Entities.submit(testEntity, Tasks.builder().body(new Callable<Object>() { - @Override - public Object call() throws Exception { - return testEntity.getConfig(TestEntity.CONF_MAP_THING_OBJECT); - } - }).build()).get(); - Object frog = testMap.get("frog"); - Object one = testMap.get("one"); - Object two = testMap.get("two"); - Object object = testMap.get("object"); - - Assert.assertTrue(frog instanceof String, "Should have found a String: " + frog); - Assert.assertEquals(frog, "frog", "Should have found a formatted String: " + frog); - Assert.assertTrue(object instanceof SimpleTestPojo, "Should have found a SimpleTestPojo: " + object); - Assert.assertTrue(one instanceof BasicEntity, "Should have found a BasicEntity: " + one); - Assert.assertTrue(two instanceof BasicEntity, "Should have found a BasicEntity: " + two); - } - - @Test - public void testBrooklynConfigWithPlainMapFunction() throws Exception { - final Entity testEntity = setupAndCheckTestEntityInBasicYamlWith( - " brooklyn.config:", - " test.confMapPlain:", - " frog: $brooklyn:formatString(\"%s\", \"frog\")", - " object:", - " $brooklyn:object:", - " type: org.apache.brooklyn.camp.brooklyn.SimpleTestPojo", - " one: $brooklyn:entity(\"one\")", - " two: $brooklyn:entity(\"two\")"); - - Map<?,?> testMap = (Map<?,?>) Entities.submit(testEntity, Tasks.builder().body(new Callable<Object>() { - @Override - public Object call() throws Exception { - return testEntity.getConfig(TestEntity.CONF_MAP_PLAIN); - } - }).build()).get(); - Object frog = testMap.get("frog"); - Object one = testMap.get("one"); - Object two = testMap.get("two"); - Object object = testMap.get("object"); - - Assert.assertTrue(frog instanceof String, "Should have found a String: " + frog); - Assert.assertEquals(frog, "frog", "Should have found a formatted String: " + frog); - Assert.assertTrue(object instanceof SimpleTestPojo, "Should have found a SimpleTestPojo: " + object); - Assert.assertTrue(one instanceof BasicEntity, "Should have found a BasicEntity: " + one); - Assert.assertTrue(two instanceof BasicEntity, "Should have found a BasicEntity: " + two); - } - - @Override - protected Logger getLogger() { - return log; - } - -} http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d03f254b/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ObjectsYamlTest.java ---------------------------------------------------------------------- diff --git a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ObjectsYamlTest.java b/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ObjectsYamlTest.java deleted file mode 100644 index 147ae1e..0000000 --- a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ObjectsYamlTest.java +++ /dev/null @@ -1,283 +0,0 @@ -/* - * 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 org.apache.brooklyn.camp.brooklyn; - -import java.util.List; -import java.util.concurrent.atomic.AtomicBoolean; - -import org.apache.brooklyn.api.entity.Entity; -import org.apache.brooklyn.api.mgmt.ManagementContext; -import org.apache.brooklyn.api.mgmt.Task; -import org.apache.brooklyn.api.objs.Configurable; -import org.apache.brooklyn.config.ConfigKey; -import org.apache.brooklyn.config.ConfigKey.HasConfigKey; -import org.apache.brooklyn.core.config.ConfigKeys; -import org.apache.brooklyn.core.entity.Entities; -import org.apache.brooklyn.core.mgmt.ManagementContextInjectable; -import org.apache.brooklyn.core.test.entity.TestEntity; -import org.apache.brooklyn.util.core.config.ConfigBag; -import org.apache.brooklyn.util.core.flags.SetFromFlag; -import org.apache.brooklyn.util.core.flags.TypeCoercions; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testng.Assert; -import org.testng.annotations.Test; - -import com.google.common.collect.Lists; - -@Test -public class ObjectsYamlTest extends AbstractYamlTest { - private static final Logger log = LoggerFactory.getLogger(ObjectsYamlTest.class); - - private static final AtomicBoolean managementContextInjected = new AtomicBoolean(false); - private static final List<String> configKeys = Lists.newLinkedList(); - - public static class TestObject implements ManagementContextInjectable { - private String string; - private Integer number; - private Object object; - - public TestObject() { } - - public String getString() { return string; } - public void setString(String string) { this.string = string; } - - public Integer getNumber() { return number; } - public void setNumber(Integer number) { this.number = number; } - - public Object getObject() { return object; } - public void setObject(Object object) { this.object = object; } - - @Override - public void setManagementContext(ManagementContext managementContext) { - log.info("Detected injection of {}", managementContext); - managementContextInjected.set(true); - } - } - - public static class ConfigurableObject implements Configurable { - public static final ConfigKey<Integer> INTEGER = ConfigKeys.newIntegerConfigKey("config.number"); - @SetFromFlag("object") - public static final ConfigKey<Object> OBJECT = ConfigKeys.newConfigKey(Object.class, "config.object"); - - @SetFromFlag("flag") - private String string; - - private Integer number; - private Object object; - private Double value; - BasicConfigurationSupport configSupport = new BasicConfigurationSupport(); - - public ConfigurableObject() { } - - public String getString() { return string; } - - public Integer getNumber() { return number; } - - public Object getObject() { return object; } - - public Double getDouble() { return value; } - public void setDouble(Double value) { this.value = value; } - - @Override - public <T> T getConfig(ConfigKey<T> key) { - return config().get(key); - } - - @Override - public <T> T setConfig(ConfigKey<T> key, T value) { - return config().set(key, value); - } - - @Override - public ConfigurationSupport config() { - return configSupport; - } - - private class BasicConfigurationSupport implements ConfigurationSupport { - private final ConfigBag bag = new ConfigBag(); - - @Override - public <T> T get(ConfigKey<T> key) { - return bag.get(key); - } - - @Override - public <T> T get(HasConfigKey<T> key) { - return get(key.getConfigKey()); - } - - @Override - public <T> T set(ConfigKey<T> key, T val) { - log.info("Detected configuration injection for {}: {}", key.getName(), val); - configKeys.add(key.getName()); - if ("config.number".equals(key.getName())) number = TypeCoercions.coerce(val, Integer.class); - if ("config.object".equals(key.getName())) object = val; - T old = bag.get(key); - bag.configure(key, val); - return old; - } - - @Override - public <T> T set(HasConfigKey<T> key, T val) { - return set(key.getConfigKey(), val); - } - - @Override - public <T> T set(ConfigKey<T> key, Task<T> val) { - throw new UnsupportedOperationException(); - } - - @Override - public <T> T set(HasConfigKey<T> key, Task<T> val) { - return set(key.getConfigKey(), val); - } - } - } - - protected Entity setupAndCheckTestEntityInBasicYamlWith(String ...extras) throws Exception { - managementContextInjected.set(false); - configKeys.clear(); - Entity app = createAndStartApplication(loadYaml("test-entity-basic-template.yaml", extras)); - waitForApplicationTasks(app); - - Assert.assertEquals(app.getDisplayName(), "test-entity-basic-template"); - - log.info("App started:"); - Entities.dumpInfo(app); - - Assert.assertTrue(app.getChildren().iterator().hasNext(), "Expected app to have child entity"); - Entity entity = app.getChildren().iterator().next(); - Assert.assertTrue(entity instanceof TestEntity, "Expected TestEntity, found " + entity.getClass()); - - return (TestEntity)entity; - } - - @Test - public void testSingleEntity() throws Exception { - setupAndCheckTestEntityInBasicYamlWith(); - } - - @Test - public void testBrooklynObject() throws Exception { - Entity testEntity = setupAndCheckTestEntityInBasicYamlWith( - " brooklyn.config:", - " test.confObject:", - " $brooklyn:object:", - " type: "+ObjectsYamlTest.class.getName()+"$TestObject", - " object.fields:", - " number: 7", - " object:", - " $brooklyn:object:", - " type: org.apache.brooklyn.camp.brooklyn.SimpleTestPojo", - " string: \"frog\""); - - Object testObject = testEntity.getConfig(TestEntity.CONF_OBJECT); - - Assert.assertTrue(testObject instanceof TestObject, "Expected a TestObject: "+testObject); - Assert.assertTrue(managementContextInjected.get()); - Assert.assertEquals(((TestObject) testObject).getNumber(), Integer.valueOf(7)); - Assert.assertEquals(((TestObject) testObject).getString(), "frog"); - - Object testObjectObject = ((TestObject) testObject).getObject(); - Assert.assertTrue(testObjectObject instanceof SimpleTestPojo, "Expected a SimpleTestPojo: "+testObjectObject); - } - - @Test - public void testBrooklynConfigurableObject() throws Exception { - Entity testEntity = setupAndCheckTestEntityInBasicYamlWith( - " brooklyn.config:", - " test.confObject:", - " $brooklyn:object:", - " type: "+ObjectsYamlTest.class.getName()+"$ConfigurableObject", - " object.fields:", - " double: 1.4", - " brooklyn.config:", - " flag: frog", - " config.number: 7", - " object:", - " $brooklyn:object:", - " type: org.apache.brooklyn.camp.brooklyn.SimpleTestPojo"); - - Object testObject = testEntity.getConfig(TestEntity.CONF_OBJECT); - - Assert.assertTrue(testObject instanceof ConfigurableObject, "Expected a ConfigurableObject: "+testObject); - Assert.assertEquals(((ConfigurableObject) testObject).getDouble(), Double.valueOf(1.4)); - Assert.assertEquals(((ConfigurableObject) testObject).getString(), "frog"); - Assert.assertEquals(((ConfigurableObject) testObject).getNumber(), Integer.valueOf(7)); - - Object testObjectObject = ((ConfigurableObject) testObject).getObject(); - Assert.assertTrue(testObjectObject instanceof SimpleTestPojo, "Expected a SimpleTestPojo: "+testObjectObject); - - Assert.assertTrue(configKeys.contains(ConfigurableObject.INTEGER.getName()), "Expected INTEGER key: "+configKeys); - Assert.assertTrue(configKeys.contains(ConfigurableObject.OBJECT.getName()), "Expected OBJECT key: "+configKeys); - } - - @Test - public void testBrooklynObjectPrefix() throws Exception { - Entity testEntity = setupAndCheckTestEntityInBasicYamlWith( - " brooklyn.config:", - " test.confListPlain:", - " - $brooklyn:object:", - " objectType: org.apache.brooklyn.camp.brooklyn.SimpleTestPojo", - " - $brooklyn:object:", - " object_type: org.apache.brooklyn.camp.brooklyn.SimpleTestPojo", - " - $brooklyn:object:", - " type: org.apache.brooklyn.camp.brooklyn.SimpleTestPojo"); - - List<?> testList = testEntity.getConfig(TestEntity.CONF_LIST_PLAIN); - - Assert.assertEquals(testList.size(), 3); - for (Object entry : testList) { - Assert.assertTrue(entry instanceof SimpleTestPojo, "Expected a SimpleTestPojo: "+entry); - } - } - - @Test - public void testBrooklynObjectWithFunction() throws Exception { - Entity testEntity = setupAndCheckTestEntityInBasicYamlWith( - " brooklyn.config:", - " test.confObject:", - " $brooklyn:object:", - " type: "+ObjectsYamlTest.class.getName()+"$TestObject", - " object.fields:", - " number: 7", - " object:", - " $brooklyn:object:", - " type: org.apache.brooklyn.camp.brooklyn.SimpleTestPojo", - " string:", - " $brooklyn:formatString(\"%s\", \"frog\")"); - - Object testObject = testEntity.getConfig(TestEntity.CONF_OBJECT); - - Assert.assertTrue(testObject instanceof TestObject, "Expected a TestObject: "+testObject); - Assert.assertTrue(managementContextInjected.get()); - Assert.assertEquals(((TestObject) testObject).getNumber(), Integer.valueOf(7)); - Assert.assertEquals(((TestObject) testObject).getString(), "frog"); - - Object testObjectObject = ((TestObject) testObject).getObject(); - Assert.assertTrue(testObjectObject instanceof SimpleTestPojo, "Expected a SimpleTestPojo: "+testObjectObject); - } - - @Override - protected Logger getLogger() { - return log; - } - -} http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d03f254b/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/PoliciesYamlTest.java ---------------------------------------------------------------------- diff --git a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/PoliciesYamlTest.java b/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/PoliciesYamlTest.java deleted file mode 100644 index 6bcf49f..0000000 --- a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/PoliciesYamlTest.java +++ /dev/null @@ -1,214 +0,0 @@ -/* - * 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 org.apache.brooklyn.camp.brooklyn; - -import java.util.Map; -import java.util.concurrent.Callable; - -import org.apache.brooklyn.api.entity.Entity; -import org.apache.brooklyn.api.policy.Policy; -import org.apache.brooklyn.config.ConfigKey; -import org.apache.brooklyn.core.entity.Entities; -import org.apache.brooklyn.core.entity.EntityInternal; -import org.apache.brooklyn.core.test.entity.TestEntity; -import org.apache.brooklyn.core.test.policy.TestPolicy; -import org.apache.brooklyn.test.Asserts; -import org.apache.brooklyn.util.collections.MutableMap; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testng.Assert; -import org.testng.annotations.Test; - -import com.google.common.base.Predicates; -import com.google.common.base.Supplier; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; - -@Test -public class PoliciesYamlTest extends AbstractYamlTest { - static final Logger log = LoggerFactory.getLogger(PoliciesYamlTest.class); - - @Test - public void testWithAppPolicy() throws Exception { - Entity app = createAndStartApplication(loadYaml("test-app-with-policy.yaml")); - waitForApplicationTasks(app); - Assert.assertEquals(app.getDisplayName(), "test-app-with-policy"); - - log.info("App started:"); - Entities.dumpInfo(app); - - Assert.assertEquals(app.policies().size(), 1); - Policy policy = app.policies().iterator().next(); - Assert.assertTrue(policy instanceof TestPolicy); - Assert.assertEquals(policy.getConfig(TestPolicy.CONF_NAME), "Name from YAML"); - Assert.assertEquals(policy.getConfig(TestPolicy.CONF_FROM_FUNCTION), "$brooklyn: is a fun place"); - Map<?, ?> leftoverProperties = ((TestPolicy) policy).getLeftoverProperties(); - Assert.assertEquals(leftoverProperties.get("policyLiteralValue1"), "Hello"); - Assert.assertEquals(leftoverProperties.get("policyLiteralValue2"), "World"); - Assert.assertEquals(leftoverProperties.size(), 2); - } - - @Test - public void testWithEntityPolicy() throws Exception { - Entity app = createAndStartApplication(loadYaml("test-entity-with-policy.yaml")); - waitForApplicationTasks(app); - Assert.assertEquals(app.getDisplayName(), "test-entity-with-policy"); - - log.info("App started:"); - Entities.dumpInfo(app); - - Assert.assertEquals(app.policies().size(), 0); - Assert.assertEquals(app.getChildren().size(), 1); - Entity child = app.getChildren().iterator().next(); - Assert.assertEquals(child.policies().size(), 1); - Policy policy = child.policies().iterator().next(); - Assert.assertNotNull(policy); - Assert.assertTrue(policy instanceof TestPolicy, "policy=" + policy + "; type=" + policy.getClass()); - Assert.assertEquals(policy.getConfig(TestPolicy.CONF_NAME), "Name from YAML"); - Assert.assertEquals(policy.getConfig(TestPolicy.CONF_FROM_FUNCTION), "$brooklyn: is a fun place"); - Assert.assertEquals(((TestPolicy) policy).getLeftoverProperties(), - ImmutableMap.of("policyLiteralValue1", "Hello", "policyLiteralValue2", "World")); - Assert.assertEquals(policy.getConfig(TestPolicy.TEST_ATTRIBUTE_SENSOR), TestEntity.NAME); - } - - @Test - public void testChildWithPolicy() throws Exception { - Entity app = createAndStartApplication(loadYaml("test-entity-basic-template.yaml", - " brooklyn.config:", - " test.confName: parent entity", - " brooklyn.children:", - " - serviceType: org.apache.brooklyn.core.test.entity.TestEntity", - " name: Child Entity", - " brooklyn.policies:", - " - policyType: org.apache.brooklyn.core.test.policy.TestPolicy", - " brooklyn.config:", - " test.confName: Name from YAML", - " test.attributeSensor: $brooklyn:sensor(\"org.apache.brooklyn.core.test.entity.TestEntity\", \"test.name\")")); - waitForApplicationTasks(app); - - Assert.assertEquals(app.getChildren().size(), 1); - Entity firstEntity = app.getChildren().iterator().next(); - Assert.assertEquals(firstEntity.getChildren().size(), 1); - final Entity child = firstEntity.getChildren().iterator().next(); - Assert.assertEquals(child.getChildren().size(), 0); - - Assert.assertEquals(app.policies().size(), 0); - Assert.assertEquals(firstEntity.policies().size(), 0); - - Asserts.eventually(new Supplier<Integer>() { - @Override - public Integer get() { - return child.policies().size(); - } - }, Predicates.<Integer> equalTo(1)); - - Policy policy = child.policies().iterator().next(); - Assert.assertTrue(policy instanceof TestPolicy); - Assert.assertEquals(policy.getConfig(TestPolicy.TEST_ATTRIBUTE_SENSOR), TestEntity.NAME); - } - - @Test - public void testMultiplePolicyReferences() throws Exception { - final Entity app = createAndStartApplication(loadYaml("test-referencing-policies.yaml")); - waitForApplicationTasks(app); - Assert.assertEquals(app.getDisplayName(), "test-referencing-policies"); - - Entity entity1 = null, entity2 = null, child1 = null, child2 = null, grandchild1 = null, grandchild2 = null; - - Assert.assertEquals(app.getChildren().size(), 2); - for (Entity child : app.getChildren()) { - if (child.getDisplayName().equals("entity 1")) - entity1 = child; - if (child.getDisplayName().equals("entity 2")) - entity2 = child; - } - Assert.assertNotNull(entity1); - Assert.assertNotNull(entity2); - - Assert.assertEquals(entity1.getChildren().size(), 2); - for (Entity child : entity1.getChildren()) { - if (child.getDisplayName().equals("child 1")) - child1 = child; - if (child.getDisplayName().equals("child 2")) - child2 = child; - } - Assert.assertNotNull(child1); - Assert.assertNotNull(child2); - - Assert.assertEquals(child1.getChildren().size(), 2); - for (Entity child : child1.getChildren()) { - if (child.getDisplayName().equals("grandchild 1")) - grandchild1 = child; - if (child.getDisplayName().equals("grandchild 2")) - grandchild2 = child; - } - Assert.assertNotNull(grandchild1); - Assert.assertNotNull(grandchild2); - - ImmutableSet<Policy> policies = new ImmutableSet.Builder<Policy>() - .add(getPolicy(app)) - .add(getPolicy(entity1)) - .add(getPolicy(entity2)) - .add(getPolicy(child1)) - .add(getPolicy(child2)) - .add(getPolicy(grandchild1)) - .add(getPolicy(grandchild2)) - .build(); - - Map<ConfigKey<Entity>, Entity> keyToEntity = new ImmutableMap.Builder<ConfigKey<Entity>, Entity>() - .put(ReferencingYamlTestEntity.TEST_REFERENCE_APP, app) - .put(ReferencingYamlTestEntity.TEST_REFERENCE_ENTITY1, entity1) - .put(ReferencingYamlTestEntity.TEST_REFERENCE_ENTITY2, entity2) - .put(ReferencingYamlTestEntity.TEST_REFERENCE_CHILD1, child1) - .put(ReferencingYamlTestEntity.TEST_REFERENCE_CHILD2, child2) - .put(ReferencingYamlTestEntity.TEST_REFERENCE_GRANDCHILD1, grandchild1) - .put(ReferencingYamlTestEntity.TEST_REFERENCE_GRANDCHILD2, grandchild2) - .build(); - - for (Policy policy : policies) - checkReferences(policy, keyToEntity); - - } - - private void checkReferences(final Policy policy, Map<ConfigKey<Entity>, Entity> keyToEntity) throws Exception { - for (final ConfigKey<Entity> key : keyToEntity.keySet()) { - final Entity entity = keyToEntity.get(key); // Grab an entity whose execution context we can use - Entity fromConfig = ((EntityInternal)entity).getExecutionContext().submit(MutableMap.of(), new Callable<Entity>() { - @Override - public Entity call() throws Exception { - return (Entity) policy.getConfig(key); - } - }).get(); - Assert.assertEquals(fromConfig, keyToEntity.get(key)); - } - } - - private Policy getPolicy(Entity entity) { - Assert.assertEquals(entity.policies().size(), 1); - Policy policy = entity.policies().iterator().next(); - Assert.assertTrue(policy instanceof TestReferencingPolicy); - return policy; - } - - @Override - protected Logger getLogger() { - return log; - } - -} http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d03f254b/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ReferencedYamlTest.java ---------------------------------------------------------------------- diff --git a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ReferencedYamlTest.java b/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ReferencedYamlTest.java deleted file mode 100644 index bb0ea90..0000000 --- a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ReferencedYamlTest.java +++ /dev/null @@ -1,180 +0,0 @@ -/* - * 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 org.apache.brooklyn.camp.brooklyn; - -import java.util.Collection; - -import org.apache.brooklyn.api.entity.Entity; -import org.apache.brooklyn.core.mgmt.osgi.OsgiStandaloneTest; -import org.apache.brooklyn.entity.stock.BasicApplication; -import org.apache.brooklyn.entity.stock.BasicEntity; -import org.apache.brooklyn.test.support.TestResourceUnavailableException; -import org.testng.Assert; -import org.testng.annotations.Test; - -import com.google.common.collect.Iterables; - -public class ReferencedYamlTest extends AbstractYamlTest { - - @Test - public void testReferenceEntityYamlAsPlatformComponent() throws Exception { - String entityName = "Reference child name"; - Entity app = createAndStartApplication( - "services:", - "- name: " + entityName, - " type: classpath://yaml-ref-entity.yaml"); - - checkChildEntitySpec(app, entityName); - } - - @Test - public void testAnonymousReferenceEntityYamlAsPlatformComponent() throws Exception { - Entity app = createAndStartApplication( - "services:", - "- type: classpath://yaml-ref-entity.yaml"); - - // the name declared at the root trumps the name on the item itself - checkChildEntitySpec(app, "Basic entity"); - } - - @Test - public void testReferenceAppYamlAsPlatformComponent() throws Exception { - Entity app = createAndStartApplication( - "services:", - "- name: Reference child name", - " type: classpath://yaml-ref-app.yaml"); - - Assert.assertEquals(app.getChildren().size(), 0); - Assert.assertEquals(app.getDisplayName(), "Reference child name"); - - //child is a proxy so equality test won't do - Assert.assertEquals(app.getEntityType().getName(), BasicApplication.class.getName()); - } - - @Test - public void testReferenceYamlAsChild() throws Exception { - String entityName = "Reference child name"; - Entity createAndStartApplication = createAndStartApplication( - "services:", - "- type: org.apache.brooklyn.entity.stock.BasicEntity", - " brooklyn.children:", - " - name: " + entityName, - " type: classpath://yaml-ref-entity.yaml"); - - checkGrandchildEntitySpec(createAndStartApplication, entityName); - } - - @Test - public void testAnonymousReferenceYamlAsChild() throws Exception { - Entity createAndStartApplication = createAndStartApplication( - "services:", - "- type: org.apache.brooklyn.entity.stock.BasicEntity", - " brooklyn.children:", - " - type: classpath://yaml-ref-entity.yaml"); - - checkGrandchildEntitySpec(createAndStartApplication, "Basic entity"); - } - - @Test - public void testCatalogReferencingYamlUrl() throws Exception { - addCatalogItems( - "brooklyn.catalog:", - " id: yaml.reference", - " version: " + TEST_VERSION, - "services:", - "- type: classpath://yaml-ref-entity.yaml"); - - String entityName = "YAML -> catalog item -> yaml url"; - Entity app = createAndStartApplication( - "services:", - "- name: " + entityName, - " type: " + ver("yaml.reference")); - - checkChildEntitySpec(app, entityName); - } - - @Test - public void testYamlUrlReferencingCatalog() throws Exception { - addCatalogItems( - "brooklyn.catalog:", - " id: yaml.basic", - " version: " + TEST_VERSION, - "services:", - "- type: org.apache.brooklyn.entity.stock.BasicEntity"); - - String entityName = "YAML -> yaml url -> catalog item"; - Entity app = createAndStartApplication( - "services:", - "- name: " + entityName, - " type: classpath://yaml-ref-catalog.yaml"); - - checkChildEntitySpec(app, entityName); - } - - /** - * Tests that a YAML referenced by URL from a catalog item - * will have access to the catalog item's bundles. - */ - @Test - public void testCatalogLeaksBundlesToReferencedYaml() throws Exception { - TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH); - - String parentCatalogId = "my.catalog.app.id.url.parent"; - addCatalogItems( - "brooklyn.catalog:", - " id: " + parentCatalogId, - " version: " + TEST_VERSION, - " libraries:", - " - url: " + OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL, - "", - "services:", - "- type: classpath://yaml-ref-bundle-without-libraries.yaml"); - - Entity app = createAndStartApplication( - "services:", - "- type: " + ver(parentCatalogId)); - - Collection<Entity> children = app.getChildren(); - Assert.assertEquals(children.size(), 1); - Entity child = Iterables.getOnlyElement(children); - Assert.assertEquals(child.getEntityType().getName(), "org.apache.brooklyn.test.osgi.entities.SimpleEntity"); - - deleteCatalogEntity(parentCatalogId); - } - - private void checkChildEntitySpec(Entity app, String entityName) { - Collection<Entity> children = app.getChildren(); - Assert.assertEquals(children.size(), 1); - Entity child = Iterables.getOnlyElement(children); - Assert.assertEquals(child.getDisplayName(), entityName); - Assert.assertEquals(child.getEntityType().getName(), BasicEntity.class.getName()); - } - - private void checkGrandchildEntitySpec(Entity createAndStartApplication, String entityName) { - Collection<Entity> children = createAndStartApplication.getChildren(); - Assert.assertEquals(children.size(), 1); - Entity child = Iterables.getOnlyElement(children); - Collection<Entity> grandChildren = child.getChildren(); - Assert.assertEquals(grandChildren.size(), 1); - Entity grandChild = Iterables.getOnlyElement(grandChildren); - Assert.assertEquals(grandChild.getDisplayName(), entityName); - Assert.assertEquals(grandChild.getEntityType().getName(), BasicEntity.class.getName()); - } - -} http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d03f254b/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ReferencingYamlTestEntity.java ---------------------------------------------------------------------- diff --git a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ReferencingYamlTestEntity.java b/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ReferencingYamlTestEntity.java deleted file mode 100644 index 7a8ac59..0000000 --- a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ReferencingYamlTestEntity.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * 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 org.apache.brooklyn.camp.brooklyn; - -import org.apache.brooklyn.api.entity.Entity; -import org.apache.brooklyn.api.entity.ImplementedBy; -import org.apache.brooklyn.config.ConfigKey; -import org.apache.brooklyn.core.config.BasicConfigKey; - -import com.google.common.reflect.TypeToken; - -@ImplementedBy(ReferencingYamlTestEntityImpl.class) -public interface ReferencingYamlTestEntity extends Entity { - @SuppressWarnings("serial") - public static final ConfigKey<Entity> TEST_REFERENCE_ROOT = BasicConfigKey.builder(new TypeToken<Entity>(){}) - .name("test.reference.root") - .build(); - @SuppressWarnings("serial") - public static final ConfigKey<Entity> TEST_REFERENCE_SCOPE_ROOT = BasicConfigKey.builder(new TypeToken<Entity>(){}) - .name("test.reference.scope_root") - .build(); - @SuppressWarnings("serial") - public static final ConfigKey<Entity> TEST_REFERENCE_APP = BasicConfigKey.builder(new TypeToken<Entity>(){}) - .name("test.reference.app") - .build(); - @SuppressWarnings("serial") - public static final ConfigKey<Entity> TEST_REFERENCE_ENTITY1 = BasicConfigKey.builder(new TypeToken<Entity>(){}) - .name("test.reference.entity1") - .build(); - @SuppressWarnings("serial") - public static final ConfigKey<Entity> TEST_REFERENCE_ENTITY1_ALT = BasicConfigKey.builder(new TypeToken<Entity>(){}) - .name("test.reference.entity1a") - .build(); - @SuppressWarnings("serial") - public static final ConfigKey<Entity> TEST_REFERENCE_ENTITY2 = BasicConfigKey.builder(new TypeToken<Entity>(){}) - .name("test.reference.entity2") - .build(); - @SuppressWarnings("serial") - public static final ConfigKey<Entity> TEST_REFERENCE_CHILD1 = BasicConfigKey.builder(new TypeToken<Entity>(){}) - .name("test.reference.child1") - .build(); - @SuppressWarnings("serial") - public static final ConfigKey<Entity> TEST_REFERENCE_CHILD2 = BasicConfigKey.builder(new TypeToken<Entity>(){}) - .name("test.reference.child2") - .build(); - @SuppressWarnings("serial") - public static final ConfigKey<Entity> TEST_REFERENCE_GRANDCHILD1 = BasicConfigKey.builder(new TypeToken<Entity>(){}) - .name("test.reference.grandchild1") - .build(); - @SuppressWarnings("serial") - public static final ConfigKey<Entity> TEST_REFERENCE_GRANDCHILD2 = BasicConfigKey.builder(new TypeToken<Entity>(){}) - .name("test.reference.grandchild2") - .build(); - @SuppressWarnings("serial") - public static final ConfigKey<Entity> TEST_REFERENCE_BOGUS = BasicConfigKey.builder(new TypeToken<Entity>(){}) - .name("test.reference.bogus") - .build(); -} http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d03f254b/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ReferencingYamlTestEntityImpl.java ---------------------------------------------------------------------- diff --git a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ReferencingYamlTestEntityImpl.java b/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ReferencingYamlTestEntityImpl.java deleted file mode 100644 index 14673bc..0000000 --- a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ReferencingYamlTestEntityImpl.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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 org.apache.brooklyn.camp.brooklyn; - -import org.apache.brooklyn.core.entity.AbstractApplication; - -public class ReferencingYamlTestEntityImpl extends AbstractApplication implements ReferencingYamlTestEntity { - -} http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d03f254b/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ReloadBrooklynPropertiesTest.java ---------------------------------------------------------------------- diff --git a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ReloadBrooklynPropertiesTest.java b/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ReloadBrooklynPropertiesTest.java deleted file mode 100644 index a5263f6..0000000 --- a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ReloadBrooklynPropertiesTest.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * 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 org.apache.brooklyn.camp.brooklyn; - -import java.io.Reader; - -import org.apache.brooklyn.api.entity.Entity; -import org.apache.brooklyn.api.mgmt.ManagementContext; -import org.apache.brooklyn.camp.CampPlatform; -import org.apache.brooklyn.camp.brooklyn.BrooklynCampConstants; -import org.apache.brooklyn.camp.brooklyn.BrooklynCampPlatformLauncherNoServer; -import org.apache.brooklyn.camp.spi.Assembly; -import org.apache.brooklyn.camp.spi.AssemblyTemplate; -import org.apache.brooklyn.core.entity.Entities; -import org.apache.brooklyn.core.entity.trait.Startable; -import org.apache.brooklyn.test.EntityTestUtils; -import org.apache.brooklyn.util.core.ResourceUtils; -import org.apache.brooklyn.util.exceptions.Exceptions; -import org.apache.brooklyn.util.stream.Streams; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testng.Assert; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -public class ReloadBrooklynPropertiesTest { - - private static final Logger LOG = LoggerFactory.getLogger(ReloadBrooklynPropertiesTest.class); - - private ManagementContext brooklynMgmt; - - @BeforeMethod(alwaysRun=true) - public void setup() { - brooklynMgmt = new BrooklynCampPlatformLauncherNoServer().launch().getBrooklynMgmt(); - } - - @AfterMethod(alwaysRun=true) - public void teardown() { - if (brooklynMgmt!=null) Entities.destroyAll(brooklynMgmt); - } - - @Test - public void testReloadBrooklynPropertiesNonDeploy() { - CampPlatform platform = brooklynMgmt.getConfig().getConfig(BrooklynCampConstants.CAMP_PLATFORM); - Assert.assertNotNull(platform); - brooklynMgmt.reloadBrooklynProperties(); - CampPlatform reloadedPlatform = brooklynMgmt.getConfig().getConfig(BrooklynCampConstants.CAMP_PLATFORM); - Assert.assertEquals(reloadedPlatform, platform); - } - - @Test - public void testReloadBrooklynPropertiesDeploy() { - brooklynMgmt.reloadBrooklynProperties(); - CampPlatform reloadedPlatform = brooklynMgmt.getConfig().getConfig(BrooklynCampConstants.CAMP_PLATFORM); - Assert.assertNotNull(reloadedPlatform); - Reader input = Streams.reader(new ResourceUtils(this).getResourceFromUrl("test-entity-basic-template.yaml")); - AssemblyTemplate template = reloadedPlatform.pdp().registerDeploymentPlan(input); - try { - Assembly assembly = template.getInstantiator().newInstance().instantiate(template, reloadedPlatform); - LOG.info("Test - created " + assembly); - final Entity app = brooklynMgmt.getEntityManager().getEntity(assembly.getId()); - LOG.info("App - " + app); - Assert.assertEquals(app.getDisplayName(), "test-entity-basic-template"); - EntityTestUtils.assertAttributeEqualsEventually(app, Startable.SERVICE_UP, true); - } catch (Exception e) { - LOG.warn("Unable to instantiate " + template + " (rethrowing): " + e); - throw Exceptions.propagate(e); - } - } -} http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d03f254b/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/SimpleTestPojo.java ---------------------------------------------------------------------- diff --git a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/SimpleTestPojo.java b/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/SimpleTestPojo.java deleted file mode 100644 index 05e32ed..0000000 --- a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/SimpleTestPojo.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 org.apache.brooklyn.camp.brooklyn; - -/** - * Dummy POJO for use with $brooklyn:object tests - */ -public class SimpleTestPojo { - private String fieldA; - private String fieldB; - - public String getFieldA() { - return fieldA; - } - - public void setFieldA(final String fieldA) { - this.fieldA = fieldA; - } - - public String getFieldB() { - return fieldB; - } - - public void setFieldB(final String fieldB) { - this.fieldB = fieldB; - } -} http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d03f254b/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/TestEntityWithInitConfig.java ---------------------------------------------------------------------- diff --git a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/TestEntityWithInitConfig.java b/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/TestEntityWithInitConfig.java deleted file mode 100644 index e5fb2f3..0000000 --- a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/TestEntityWithInitConfig.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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 org.apache.brooklyn.camp.brooklyn; - -import org.apache.brooklyn.api.entity.Entity; -import org.apache.brooklyn.api.entity.ImplementedBy; -import org.apache.brooklyn.config.ConfigKey; -import org.apache.brooklyn.core.config.BasicConfigKey; -import org.apache.brooklyn.core.entity.EntityInternal; -import org.apache.brooklyn.core.entity.trait.Startable; - -@ImplementedBy(TestEntityWithInitConfigImpl.class) -public interface TestEntityWithInitConfig extends Entity, Startable, EntityInternal { - public static final ConfigKey<Entity> TEST_ENTITY = BasicConfigKey.builder(Entity.class) - .name("test.entity") - .build(); - public Entity getEntityCachedOnInit(); -} http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d03f254b/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/TestEntityWithInitConfigImpl.java ---------------------------------------------------------------------- diff --git a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/TestEntityWithInitConfigImpl.java b/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/TestEntityWithInitConfigImpl.java deleted file mode 100644 index ad0431a..0000000 --- a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/TestEntityWithInitConfigImpl.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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 org.apache.brooklyn.camp.brooklyn; - -import java.util.Collection; - -import org.apache.brooklyn.api.entity.Entity; -import org.apache.brooklyn.api.location.Location; -import org.apache.brooklyn.core.entity.AbstractEntity; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class TestEntityWithInitConfigImpl extends AbstractEntity implements TestEntityWithInitConfig { - - private static final Logger LOG = LoggerFactory.getLogger(TestEntityWithInitConfigImpl.class); - private Entity entityCachedOnInit; - - @Override - public void init() { - super.init(); - entityCachedOnInit = getConfig(TEST_ENTITY); - } - - @Override - public void start(Collection<? extends Location> locations) { - LOG.trace("Starting {}", this); - } - - @Override - public void stop() { - LOG.trace("Stopping {}", this); - } - - @Override - public void restart() { - LOG.trace("Restarting {}", this); - } - - public Entity getEntityCachedOnInit() { - return entityCachedOnInit; - } -} http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d03f254b/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/TestReferencingEnricher.java ---------------------------------------------------------------------- diff --git a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/TestReferencingEnricher.java b/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/TestReferencingEnricher.java deleted file mode 100644 index 8468014..0000000 --- a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/TestReferencingEnricher.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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 org.apache.brooklyn.camp.brooklyn; - -import org.apache.brooklyn.api.entity.Entity; -import org.apache.brooklyn.config.ConfigKey; -import org.apache.brooklyn.core.config.BasicConfigKey; -import org.apache.brooklyn.core.enricher.AbstractEnricher; - -public class TestReferencingEnricher extends AbstractEnricher { - public static final ConfigKey<Entity> TEST_APPLICATION = new BasicConfigKey<Entity>(Entity.class, "test.reference.app"); - public static final ConfigKey<Entity> TEST_ENTITY_1 = new BasicConfigKey<Entity>(Entity.class, "test.reference.entity1"); - public static final ConfigKey<Entity> TEST_ENTITY_2 = new BasicConfigKey<Entity>(Entity.class, "test.reference.entity2"); - public static final ConfigKey<Entity> TEST_CHILD_1 = new BasicConfigKey<Entity>(Entity.class, "test.reference.child1"); - public static final ConfigKey<Entity> TEST_CHILD_2 = new BasicConfigKey<Entity>(Entity.class, "test.reference.child2"); - public static final ConfigKey<Entity> TEST_GRANDCHILD_1 = new BasicConfigKey<Entity>(Entity.class, "test.reference.grandchild1"); - public static final ConfigKey<Entity> TEST_GRANDCHILD_2 = new BasicConfigKey<Entity>(Entity.class, "test.reference.grandchild2"); -} http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d03f254b/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/TestReferencingPolicy.java ---------------------------------------------------------------------- diff --git a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/TestReferencingPolicy.java b/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/TestReferencingPolicy.java deleted file mode 100644 index e8b339e..0000000 --- a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/TestReferencingPolicy.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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 org.apache.brooklyn.camp.brooklyn; - -import org.apache.brooklyn.api.entity.Entity; -import org.apache.brooklyn.config.ConfigKey; -import org.apache.brooklyn.core.config.BasicConfigKey; -import org.apache.brooklyn.core.policy.AbstractPolicy; - -public class TestReferencingPolicy extends AbstractPolicy { - public static final ConfigKey<Entity> TEST_APPLICATION = new BasicConfigKey<Entity>(Entity.class, "test.reference.app"); - public static final ConfigKey<Entity> TEST_ENTITY_1 = new BasicConfigKey<Entity>(Entity.class, "test.reference.entity1"); - public static final ConfigKey<Entity> TEST_ENTITY_2 = new BasicConfigKey<Entity>(Entity.class, "test.reference.entity2"); - public static final ConfigKey<Entity> TEST_CHILD_1 = new BasicConfigKey<Entity>(Entity.class, "test.reference.child1"); - public static final ConfigKey<Entity> TEST_CHILD_2 = new BasicConfigKey<Entity>(Entity.class, "test.reference.child2"); - public static final ConfigKey<Entity> TEST_GRANDCHILD_1 = new BasicConfigKey<Entity>(Entity.class, "test.reference.grandchild1"); - public static final ConfigKey<Entity> TEST_GRANDCHILD_2 = new BasicConfigKey<Entity>(Entity.class, "test.reference.grandchild2"); -} http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d03f254b/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/TestSensorAndEffectorInitializer.java ---------------------------------------------------------------------- diff --git a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/TestSensorAndEffectorInitializer.java b/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/TestSensorAndEffectorInitializer.java deleted file mode 100644 index 91c18ed..0000000 --- a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/TestSensorAndEffectorInitializer.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * 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 org.apache.brooklyn.camp.brooklyn; - -import java.util.Map; - -import org.apache.brooklyn.api.effector.Effector; -import org.apache.brooklyn.api.entity.EntityInitializer; -import org.apache.brooklyn.api.entity.EntityLocal; -import org.apache.brooklyn.api.sensor.AttributeSensor; -import org.apache.brooklyn.core.effector.EffectorBody; -import org.apache.brooklyn.core.effector.Effectors; -import org.apache.brooklyn.core.entity.EntityInternal; -import org.apache.brooklyn.core.sensor.Sensors; -import org.apache.brooklyn.util.core.config.ConfigBag; -import org.testng.Assert; - -import com.google.common.base.Preconditions; - -public class TestSensorAndEffectorInitializer implements EntityInitializer { - - public static final String EFFECTOR_SAY_HELLO = "sayHello"; - public static final String SENSOR_LAST_HELLO = "lastHello"; - public static final String SENSOR_HELLO_DEFINED = "sensorHelloDefined"; - public static final String SENSOR_HELLO_DEFINED_EMITTED = "sensorHelloDefinedEmitted"; - - protected String helloWord() { return "Hello"; } - - public void apply(EntityLocal entity) { - Effector<String> eff = Effectors.effector(String.class, EFFECTOR_SAY_HELLO).parameter(String.class, "name").impl( - new EffectorBody<String>() { - @Override - public String call(ConfigBag parameters) { - Object name = parameters.getStringKey("name"); - entity().sensors().set(Sensors.newStringSensor(SENSOR_LAST_HELLO), ""+name); - return helloWord()+" "+name; - } - }).build(); - ((EntityInternal)entity).getMutableEntityType().addEffector(eff); - - ((EntityInternal)entity).getMutableEntityType().addSensor(Sensors.newStringSensor(SENSOR_HELLO_DEFINED)); - - AttributeSensor<String> emitted = Sensors.newStringSensor(SENSOR_HELLO_DEFINED_EMITTED); - ((EntityInternal)entity).getMutableEntityType().addSensor(emitted); - entity.sensors().set(emitted, "1"); - } - - public static class TestConfigurableInitializer extends TestSensorAndEffectorInitializer { - public static final String HELLO_WORD = "helloWord"; - final String helloWord; - public TestConfigurableInitializer(Map<String,String> params) { - Preconditions.checkNotNull(params); - if (params.containsKey(HELLO_WORD)) { - helloWord = params.get(HELLO_WORD); - Assert.assertEquals(params.size(), 1); - } else { - helloWord = "Hello"; - Assert.assertEquals(params.size(), 0); - } - } - - @Override - protected String helloWord() { - return helloWord; - } - } - -} http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d03f254b/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/VanillaBashNetcatYamlTest.java ---------------------------------------------------------------------- diff --git a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/VanillaBashNetcatYamlTest.java b/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/VanillaBashNetcatYamlTest.java deleted file mode 100644 index 52dd4cc..0000000 --- a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/VanillaBashNetcatYamlTest.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * 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 org.apache.brooklyn.camp.brooklyn; - -import org.apache.brooklyn.api.effector.Effector; -import org.apache.brooklyn.api.entity.Entity; -import org.apache.brooklyn.api.mgmt.Task; -import org.apache.brooklyn.api.sensor.AttributeSensor; -import org.apache.brooklyn.camp.brooklyn.BrooklynCampConstants; -import org.apache.brooklyn.core.effector.Effectors; -import org.apache.brooklyn.core.entity.Attributes; -import org.apache.brooklyn.core.entity.Entities; -import org.apache.brooklyn.core.entity.EntityPredicates; -import org.apache.brooklyn.core.entity.lifecycle.Lifecycle; -import org.apache.brooklyn.core.sensor.Sensors; -import org.apache.brooklyn.test.EntityTestUtils; -import org.apache.brooklyn.util.collections.MutableMap; -import org.apache.brooklyn.util.net.Networking; -import org.apache.brooklyn.util.text.StringPredicates; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testng.Assert; -import org.testng.annotations.Test; - -import com.google.common.base.Preconditions; -import com.google.common.base.Predicates; -import com.google.common.collect.Iterables; - -@Test -public class VanillaBashNetcatYamlTest extends AbstractYamlTest { - - private static final Logger log = LoggerFactory.getLogger(VanillaBashNetcatYamlTest.class); - - private static final AttributeSensor<String> SENSOR_OUTPUT_ALL = Sensors.newStringSensor("output.all"); - final static Effector<String> EFFECTOR_SAY_HI = Effectors.effector(String.class, "sayHiNetcat").buildAbstract(); - - @Test(groups="Integration") - public void testInvocationSensorAndEnricher() throws Exception { - Preconditions.checkArgument(Networking.isPortAvailable(4321), "port 4321 must not be in use (no leaked nc instances) for this test to succeed!"); - - Entity app = createAndStartApplication(loadYaml("vanilla-bash-netcat-w-client.yaml")); - waitForApplicationTasks(app); - - log.info("App started:"); - Entities.dumpInfo(app); - - Assert.assertEquals(app.getDisplayName(), "Simple Netcat with Client"); - - // comparing by plan ID is one common way - Iterable<Entity> netcatI = Iterables.filter(app.getChildren(), EntityPredicates.configEqualTo(BrooklynCampConstants.PLAN_ID, "netcat-server")); - Assert.assertTrue(netcatI.iterator().hasNext(), "no 'netcat-server' child of app: "+app.getChildren()); - Entity netcat = Iterables.getOnlyElement(netcatI); - - // make sure netcat is running - EntityTestUtils.assertAttributeEventually(netcat, Attributes.SERVICE_STATE_ACTUAL, Predicates.equalTo(Lifecycle.RUNNING)); - - // find the pinger, now comparing by name - Iterable<Entity> pingerI = Iterables.filter(app.getChildren(), EntityPredicates.displayNameEqualTo("Simple Pinger")); - Assert.assertTrue(pingerI.iterator().hasNext(), "no 'Simple Pinger' child of app: "+app.getChildren()); - Entity pinger = Iterables.getOnlyElement(pingerI); - - // invoke effector - Task<String> ping; - ping = pinger.invoke(EFFECTOR_SAY_HI, MutableMap.<String,Object>of()); - Assert.assertEquals(ping.get().trim(), "hello"); - // and check we get the right result - EntityTestUtils.assertAttributeEventually(netcat, SENSOR_OUTPUT_ALL, StringPredicates.containsLiteral("hi netcat")); - log.info("invoked ping from "+pinger+" to "+netcat+", 'all' sensor shows:\n"+ - netcat.getAttribute(SENSOR_OUTPUT_ALL)); - - // netcat should now fail and restart - EntityTestUtils.assertAttributeEventually(netcat, Attributes.SERVICE_STATE_ACTUAL, Predicates.not(Predicates.equalTo(Lifecycle.RUNNING))); - log.info("detected failure, state is: "+netcat.getAttribute(Attributes.SERVICE_STATE_ACTUAL)); - EntityTestUtils.assertAttributeEventually(netcat, Attributes.SERVICE_STATE_ACTUAL, Predicates.equalTo(Lifecycle.RUNNING)); - log.info("detected recovery, state is: "+netcat.getAttribute(Attributes.SERVICE_STATE_ACTUAL)); - - // invoke effector again, now with a parameter - ping = pinger.invoke(EFFECTOR_SAY_HI, MutableMap.<String,Object>of("message", "yo yo yo")); - Assert.assertEquals(ping.get().trim(), "hello"); - // checking right result - EntityTestUtils.assertAttributeEventually(netcat, SENSOR_OUTPUT_ALL, StringPredicates.containsLiteral("yo yo yo")); - log.info("invoked ping again from "+pinger+" to "+netcat+", 'all' sensor shows:\n"+ - netcat.getAttribute(SENSOR_OUTPUT_ALL)); - - // and it's propagated to the app - EntityTestUtils.assertAttributeEventually(app, Sensors.newStringSensor("output.last"), StringPredicates.containsLiteral("yo yo yo")); - - log.info("after all is said and done, app is:"); - Entities.dumpInfo(app); - } - - @Override - protected Logger getLogger() { - return log; - } - -}
