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/catalog/CatalogYamlTemplateTest.java ---------------------------------------------------------------------- diff --git a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlTemplateTest.java b/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlTemplateTest.java deleted file mode 100644 index d83711c..0000000 --- a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlTemplateTest.java +++ /dev/null @@ -1,282 +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.catalog; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; - -import java.util.List; - -import org.apache.brooklyn.api.entity.Application; -import org.apache.brooklyn.api.entity.Entity; -import org.apache.brooklyn.api.entity.EntitySpec; -import org.apache.brooklyn.api.typereg.RegisteredType; -import org.apache.brooklyn.camp.brooklyn.AbstractYamlTest; -import org.apache.brooklyn.core.entity.Entities; -import org.apache.brooklyn.core.mgmt.BrooklynTags; -import org.apache.brooklyn.core.mgmt.BrooklynTags.NamedStringTag; -import org.apache.brooklyn.core.mgmt.EntityManagementUtils; -import org.apache.brooklyn.core.mgmt.osgi.OsgiStandaloneTest; -import org.apache.brooklyn.core.test.entity.TestEntity; -import org.apache.brooklyn.core.typereg.RegisteredTypePredicates; -import org.apache.brooklyn.core.typereg.RegisteredTypes; -import org.apache.brooklyn.entity.group.DynamicCluster; -import org.apache.brooklyn.entity.stock.BasicApplication; -import org.apache.brooklyn.test.Asserts; -import org.apache.brooklyn.test.support.TestResourceUnavailableException; -import org.apache.brooklyn.util.core.config.ConfigBag; -import org.apache.brooklyn.util.osgi.OsgiTestResources; -import org.testng.Assert; -import org.testng.TestListenerAdapter; -import org.testng.TestNG; -import org.testng.annotations.Test; - -import com.google.common.collect.Iterables; - - -public class CatalogYamlTemplateTest extends AbstractYamlTest { - - private static final String SIMPLE_ENTITY_TYPE = OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_SIMPLE_ENTITY; - - @Test - public void testAddCatalogItem() throws Exception { - RegisteredType item = makeItem(); - Assert.assertTrue(RegisteredTypePredicates.IS_APPLICATION.apply(item), "item: "+item); - String yaml = RegisteredTypes.getImplementationDataStringForSpec(item); - Assert.assertTrue(yaml.indexOf("sample comment")>=0, - "YAML did not include original comments; it was:\n"+yaml); - Assert.assertFalse(yaml.indexOf("description")>=0, - "YAML included metadata which should have been excluded; it was:\n"+yaml); - - deleteCatalogEntity("t1"); - } - - @Test - public void testAddCatalogItemAndCheckSource() throws Exception { - // this will fail with the Eclipse TestNG plugin -- use the static main instead to run in eclipse! - // see Yamls.KnownClassVersionException for details - - RegisteredType item = makeItem(); - String yaml = RegisteredTypes.getImplementationDataStringForSpec(item); - Assert.assertTrue(yaml.indexOf("sample comment")>=0, - "YAML did not include original comments; it was:\n"+yaml); - Assert.assertFalse(yaml.indexOf("description")>=0, - "YAML included metadata which should have been excluded; it was:\n"+yaml); - - deleteCatalogEntity("t1"); - } - - public void testServiceTypeEntityOfTypeCatalogTemplateNotWrapped() throws Exception { - addCatalogItems( - "brooklyn.catalog:", - " id: t1", - " item_type: template", - " name: myT1", - " item:", - " services:", - " - type: " + TestEntity.class.getName()); - addCatalogItems( - "brooklyn.catalog:", - " id: t2", - " item_type: template", - " name: myT2", - " item:", - " services:", - " - type: t1", - " - type: t1"); - - Entity app = createAndStartApplication( - "services:", - "- type: t2"); - waitForApplicationTasks(app); - - Entities.dumpInfo(app); - Entity t1a = Iterables.get(app.getChildren(), 0); - Entity t1b = Iterables.get(app.getChildren(), 1); - assertEquals(app.getChildren().size(), 2); - assertEquals(t1a.getChildren().size(), 0); - assertEquals(t1b.getChildren().size(), 0); - - assertTrue(app instanceof BasicApplication); - assertTrue(t1a instanceof TestEntity); - assertTrue(t1b instanceof TestEntity); - } - - @Test - public void testChildEntityOfTypeCatalogTemplateNotWrapped() throws Exception { - addCatalogItems( - "brooklyn.catalog:", - " id: t1", - " item_type: template", - " name: myT1", - " item:", - " services:", - " - type: " + TestEntity.class.getName()); - addCatalogItems( - "brooklyn.catalog:", - " id: t2", - " item_type: template", - " name: myT2", - " item:", - " services:", - " - type: " + TestEntity.class.getName(), - " brooklyn.children:", - " - type: t1"); - - Entity app = createAndStartApplication( - "services:", - "- type: t2"); - waitForApplicationTasks(app); - - Entities.dumpInfo(app); - Entity t2 = Iterables.getOnlyElement(app.getChildren()); - Entity t1 = Iterables.getOnlyElement(t2.getChildren()); - assertEquals(t1.getChildren().size(), 0); - - assertTrue(app instanceof BasicApplication); - assertTrue(t1 instanceof TestEntity); - assertTrue(t2 instanceof TestEntity); - } - - @Test - public void testMemberSpecEntityOfTypeCatalogTemplateNotWrapped() throws Exception { - addCatalogItems( - "brooklyn.catalog:", - " id: t1", - " item_type: template", - " name: myT1", - " item:", - " services:", - " - type: " + TestEntity.class.getName()); - addCatalogItems( - "brooklyn.catalog:", - " id: t2", - " item_type: template", - " name: myT2", - " item:", - " services:", - " - type: " + DynamicCluster.class.getName(), - " brooklyn.config:", - " memberSpec:", - " $brooklyn:entitySpec:", - " type: t1", - " cluster.initial.size: 1"); - - Entity app = createAndStartApplication( - "location: localhost", - "services:", - "- type: t2"); - waitForApplicationTasks(app); - - Entities.dumpInfo(app); - DynamicCluster t2 = (DynamicCluster) Iterables.getOnlyElement(app.getChildren()); - Entity t1 = Iterables.getOnlyElement(t2.getMembers()); - assertEquals(t1.getChildren().size(), 0); - - assertTrue(app instanceof BasicApplication); - assertTrue(t2 instanceof DynamicCluster); - assertTrue(t1 instanceof TestEntity); - } - - @Test - public void testMetadataOnSpecCreatedFromItem() throws Exception { - makeItem(); - EntitySpec<? extends Application> spec = EntityManagementUtils.createEntitySpecForApplication(mgmt(), - "services: [ { type: t1 } ]\n" + - "location: localhost"); - - List<NamedStringTag> yamls = BrooklynTags.findAll(BrooklynTags.YAML_SPEC_KIND, spec.getTags()); - Assert.assertEquals(yamls.size(), 1, "Expected 1 yaml tag; instead had: "+yamls); - String yaml = Iterables.getOnlyElement(yamls).getContents(); - Asserts.assertStringContains(yaml, "services:", "t1", "localhost"); - - EntitySpec<?> child = Iterables.getOnlyElement( spec.getChildren() ); - Assert.assertEquals(child.getType().getName(), SIMPLE_ENTITY_TYPE); - Assert.assertEquals(child.getCatalogItemId(), "t1:"+TEST_VERSION); - } - - @Test - public void testMetadataOnSpecCreatedFromItemReferencingAnApp() throws Exception { - // this nested ref to an app caused nested plan contents also to be recorded, - // due to how tags are merged. the *first* one is the most important, however, - // and ordering of tags should guarantee that. - // similarly ensure we get the right outermost non-null catalog item id. - addCatalogItems( - "brooklyn.catalog:", - " version: '1'", - " items:", - " - id: app1", - " name: myApp1", - " item:", - " type: org.apache.brooklyn.entity.stock.BasicApplication", - " brooklyn.config: { foo: bar }", - " - id: app1r", - " item_type: template", - " item:", - " services:", - " - type: app1", - " brooklyn.config:", - " foo: boo" - ); - - EntitySpec<? extends Application> spec = EntityManagementUtils.createEntitySpecForApplication(mgmt(), - "services: [ { type: app1r } ]\n" + - "location: localhost"); - - List<NamedStringTag> yamls = BrooklynTags.findAll(BrooklynTags.YAML_SPEC_KIND, spec.getTags()); - Assert.assertTrue(yamls.size() >= 1, "Expected at least 1 yaml tag; instead had: "+yamls); - String yaml = yamls.iterator().next().getContents(); - Asserts.assertStringContains(yaml, "services:", "type: app1r", "localhost"); - - Assert.assertEquals(spec.getChildren().size(), 0); - Assert.assertEquals(spec.getType(), BasicApplication.class); - Assert.assertEquals(ConfigBag.newInstance(spec.getConfig()).getStringKey("foo"), "boo"); - Assert.assertEquals(spec.getCatalogItemId(), "app1r:1"); - } - - private RegisteredType makeItem() { - TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH); - - addCatalogItems( - "brooklyn.catalog:", - " id: t1", - " item_type: template", - " name: My Catalog App", - " description: My description", - " icon_url: classpath://path/to/myicon.jpg", - " version: " + TEST_VERSION, - " libraries:", - " - url: " + OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL, - " item:", - " services:", - " # this sample comment should be included", - " - type: " + SIMPLE_ENTITY_TYPE); - - return mgmt().getTypeRegistry().get("t1", TEST_VERSION); - } - - // convenience for running in eclipse when the TestNG plugin drags in old version of snake yaml - public static void main(String[] args) { - TestListenerAdapter tla = new TestListenerAdapter(); - TestNG testng = new TestNG(); - testng.setTestClasses(new Class[] { CatalogYamlTemplateTest.class }); - testng.addListener(tla); - testng.run(); - } -}
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/catalog/CatalogYamlVersioningTest.java ---------------------------------------------------------------------- diff --git a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlVersioningTest.java b/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlVersioningTest.java deleted file mode 100644 index 440c114..0000000 --- a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlVersioningTest.java +++ /dev/null @@ -1,269 +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.catalog; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertTrue; -import static org.testng.Assert.fail; - -import org.apache.brooklyn.api.entity.Entity; -import org.apache.brooklyn.api.typereg.BrooklynTypeRegistry; -import org.apache.brooklyn.api.typereg.RegisteredType; -import org.apache.brooklyn.camp.brooklyn.AbstractYamlTest; -import org.apache.brooklyn.core.catalog.internal.BasicBrooklynCatalog; -import org.apache.brooklyn.core.config.ConfigKeys; -import org.apache.brooklyn.core.typereg.RegisteredTypePredicates; -import org.apache.brooklyn.core.typereg.RegisteredTypes; -import org.apache.brooklyn.entity.stock.BasicApplication; -import org.apache.brooklyn.entity.stock.BasicEntity; -import org.testng.Assert; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import com.google.common.base.Predicates; -import com.google.common.collect.Iterables; - -public class CatalogYamlVersioningTest extends AbstractYamlTest { - - private BrooklynTypeRegistry types; - - @BeforeMethod(alwaysRun = true) - public void setUp() { - super.setUp(); - types = mgmt().getTypeRegistry(); - } - - @Test - public void testAddItem() { - String symbolicName = "sampleId"; - String version = "0.1.0"; - addCatalogEntity(symbolicName, version); - assertSingleCatalogItem(symbolicName, version); - } - - @Test - public void testAddUnversionedItem() { - String symbolicName = "sampleId"; - addCatalogEntity(symbolicName, null); - assertSingleCatalogItem(symbolicName, BasicBrooklynCatalog.NO_VERSION); - } - - @Test - public void testAddSameVersionFailsWhenIconIsDifferent() { - String symbolicName = "sampleId"; - String version = "0.1.0"; - addCatalogEntity(symbolicName, version); - addCatalogEntity(symbolicName, version); - try { - addCatalogEntity(symbolicName, version, BasicEntity.class.getName(), "classpath:/another/icon.png"); - fail("Expected to fail"); - } catch (IllegalStateException e) { - assertEquals(e.getMessage(), "Updating existing catalog entries is forbidden: " + symbolicName + ":" + version + ". Use forceUpdate argument to override."); - } - } - - @Test - public void testAddSameVersionForce() { - String symbolicName = "sampleId"; - String version = "0.1.0"; - addCatalogEntity(symbolicName, version); - forceCatalogUpdate(); - String expectedType = "org.apache.brooklyn.entity.stock.BasicApplication"; - addCatalogEntity(symbolicName, version, expectedType); - RegisteredType item = types.get(symbolicName, version); - String yaml = RegisteredTypes.getImplementationDataStringForSpec(item); - assertTrue(yaml.contains(expectedType), "Version not updated:\n"+yaml); - } - - @Test - public void testGetLatest() { - String symbolicName = "sampleId"; - String v1 = "0.1.0"; - String v2 = "0.2.0"; - addCatalogEntity(symbolicName, v1); - addCatalogEntity(symbolicName, v2); - RegisteredType item = types.get(symbolicName, BasicBrooklynCatalog.DEFAULT_VERSION); - assertEquals(item.getVersion(), v2); - } - - @Test - public void testGetLatestStable() { - String symbolicName = "sampleId"; - String v1 = "0.1.0"; - String v2 = "0.2.0-SNAPSHOT"; - addCatalogEntity(symbolicName, v1); - addCatalogEntity(symbolicName, v2); - RegisteredType item = types.get(symbolicName, BasicBrooklynCatalog.DEFAULT_VERSION); - assertEquals(item.getVersion(), v1); - } - - @Test - public void testDelete() { - String symbolicName = "sampleId"; - String version = "0.1.0"; - addCatalogEntity(symbolicName, version); - - Iterable<RegisteredType> matches; - matches = types.getMatching(RegisteredTypePredicates.symbolicName(Predicates.equalTo(symbolicName))); - assertTrue(matches.iterator().hasNext()); - - mgmt().getCatalog().deleteCatalogItem(symbolicName, version); - matches = types.getMatching(RegisteredTypePredicates.symbolicName(Predicates.equalTo(symbolicName))); - assertFalse(matches.iterator().hasNext()); - } - - @Test - public void testDeleteDefault() { - String symbolicName = "sampleId"; - addCatalogEntity(symbolicName, null); - - Iterable<RegisteredType> matches; - matches = types.getMatching(RegisteredTypePredicates.symbolicName(Predicates.equalTo(symbolicName))); - assertTrue(matches.iterator().hasNext()); - - mgmt().getCatalog().deleteCatalogItem(symbolicName, BasicBrooklynCatalog.NO_VERSION); - matches = types.getMatching(RegisteredTypePredicates.symbolicName(Predicates.equalTo(symbolicName))); - assertFalse(matches.iterator().hasNext()); - } - - @Test - public void testList() { - String symbolicName = "sampleId"; - String v1 = "0.1.0"; - String v2 = "0.2.0-SNAPSHOT"; - addCatalogEntity(symbolicName, v1); - addCatalogEntity(symbolicName, v2); - Iterable<RegisteredType> items = types.getMatching(RegisteredTypePredicates.symbolicName(Predicates.equalTo(symbolicName))); - assertEquals(Iterables.size(items), 2); - } - - @Test - public void testVersionedReference() throws Exception { - String symbolicName = "sampleId"; - String parentName = "parentId"; - String v1 = "0.1.0"; - String v2 = "0.2.0"; - String expectedType = BasicApplication.class.getName(); - - addCatalogEntity(symbolicName, v1, expectedType); - addCatalogEntity(symbolicName, v2); - addCatalogEntity(parentName, v1, symbolicName + ":" + v1); - - Entity app = createAndStartApplication( - "services:", - "- type: " + parentName + ":" + v1); - - assertEquals(app.getEntityType().getName(), expectedType); - } - - @Test - public void testUnversionedReference() throws Exception { - String symbolicName = "sampleId"; - String parentName = "parentId"; - String v1 = "0.1.0"; - String v2 = "0.2.0"; - String expectedType = BasicApplication.class.getName(); - - addCatalogEntity(symbolicName, v1); - addCatalogEntity(symbolicName, v2, expectedType); - addCatalogEntity(parentName, v1, symbolicName); - - Entity app = createAndStartApplication( - "services:", - "- type: " + parentName + ":" + v1); - - assertEquals(app.getEntityType().getName(), expectedType); - } - - private void doTestVersionedReferenceJustAdded(boolean isVersionImplicitSyntax) throws Exception { - addCatalogItems( "brooklyn.catalog:", - " version: 0.9", - " items:", - " - id: referrent", - " item:", - " type: "+BasicEntity.class.getName(), - " - id: referrent", - " version: 1.1", - " item:", - " type: "+BasicEntity.class.getName(), - " brooklyn.config: { foo: bar }", - " - id: referrer", - " version: 1.0", - " item:", - (isVersionImplicitSyntax ? - " type: referrent:1.1" : - " type: referrent\n" + - " version: 1.1")); - - Iterable<RegisteredType> items = types.getMatching(RegisteredTypePredicates.symbolicName(Predicates.equalTo("referrer"))); - Assert.assertEquals(Iterables.size(items), 1, "Wrong number of: "+items); - RegisteredType item = Iterables.getOnlyElement(items); - Assert.assertEquals(item.getVersion(), "1.0"); - - Entity app = createAndStartApplication( - "services:", - (isVersionImplicitSyntax ? - "- type: referrer:1.0" : - "- type: referrer\n" + - " version: 1.0") ); - Entity child = Iterables.getOnlyElement(app.getChildren()); - Assert.assertTrue(child instanceof BasicEntity, "Wrong child: "+child); - Assert.assertEquals(child.getConfig(ConfigKeys.newStringConfigKey("foo")), "bar"); - } - - @Test - public void testVersionedReferenceJustAddedExplicitVersion() throws Exception { - doTestVersionedReferenceJustAdded(false); - } - - @Test - public void testVersionedReferenceJustAddedImplicitVersionSyntax() throws Exception { - doTestVersionedReferenceJustAdded(true); - } - - private void assertSingleCatalogItem(String symbolicName, String version) { - Iterable<RegisteredType> items = types.getMatching(RegisteredTypePredicates.symbolicName(Predicates.equalTo(symbolicName))); - RegisteredType item = Iterables.getOnlyElement(items); - assertEquals(item.getSymbolicName(), symbolicName); - assertEquals(item.getVersion(), version); - } - - private void addCatalogEntity(String symbolicName, String version) { - addCatalogEntity(symbolicName, version, BasicEntity.class.getName()); - } - - private void addCatalogEntity(String symbolicName, String version, String type) { - addCatalogEntity(symbolicName, version, type, "classpath://path/to/myicon.jpg"); - } - - private void addCatalogEntity(String symbolicName, String version, String type, String iconUrl) { - addCatalogItems( - "brooklyn.catalog:", - " id: " + symbolicName, - " name: My Catalog App", - " description: My description", - " icon_url: "+iconUrl, - (version != null ? " version: " + version : ""), - "", - "services:", - "- type: " + type); - } - -} 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/catalog/SpecParameterParsingTest.java ---------------------------------------------------------------------- diff --git a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/SpecParameterParsingTest.java b/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/SpecParameterParsingTest.java deleted file mode 100644 index 869ebc0..0000000 --- a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/SpecParameterParsingTest.java +++ /dev/null @@ -1,156 +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.catalog; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertTrue; - -import java.util.List; - -import org.apache.brooklyn.api.catalog.CatalogItem; -import org.apache.brooklyn.api.entity.EntitySpec; -import org.apache.brooklyn.api.internal.AbstractBrooklynObjectSpec; -import org.apache.brooklyn.api.objs.SpecParameter; -import org.apache.brooklyn.api.typereg.RegisteredType; -import org.apache.brooklyn.camp.brooklyn.AbstractYamlTest; -import org.apache.brooklyn.entity.stock.BasicApplication; -import org.apache.brooklyn.test.support.TestResourceUnavailableException; -import org.apache.brooklyn.util.osgi.OsgiTestResources; -import org.testng.Assert; -import org.testng.annotations.Test; - -import com.google.common.base.Function; -import com.google.common.base.Joiner; -import com.google.common.collect.Iterables; -import com.google.common.reflect.TypeToken; - -public class SpecParameterParsingTest extends AbstractYamlTest { - - @Test - public void testYamlInputsParsed() { - String itemId = add( - "brooklyn.catalog:", - " id: test.inputs", - " version: 0.0.1", - " item: ", - " type: "+ BasicApplication.class.getName(), - " brooklyn.parameters:", - " - simple", - " - name: explicit_name", - " - name: third_input", - " type: integer"); - EntitySpec<?> item = mgmt().getTypeRegistry().createSpec(mgmt().getTypeRegistry().get(itemId), null, EntitySpec.class); - List<SpecParameter<?>> inputs = item.getParameters(); - assertEquals(inputs.size(), 3); - SpecParameter<?> firstInput = inputs.get(0); - assertEquals(firstInput.getLabel(), "simple"); - assertEquals(firstInput.isPinned(), true); - assertEquals(firstInput.getConfigKey().getName(), "simple"); - assertEquals(firstInput.getConfigKey().getTypeToken(), TypeToken.of(String.class)); - - SpecParameter<?> secondInput = inputs.get(1); - assertEquals(secondInput.getLabel(), "explicit_name"); - assertEquals(secondInput.isPinned(), true); - assertEquals(secondInput.getConfigKey().getName(), "explicit_name"); - assertEquals(secondInput.getConfigKey().getTypeToken(), TypeToken.of(String.class)); - - SpecParameter<?> thirdInput = inputs.get(2); - assertEquals(thirdInput.getLabel(), "third_input"); - assertEquals(thirdInput.isPinned(), true); - assertEquals(thirdInput.getConfigKey().getName(), "third_input"); - assertEquals(thirdInput.getConfigKey().getTypeToken(), TypeToken.of(Integer.class)); - } - - @Test - public void testOsgiType() { - TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_PATH); - - String itemId = add( - "brooklyn.catalog:", - " id: test.inputs", - " version: 0.0.1", - " libraries:", - " - classpath://" + OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_PATH, - " item: ", - " type: "+ BasicApplication.class.getName(), - " brooklyn.parameters:", - " - name: simple", - " type: " + OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_SIMPLE_ENTITY); - AbstractBrooklynObjectSpec<?,?> spec = createSpec(itemId); - List<SpecParameter<?>> inputs = spec.getParameters(); - assertEquals(inputs.size(), 1); - SpecParameter<?> firstInput = inputs.get(0); - assertEquals(firstInput.getLabel(), "simple"); - assertTrue(firstInput.isPinned()); - assertEquals(firstInput.getConfigKey().getName(), "simple"); - assertEquals(firstInput.getConfigKey().getTypeToken().getRawType().getName(), OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_SIMPLE_ENTITY); - } - - @Test - public void testOsgiClassScanned() { - TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_PATH); - TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiTestResources.BROOKLYN_TEST_MORE_ENTITIES_V2_PATH); - - addMulti("brooklyn.catalog:", - " items:", - " - scanJavaAnnotations: true", - " version: 2.0.test_java", - " libraries:", - " - classpath://" + OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_PATH, - " - classpath://" + OsgiTestResources.BROOKLYN_TEST_MORE_ENTITIES_V2_PATH); - - RegisteredType item = mgmt().getTypeRegistry().get(OsgiTestResources.BROOKLYN_TEST_MORE_ENTITIES_MORE_ENTITY); - assertEquals(item.getVersion(), "2.0.test_java"); - assertEquals(item.getLibraries().size(), 2); - AbstractBrooklynObjectSpec<?,?> spec = createSpec(item); - List<SpecParameter<?>> inputs = spec.getParameters(); - if (inputs.isEmpty()) Assert.fail("no inputs (if you're in the IDE, mvn clean install may need to be run to rebuild osgi test JARs)"); - assertEquals(inputs.size(), 1); - SpecParameter<?> input = inputs.get(0); - assertEquals(input.getLabel(), "more_config"); - assertFalse(input.isPinned()); - assertEquals(input.getConfigKey().getName(), "more_config"); - } - - private String add(String... def) { - return Iterables.getOnlyElement(addMulti(def)); - } - - private Iterable<String> addMulti(String... def) { - return Iterables.transform(catalog.addItems(Joiner.on('\n').join(def)), - new Function<CatalogItem<?,?>, String>() { - @Override - public String apply(CatalogItem<?, ?> input) { - return input.getId(); - } - }); - } - - private AbstractBrooklynObjectSpec<?, ?> createSpec(String itemId) { - RegisteredType item = mgmt().getTypeRegistry().get(itemId); - Assert.assertNotNull(item, "Could not load: "+itemId); - return createSpec(item); - } - - private AbstractBrooklynObjectSpec<?, ?> createSpec(RegisteredType item) { - return mgmt().getTypeRegistry().createSpec(item, null, EntitySpec.class); - } - -} 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/catalog/SpecParameterUnwrappingTest.java ---------------------------------------------------------------------- diff --git a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/SpecParameterUnwrappingTest.java b/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/SpecParameterUnwrappingTest.java deleted file mode 100644 index 1f7ba48..0000000 --- a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/SpecParameterUnwrappingTest.java +++ /dev/null @@ -1,379 +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.catalog; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; - -import java.util.Iterator; -import java.util.List; - -import org.apache.brooklyn.api.catalog.CatalogItem; -import org.apache.brooklyn.api.entity.Application; -import org.apache.brooklyn.api.entity.Entity; -import org.apache.brooklyn.api.entity.EntitySpec; -import org.apache.brooklyn.api.internal.AbstractBrooklynObjectSpec; -import org.apache.brooklyn.api.objs.BrooklynObject; -import org.apache.brooklyn.api.objs.SpecParameter; -import org.apache.brooklyn.camp.brooklyn.AbstractYamlTest; -import org.apache.brooklyn.config.ConfigKey; -import org.apache.brooklyn.core.config.ConfigKeys; -import org.apache.brooklyn.core.entity.AbstractApplication; -import org.apache.brooklyn.core.entity.AbstractEntity; -import org.apache.brooklyn.core.location.AbstractLocation; -import org.apache.brooklyn.core.mgmt.EntityManagementUtils; -import org.apache.brooklyn.core.mgmt.internal.LocalManagementContext; -import org.apache.brooklyn.core.objs.BasicSpecParameter; -import org.apache.brooklyn.core.policy.AbstractPolicy; -import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests; -import org.apache.brooklyn.entity.stock.BasicApplication; -import org.testng.SkipException; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Iterables; - -public class SpecParameterUnwrappingTest extends AbstractYamlTest { - private static final String SYMBOLIC_NAME = "my.catalog.app.id.load"; - - private static final ConfigKey<String> SHARED_CONFIG = ConfigKeys.newStringConfigKey("sample.config"); - public static class ConfigAppForTest extends AbstractApplication { - public static final ConfigKey<String> SAMPLE_CONFIG = SHARED_CONFIG; - } - public static class ConfigEntityForTest extends AbstractEntity { - public static final ConfigKey<String> SAMPLE_CONFIG = SHARED_CONFIG; - } - public static class ConfigPolicyForTest extends AbstractPolicy { - public static final ConfigKey<String> SAMPLE_CONFIG = SHARED_CONFIG; - } - public static class ConfigLocationForTest extends AbstractLocation { - public static final ConfigKey<String> SAMPLE_CONFIG = SHARED_CONFIG; - } - - @Override - protected LocalManagementContext newTestManagementContext() { - // Don't need OSGi - return LocalManagementContextForTests.newInstance(); - } - - @DataProvider(name="brooklynTypes") - public Object[][] brooklynTypes() { - return new Object[][] { - {ConfigEntityForTest.class}, - {ConfigPolicyForTest.class}, - {ConfigLocationForTest.class}}; - } - - @Test(dataProvider = "brooklynTypes") - public void testParameters(Class<? extends BrooklynObject> testClass) { - addCatalogItems("brooklyn.catalog:", - " id: " + SYMBOLIC_NAME, - " version: " + TEST_VERSION, - " item:", - " type: " + testClass.getName(), - " brooklyn.parameters:", - " - simple"); - - ConfigKey<String> SIMPLE_CONFIG = ConfigKeys.newStringConfigKey("simple"); - SpecParameter<String> SIMPLE_PARAM = new BasicSpecParameter<>("simple", true, SIMPLE_CONFIG); - CatalogItem<?, ?> item = catalog.getCatalogItem(SYMBOLIC_NAME, TEST_VERSION); - AbstractBrooklynObjectSpec<?,?> spec = createSpec(item); - assertEquals(ImmutableSet.copyOf(spec.getParameters()), ImmutableList.of(SIMPLE_PARAM)); - } - - @Test(dataProvider = "brooklynTypes") - public void testDefaultParameters(Class<? extends BrooklynObject> testClass) { - addCatalogItems( - "brooklyn.catalog:", - " id: " + SYMBOLIC_NAME, - " version: " + TEST_VERSION, - " item:", - " type: "+ testClass.getName()); - - CatalogItem<?, ?> item = catalog.getCatalogItem(SYMBOLIC_NAME, TEST_VERSION); - AbstractBrooklynObjectSpec<?, ?> spec = createSpec(item); - assertEquals(ImmutableSet.copyOf(spec.getParameters()), ImmutableSet.copyOf(BasicSpecParameter.fromClass(mgmt(),testClass))); - } - - @Test - public void testRootParametersUnwrapped() { - addCatalogItems( - "brooklyn.catalog:", - " id: " + SYMBOLIC_NAME, - " version: " + TEST_VERSION, - " item:", - " services:", - " - type: " + ConfigEntityForTest.class.getName(), - " brooklyn.parameters:", - " - simple"); - - CatalogItem<?, ?> item = catalog.getCatalogItem(SYMBOLIC_NAME, TEST_VERSION); - AbstractBrooklynObjectSpec<?,?> spec = createSpec(item); - List<SpecParameter<?>> inputs = spec.getParameters(); - assertEquals(inputs.size(), 1); - SpecParameter<?> firstInput = inputs.get(0); - assertEquals(firstInput.getLabel(), "simple"); - } - - @Test(dataProvider="brooklynTypes") - public void testDepentantCatalogsInheritParameters(Class<? extends BrooklynObject> type) { - if (type == ConfigLocationForTest.class) { - //TODO - throw new SkipException("Locations don't inherit parameters, should migrate to the type registry first"); - } - addCatalogItems( - "brooklyn.catalog:", - " version: " + TEST_VERSION, - " items:", - " - id: paramItem", - " item:", - " type: " + type.getName(), - " brooklyn.parameters:", - " - simple", - " - id: " + SYMBOLIC_NAME, - " item:", - " type: paramItem:" + TEST_VERSION); - - CatalogItem<?, ?> item = catalog.getCatalogItem(SYMBOLIC_NAME, TEST_VERSION); - AbstractBrooklynObjectSpec<?,?> spec = createSpec(item); - List<SpecParameter<?>> inputs = spec.getParameters(); - assertEquals(inputs.size(), 1); - SpecParameter<?> firstInput = inputs.get(0); - assertEquals(firstInput.getLabel(), "simple"); - } - - @Test(dataProvider="brooklynTypes") - public void testDepentantCatalogsOverrideParameters(Class<? extends BrooklynObject> type) { - addCatalogItems( - "brooklyn.catalog:", - " version: " + TEST_VERSION, - " items:", - " - id: paramItem", - " item:", - " type: " + type.getName(), - " brooklyn.parameters:", - " - simple", - " - id: " + SYMBOLIC_NAME, - " item:", - // Don't set explicit version, not supported by locations - " type: paramItem", - " brooklyn.parameters:", - " - override"); - - CatalogItem<?, ?> item = catalog.getCatalogItem(SYMBOLIC_NAME, TEST_VERSION); - AbstractBrooklynObjectSpec<?,?> spec = createSpec(item); - List<SpecParameter<?>> inputs = spec.getParameters(); - assertEquals(inputs.size(), 1); - SpecParameter<?> firstInput = inputs.get(0); - assertEquals(firstInput.getLabel(), "override"); - } - - @Test - public void testChildEntitiyHasParameters() { - addCatalogItems( - "brooklyn.catalog:", - " id: " + SYMBOLIC_NAME, - " version: " + TEST_VERSION, - " items:", - " - item:", - " type: " + ConfigEntityForTest.class.getName(), - " brooklyn.children:", - " - type: " + ConfigEntityForTest.class.getName(), - " brooklyn.parameters:", - " - simple"); - - CatalogItem<?, ?> item = catalog.getCatalogItem(SYMBOLIC_NAME, TEST_VERSION); - @SuppressWarnings({ "rawtypes", "unchecked"}) - EntitySpec<?> parentSpec = (EntitySpec<?>) catalog.createSpec((CatalogItem)item); - EntitySpec<?> spec = parentSpec.getChildren().get(0); - SpecParameter<?> firstInput = spec.getParameters().get(0); - assertEquals(firstInput.getLabel(), "simple"); - } - - @Test - public void testAppSpecInheritsCatalogParameters() { - addCatalogItems( - "brooklyn.catalog:", - " version: " + TEST_VERSION, - " items:", - " - id: " + SYMBOLIC_NAME, - " item:", - " type: " + BasicApplication.class.getName(), - " brooklyn.parameters:", - " - simple"); - - EntitySpec<? extends Application> spec = createAppSpec( - "services:", - "- type: " + ver(SYMBOLIC_NAME)); - List<SpecParameter<?>> params = spec.getParameters(); - assertEquals(params.size(), 1); - SpecParameter<?> firstInput = params.get(0); - assertEquals(firstInput.getLabel(), "simple"); - } - - - @Test - public void testAppSpecInheritsCatalogRootParameters() { - addCatalogItems( - "brooklyn.catalog:", - " version: " + TEST_VERSION, - " items:", - " - id: " + SYMBOLIC_NAME, - " item:", - " type: " + BasicApplication.class.getName(), - " brooklyn.parameters:", - " - simple"); - - EntitySpec<? extends Application> spec = createAppSpec( - "services:", - "- type: " + ver(SYMBOLIC_NAME)); - List<SpecParameter<?>> params = spec.getParameters(); - assertEquals(params.size(), 1); - SpecParameter<?> firstInput = params.get(0); - assertEquals(firstInput.getLabel(), "simple"); - } - - @Test - public void testAppSpecInheritsCatalogRootParametersWithServices() { - addCatalogItems( - "brooklyn.catalog:", - " version: " + TEST_VERSION, - " items:", - " - id: " + SYMBOLIC_NAME, - " item:", - " brooklyn.parameters:", - " - simple", - " services:", - " - type: " + BasicApplication.class.getName()); - - EntitySpec<? extends Application> spec = createAppSpec( - "services:", - "- type: " + ver(SYMBOLIC_NAME)); - List<SpecParameter<?>> params = spec.getParameters(); - assertEquals(params.size(), 1); - SpecParameter<?> firstInput = params.get(0); - assertEquals(firstInput.getLabel(), "simple"); - } - - @Test - public void testUnresolvedCatalogItemParameters() { - // Insert template which is not instantiatable during catalog addition due to - // missing dependencies, but the spec can be created (the - // dependencies are already parsed). - addCatalogItems( - "brooklyn.catalog:", - " version: " + TEST_VERSION, - " items:", - " - id: " + SYMBOLIC_NAME, - " itemType: template", - " item:", - " services:", - " - type: basic-app", - " - id: basic-app", - " item:", - " type: " + ConfigAppForTest.class.getName()); - EntitySpec<? extends Application> spec = createAppSpec( - "services:", - "- type: " + ver(SYMBOLIC_NAME)); - List<SpecParameter<?>> params = spec.getParameters(); - assertEquals(params.size(), 2); // sample + defaultDisplayName - assertEquals(ImmutableSet.copyOf(params), ImmutableSet.copyOf(BasicSpecParameter.fromClass(mgmt(), ConfigAppForTest.class))); - } - - @Test - public void testParametersCoercedOnSetAndReferences() throws Exception { - Integer testValue = Integer.valueOf(55); - addCatalogItems( - "brooklyn.catalog:", - " id: " + SYMBOLIC_NAME, - " version: " + TEST_VERSION, - " item:", - " type: " + BasicApplication.class.getName(), - " brooklyn.parameters:", - " - name: num", - " type: integer", - " brooklyn.children:", - " - type: " + ConfigEntityForTest.class.getName(), - " brooklyn.config:", - " refConfig: $brooklyn:scopeRoot().config(\"num\")", - " - type: " + ConfigEntityForTest.class.getName(), - " brooklyn.config:", - " refConfig: $brooklyn:config(\"num\")"); //inherited config - - Entity app = createAndStartApplication( - "services:", - "- type: " + BasicApplication.class.getName(), - " brooklyn.children:", - " - type: " + ver(SYMBOLIC_NAME), - " brooklyn.config:", - " num: \"" + testValue + "\""); - - Entity scopeRoot = Iterables.getOnlyElement(app.getChildren()); - - ConfigKey<Object> numKey = ConfigKeys.newConfigKey(Object.class, "num"); - assertEquals(scopeRoot.config().get(numKey), testValue); - - ConfigKey<Object> refConfigKey = ConfigKeys.newConfigKey(Object.class, "refConfig"); - - Iterator<Entity> childIter = scopeRoot.getChildren().iterator(); - Entity c1 = childIter.next(); - assertEquals(c1.config().get(refConfigKey), testValue); - Entity c2 = childIter.next(); - assertEquals(c2.config().get(refConfigKey), testValue); - assertFalse(childIter.hasNext()); - } - - @Test - public void testAppRootParameters() throws Exception { - EntitySpec<? extends Application> spec = createAppSpec( - "brooklyn.parameters:", - "- simple", - "services:", - "- type: " + BasicApplication.class.getName()); - List<SpecParameter<?>> inputs = spec.getParameters(); - assertEquals(inputs.size(), 1); - SpecParameter<?> firstInput = inputs.get(0); - assertEquals(firstInput.getLabel(), "simple"); - } - - @Test - public void testAppServiceParameters() throws Exception { - EntitySpec<? extends Application> spec = createAppSpec( - "services:", - "- type: " + BasicApplication.class.getName(), - " brooklyn.parameters:", - " - simple"); - List<SpecParameter<?>> inputs = spec.getParameters(); - assertEquals(inputs.size(), 1); - SpecParameter<?> firstInput = inputs.get(0); - assertEquals(firstInput.getLabel(), "simple"); - } - - @SuppressWarnings({"unchecked", "rawtypes"}) - private AbstractBrooklynObjectSpec<?, ?> createSpec(CatalogItem<?, ?> item) { - return (AbstractBrooklynObjectSpec<?,?>) catalog.createSpec((CatalogItem)item); - } - - private EntitySpec<? extends Application> createAppSpec(String... lines) { - return EntityManagementUtils.createEntitySpecForApplication(mgmt(), joinLines(lines)); - } - -} 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/catalog/TestBasicApp.java ---------------------------------------------------------------------- diff --git a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/TestBasicApp.java b/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/TestBasicApp.java deleted file mode 100644 index ccd52e4..0000000 --- a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/TestBasicApp.java +++ /dev/null @@ -1,27 +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.catalog; - -import org.apache.brooklyn.api.entity.ImplementedBy; -import org.apache.brooklyn.entity.stock.BasicApplication; - -@ImplementedBy(TestBasicAppImpl.class) -public interface TestBasicApp extends BasicApplication { - -} 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/catalog/TestBasicAppImpl.java ---------------------------------------------------------------------- diff --git a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/TestBasicAppImpl.java b/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/TestBasicAppImpl.java deleted file mode 100644 index 358f2c7..0000000 --- a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/TestBasicAppImpl.java +++ /dev/null @@ -1,24 +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.catalog; - -import org.apache.brooklyn.entity.stock.BasicApplicationImpl; - -public class TestBasicAppImpl extends BasicApplicationImpl implements TestBasicApp { -} 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/policy/CreatePasswordSensorIntegrationTest.java ---------------------------------------------------------------------- diff --git a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/policy/CreatePasswordSensorIntegrationTest.java b/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/policy/CreatePasswordSensorIntegrationTest.java deleted file mode 100644 index 360b705..0000000 --- a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/policy/CreatePasswordSensorIntegrationTest.java +++ /dev/null @@ -1,67 +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.policy; - -import org.apache.brooklyn.api.entity.Entity; -import org.apache.brooklyn.api.sensor.AttributeSensor; -import org.apache.brooklyn.camp.brooklyn.AbstractYamlTest; -import org.apache.brooklyn.core.entity.Entities; -import org.apache.brooklyn.core.sensor.Sensors; -import org.apache.brooklyn.entity.software.base.EmptySoftwareProcess; -import org.apache.brooklyn.test.Asserts; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testng.annotations.Test; - -import com.google.common.collect.Iterables; - -public class CreatePasswordSensorIntegrationTest extends AbstractYamlTest { - - private static final Logger LOG = LoggerFactory.getLogger(CreatePasswordSensorIntegrationTest.class); - AttributeSensor<String> PASSWORD_1 = Sensors.newStringSensor("test.password.1", "Host name as known internally in " + - "the subnet where it is running (if different to host.name)"); - AttributeSensor<String> PASSWORD_2 = Sensors.newStringSensor("test.password.2", "Host name as known internally in " + - "the subnet where it is running (if different to host.name)"); - - @Test(groups = "Integration") - public void testProvisioningProperties() throws Exception { - final Entity app = createAndStartApplication(loadYaml("EmptySoftwareProcessWithPassword.yaml")); - - waitForApplicationTasks(app); - EmptySoftwareProcess entity = Iterables.getOnlyElement(Entities.descendants(app, EmptySoftwareProcess.class)); - - assertPasswordLength(entity, PASSWORD_1, 15); - - assertPasswordOnlyContains(entity, PASSWORD_2, "abc"); - - } - - private void assertPasswordOnlyContains(EmptySoftwareProcess entity, AttributeSensor<String> password, String acceptableChars) { - String attribute_2 = entity.getAttribute(password); - for (char c : attribute_2.toCharArray()) { - Asserts.assertTrue(acceptableChars.indexOf(c) != -1); - } - } - - private void assertPasswordLength(EmptySoftwareProcess entity, AttributeSensor<String> password, int expectedLength) { - String attribute_1 = entity.getAttribute(password); - Asserts.assertEquals(attribute_1.length(), expectedLength); - } - -} 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/spi/creation/service/ServiceTypeResolverTest.java ---------------------------------------------------------------------- diff --git a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/spi/creation/service/ServiceTypeResolverTest.java b/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/spi/creation/service/ServiceTypeResolverTest.java deleted file mode 100644 index cbaccf0..0000000 --- a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/spi/creation/service/ServiceTypeResolverTest.java +++ /dev/null @@ -1,39 +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.spi.creation.service; - -import static org.testng.Assert.assertEquals; - -import org.apache.brooklyn.api.entity.EntitySpec; -import org.apache.brooklyn.camp.brooklyn.AbstractYamlTest; -import org.apache.brooklyn.entity.stock.BasicEntity; -import org.testng.annotations.Test; - - -public class ServiceTypeResolverTest extends AbstractYamlTest { - - @Test - public void testAddCatalogItemVerySimple() throws Exception { - EntitySpec<?> spec = createAppEntitySpec( - "services:", - "- type: \"test-resolver:" + BasicEntity.class.getName() + "\""); - assertEquals(spec.getChildren().get(0).getFlags().get("resolver"), TestServiceTypeResolver.class); - } - -} 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/spi/creation/service/TestServiceTypeResolver.java ---------------------------------------------------------------------- diff --git a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/spi/creation/service/TestServiceTypeResolver.java b/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/spi/creation/service/TestServiceTypeResolver.java deleted file mode 100644 index 7fd6d8a..0000000 --- a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/spi/creation/service/TestServiceTypeResolver.java +++ /dev/null @@ -1,54 +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.spi.creation.service; - -import org.apache.brooklyn.api.catalog.CatalogItem; -import org.apache.brooklyn.api.entity.Entity; -import org.apache.brooklyn.api.entity.EntitySpec; -import org.apache.brooklyn.camp.brooklyn.spi.creation.BrooklynComponentTemplateResolver; -import org.apache.brooklyn.core.catalog.internal.CatalogUtils; -import org.apache.brooklyn.util.text.Strings; - -@SuppressWarnings("deprecation") -public class TestServiceTypeResolver implements ServiceTypeResolver { - - private static final String PREFIX = "test-resolver"; - - @Override - public String getTypePrefix() { - return PREFIX; - } - - @Override - public String getBrooklynType(String serviceType) { - return Strings.removeFromStart(serviceType, PREFIX + ":"); - } - - @SuppressWarnings("unchecked") - @Override - public CatalogItem<Entity, EntitySpec<?>> getCatalogItem(BrooklynComponentTemplateResolver resolver, String serviceType) { - return (CatalogItem<Entity, EntitySpec<?>>) CatalogUtils.getCatalogItemOptionalVersion(resolver.getManagementContext(), getBrooklynType(serviceType)); - } - - @Override - public <T extends Entity> void decorateSpec(BrooklynComponentTemplateResolver resolver, EntitySpec<T> spec) { - spec.configure("resolver", TestServiceTypeResolver.class); - } - -} 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/spi/dsl/DslParseTest.java ---------------------------------------------------------------------- diff --git a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/spi/dsl/DslParseTest.java b/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/spi/dsl/DslParseTest.java deleted file mode 100644 index ca754c5..0000000 --- a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/spi/dsl/DslParseTest.java +++ /dev/null @@ -1,78 +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.spi.dsl; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; - -import java.util.Arrays; -import java.util.List; - -import org.apache.brooklyn.camp.brooklyn.spi.dsl.parse.DslParser; -import org.apache.brooklyn.camp.brooklyn.spi.dsl.parse.FunctionWithArgs; -import org.apache.brooklyn.camp.brooklyn.spi.dsl.parse.QuotedString; -import org.apache.brooklyn.util.text.StringEscapes.JavaStringEscapes; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Iterables; - -@Test -public class DslParseTest { - - public void testParseString() { - assertEquals(new DslParser("\"hello world\"").parse(), new QuotedString(JavaStringEscapes.wrapJavaString("hello world"))); - } - - public void testParseNoArgFunction() { - Object fx = new DslParser("f()").parse(); - fx = Iterables.getOnlyElement( (List<?>)fx ); - assertEquals( ((FunctionWithArgs)fx).getFunction(), "f" ); - assertEquals( ((FunctionWithArgs)fx).getArgs(), ImmutableList.of()); - } - - public void testParseOneArgFunction() { - Object fx = new DslParser("f(\"x\")").parse(); - fx = Iterables.getOnlyElement( (List<?>)fx ); - assertEquals( ((FunctionWithArgs)fx).getFunction(), "f" ); - assertEquals( ((FunctionWithArgs)fx).getArgs(), Arrays.asList(new QuotedString("\"x\"")) ); - } - - public void testParseMultiArgMultiTypeFunction() { - // TODO Parsing "f(\"x\", 1)" fails, because it interprets 1 as a function rather than a number. Is that expected? - Object fx = new DslParser("f(\"x\", \"y\")").parse(); - fx = Iterables.getOnlyElement( (List<?>)fx ); - assertEquals( ((FunctionWithArgs)fx).getFunction(), "f" ); - assertEquals( ((FunctionWithArgs)fx).getArgs(), ImmutableList.of(new QuotedString("\"x\""), new QuotedString("\"y\""))); - } - - - public void testParseFunctionChain() { - Object fx = new DslParser("f(\"x\").g()").parse(); - assertTrue(((List<?>)fx).size() == 2, ""+fx); - Object fx1 = ((List<?>)fx).get(0); - Object fx2 = ((List<?>)fx).get(1); - assertEquals( ((FunctionWithArgs)fx1).getFunction(), "f" ); - assertEquals( ((FunctionWithArgs)fx1).getArgs(), ImmutableList.of(new QuotedString("\"x\"")) ); - assertEquals( ((FunctionWithArgs)fx2).getFunction(), "g" ); - assertTrue( ((FunctionWithArgs)fx2).getArgs().isEmpty() ); - } - - -} 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/test/lite/CampPlatformWithJustBrooklynMgmt.java ---------------------------------------------------------------------- diff --git a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/test/lite/CampPlatformWithJustBrooklynMgmt.java b/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/test/lite/CampPlatformWithJustBrooklynMgmt.java deleted file mode 100644 index 20681a6..0000000 --- a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/test/lite/CampPlatformWithJustBrooklynMgmt.java +++ /dev/null @@ -1,41 +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.test.lite; - -import org.apache.brooklyn.api.mgmt.ManagementContext; -import org.apache.brooklyn.camp.BasicCampPlatform; -import org.apache.brooklyn.camp.brooklyn.BrooklynCampConstants; -import org.apache.brooklyn.core.internal.BrooklynProperties; -import org.apache.brooklyn.core.mgmt.HasBrooklynManagementContext; - -public class CampPlatformWithJustBrooklynMgmt extends BasicCampPlatform implements HasBrooklynManagementContext { - - private ManagementContext mgmt; - - public CampPlatformWithJustBrooklynMgmt(ManagementContext mgmt) { - this.mgmt = mgmt; - ((BrooklynProperties)mgmt.getConfig()).put(BrooklynCampConstants.CAMP_PLATFORM, this); - } - - @Override - public ManagementContext getBrooklynManagementContext() { - return mgmt; - } - -} 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/test/lite/CampYamlLiteTest.java ---------------------------------------------------------------------- diff --git a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/test/lite/CampYamlLiteTest.java b/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/test/lite/CampYamlLiteTest.java deleted file mode 100644 index 9cd6bc5..0000000 --- a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/test/lite/CampYamlLiteTest.java +++ /dev/null @@ -1,261 +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.test.lite; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; - -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.Reader; -import java.util.Collection; -import java.util.List; -import java.util.Map; - -import org.apache.brooklyn.api.catalog.CatalogItem; -import org.apache.brooklyn.api.catalog.CatalogItem.CatalogBundle; -import org.apache.brooklyn.api.entity.Entity; -import org.apache.brooklyn.api.entity.EntitySpec; -import org.apache.brooklyn.api.mgmt.Task; -import org.apache.brooklyn.api.typereg.OsgiBundleWithUrl; -import org.apache.brooklyn.api.typereg.RegisteredType; -import org.apache.brooklyn.camp.spi.Assembly; -import org.apache.brooklyn.camp.spi.AssemblyTemplate; -import org.apache.brooklyn.camp.spi.pdp.PdpYamlTest; -import org.apache.brooklyn.camp.test.mock.web.MockWebPlatform; -import org.apache.brooklyn.core.catalog.CatalogPredicates; -import org.apache.brooklyn.core.catalog.internal.BasicBrooklynCatalog; -import org.apache.brooklyn.core.catalog.internal.CatalogDto; -import org.apache.brooklyn.core.catalog.internal.CatalogUtils; -import org.apache.brooklyn.core.config.ConfigKeys; -import org.apache.brooklyn.core.effector.AddChildrenEffector; -import org.apache.brooklyn.core.effector.Effectors; -import org.apache.brooklyn.core.entity.Entities; -import org.apache.brooklyn.core.mgmt.internal.LocalManagementContext; -import org.apache.brooklyn.core.mgmt.osgi.OsgiStandaloneTest; -import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests; -import org.apache.brooklyn.core.test.entity.TestApplication; -import org.apache.brooklyn.core.test.entity.TestEntity; -import org.apache.brooklyn.core.typereg.RegisteredTypeLoadingContexts; -import org.apache.brooklyn.core.typereg.RegisteredTypes; -import org.apache.brooklyn.test.support.TestResourceUnavailableException; -import org.apache.brooklyn.util.collections.MutableMap; -import org.apache.brooklyn.util.core.ResourceUtils; -import org.apache.brooklyn.util.core.config.ConfigBag; -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; - -import com.google.common.base.Joiner; -import com.google.common.base.Predicates; -import com.google.common.collect.Iterables; - -/** Tests of lightweight CAMP integration. Since the "real" integration is in brooklyn-camp project, - * but some aspects of CAMP we want to be able to test here. */ -public class CampYamlLiteTest { - private static final String TEST_VERSION = "0.1.2"; - - private static final Logger log = LoggerFactory.getLogger(CampYamlLiteTest.class); - - protected LocalManagementContext mgmt; - protected CampPlatformWithJustBrooklynMgmt platform; - - @BeforeMethod(alwaysRun=true) - public void setUp() { - mgmt = LocalManagementContextForTests.newInstanceWithOsgi(); - platform = new CampPlatformWithJustBrooklynMgmt(mgmt); - MockWebPlatform.populate(platform, TestAppAssemblyInstantiator.class); - } - - @AfterMethod(alwaysRun=true) - public void tearDown() { - if (mgmt!=null) mgmt.terminate(); - } - - /** based on {@link PdpYamlTest} for parsing, - * then creating a {@link TestAppAssembly} */ - @Test - public void testYamlServiceMatchAndBrooklynInstantiate() throws Exception { - Reader input = new InputStreamReader(getClass().getResourceAsStream("test-app-service-blueprint.yaml")); - AssemblyTemplate at = platform.pdp().registerDeploymentPlan(input); - log.info("AT is:\n"+at.toString()); - Assert.assertEquals(at.getName(), "sample"); - Assert.assertEquals(at.getPlatformComponentTemplates().links().size(), 1); - - // now use brooklyn to instantiate - note it won't be faithful, but it will set some config keys - Assembly assembly = at.getInstantiator().newInstance().instantiate(at, platform); - - TestApplication app = ((TestAppAssembly)assembly).getBrooklynApp(); - Assert.assertEquals( app.getConfig(TestEntity.CONF_NAME), "sample" ); - Map<String, String> map = app.getConfig(TestEntity.CONF_MAP_THING); - Assert.assertEquals( map.get("desc"), "Tomcat sample JSP and servlet application." ); - - Assert.assertEquals( app.getChildren().size(), 1 ); - Entity svc = Iterables.getOnlyElement(app.getChildren()); - Assert.assertEquals( svc.getConfig(TestEntity.CONF_NAME), "Hello WAR" ); - map = svc.getConfig(TestEntity.CONF_MAP_THING); - Assert.assertEquals( map.get("type"), MockWebPlatform.APPSERVER.getType() ); - // desc ensures we got the information from the matcher, as this value is NOT in the yaml - Assert.assertEquals( map.get("desc"), MockWebPlatform.APPSERVER.getDescription() ); - } - - /** based on {@link PdpYamlTest} for parsing, - * then creating a {@link TestAppAssembly} */ - @SuppressWarnings({ "rawtypes", "unchecked" }) - @Test - public void testAddChildrenEffector() throws Exception { - String childYaml = Streams.readFullyString(getClass().getResourceAsStream("test-app-service-blueprint.yaml")); - AddChildrenEffector newEff = new AddChildrenEffector(ConfigBag.newInstance() - .configure(AddChildrenEffector.EFFECTOR_NAME, "add_tomcat") - .configure(AddChildrenEffector.BLUEPRINT_YAML, childYaml) - .configure(AddChildrenEffector.EFFECTOR_PARAMETER_DEFS, MutableMap.of("war", (Object)MutableMap.of( - "defaultValue", "foo.war"))) ) ; - TestApplication app = mgmt.getEntityManager().createEntity(EntitySpec.create(TestApplication.class).addInitializer(newEff)); - - // test adding, with a parameter - Task<List> task = app.invoke(Effectors.effector(List.class, "add_tomcat").buildAbstract(), MutableMap.of("war", "foo.bar")); - List result = task.get(); - - Entity newChild = Iterables.getOnlyElement(app.getChildren()); - Assert.assertEquals(newChild.getConfig(ConfigKeys.newStringConfigKey("war")), "foo.bar"); - - Assert.assertEquals(Iterables.getOnlyElement(result), newChild.getId()); - Entities.unmanage(newChild); - - // and test default value - task = app.invoke(Effectors.effector(List.class, "add_tomcat").buildAbstract(), MutableMap.<String,Object>of()); - result = task.get(); - - newChild = Iterables.getOnlyElement(app.getChildren()); - Assert.assertEquals(newChild.getConfig(ConfigKeys.newStringConfigKey("war")), "foo.war"); - - Assert.assertEquals(Iterables.getOnlyElement(result), newChild.getId()); - Entities.unmanage(newChild); - } - - @Test - public void testYamlServiceForCatalog() { - TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH); - - CatalogItem<?, ?> realItem = Iterables.getOnlyElement(mgmt.getCatalog().addItems(Streams.readFullyString(getClass().getResourceAsStream("test-app-service-blueprint.yaml")))); - Iterable<CatalogItem<Object, Object>> retrievedItems = mgmt.getCatalog() - .getCatalogItems(CatalogPredicates.symbolicName(Predicates.equalTo("catalog-name"))); - - Assert.assertEquals(Iterables.size(retrievedItems), 1, "Wrong retrieved items: "+retrievedItems); - CatalogItem<Object, Object> retrievedItem = Iterables.getOnlyElement(retrievedItems); - Assert.assertEquals(retrievedItem, realItem); - - Collection<CatalogBundle> bundles = retrievedItem.getLibraries(); - Assert.assertEquals(bundles.size(), 1); - CatalogBundle bundle = Iterables.getOnlyElement(bundles); - Assert.assertEquals(bundle.getUrl(), OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL); - Assert.assertEquals(bundle.getVersion(), "0.1.0"); - - @SuppressWarnings({ "unchecked", "rawtypes" }) - EntitySpec<?> spec1 = (EntitySpec<?>) mgmt.getCatalog().createSpec((CatalogItem)retrievedItem); - assertNotNull(spec1); - Assert.assertEquals(spec1.getConfig().get(TestEntity.CONF_NAME), "sample"); - - // TODO other assertions, about children - } - - @Test - public void testRegisterCustomEntityWithBundleWhereEntityIsFromCoreAndIconFromBundle() throws IOException { - TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH); - - String symbolicName = "my.catalog.app.id"; - String bundleUrl = OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL; - String yaml = getSampleMyCatalogAppYaml(symbolicName, bundleUrl); - - mgmt.getCatalog().addItems(yaml); - - assertMgmtHasSampleMyCatalogApp(symbolicName, bundleUrl); - } - - @Test - public void testResetXmlWithCustomEntity() throws IOException { - TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH); - - String symbolicName = "my.catalog.app.id"; - String bundleUrl = OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL; - String yaml = getSampleMyCatalogAppYaml(symbolicName, bundleUrl); - - LocalManagementContext mgmt2 = LocalManagementContextForTests.newInstanceWithOsgi(); - try { - CampPlatformWithJustBrooklynMgmt platform2 = new CampPlatformWithJustBrooklynMgmt(mgmt2); - MockWebPlatform.populate(platform2, TestAppAssemblyInstantiator.class); - - mgmt2.getCatalog().addItems(yaml); - String xml = ((BasicBrooklynCatalog) mgmt2.getCatalog()).toXmlString(); - ((BasicBrooklynCatalog) mgmt.getCatalog()).reset(CatalogDto.newDtoFromXmlContents(xml, "copy of temporary catalog")); - } finally { - mgmt2.terminate(); - } - - assertMgmtHasSampleMyCatalogApp(symbolicName, bundleUrl); - } - - private String getSampleMyCatalogAppYaml(String symbolicName, String bundleUrl) { - return "brooklyn.catalog:\n" + - " id: " + symbolicName + "\n" + - " name: My Catalog App\n" + - " description: My description\n" + - " icon_url: classpath:/org/apache/brooklyn/test/osgi/entities/icon.gif\n" + - " version: " + TEST_VERSION + "\n" + - " libraries:\n" + - " - url: " + bundleUrl + "\n" + - "\n" + - "services:\n" + - "- type: io.camp.mock:AppServer\n"; - } - - private void assertMgmtHasSampleMyCatalogApp(String symbolicName, String bundleUrl) { - RegisteredType item = mgmt.getTypeRegistry().get(symbolicName); - assertNotNull(item, "failed to load item with id=" + symbolicName + " from catalog. Entries were: " + - Joiner.on(",").join(mgmt.getTypeRegistry().getAll())); - assertEquals(item.getSymbolicName(), symbolicName); - - RegisteredTypes.tryValidate(item, RegisteredTypeLoadingContexts.spec(Entity.class)).get(); - - // stored as yaml, not java - String planYaml = RegisteredTypes.getImplementationDataStringForSpec(item); - assertNotNull(planYaml); - Assert.assertTrue(planYaml.contains("io.camp.mock:AppServer")); - - // and let's check we have libraries - Collection<OsgiBundleWithUrl> libs = item.getLibraries(); - assertEquals(libs.size(), 1); - OsgiBundleWithUrl bundle = Iterables.getOnlyElement(libs); - assertEquals(bundle.getUrl(), bundleUrl); - - // now let's check other things on the item - assertEquals(item.getDisplayName(), "My Catalog App"); - assertEquals(item.getDescription(), "My description"); - assertEquals(item.getIconUrl(), "classpath:/org/apache/brooklyn/test/osgi/entities/icon.gif"); - - // and confirm we can resolve ICON - byte[] iconData = Streams.readFully(ResourceUtils.create(CatalogUtils.newClassLoadingContext(mgmt, item)).getResourceFromUrl(item.getIconUrl())); - assertEquals(iconData.length, 43); - } - -} 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/test/lite/TestAppAssembly.java ---------------------------------------------------------------------- diff --git a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/test/lite/TestAppAssembly.java b/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/test/lite/TestAppAssembly.java deleted file mode 100644 index 877c00b..0000000 --- a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/test/lite/TestAppAssembly.java +++ /dev/null @@ -1,36 +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.test.lite; - -import org.apache.brooklyn.camp.spi.Assembly; -import org.apache.brooklyn.core.test.entity.TestApplication; - -public class TestAppAssembly extends Assembly { - - private TestApplication brooklynApp; - - public TestAppAssembly(TestApplication brooklynApp) { - this.brooklynApp = brooklynApp; - } - - public TestApplication getBrooklynApp() { - return brooklynApp; - } - -}
