You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by sv...@apache.org on 2017/02/13 06:26:44 UTC
[4/9] brooklyn-server git commit: Split CatalogYamlEntityTest for
non-osgi and osgi
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/c5ae189c/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlEntityTest.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlEntityTest.java b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlEntityTest.java
index f9868f8..fc9347a 100644
--- a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlEntityTest.java
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlEntityTest.java
@@ -18,16 +18,12 @@
*/
package org.apache.brooklyn.camp.brooklyn.catalog;
+import static com.google.common.base.Preconditions.checkNotNull;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
-import java.io.InputStream;
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-
import org.apache.brooklyn.api.catalog.BrooklynCatalog;
import org.apache.brooklyn.api.entity.Entity;
import org.apache.brooklyn.api.entity.EntitySpec;
@@ -38,44 +34,25 @@ import org.apache.brooklyn.camp.brooklyn.AbstractYamlTest;
import org.apache.brooklyn.config.ConfigKey;
import org.apache.brooklyn.core.catalog.internal.CatalogUtils;
import org.apache.brooklyn.core.config.ConfigKeys;
-import org.apache.brooklyn.core.mgmt.osgi.OsgiStandaloneTest;
import org.apache.brooklyn.core.test.entity.TestEntity;
import org.apache.brooklyn.core.test.entity.TestEntityImpl;
import org.apache.brooklyn.core.typereg.RegisteredTypes;
import org.apache.brooklyn.entity.stock.BasicApplication;
import org.apache.brooklyn.entity.stock.BasicEntity;
-import org.apache.brooklyn.test.support.TestResourceUnavailableException;
-import org.apache.brooklyn.util.collections.MutableList;
-import org.apache.brooklyn.util.core.ResourceUtils;
import org.apache.brooklyn.util.exceptions.Exceptions;
-import org.apache.brooklyn.util.osgi.OsgiTestResources;
import org.testng.Assert;
import org.testng.annotations.Test;
import com.google.common.base.Joiner;
-import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
public class CatalogYamlEntityTest extends AbstractYamlTest {
- private static final String SIMPLE_ENTITY_TYPE = OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_SIMPLE_ENTITY;
-
- @Override
- protected boolean disableOsgi() {
- return false;
- }
-
@Test
public void testAddCatalogItemVerySimple() throws Exception {
String symbolicName = "my.catalog.app.id.load";
- addCatalogItems(
- "brooklyn.catalog:",
- " id: " + symbolicName,
- " version: " + TEST_VERSION,
- " itemType: entity",
- " item:",
- " type: "+ BasicEntity.class.getName());
+ addCatalogEntity(IdAndVersion.of(symbolicName, TEST_VERSION), BasicEntity.class.getName());
RegisteredType item = mgmt().getTypeRegistry().get(symbolicName, TEST_VERSION);
String planYaml = RegisteredTypes.getImplementationDataStringForSpec(item);
@@ -83,23 +60,10 @@ public class CatalogYamlEntityTest extends AbstractYamlTest {
deleteCatalogEntity(symbolicName);
}
- @Test
- public void testAddCatalogItem() throws Exception {
- TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH);
-
- String symbolicName = "my.catalog.app.id.load";
- addCatalogOSGiEntity(symbolicName);
- RegisteredType item = mgmt().getTypeRegistry().get(symbolicName, TEST_VERSION);
- assertEquals(item.getSymbolicName(), symbolicName);
-
- deleteCatalogEntity(symbolicName);
- }
// Legacy / backwards compatibility: should always specify itemType
@Test
public void testAddCatalogItemAsStringWithoutItemType() throws Exception {
- TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH);
-
String symbolicName = "my.catalog.app.id.load";
addCatalogItems(
"brooklyn.catalog:",
@@ -108,9 +72,7 @@ public class CatalogYamlEntityTest extends AbstractYamlTest {
" name: My Catalog App",
" description: My description",
" icon_url: classpath://path/to/myicon.jpg",
- " libraries:",
- " - url: " + OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL,
- " item: " + SIMPLE_ENTITY_TYPE);
+ " item: " + BasicEntity.class.getName());
RegisteredType item = mgmt().getTypeRegistry().get(symbolicName, TEST_VERSION);
assertEquals(item.getSymbolicName(), symbolicName);
@@ -120,20 +82,13 @@ public class CatalogYamlEntityTest extends AbstractYamlTest {
@Test
public void testAddCatalogItemTypeExplicitTypeAsString() throws Exception {
- TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH);
-
String symbolicName = "my.catalog.app.id.load";
addCatalogItems(
"brooklyn.catalog:",
" id: " + symbolicName,
" version: " + TEST_VERSION,
" itemType: entity",
- " name: My Catalog App",
- " description: My description",
- " icon_url: classpath://path/to/myicon.jpg",
- " libraries:",
- " - url: " + OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL,
- " item: " + SIMPLE_ENTITY_TYPE);
+ " item: " + BasicEntity.class.getName());
RegisteredType item = mgmt().getTypeRegistry().get(symbolicName, TEST_VERSION);
assertEquals(item.getSymbolicName(), symbolicName);
@@ -143,21 +98,14 @@ public class CatalogYamlEntityTest extends AbstractYamlTest {
@Test
public void testAddCatalogItemLegacySyntax() throws Exception {
- TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH);
-
String symbolicName = "my.catalog.app.id.load";
addCatalogItems(
"brooklyn.catalog:",
" id: " + symbolicName,
- " 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,
"",
"services:",
- "- type: " + SIMPLE_ENTITY_TYPE);
+ "- type: " + BasicEntity.class.getName());
RegisteredType item = mgmt().getTypeRegistry().get(symbolicName, TEST_VERSION);
assertEquals(item.getSymbolicName(), symbolicName);
@@ -168,17 +116,13 @@ public class CatalogYamlEntityTest extends AbstractYamlTest {
// Legacy / backwards compatibility: should use id
@Test
public void testAddCatalogItemUsingNameInsteadOfIdWithoutVersion() throws Exception {
- TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH);
-
String id = "unversioned.app";
addCatalogItems(
"brooklyn.catalog:",
" name: " + id,
" itemType: entity",
- " libraries:",
- " - " + OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL,
" item:",
- " type: "+ SIMPLE_ENTITY_TYPE);
+ " type: "+ BasicEntity.class.getName());
RegisteredType catalogItem = mgmt().getTypeRegistry().get(id, BrooklynCatalog.DEFAULT_VERSION);
assertEquals(catalogItem.getVersion(), "0.0.0.SNAPSHOT");
mgmt().getCatalog().deleteCatalogItem(id, "0.0.0.SNAPSHOT");
@@ -187,17 +131,13 @@ public class CatalogYamlEntityTest extends AbstractYamlTest {
// Legacy / backwards compatibility: should use id
@Test
public void testAddCatalogItemUsingNameInsteadOfIdWithInlinedVersion() throws Exception {
- TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH);
-
String id = "inline_version.app";
addCatalogItems(
"brooklyn.catalog:",
" name: " + id+":"+TEST_VERSION,
" itemType: entity",
- " libraries:",
- " - " + OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL,
"services:",
- "- type: " + SIMPLE_ENTITY_TYPE);
+ "- type: " + BasicEntity.class.getName());
RegisteredType catalogItem = mgmt().getTypeRegistry().get(id, TEST_VERSION);
assertEquals(catalogItem.getVersion(), TEST_VERSION);
mgmt().getCatalog().deleteCatalogItem(id, TEST_VERSION);
@@ -205,51 +145,62 @@ public class CatalogYamlEntityTest extends AbstractYamlTest {
@Test
public void testLaunchApplicationReferencingCatalog() throws Exception {
- TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH);
+ String symbolicName = "myitem";
+ addCatalogEntity(IdAndVersion.of(symbolicName, TEST_VERSION), TestEntity.class.getName());
- String symbolicName = "my.catalog.app.id.launch";
- registerAndLaunchAndAssertSimpleEntity(symbolicName, SIMPLE_ENTITY_TYPE);
+ Entity app = createAndStartApplication(
+ "services:",
+ "- type: "+ver(symbolicName, TEST_VERSION));
+
+ Entity entity = Iterables.getOnlyElement(app.getChildren());
+ assertEquals(entity.getEntityType().getName(), TestEntity.class.getName());
+
+ deleteCatalogEntity(symbolicName);
}
@Test
public void testLaunchApplicationUnversionedCatalogReference() throws Exception {
- TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH);
+ String symbolicName = "myitem";
+ addCatalogEntity(IdAndVersion.of(symbolicName, TEST_VERSION), TestEntity.class.getName());
- String symbolicName = "my.catalog.app.id.fail";
- addCatalogOSGiEntity(symbolicName, SIMPLE_ENTITY_TYPE);
- try {
- String yaml = "name: simple-app-yaml\n" +
- "location: localhost\n" +
- "services: \n" +
- " - serviceType: " + symbolicName;
- createAndStartApplication(yaml);
- } finally {
- deleteCatalogEntity(symbolicName);
- }
+ Entity app = createAndStartApplication(
+ "services:",
+ "- type: "+symbolicName);
+
+ Entity entity = Iterables.getOnlyElement(app.getChildren());
+ assertEquals(entity.getEntityType().getName(), TestEntity.class.getName());
+
+ deleteCatalogEntity(symbolicName);
}
@Test
public void testLaunchApplicationWithCatalogReferencingOtherCatalog() throws Exception {
- TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH);
-
String referencedSymbolicName = "my.catalog.app.id.referenced";
String referrerSymbolicName = "my.catalog.app.id.referring";
- addCatalogOSGiEntities(ImmutableMap.of(
- referencedSymbolicName, SIMPLE_ENTITY_TYPE,
- referrerSymbolicName, ver(referencedSymbolicName)));
-
+
+ addCatalogItems(
+ "brooklyn.catalog:",
+ " name: My Catalog App",
+ " description: My description",
+ " icon_url: classpath://path/to/myicon.jpg",
+ " version: " + TEST_VERSION,
+ " items:",
+ " - id: " + referencedSymbolicName,
+ " item:",
+ " type: " + TestEntity.class.getName(),
+ " - id: " + referrerSymbolicName,
+ " item:",
+ " type: " + ver(referencedSymbolicName, TEST_VERSION));
+
RegisteredType referrer = mgmt().getTypeRegistry().get(referrerSymbolicName, TEST_VERSION);
String planYaml = RegisteredTypes.getImplementationDataStringForSpec(referrer);
Assert.assertTrue(planYaml.indexOf("services")>=0, "expected services in: "+planYaml);
- String yaml = "name: simple-app-yaml\n" +
- "location: localhost\n" +
- "services: \n" +
- " - type: " + ver(referrerSymbolicName);
- Entity app = createAndStartApplication(yaml);
+ Entity app = createAndStartApplication("services:",
+ "- type: " + ver(referrerSymbolicName, TEST_VERSION));
- Entity simpleEntity = Iterables.getOnlyElement(app.getChildren());
- assertEquals(simpleEntity.getEntityType().getName(), SIMPLE_ENTITY_TYPE);
+ Entity entity = Iterables.getOnlyElement(app.getChildren());
+ assertEquals(entity.getEntityType().getName(), TestEntity.class.getName());
deleteCatalogEntity(referencedSymbolicName);
deleteCatalogEntity(referrerSymbolicName);
@@ -257,21 +208,17 @@ public class CatalogYamlEntityTest extends AbstractYamlTest {
@Test
public void testLaunchApplicationWithCatalogReferencingOtherCatalogInTwoSteps() throws Exception {
- TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH);
-
String referencedSymbolicName = "my.catalog.app.id.referenced";
String referrerSymbolicName = "my.catalog.app.id.referring";
- addCatalogOSGiEntity(referencedSymbolicName, SIMPLE_ENTITY_TYPE);
- addCatalogOSGiEntity(referrerSymbolicName, ver(referencedSymbolicName));
- String yaml = "name: simple-app-yaml\n" +
- "location: localhost\n" +
- "services: \n" +
- " - serviceType: " + ver(referrerSymbolicName);
- Entity app = createAndStartApplication(yaml);
+ addCatalogEntity(IdAndVersion.of(referencedSymbolicName, TEST_VERSION), TestEntity.class.getName());
+ addCatalogEntity(IdAndVersion.of(referrerSymbolicName, TEST_VERSION), ver(referencedSymbolicName, TEST_VERSION));
- Entity simpleEntity = Iterables.getOnlyElement(app.getChildren());
- assertEquals(simpleEntity.getEntityType().getName(), SIMPLE_ENTITY_TYPE);
+ Entity app = createAndStartApplication("services:",
+ "- type: " + ver(referrerSymbolicName, TEST_VERSION));
+
+ Entity entity = Iterables.getOnlyElement(app.getChildren());
+ assertEquals(entity.getEntityType().getName(), TestEntity.class.getName());
deleteCatalogEntity(referencedSymbolicName);
deleteCatalogEntity(referrerSymbolicName);
@@ -279,33 +226,34 @@ public class CatalogYamlEntityTest extends AbstractYamlTest {
@Test
public void testLaunchApplicationChildWithCatalogReferencingOtherCatalog() throws Exception {
- TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH);
-
String referencedSymbolicName = "my.catalog.app.id.child.referenced";
String referrerSymbolicName = "my.catalog.app.id.child.referring";
- addCatalogOSGiEntity(referencedSymbolicName, SIMPLE_ENTITY_TYPE);
- addCatalogChildOSGiEntity(referrerSymbolicName, ver(referencedSymbolicName));
+
+ addCatalogEntity(IdAndVersion.of(referencedSymbolicName, TEST_VERSION), TestEntity.class.getName());
+ addCatalogItems(
+ "brooklyn.catalog:",
+ " id: " + referrerSymbolicName,
+ " version: " + TEST_VERSION,
+ " itemType: entity",
+ " item:",
+ " services:",
+ " - type: " + BasicEntity.class.getName(),
+ " brooklyn.children:",
+ " - type: " + ver(referencedSymbolicName, TEST_VERSION));
+
Entity app = createAndStartApplication(
- "name: simple-app-yaml",
- "location: localhost",
- "services:",
- "- type: "+BasicEntity.class.getName(),
- " brooklyn.children:",
- " - type: " + ver(referrerSymbolicName));
+ "services:",
+ "- type: "+BasicEntity.class.getName(),
+ " brooklyn.children:",
+ " - type: " + ver(referrerSymbolicName));
- Collection<Entity> children = app.getChildren();
- assertEquals(children.size(), 1);
- Entity child = Iterables.getOnlyElement(children);
+ Entity child = Iterables.getOnlyElement(app.getChildren());
assertEquals(child.getEntityType().getName(), BasicEntity.class.getName());
- Collection<Entity> grandChildren = child.getChildren();
- assertEquals(grandChildren.size(), 1);
- Entity grandChild = Iterables.getOnlyElement(grandChildren);
+ Entity grandChild = Iterables.getOnlyElement(child.getChildren());
assertEquals(grandChild.getEntityType().getName(), BasicEntity.class.getName());
- Collection<Entity> grandGrandChildren = grandChild.getChildren();
- assertEquals(grandGrandChildren.size(), 1);
- Entity grandGrandChild = Iterables.getOnlyElement(grandGrandChildren);
- assertEquals(grandGrandChild.getEntityType().getName(), SIMPLE_ENTITY_TYPE);
+ Entity grandGrandChild = Iterables.getOnlyElement(grandChild.getChildren());
+ assertEquals(grandGrandChild.getEntityType().getName(), TestEntity.class.getName());
deleteCatalogEntity(referencedSymbolicName);
deleteCatalogEntity(referrerSymbolicName);
@@ -313,33 +261,33 @@ public class CatalogYamlEntityTest extends AbstractYamlTest {
@Test
public void testLaunchApplicationChildWithCatalogReferencingOtherCatalogServicesBlock() throws Exception {
- TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH);
-
String referencedSymbolicName = "my.catalog.app.id.child.referenced";
String referrerSymbolicName = "my.catalog.app.id.child.referring";
- addCatalogOSGiEntity(referencedSymbolicName, SIMPLE_ENTITY_TYPE);
- addCatalogChildOSGiEntityWithServicesBlock(referrerSymbolicName, ver(referencedSymbolicName));
+ addCatalogEntity(IdAndVersion.of(referencedSymbolicName, TEST_VERSION), TestEntity.class.getName());
+
+ addCatalogItems(
+ "brooklyn.catalog:",
+ " id: " + referrerSymbolicName,
+ " version: " + TEST_VERSION,
+ " itemType: entity",
+ " item:",
+ " services:",
+ " - type: " + BasicEntity.class.getName(),
+ " brooklyn.children:",
+ " - type: " + ver(referencedSymbolicName, TEST_VERSION));
Entity app = createAndStartApplication(
- "name: simple-app-yaml",
- "location: localhost",
"services:",
- "- serviceType: "+BasicEntity.class.getName(),
+ "- type: "+BasicEntity.class.getName(),
" brooklyn.children:",
" - type: " + ver(referrerSymbolicName));
- Collection<Entity> children = app.getChildren();
- assertEquals(children.size(), 1);
- Entity child = Iterables.getOnlyElement(children);
+ Entity child = Iterables.getOnlyElement(app.getChildren());
assertEquals(child.getEntityType().getName(), BasicEntity.class.getName());
- Collection<Entity> grandChildren = child.getChildren();
- assertEquals(grandChildren.size(), 1);
- Entity grandChild = Iterables.getOnlyElement(grandChildren);
+ Entity grandChild = Iterables.getOnlyElement(child.getChildren());
assertEquals(grandChild.getEntityType().getName(), BasicEntity.class.getName());
- Collection<Entity> grandGrandChildren = grandChild.getChildren();
- assertEquals(grandGrandChildren.size(), 1);
- Entity grandGrandChild = Iterables.getOnlyElement(grandGrandChildren);
- assertEquals(grandGrandChild.getEntityType().getName(), SIMPLE_ENTITY_TYPE);
+ Entity grandGrandChild = Iterables.getOnlyElement(grandChild.getChildren());
+ assertEquals(grandGrandChild.getEntityType().getName(), TestEntity.class.getName());
deleteCatalogEntity(referencedSymbolicName);
deleteCatalogEntity(referrerSymbolicName);
@@ -347,30 +295,34 @@ public class CatalogYamlEntityTest extends AbstractYamlTest {
@Test
public void testLaunchApplicationWithTypeUsingJavaColonPrefix() throws Exception {
- TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH);
-
- String symbolicName = SIMPLE_ENTITY_TYPE;
- String serviceName = "java:"+SIMPLE_ENTITY_TYPE;
- registerAndLaunchAndAssertSimpleEntity(symbolicName, serviceName);
+ String symbolicName = "t1";
+ String actualType = TestEntity.class.getName();
+ String serviceType = "java:"+actualType;
+ registerAndLaunchAndAssertSimpleEntity(symbolicName, serviceType, actualType);
}
@Test
public void testLaunchApplicationLoopWithJavaTypeName() throws Exception {
- TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH);
-
- String symbolicName = SIMPLE_ENTITY_TYPE;
- String serviceName = SIMPLE_ENTITY_TYPE;
+ String symbolicName = TestEntity.class.getName();
+ String serviceName = TestEntity.class.getName();
registerAndLaunchAndAssertSimpleEntity(symbolicName, serviceName);
}
@Test
public void testLaunchApplicationChildLoopCatalogIdFails() throws Exception {
- TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH);
-
String referrerSymbolicName = "my.catalog.app.id.child.referring";
try {
// TODO only fails if using 'services', because that forces plan parsing; should fail in all cases
- addCatalogChildOSGiEntityWithServicesBlock(referrerSymbolicName, ver(referrerSymbolicName));
+ addCatalogItems(
+ "brooklyn.catalog:",
+ " id: " + referrerSymbolicName,
+ " version: " + TEST_VERSION,
+ " itemType: entity",
+ " item:",
+ " services:",
+ " - type: " + BasicEntity.class.getName(),
+ " brooklyn.children:",
+ " - type: " + ver(referrerSymbolicName, TEST_VERSION));
fail("Expected to throw");
} catch (Exception e) {
Exceptions.propagateIfFatal(e);
@@ -379,177 +331,33 @@ public class CatalogYamlEntityTest extends AbstractYamlTest {
}
@Test
- public void testReferenceInstalledBundleByName() {
- TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH);
-
- String firstItemId = "my.catalog.app.id.register_bundle";
- String secondItemId = "my.catalog.app.id.reference_bundle";
- addCatalogItems(
- "brooklyn.catalog:",
- " id: " + firstItemId,
- " version: " + TEST_VERSION,
- " itemType: entity",
- " libraries:",
- " - url: " + OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL,
- " item:",
- " type: " + SIMPLE_ENTITY_TYPE);
- deleteCatalogEntity(firstItemId);
-
- addCatalogItems(
- "brooklyn.catalog:",
- " id: " + secondItemId,
- " version: " + TEST_VERSION,
- " itemType: entity",
- " libraries:",
- " - name: " + OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_NAME,
- " version: " + OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_VERSION,
- " item:",
- " type: " + SIMPLE_ENTITY_TYPE);
-
- deleteCatalogEntity(secondItemId);
- }
-
- @Test
- public void testReferenceNonInstalledBundledByNameFails() {
- String nonExistentId = "none-existent-id";
- String nonExistentVersion = "9.9.9";
- try {
- addCatalogItems(
- "brooklyn.catalog:",
- " id: my.catalog.app.id.non_existing.ref",
- " version: " + TEST_VERSION,
- " itemType: entity",
- " libraries:",
- " - name: " + nonExistentId,
- " version: " + nonExistentVersion,
- " item:",
- " type: " + SIMPLE_ENTITY_TYPE);
- fail();
- } catch (IllegalStateException e) {
- Assert.assertEquals(e.getMessage(), "Bundle from null failed to install: Bundle CatalogBundleDto{symbolicName=" + nonExistentId + ", version=" + nonExistentVersion + ", url=null} not previously registered, but URL is empty.");
- }
- }
-
- @Test
- public void testPartialBundleReferenceFails() {
- try {
- addCatalogItems(
- "brooklyn.catalog:",
- " id: my.catalog.app.id.non_existing.ref",
- " version: " + TEST_VERSION,
- " itemType: entity",
- " libraries:",
- " - name: io.brooklyn.brooklyn-test-osgi-entities",
- " item:",
- " type: " + SIMPLE_ENTITY_TYPE);
- fail();
- } catch (NullPointerException e) {
- Assert.assertEquals(e.getMessage(), "both name and version are required");
- }
- try {
- addCatalogItems(
- "brooklyn.catalog:",
- " id: my.catalog.app.id.non_existing.ref",
- " version: " + TEST_VERSION,
- " itemType: entity",
- " libraries:",
- " - version: " + OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_VERSION,
- " item:",
- " type: " + SIMPLE_ENTITY_TYPE);
- fail();
- } catch (NullPointerException e) {
- Assert.assertEquals(e.getMessage(), "both name and version are required");
- }
- }
-
- @Test
- public void testFullBundleReference() {
- TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH);
-
- String itemId = "my.catalog.app.id.full_ref";
- addCatalogItems(
- "brooklyn.catalog:",
- " id: " + itemId,
- " version: " + TEST_VERSION,
- " itemType: entity",
- " libraries:",
- " - name: " + OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_NAME,
- " version: " + OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_VERSION,
- " url: " + OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL,
- " item:",
- " type: " + SIMPLE_ENTITY_TYPE);
- deleteCatalogEntity(itemId);
- }
-
- /**
- * Test that the name:version contained in the OSGi bundle will
- * override the values supplied in the YAML.
- */
- @Test
- public void testFullBundleReferenceUrlMetaOverridesLocalNameVersion() {
- TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH);
-
- String firstItemId = "my.catalog.app.id.register_bundle";
- String nonExistentId = "non_existent_id";
- String nonExistentVersion = "9.9.9";
- try {
- addCatalogItems(
- "brooklyn.catalog:",
- " id: " + firstItemId,
- " version: " + TEST_VERSION,
- " itemType: entity",
- " libraries:",
- " - name: " + nonExistentId,
- " version: " + nonExistentVersion,
- " url: " + OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL,
- "",
- " item:",
- " type: " + SIMPLE_ENTITY_TYPE);
- fail();
- } catch (IllegalStateException e) {
- assertEquals(e.getMessage(), "Bundle from " + OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL + " failed to install: " +
- "Bundle already installed as " + OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_NAME + ":" +
- OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_VERSION + " but user explicitly requested " +
- "CatalogBundleDto{symbolicName=" + nonExistentId + ", version=" + nonExistentVersion + ", url=" +
- OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL + "}");
- }
- }
-
- @Test
public void testUpdatingItemAllowedIfSame() {
- TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH);
-
- String id = "my.catalog.app.id.duplicate";
- addCatalogOSGiEntity(id);
- addCatalogOSGiEntity(id);
+ String symbolicName = "my.catalog.app.id.duplicate";
+ addCatalogEntity(IdAndVersion.of(symbolicName, TEST_VERSION), TestEntity.class.getName());
+ addCatalogEntity(IdAndVersion.of(symbolicName, TEST_VERSION), TestEntity.class.getName());
}
@Test(expectedExceptions = IllegalStateException.class)
public void testUpdatingItemFailsIfDifferent() {
- TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH);
-
- String id = "my.catalog.app.id.duplicate";
- addCatalogOSGiEntity(id);
- addCatalogOSGiEntity(id, SIMPLE_ENTITY_TYPE, true);
+ String symbolicName = "my.catalog.app.id.duplicate";
+ addCatalogEntity(IdAndVersion.of(symbolicName, TEST_VERSION), TestEntity.class.getName());
+ addCatalogEntity(IdAndVersion.of(symbolicName, TEST_VERSION), BasicEntity.class.getName());
}
@Test
public void testForcedUpdatingItem() {
- TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH);
-
- String id = "my.catalog.app.id.duplicate";
- addCatalogOSGiEntity(id);
+ String symbolicName = "my.catalog.app.id.duplicate";
+ addCatalogEntity(IdAndVersion.of(symbolicName, TEST_VERSION), TestEntity.class.getName());
forceCatalogUpdate();
- addCatalogOSGiEntity(id);
- deleteCatalogEntity(id);
+ addCatalogEntity(IdAndVersion.of(symbolicName, TEST_VERSION), TestEntity.class.getName());
+ deleteCatalogEntity(symbolicName);
}
@Test
public void testCreateSpecFromCatalogItem() {
- TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH);
-
String id = "my.catalog.app.id.create_spec";
- addCatalogOSGiEntity(id);
+ addCatalogEntity(IdAndVersion.of(id, TEST_VERSION), TestEntity.class.getName());
+
BrooklynTypeRegistry catalog = mgmt().getTypeRegistry();
RegisteredType item = catalog.get(id, TEST_VERSION);
EntitySpec<?> spec = catalog.createSpec(item, null, EntitySpec.class);
@@ -559,65 +367,29 @@ public class CatalogYamlEntityTest extends AbstractYamlTest {
}
@Test
- public void testLoadResourceFromBundle() throws Exception {
- String id = "resource.test";
- addCatalogOSGiEntity(id, SIMPLE_ENTITY_TYPE);
- String yaml =
- "services: \n" +
- " - serviceType: "+ver(id);
- Entity app = createAndStartApplication(yaml);
- Entity simpleEntity = Iterables.getOnlyElement(app.getChildren());
- InputStream icon = new ResourceUtils(simpleEntity).getResourceFromUrl("classpath:/org/apache/brooklyn/test/osgi/entities/icon.gif");
- assertTrue(icon != null);
- icon.close();
- }
-
- @Test
public void testMissingTypeDoesNotRecurse() {
String symbolicName = "my.catalog.app.id.basic";
- addCatalogItems(
- "brooklyn.catalog:",
- " id: " + symbolicName,
- " version: " + TEST_VERSION,
- " itemType: entity",
- " item:",
- " type: org.apache.brooklyn.entity.stock.BasicEntity");
+ addCatalogEntity(IdAndVersion.of(symbolicName, TEST_VERSION), TestEntity.class.getName());
try {
- addCatalogItems(
- "brooklyn.catalog:",
- " id: " + symbolicName,
- " version: " + TEST_VERSION + "-update",
- " itemType: entity",
- " item:",
- " type: " + symbolicName);
- fail("Catalog addition expected to fail due to non-existent java type " + symbolicName);
+ addCatalogEntity(IdAndVersion.of(symbolicName, TEST_VERSION + "-update"), symbolicName);
+ fail("Catalog addition expected to fail due to recursive reference to " + symbolicName);
} catch (IllegalStateException e) {
assertTrue(e.toString().contains("recursive"), "Unexpected error message: "+e);
}
}
@Test
- public void testVersionedTypeDoesNotRecurse() {
+ public void testVersionedTypeDoesNotRecurse() throws Exception {
+ // Alternatively, we could change this to tell foo:v2 reference foo:v1, but that feels
+ // like a bad idea!
String symbolicName = "my.catalog.app.id.basic";
- addCatalogItems(
- "brooklyn.catalog:",
- " id: " + symbolicName,
- " version: " + TEST_VERSION,
- " itemType: entity",
- " item:",
- " type: org.apache.brooklyn.entity.stock.BasicEntity");
+ addCatalogEntity(IdAndVersion.of(symbolicName, TEST_VERSION), TestEntity.class.getName());
String versionedId = CatalogUtils.getVersionedId(symbolicName, TEST_VERSION);
try {
- addCatalogItems(
- "brooklyn.catalog:",
- " id: " + symbolicName,
- " version: " + TEST_VERSION + "-update",
- " itemType: entity",
- " item:",
- " type: " + versionedId);
- fail("Catalog addition expected to fail due to non-existent java type " + versionedId);
+ addCatalogEntity(IdAndVersion.of(symbolicName, TEST_VERSION + "-update"), versionedId);
+ fail("Catalog addition expected to fail due to recursive reference to " + versionedId);
} catch (IllegalStateException e) {
assertTrue(e.toString().contains("recursive"), "Unexpected error message: "+e);
}
@@ -625,33 +397,17 @@ public class CatalogYamlEntityTest extends AbstractYamlTest {
@Test
public void testIndirectRecursionFails() throws Exception {
- String symbolicName = "my.catalog.app.id.basic";
+ String callerSymbolicName = "my.catalog.app.id.caller";
+ String calleeSymbolicName = "my.catalog.app.id.callee";
+
// Need to have a stand alone caller first so we can create an item to depend on it.
// After that replace it/insert a new version which completes the cycle
- addCatalogItems(
- "brooklyn.catalog:",
- " id: " + symbolicName + ".caller",
- " version: " + TEST_VERSION + "pre",
- " itemType: entity",
- " item:",
- " type: "+BasicEntity.class.getName());
+ addCatalogEntity(IdAndVersion.of(callerSymbolicName, TEST_VERSION + "-pre"), TestEntity.class.getName());
- addCatalogItems(
- "brooklyn.catalog:",
- " id: " + symbolicName + ".callee",
- " version: " + TEST_VERSION,
- " itemType: entity",
- " item:",
- " type: " + symbolicName + ".caller");
+ addCatalogEntity(IdAndVersion.of(calleeSymbolicName, TEST_VERSION), callerSymbolicName);
try {
- addCatalogItems(
- "brooklyn.catalog:",
- " id: " + symbolicName + ".caller",
- " version: " + TEST_VERSION,
- " itemType: entity",
- " item:",
- " type: " + symbolicName + ".callee");
+ addCatalogEntity(IdAndVersion.of(callerSymbolicName, TEST_VERSION), calleeSymbolicName);
fail();
} catch (IllegalStateException e) {
assertTrue(e.toString().contains("recursive"), "Unexpected error message: "+e);
@@ -660,38 +416,29 @@ public class CatalogYamlEntityTest extends AbstractYamlTest {
@Test
public void testChildItemsDoNotRecurse() throws Exception {
- String symbolicName = "my.catalog.app.id.basic";
+ String callerSymbolicName = "my.catalog.app.id.caller";
+ String calleeSymbolicName = "my.catalog.app.id.callee";
+
// Need to have a stand alone caller first so we can create an item to depend on it.
// After that replace it/insert a new version which completes the cycle
- addCatalogItems(
- "brooklyn.catalog:",
- " id: " + symbolicName + ".caller",
- " version: " + TEST_VERSION + "pre",
- " itemType: entity",
- " item:",
- " type: org.apache.brooklyn.entity.stock.BasicEntity");
+
+ addCatalogEntity(IdAndVersion.of(callerSymbolicName, TEST_VERSION + "-pre"), TestEntity.class.getName());
- addCatalogItems(
- "brooklyn.catalog:",
- " id: " + symbolicName + ".callee",
- " version: " + TEST_VERSION,
- " itemType: entity",
- " item:",
- " type: " + symbolicName + ".caller");
+ addCatalogEntity(IdAndVersion.of(calleeSymbolicName, TEST_VERSION), callerSymbolicName);
try {
// TODO Only passes if include "services:" and if itemType=entity, rather than "template"!
// Being a child is important, triggers the case where: we allow retrying with other transformers.
addCatalogItems(
"brooklyn.catalog:",
- " id: " + symbolicName + ".caller",
+ " id: " + callerSymbolicName,
" version: " + TEST_VERSION,
" itemType: entity",
" item:",
" services:",
- " - type: org.apache.brooklyn.entity.stock.BasicEntity",
+ " - type: " + BasicEntity.class.getName(),
" brooklyn.children:",
- " - type: " + symbolicName + ".callee");
+ " - type: " + calleeSymbolicName);
fail();
} catch (IllegalStateException e) {
assertTrue(e.toString().contains("recursive"), "Unexpected error message: "+e);
@@ -701,116 +448,92 @@ public class CatalogYamlEntityTest extends AbstractYamlTest {
@Test
public void testRecursiveCheckForDepenentsOnly() throws Exception {
String symbolicName = "my.catalog.app.id.basic";
- addCatalogItems(
- "brooklyn.catalog:",
- " id: " + symbolicName,
- " version: " + TEST_VERSION,
- " itemType: entity",
- " item:",
- " type: org.apache.brooklyn.entity.stock.BasicEntity");
+ addCatalogEntity(symbolicName, TestEntity.class.getName());
createAndStartApplication(
"services:",
- "- type: " + ver(symbolicName),
+ "- type: " + symbolicName,
" brooklyn.children:",
- " - type: " + ver(symbolicName),
- "- type: " + ver(symbolicName),
+ " - type: " + symbolicName,
+ "- type: " + symbolicName,
" brooklyn.children:",
- " - type: " + ver(symbolicName));
- }
-
- @Test
- public void testOsgiNotLeakingToParent() {
- addCatalogOSGiEntity(SIMPLE_ENTITY_TYPE);
- try {
- addCatalogItems(
- "brooklyn.catalog:",
- " id: " + SIMPLE_ENTITY_TYPE,
- " version: " + TEST_VERSION + "-update",
- " itemType: entity",
- " item:",
- " type: " + SIMPLE_ENTITY_TYPE);
- fail("Catalog addition expected to fail due to non-existent java type " + SIMPLE_ENTITY_TYPE);
- } catch (IllegalStateException e) {
- assertTrue(e.toString().contains("recursive"), "Unexpected error message: "+e);
- }
+ " - type: " + symbolicName);
}
@Test
public void testConfigAppliedToCatalogItem() throws Exception {
- addCatalogOSGiEntity("test", TestEntity.class.getName());
- String testName = "test-applies-config-on-catalog-item";
+ addCatalogEntity("test", TestEntity.class.getName());
+ String val = "test-applies-config-on-catalog-item";
Entity app = createAndStartApplication(
"services:",
- "- type: " + ver("test"),
+ "- type: test",
" brooklyn.config:",
- " test.confName: " + testName);
+ " test.confName: " + val);
Entity testEntity = Iterables.getOnlyElement(app.getChildren());
- assertEquals(testEntity.config().get(TestEntity.CONF_NAME), testName);
+ assertEquals(testEntity.config().get(TestEntity.CONF_NAME), val);
}
@Test
public void testFlagsAppliesToCatalogItem() throws Exception {
- addCatalogOSGiEntity("test", TestEntity.class.getName());
- String testName = "test-applies-config-on-catalog-item";
+ addCatalogEntity("test", TestEntity.class.getName());
+ String val = "test-applies-config-on-catalog-item";
Entity app = createAndStartApplication(
"services:",
"- type: " + ver("test"),
- " confName: " + testName);
+ " confName: " + val);
Entity testEntity = Iterables.getOnlyElement(app.getChildren());
- assertEquals(testEntity.config().get(TestEntity.CONF_NAME), testName);
+ assertEquals(testEntity.config().get(TestEntity.CONF_NAME), val);
}
@Test
public void testExplicitFlagsAppliesToCatalogItem() throws Exception {
- addCatalogOSGiEntity("test", TestEntity.class.getName());
- String testName = "test-applies-config-on-catalog-item";
+ addCatalogEntity("test", TestEntity.class.getName());
+ String val = "test-applies-config-on-catalog-item";
Entity app = createAndStartApplication(
"services:",
"- type: " + ver("test"),
" brooklyn.flags:",
- " confName: " + testName);
+ " confName: " + val);
Entity testEntity = Iterables.getOnlyElement(app.getChildren());
- assertEquals(testEntity.config().get(TestEntity.CONF_NAME), testName);
+ assertEquals(testEntity.config().get(TestEntity.CONF_NAME), val);
}
-
@Test
public void testConfigAppliedToCatalogItemImpl() throws Exception {
- addCatalogOSGiEntity("test", TestEntityImpl.class.getName());
- String testName = "test-applies-config-on-catalog-item";
+ addCatalogEntity("test", TestEntityImpl.class.getName());
+ String val = "test-applies-config-on-catalog-item";
Entity app = createAndStartApplication(
"services:",
"- type: " + ver("test"),
" brooklyn.config:",
- " test.confName: " + testName);
+ " test.confName: " + val);
Entity testEntity = Iterables.getOnlyElement(app.getChildren());
- assertEquals(testEntity.config().get(TestEntity.CONF_NAME), testName);
+ assertEquals(testEntity.config().get(TestEntity.CONF_NAME), val);
}
@Test
public void testFlagsAppliesToCatalogItemImpl() throws Exception {
- addCatalogOSGiEntity("test", TestEntityImpl.class.getName());
- String testName = "test-applies-config-on-catalog-item";
+ addCatalogEntity("test", TestEntityImpl.class.getName());
+ String val = "test-applies-config-on-catalog-item";
Entity app = createAndStartApplication(
"services:",
"- type: " + ver("test"),
- " confName: " + testName);
+ " confName: " + val);
Entity testEntity = Iterables.getOnlyElement(app.getChildren());
- assertEquals(testEntity.config().get(TestEntity.CONF_NAME), testName);
+ assertEquals(testEntity.config().get(TestEntity.CONF_NAME), val);
}
@Test
public void testExplicitFlagsAppliesToCatalogItemImpl() throws Exception {
- addCatalogOSGiEntity("test", TestEntityImpl.class.getName());
- String testName = "test-applies-config-on-catalog-item";
+ addCatalogEntity("test", TestEntityImpl.class.getName());
+ String val = "test-applies-config-on-catalog-item";
Entity app = createAndStartApplication(
"services:",
"- type: " + ver("test"),
" brooklyn.flags:",
- " confName: " + testName);
+ " confName: " + val);
Entity testEntity = Iterables.getOnlyElement(app.getChildren());
- assertEquals(testEntity.config().get(TestEntity.CONF_NAME), testName);
+ assertEquals(testEntity.config().get(TestEntity.CONF_NAME), val);
}
@Test
@@ -890,70 +613,12 @@ public class CatalogYamlEntityTest extends AbstractYamlTest {
mgmt().getCatalog().deleteCatalogItem(id, version);
}
- @Test
- public void testCreateOsgiSpecFromRegistry() throws Exception {
- TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH);
-
- String symbolicName = "my.catalog.app.id.registry.spec";
- addCatalogItems(
- "brooklyn.catalog:",
- " id: " + symbolicName,
- " 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: " + SIMPLE_ENTITY_TYPE);
-
- BrooklynTypeRegistry registry = mgmt().getTypeRegistry();
- RegisteredType item = registry.get(symbolicName, TEST_VERSION);
- AbstractBrooklynObjectSpec<?, ?> spec = registry.createSpec(item, null, null);
- assertEquals(spec.getCatalogItemId(), ver(symbolicName));
-
- deleteCatalogEntity(symbolicName);
- }
-
- @Test
- public void testIndirectCatalogItemCanLoadResources() throws Exception {
- TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH);
-
- String symbolicNameInner = "my.catalog.app.id.inner";
- String symbolicNameOuter = "my.catalog.app.id.outer";
- addCatalogItems(
- "brooklyn.catalog:",
- " version: " + TEST_VERSION,
- " items:",
- " - id: " + symbolicNameInner,
- " name: My Catalog App",
- " description: My description",
- " icon_url: classpath://path/to/myicon.jpg",
- " libraries:",
- " - url: " + OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL,
- " item: " + SIMPLE_ENTITY_TYPE,
- " - id: " + symbolicNameOuter,
- " item: " + symbolicNameInner);
-
- String yaml = "name: " + symbolicNameOuter + "\n" +
- "services: \n" +
- " - serviceType: "+ver(symbolicNameOuter);
- Entity app = createAndStartApplication(yaml);
- Entity entity = app.getChildren().iterator().next();
-
- ResourceUtils.create(entity).getResourceAsString("classpath://yaml-ref-osgi-entity.yaml");
-
- deleteCatalogEntity(symbolicNameInner);
- deleteCatalogEntity(symbolicNameOuter);
- }
-
// The test is disabled as it fails. The entity will get assigned the outer-most catalog
// item which doesn't have the necessary libraries with visibility to the entity's classpath
// When loading resources from inside the entity then we will use the wrong BCLCS. A workaround
// has been implemented which explicitly adds the entity's class loader to the fallbacks.
@Test(groups="WIP")
public void testCatalogItemIdInReferencedItems() throws Exception {
- TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH);
-
String symbolicNameInner = "my.catalog.app.id.inner";
String symbolicNameOuter = "my.catalog.app.id.outer";
addCatalogItems(
@@ -961,12 +626,7 @@ public class CatalogYamlEntityTest extends AbstractYamlTest {
" version: " + TEST_VERSION,
" items:",
" - id: " + symbolicNameInner,
- " name: My Catalog App",
- " description: My description",
- " icon_url: classpath://path/to/myicon.jpg",
- " libraries:",
- " - url: " + OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL,
- " item: " + SIMPLE_ENTITY_TYPE,
+ " item: " + TestEntity.class.getName(),
" - id: " + symbolicNameOuter,
" item: " + symbolicNameInner);
@@ -985,97 +645,47 @@ public class CatalogYamlEntityTest extends AbstractYamlTest {
}
private void registerAndLaunchAndAssertSimpleEntity(String symbolicName, String serviceType) throws Exception {
- addCatalogOSGiEntity(symbolicName, serviceType);
- String yaml = "name: simple-app-yaml\n" +
- "location: localhost\n" +
- "services: \n" +
- " - serviceType: "+ver(symbolicName);
- Entity app = createAndStartApplication(yaml);
+ registerAndLaunchAndAssertSimpleEntity(symbolicName, serviceType, serviceType);
+ }
+
+ private void registerAndLaunchAndAssertSimpleEntity(String symbolicName, String serviceType, String expectedType) throws Exception {
+ addCatalogEntity(IdAndVersion.of(symbolicName, TEST_VERSION), serviceType);
+
+ Entity app = createAndStartApplication(
+ "services:",
+ "- type: "+ver(symbolicName, TEST_VERSION));
Entity simpleEntity = Iterables.getOnlyElement(app.getChildren());
- assertEquals(simpleEntity.getEntityType().getName(), SIMPLE_ENTITY_TYPE);
+ assertEquals(simpleEntity.getEntityType().getName(), expectedType);
deleteCatalogEntity(symbolicName);
}
- private void addCatalogOSGiEntity(String symbolicName) {
- addCatalogOSGiEntity(symbolicName, SIMPLE_ENTITY_TYPE);
- }
-
- private void addCatalogOSGiEntity(String symbolicName, String serviceType) {
- addCatalogOSGiEntity(symbolicName, serviceType, false);
- }
-
- private void addCatalogOSGiEntity(String symbolicName, String serviceType, boolean extraLib) {
- addCatalogItems(
- "brooklyn.catalog:",
- " id: " + symbolicName,
- " version: " + TEST_VERSION,
- " itemType: entity",
- " name: My Catalog App",
- " description: My description",
- " icon_url: classpath://path/to/myicon.jpg",
- " libraries:",
- " - url: " + OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL +
- (extraLib ? "\n"+" - url: "+OsgiStandaloneTest.BROOKLYN_OSGI_TEST_A_0_1_0_URL : ""),
- " item:",
- " type: " + serviceType);
- }
-
- private void addCatalogOSGiEntities(Map<String, String> idAndTypes) {
- List<String> lines = MutableList.of(
- "brooklyn.catalog:",
- " 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,
- " items:");
+ public static class IdAndVersion {
+ public final String id;
+ public final String version;
- for (Map.Entry<String, String> entry : idAndTypes.entrySet()) {
- lines.addAll(MutableList.of(
- " - id: " + entry.getKey(),
- " item:",
- " type: " + entry.getValue()));
+ public static IdAndVersion of(String id, String version) {
+ return new IdAndVersion(id, version);
+ }
+
+ public IdAndVersion(String id, String version) {
+ this.id = checkNotNull(id, "id");
+ this.version = checkNotNull(version, "version");
}
-
- addCatalogItems(lines);
}
- private void addCatalogChildOSGiEntityWithServicesBlock(String symbolicName, String serviceType) {
- addCatalogItems(
- "brooklyn.catalog:",
- " id: " + symbolicName,
- " version: " + TEST_VERSION,
- " itemType: entity",
- " name: My Catalog App",
- " description: My description",
- " icon_url: classpath://path/to/myicon.jpg",
- " libraries:",
- " - url: " + OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL,
- " item:",
- " services:",
- " - type: " + BasicEntity.class.getName(),
- " brooklyn.children:",
- " - type: " + serviceType);
+ private void addCatalogEntity(String symbolicName, String entityType) {
+ addCatalogEntity(IdAndVersion.of(symbolicName, TEST_VERSION), entityType);
}
- private void addCatalogChildOSGiEntity(String symbolicName, String serviceType) {
+ private void addCatalogEntity(IdAndVersion idAndVersion, String serviceType) {
addCatalogItems(
- "brooklyn.catalog:",
- " id: " + symbolicName,
- " itemType: entity",
- " 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:",
- " type: " + BasicEntity.class.getName(),
- " brooklyn.children:",
- " - type: " + serviceType);
+ "brooklyn.catalog:",
+ " id: " + idAndVersion.id,
+ " version: " + idAndVersion.version,
+ " itemType: entity",
+ " item:",
+ " type: " + serviceType);
}
-
}