You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by ha...@apache.org on 2015/08/05 22:56:16 UTC
[12/20] incubator-brooklyn git commit: Package rename to
org.apache.brooklyn: usage/camp/
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e406d1ad/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/MapReferenceYamlTest.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/MapReferenceYamlTest.java b/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/MapReferenceYamlTest.java
deleted file mode 100644
index 0a02838..0000000
--- a/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/MapReferenceYamlTest.java
+++ /dev/null
@@ -1,130 +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 io.brooklyn.camp.brooklyn;
-
-import java.util.Map;
-import java.util.concurrent.Callable;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.testng.Assert;
-import org.testng.annotations.Test;
-
-import brooklyn.entity.Entity;
-import brooklyn.entity.basic.BasicEntity;
-import brooklyn.entity.basic.Entities;
-import brooklyn.entity.proxy.ProxySslConfig;
-import brooklyn.test.entity.TestEntity;
-import brooklyn.util.task.Tasks;
-
-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: brooklyn.entity.proxy.ProxySslConfig",
- " 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 ProxySslConfig, "Should have found a ProxySslConfig: " + 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: brooklyn.entity.proxy.ProxySslConfig",
- " 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 ProxySslConfig, "Should have found a ProxySslConfig: " + 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/incubator-brooklyn/blob/e406d1ad/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/ObjectsYamlTest.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/ObjectsYamlTest.java b/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/ObjectsYamlTest.java
deleted file mode 100644
index 6f5a968..0000000
--- a/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/ObjectsYamlTest.java
+++ /dev/null
@@ -1,280 +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 io.brooklyn.camp.brooklyn;
-
-import java.util.List;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.testng.Assert;
-import org.testng.annotations.Test;
-
-import brooklyn.config.ConfigKey;
-import brooklyn.config.ConfigKey.HasConfigKey;
-import brooklyn.entity.Entity;
-import brooklyn.entity.basic.ConfigKeys;
-import brooklyn.entity.basic.Entities;
-import brooklyn.entity.proxy.ProxySslConfig;
-import brooklyn.entity.trait.Configurable;
-import brooklyn.management.ManagementContext;
-import brooklyn.management.ManagementContextInjectable;
-import brooklyn.management.Task;
-import brooklyn.test.entity.TestEntity;
-import brooklyn.util.config.ConfigBag;
-import brooklyn.util.flags.SetFromFlag;
-import brooklyn.util.flags.TypeCoercions;
-
-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 injectManagementContext(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 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: io.brooklyn.camp.brooklyn.ObjectsYamlTest$TestObject",
- " object.fields:",
- " number: 7",
- " object:",
- " $brooklyn:object:",
- " type: brooklyn.entity.proxy.ProxySslConfig",
- " 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 ProxySslConfig, "Expected a ProxySslConfig: "+testObjectObject);
- }
-
- @Test
- public void testBrooklynConfigurableObject() throws Exception {
- Entity testEntity = setupAndCheckTestEntityInBasicYamlWith(
- " brooklyn.config:",
- " test.confObject:",
- " $brooklyn:object:",
- " type: io.brooklyn.camp.brooklyn.ObjectsYamlTest$ConfigurableObject",
- " object.fields:",
- " double: 1.4",
- " brooklyn.config:",
- " flag: frog",
- " config.number: 7",
- " object:",
- " $brooklyn:object:",
- " type: brooklyn.entity.proxy.ProxySslConfig");
-
- 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 ProxySslConfig, "Expected a ProxySslConfig: "+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: brooklyn.entity.proxy.ProxySslConfig",
- " - $brooklyn:object:",
- " object_type: brooklyn.entity.proxy.ProxySslConfig",
- " - $brooklyn:object:",
- " type: brooklyn.entity.proxy.ProxySslConfig");
-
- List<?> testList = testEntity.getConfig(TestEntity.CONF_LIST_PLAIN);
-
- Assert.assertEquals(testList.size(), 3);
- for (Object entry : testList) {
- Assert.assertTrue(entry instanceof ProxySslConfig, "Expected a ProxySslConfig: "+entry);
- }
- }
-
- @Test
- public void testBrooklynObjectWithFunction() throws Exception {
- Entity testEntity = setupAndCheckTestEntityInBasicYamlWith(
- " brooklyn.config:",
- " test.confObject:",
- " $brooklyn:object:",
- " type: io.brooklyn.camp.brooklyn.ObjectsYamlTest$TestObject",
- " object.fields:",
- " number: 7",
- " object:",
- " $brooklyn:object:",
- " type: brooklyn.entity.proxy.ProxySslConfig",
- " 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 ProxySslConfig, "Expected a ProxySslConfig: "+testObjectObject);
- }
-
- @Override
- protected Logger getLogger() {
- return log;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e406d1ad/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/PoliciesYamlTest.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/PoliciesYamlTest.java b/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/PoliciesYamlTest.java
deleted file mode 100644
index 7ca9602..0000000
--- a/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/PoliciesYamlTest.java
+++ /dev/null
@@ -1,215 +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 io.brooklyn.camp.brooklyn;
-
-import java.util.Map;
-import java.util.concurrent.Callable;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.testng.Assert;
-import org.testng.annotations.Test;
-
-import brooklyn.config.ConfigKey;
-import brooklyn.entity.Entity;
-import brooklyn.entity.basic.Entities;
-import brooklyn.entity.basic.EntityInternal;
-import brooklyn.policy.Policy;
-import brooklyn.test.Asserts;
-import brooklyn.test.entity.TestEntity;
-import brooklyn.test.policy.TestPolicy;
-import brooklyn.util.collections.MutableMap;
-
-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.getPolicies().size(), 1);
- Policy policy = app.getPolicies().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.getPolicies().size(), 0);
- Assert.assertEquals(app.getChildren().size(), 1);
- Entity child = app.getChildren().iterator().next();
- Assert.assertEquals(child.getPolicies().size(), 1);
- Policy policy = child.getPolicies().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: brooklyn.test.entity.TestEntity",
- " name: Child Entity",
- " brooklyn.policies:",
- " - policyType: brooklyn.test.policy.TestPolicy",
- " brooklyn.config:",
- " test.confName: Name from YAML",
- " test.attributeSensor: $brooklyn:sensor(\"brooklyn.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.getPolicies().size(), 0);
- Assert.assertEquals(firstEntity.getPolicies().size(), 0);
-
- Asserts.eventually(new Supplier<Integer>() {
- @Override
- public Integer get() {
- return child.getPolicies().size();
- }
- }, Predicates.<Integer> equalTo(1));
-
- Policy policy = child.getPolicies().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.getPolicies().size(), 1);
- Policy policy = entity.getPolicies().iterator().next();
- Assert.assertTrue(policy instanceof TestReferencingPolicy);
- return policy;
- }
-
- @Override
- protected Logger getLogger() {
- return log;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e406d1ad/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/ReferencedYamlTest.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/ReferencedYamlTest.java b/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/ReferencedYamlTest.java
deleted file mode 100644
index 6c10779..0000000
--- a/usage/camp/src/test/java/io/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 io.brooklyn.camp.brooklyn;
-
-import java.util.Collection;
-
-import org.apache.brooklyn.test.TestResourceUnavailableException;
-import org.testng.Assert;
-import org.testng.annotations.Test;
-
-import brooklyn.entity.Entity;
-import brooklyn.entity.basic.BasicApplication;
-import brooklyn.entity.basic.BasicEntity;
-import brooklyn.management.osgi.OsgiStandaloneTest;
-
-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");
-
- checkChildEntitySpec(app, "service");
- }
-
- @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: brooklyn.entity.basic.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: brooklyn.entity.basic.BasicEntity",
- " brooklyn.children:",
- " - type: classpath://yaml-ref-entity.yaml");
-
- checkGrandchildEntitySpec(createAndStartApplication, "service");
- }
-
- @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: brooklyn.entity.basic.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(), "brooklyn.osgi.tests.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/incubator-brooklyn/blob/e406d1ad/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/ReferencingYamlTestEntity.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/ReferencingYamlTestEntity.java b/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/ReferencingYamlTestEntity.java
deleted file mode 100644
index 02d778a..0000000
--- a/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/ReferencingYamlTestEntity.java
+++ /dev/null
@@ -1,66 +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 io.brooklyn.camp.brooklyn;
-
-import brooklyn.config.ConfigKey;
-import brooklyn.entity.Entity;
-import brooklyn.entity.proxying.ImplementedBy;
-import brooklyn.event.basic.BasicConfigKey;
-
-import com.google.common.reflect.TypeToken;
-
-@ImplementedBy(ReferencingYamlTestEntityImpl.class)
-public interface ReferencingYamlTestEntity extends Entity {
- @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/incubator-brooklyn/blob/e406d1ad/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/ReferencingYamlTestEntityImpl.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/ReferencingYamlTestEntityImpl.java b/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/ReferencingYamlTestEntityImpl.java
deleted file mode 100644
index 1bf83f4..0000000
--- a/usage/camp/src/test/java/io/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 io.brooklyn.camp.brooklyn;
-
-import brooklyn.entity.basic.AbstractApplication;
-
-public class ReferencingYamlTestEntityImpl extends AbstractApplication implements ReferencingYamlTestEntity {
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e406d1ad/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/ReloadBrooklynPropertiesTest.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/ReloadBrooklynPropertiesTest.java b/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/ReloadBrooklynPropertiesTest.java
deleted file mode 100644
index a049de4..0000000
--- a/usage/camp/src/test/java/io/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 io.brooklyn.camp.brooklyn;
-
-import io.brooklyn.camp.CampPlatform;
-import io.brooklyn.camp.spi.Assembly;
-import io.brooklyn.camp.spi.AssemblyTemplate;
-
-import java.io.Reader;
-
-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;
-
-import brooklyn.entity.Entity;
-import brooklyn.entity.basic.Entities;
-import brooklyn.entity.trait.Startable;
-import brooklyn.management.ManagementContext;
-import brooklyn.test.EntityTestUtils;
-import brooklyn.util.ResourceUtils;
-import brooklyn.util.exceptions.Exceptions;
-import brooklyn.util.stream.Streams;
-
-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/incubator-brooklyn/blob/e406d1ad/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/TestEntityWithInitConfig.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/TestEntityWithInitConfig.java b/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/TestEntityWithInitConfig.java
deleted file mode 100644
index 1028859..0000000
--- a/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/TestEntityWithInitConfig.java
+++ /dev/null
@@ -1,35 +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 io.brooklyn.camp.brooklyn;
-
-import brooklyn.config.ConfigKey;
-import brooklyn.entity.Entity;
-import brooklyn.entity.basic.EntityInternal;
-import brooklyn.entity.basic.EntityLocal;
-import brooklyn.entity.proxying.ImplementedBy;
-import brooklyn.entity.trait.Startable;
-import brooklyn.event.basic.BasicConfigKey;
-
-@ImplementedBy(TestEntityWithInitConfigImpl.class)
-public interface TestEntityWithInitConfig extends Entity, Startable, EntityLocal, 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/incubator-brooklyn/blob/e406d1ad/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/TestEntityWithInitConfigImpl.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/TestEntityWithInitConfigImpl.java b/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/TestEntityWithInitConfigImpl.java
deleted file mode 100644
index 0cd516f..0000000
--- a/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/TestEntityWithInitConfigImpl.java
+++ /dev/null
@@ -1,59 +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 io.brooklyn.camp.brooklyn;
-
-import java.util.Collection;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import brooklyn.entity.Entity;
-import brooklyn.entity.basic.AbstractEntity;
-import brooklyn.location.Location;
-
-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/incubator-brooklyn/blob/e406d1ad/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/TestReferencingEnricher.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/TestReferencingEnricher.java b/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/TestReferencingEnricher.java
deleted file mode 100644
index 5a95eb8..0000000
--- a/usage/camp/src/test/java/io/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 io.brooklyn.camp.brooklyn;
-
-import brooklyn.config.ConfigKey;
-import brooklyn.enricher.basic.AbstractEnricher;
-import brooklyn.entity.Entity;
-import brooklyn.event.basic.BasicConfigKey;
-
-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/incubator-brooklyn/blob/e406d1ad/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/TestReferencingPolicy.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/TestReferencingPolicy.java b/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/TestReferencingPolicy.java
deleted file mode 100644
index 1050402..0000000
--- a/usage/camp/src/test/java/io/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 io.brooklyn.camp.brooklyn;
-
-import brooklyn.config.ConfigKey;
-import brooklyn.entity.Entity;
-import brooklyn.event.basic.BasicConfigKey;
-import brooklyn.policy.basic.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/incubator-brooklyn/blob/e406d1ad/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/TestSensorAndEffectorInitializer.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/TestSensorAndEffectorInitializer.java b/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/TestSensorAndEffectorInitializer.java
deleted file mode 100644
index 4e42d8d..0000000
--- a/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/TestSensorAndEffectorInitializer.java
+++ /dev/null
@@ -1,86 +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 io.brooklyn.camp.brooklyn;
-
-import java.util.Map;
-
-import org.testng.Assert;
-
-import com.google.common.base.Preconditions;
-
-import brooklyn.entity.Effector;
-import brooklyn.entity.basic.EntityInternal;
-import brooklyn.entity.basic.EntityLocal;
-import brooklyn.entity.effector.EffectorBody;
-import brooklyn.entity.effector.Effectors;
-import brooklyn.entity.proxying.EntityInitializer;
-import brooklyn.event.AttributeSensor;
-import brooklyn.event.basic.Sensors;
-import brooklyn.util.config.ConfigBag;
-
-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"; }
-
- @Override
- 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().setAttribute(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.setAttribute(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/incubator-brooklyn/blob/e406d1ad/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/VanillaBashNetcatYamlTest.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/VanillaBashNetcatYamlTest.java b/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/VanillaBashNetcatYamlTest.java
deleted file mode 100644
index dd1b647..0000000
--- a/usage/camp/src/test/java/io/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 io.brooklyn.camp.brooklyn;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.testng.Assert;
-import org.testng.annotations.Test;
-
-import brooklyn.entity.Effector;
-import brooklyn.entity.Entity;
-import brooklyn.entity.basic.Attributes;
-import brooklyn.entity.basic.Entities;
-import brooklyn.entity.basic.EntityPredicates;
-import brooklyn.entity.basic.Lifecycle;
-import brooklyn.entity.effector.Effectors;
-import brooklyn.event.AttributeSensor;
-import brooklyn.event.basic.Sensors;
-import brooklyn.management.Task;
-import brooklyn.test.EntityTestUtils;
-import brooklyn.util.collections.MutableMap;
-import brooklyn.util.net.Networking;
-import brooklyn.util.text.StringPredicates;
-
-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;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e406d1ad/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/WrapAppTest.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/WrapAppTest.java b/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/WrapAppTest.java
deleted file mode 100644
index b2db240..0000000
--- a/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/WrapAppTest.java
+++ /dev/null
@@ -1,93 +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 io.brooklyn.camp.brooklyn;
-
-import java.io.StringReader;
-
-import org.testng.Assert;
-import org.testng.annotations.Test;
-
-import brooklyn.entity.basic.StartableApplication;
-
-public class WrapAppTest extends AbstractYamlTest {
- private static final String NO_WRAP_APP_IMPLICIT =
- "name: Empty App\n" +
- "services:\n" +
- " - type: brooklyn.test.entity.TestApplication";
-
- private static final String NO_WRAP_APP_EXPLICIT =
- "name: Empty App\n" +
- "wrappedApp: false\n" +
- "services:\n" +
- " - type: brooklyn.test.entity.TestApplication";
-
- private static final String WRAP_APP_IMPLICIT =
- "name: Empty App\n" +
- "services:\n" +
- " - type: brooklyn.test.entity.TestApplication\n" +
- " - type: brooklyn.test.entity.TestApplication";
-
- private static final String WRAP_APP_EXPLICIT =
- "name: Empty App\n" +
- "wrappedApp: true\n" +
- "services:\n" +
- " - type: brooklyn.test.entity.TestApplication";
-
- private static final String WRAP_ENTITY =
- "name: Empty App\n" +
- "services:\n" +
- " - type: brooklyn.test.entity.TestEntity";
-
- @Test
- public void testNoWrapAppImplicit() throws Exception {
- StartableApplication app = createApp(NO_WRAP_APP_IMPLICIT);
- Assert.assertTrue(app.getChildren().size() == 0);
- }
-
- @Test
- public void testNoWrapAppExplicit() throws Exception {
- StartableApplication app = createApp(NO_WRAP_APP_EXPLICIT);
- Assert.assertTrue(app.getChildren().size() == 0);
- }
-
- @Test
- public void testWrapAppImplicit() throws Exception {
- StartableApplication app = createApp(WRAP_APP_IMPLICIT);
- Assert.assertTrue(app.getChildren().size() == 2);
- }
-
- @Test
- public void testWrapAppExplicit() throws Exception {
- StartableApplication app = createApp(WRAP_APP_EXPLICIT);
- Assert.assertTrue(app.getChildren().size() == 1);
- }
-
- @Test
- public void testWrapEntity() throws Exception {
- StartableApplication app = createApp(WRAP_ENTITY);
- Assert.assertTrue(app.getChildren().size() == 1);
- }
-
- private StartableApplication createApp(String yaml) throws Exception {
- StringReader in = new StringReader(yaml);
- StartableApplication app = (StartableApplication)createAndStartApplication(in);
- in.close();
- return app;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/e406d1ad/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/catalog/AbstractCatalogXmlTest.java
----------------------------------------------------------------------
diff --git a/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/catalog/AbstractCatalogXmlTest.java b/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/catalog/AbstractCatalogXmlTest.java
deleted file mode 100644
index 3110f43..0000000
--- a/usage/camp/src/test/java/io/brooklyn/camp/brooklyn/catalog/AbstractCatalogXmlTest.java
+++ /dev/null
@@ -1,109 +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 io.brooklyn.camp.brooklyn.catalog;
-
-import org.apache.brooklyn.test.TestResourceUnavailableException;
-import io.brooklyn.camp.brooklyn.AbstractYamlTest;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.StringReader;
-
-import brooklyn.config.BrooklynProperties;
-import brooklyn.config.BrooklynServerConfig;
-import brooklyn.entity.Entity;
-import brooklyn.management.internal.LocalManagementContext;
-import brooklyn.management.osgi.OsgiTestResources;
-import brooklyn.test.entity.LocalManagementContextForTests;
-import brooklyn.util.ResourceUtils;
-import brooklyn.util.exceptions.Exceptions;
-import brooklyn.util.os.Os;
-import brooklyn.util.stream.ReaderInputStream;
-import brooklyn.util.stream.Streams;
-
-import com.google.common.io.ByteStreams;
-
-public class AbstractCatalogXmlTest extends AbstractYamlTest {
-
- private String catalogUrl;
-
- public AbstractCatalogXmlTest(String catalogUrl) {
- this.catalogUrl = catalogUrl;
- }
-
- @Override
- protected LocalManagementContext newTestManagementContext() {
- ResourceUtils ru = new ResourceUtils(this);
- File jar = createJar(ru);
- File catalog = createCatalog(ru, jar);
-
- BrooklynProperties properties = BrooklynProperties.Factory.newEmpty();
- properties.put(BrooklynServerConfig.BROOKLYN_CATALOG_URL, catalog.toURI().toString());
- return LocalManagementContextForTests.builder(true)
- .useProperties(properties)
- .disableOsgi(false)
- .build();
- }
-
- protected Entity startApp(String type) throws Exception {
- String yaml = "name: simple-app-yaml\n" +
- "location: localhost\n" +
- "services: \n" +
- " - type: " + type;
- return createAndStartApplication(yaml);
- }
-
- private File createCatalog(ResourceUtils ru, File tmpJar) {
- String catalogTemplate = ru.getResourceAsString(catalogUrl);
- String catalog = catalogTemplate.replace("${osgi-entities-path}", tmpJar.toURI().toString());
- File catalogTmp = Os.newTempFile("simple-catalog-", ".xml");
- copy(catalog, catalogTmp);
- return catalogTmp;
- }
-
- private File createJar(ResourceUtils ru) {
- TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_PATH);
- File tmpJar = Os.newTempFile("osgi-entities-", ".jar");
- InputStream in = ru.getResourceFromUrl("classpath://" + OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_PATH);
- copy(in, tmpJar);
- return tmpJar;
- }
-
- private void copy(String src, File dst) {
- try {
- copy(new ReaderInputStream(new StringReader(src), "UTF-8"), dst);
- } catch (Exception e) {
- throw Exceptions.propagate(e);
- }
- }
-
- private void copy(InputStream in, File tmpJar) {
- try {
- OutputStream out = new FileOutputStream(tmpJar);
- ByteStreams.copy(in, out);
- Streams.closeQuietly(in);
- Streams.closeQuietly(out);
- } catch (Exception e) {
- throw Exceptions.propagate(e);
- }
- }
-
-}