fix more tests, pointing at type registry instead of catalog

note items added via OSGi will no longer show up in calls to search the catalog;
callers should use type registry instead.

at this point most things are done except:

* REST calls to catalog won't show things added via bundles (as they are in 
TypeRegistry)
* TEMPLATE items aren't supported
* LOCATION items aren't put/removed from BasicLocationRegistry (but I think 
that is no longer needed?)

need to fix those then can declare victory on this!


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/b016e67e
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/b016e67e
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/b016e67e

Branch: refs/heads/master
Commit: b016e67e9bef300677344b0d7eedcaee6e1940c0
Parents: 520fb6a
Author: Alex Heneveld <[email protected]>
Authored: Mon Jul 3 13:13:18 2017 +0100
Committer: Alex Heneveld <[email protected]>
Committed: Mon Jul 3 14:03:50 2017 +0100

----------------------------------------------------------------------
 .../api/typereg/BrooklynTypeRegistry.java       |  4 +-
 .../camp/brooklyn/ConfigParametersYamlTest.java |  3 +-
 .../catalog/CatalogOsgiLibraryTest.java         | 17 ++++---
 .../catalog/SpecParameterUnwrappingTest.java    | 42 +++++++++--------
 .../core/typereg/BasicBrooklynTypeRegistry.java |  5 ++-
 .../core/mgmt/rebind/RebindCatalogItemTest.java | 47 +++++++++++++++++++-
 .../core/mgmt/rebind/RebindTestFixture.java     | 33 --------------
 7 files changed, 79 insertions(+), 72 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/b016e67e/api/src/main/java/org/apache/brooklyn/api/typereg/BrooklynTypeRegistry.java
----------------------------------------------------------------------
diff --git 
a/api/src/main/java/org/apache/brooklyn/api/typereg/BrooklynTypeRegistry.java 
b/api/src/main/java/org/apache/brooklyn/api/typereg/BrooklynTypeRegistry.java
index 33c6733..96b0bc6 100644
--- 
a/api/src/main/java/org/apache/brooklyn/api/typereg/BrooklynTypeRegistry.java
+++ 
b/api/src/main/java/org/apache/brooklyn/api/typereg/BrooklynTypeRegistry.java
@@ -18,8 +18,6 @@
  */
 package org.apache.brooklyn.api.typereg;
 
-import java.util.Collection;
-
 import javax.annotation.Nullable;
 
 import org.apache.brooklyn.api.entity.Entity;
@@ -52,7 +50,7 @@ public interface BrooklynTypeRegistry {
     /** @return The item matching the given given 
      * {@link RegisteredType#getSymbolicName() symbolicName} 
      * and optionally {@link RegisteredType#getVersion()},
-     * taking the best version if the version is null or a default marker,
+     * taking the best version if the version is null, blank, or a default 
marker,
      * returning null if no matches are found. */
     RegisteredType get(String symbolicName, String version);
     /** as {@link #get(String, String)} but the given string here 

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/b016e67e/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ConfigParametersYamlTest.java
----------------------------------------------------------------------
diff --git 
a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ConfigParametersYamlTest.java
 
b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ConfigParametersYamlTest.java
index 6e62bae..98ccb0b 100644
--- 
a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ConfigParametersYamlTest.java
+++ 
b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ConfigParametersYamlTest.java
@@ -1229,7 +1229,8 @@ public class ConfigParametersYamlTest extends 
AbstractYamlRebindTest {
         
         // check on spec
         
-        AbstractBrooklynObjectSpec<?, ?> spec = 
mgmt().getCatalog().peekSpec(mgmt().getCatalog().getCatalogItem("wrapper-entity",
 null));
+        AbstractBrooklynObjectSpec<?, ?> spec = 
mgmt().getTypeRegistry().createSpec(
+            mgmt().getTypeRegistry().get("wrapper-entity", ""), null, null);
         Assert.assertEquals(spec.getParameters().size(), 
SpecParameterUnwrappingTest.NUM_ENTITY_DEFAULT_CONFIG_KEYS + 
NUM_CONFIG_KEYS_FROM_TEST_BLUEPRINT, 
             "params: "+spec.getParameters());
         

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/b016e67e/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiLibraryTest.java
----------------------------------------------------------------------
diff --git 
a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiLibraryTest.java
 
b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiLibraryTest.java
index bd07075..7f7cbe7 100644
--- 
a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiLibraryTest.java
+++ 
b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiLibraryTest.java
@@ -27,11 +27,10 @@ import java.util.Arrays;
 import java.util.Map;
 import java.util.Objects;
 
-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.internal.AbstractBrooklynObjectSpec;
 import org.apache.brooklyn.api.mgmt.ManagementContext;
+import org.apache.brooklyn.api.typereg.OsgiBundleWithUrl;
 import org.apache.brooklyn.api.typereg.RegisteredType;
 import org.apache.brooklyn.camp.brooklyn.AbstractYamlTest;
 import org.apache.brooklyn.core.config.external.AbstractExternalConfigSupplier;
@@ -124,7 +123,7 @@ public class CatalogOsgiLibraryTest extends 
AbstractYamlTest {
                 "    services:",
                 "    - type: 
org.apache.brooklyn.test.osgi.entities.SimpleApplication");
 
-        CatalogItem<?, ?> item = 
mgmt().getCatalog().getCatalogItem("simple-osgi-library", "1.0");
+        RegisteredType item = 
mgmt().getTypeRegistry().get("simple-osgi-library", "1.0");
         assertCatalogLibraryUrl(item, classpathUrl);
     }
 
@@ -141,7 +140,7 @@ public class CatalogOsgiLibraryTest extends 
AbstractYamlTest {
                 "    services:",
                 "    - type: 
org.apache.brooklyn.test.osgi.entities.SimpleApplication");
 
-        CatalogItem<?, ?> item = 
mgmt().getCatalog().getCatalogItem("simple-osgi-library", "1.0");
+        RegisteredType item = 
mgmt().getTypeRegistry().get("simple-osgi-library", "1.0");
         assertCatalogLibraryUrl(item, classpathUrl);
     }
 
@@ -158,7 +157,7 @@ public class CatalogOsgiLibraryTest extends 
AbstractYamlTest {
                 "    services:",
                 "    - type: 
org.apache.brooklyn.test.osgi.entities.SimpleApplication");
 
-        CatalogItem<?, ?> item = 
mgmt().getCatalog().getCatalogItem("simple-osgi-library", "1.0");
+        RegisteredType item = 
mgmt().getTypeRegistry().get("simple-osgi-library", "1.0");
         assertCatalogLibraryUrl(item, jarUrl.toString());
     }
 
@@ -220,7 +219,7 @@ public class CatalogOsgiLibraryTest extends 
AbstractYamlTest {
                 "    services:",
                 "    - type: 
org.apache.brooklyn.test.osgi.entities.SimpleApplication");
 
-        CatalogItem<?, ?> item = 
mgmt().getCatalog().getCatalogItem("simple-osgi-library", "1.0");
+        RegisteredType item = 
mgmt().getTypeRegistry().get("simple-osgi-library", "1.0");
         assertCatalogLibraryUrl(item, classpathUrl);
     }
 
@@ -415,7 +414,7 @@ public class CatalogOsgiLibraryTest extends 
AbstractYamlTest {
         }
         String expectedUrl = "http://"; + escapedUsername + ":" + 
escapedPassword+ "@" + jarUrl.getHost() + ":" + jarUrl.getPort() + 
jarUrl.getPath();
         
-        CatalogItem<?, ?> item = 
mgmt().getCatalog().getCatalogItem("simple-osgi-library", "1.0");
+        RegisteredType item = 
mgmt().getTypeRegistry().get("simple-osgi-library", "1.0");
         assertCatalogLibraryUrl(item, expectedUrl);
     }
     
@@ -432,8 +431,8 @@ public class CatalogOsgiLibraryTest extends 
AbstractYamlTest {
         }
     }
     
-    protected void assertCatalogLibraryUrl(CatalogItem<?,?> item, String 
expectedUrl) {
-        for (CatalogBundle b: item.getLibraries()) {
+    protected void assertCatalogLibraryUrl(RegisteredType item, String 
expectedUrl) {
+        for (OsgiBundleWithUrl b: item.getLibraries()) {
             if (Objects.equals(b.getUrl(), expectedUrl)) {
                 return;
             }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/b016e67e/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/SpecParameterUnwrappingTest.java
----------------------------------------------------------------------
diff --git 
a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/SpecParameterUnwrappingTest.java
 
b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/SpecParameterUnwrappingTest.java
index 1e20f5e..e5a69c7 100644
--- 
a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/SpecParameterUnwrappingTest.java
+++ 
b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/SpecParameterUnwrappingTest.java
@@ -119,8 +119,7 @@ public class SpecParameterUnwrappingTest extends 
AbstractYamlTest {
 
         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 = catalog.peekSpec(item);
+        AbstractBrooklynObjectSpec<?,?> spec = peekSpec();
         assertTrue(Iterables.tryFind(spec.getParameters(), 
Predicates.<SpecParameter<?>>equalTo(SIMPLE_PARAM)).isPresent());
     }
 
@@ -134,8 +133,7 @@ public class SpecParameterUnwrappingTest extends 
AbstractYamlTest {
             "  item:",
             "    type: "+ testClass.getName());
 
-        CatalogItem<?, ?> item = catalog.getCatalogItem(SYMBOLIC_NAME, 
TEST_VERSION);
-        AbstractBrooklynObjectSpec<?, ?> spec = catalog.peekSpec(item);
+        AbstractBrooklynObjectSpec<?, ?> spec = peekSpec();
         assertEquals(ImmutableSet.copyOf(spec.getParameters()), 
ImmutableSet.copyOf(BasicSpecParameter.fromClass(mgmt(),testClass)));
     }
 
@@ -153,8 +151,7 @@ public class SpecParameterUnwrappingTest extends 
AbstractYamlTest {
                 "    - simple");
         final int NUM_CONFIG_KEYS_FROM_TEST_BLUEPRINT = 1;
 
-        CatalogItem<?, ?> item = catalog.getCatalogItem(SYMBOLIC_NAME, 
TEST_VERSION);
-        AbstractBrooklynObjectSpec<?,?> spec = catalog.peekSpec(item);
+        AbstractBrooklynObjectSpec<?,?> spec = peekSpec();
         List<SpecParameter<?>> params = spec.getParameters();
         assertTrue(Iterables.tryFind(params, 
nameEqualTo("simple")).isPresent());
         assertTrue(Iterables.tryFind(params, 
nameEqualTo(SHARED_CONFIG.getName())).isPresent());
@@ -181,8 +178,7 @@ public class SpecParameterUnwrappingTest extends 
AbstractYamlTest {
                 "      type: paramItem");
         final int NUM_CONFIG_KEYS_FROM_TEST_BLUEPRINT = 1;
 
-        CatalogItem<?, ?> item = catalog.getCatalogItem(SYMBOLIC_NAME, 
TEST_VERSION);
-        AbstractBrooklynObjectSpec<?,?> spec = catalog.peekSpec(item);
+        AbstractBrooklynObjectSpec<?,?> spec = peekSpec();
         List<SpecParameter<?>> params = spec.getParameters();
         // should have simple in parent yaml type and sample from parent java 
type
         assertEquals(params.size(), 
getNumDefaultConfigKeysFor(type.getSimpleName()) + 
NUM_CONFIG_KEYS_FROM_TEST_BLUEPRINT,
@@ -223,8 +219,7 @@ public class SpecParameterUnwrappingTest extends 
AbstractYamlTest {
                 "      - another");
         final int NUM_CONFIG_KEYS_FROM_TEST_BLUEPRINT = 2;
 
-        CatalogItem<?, ?> item = catalog.getCatalogItem(SYMBOLIC_NAME, 
TEST_VERSION);
-        AbstractBrooklynObjectSpec<?,?> spec = catalog.peekSpec(item);
+        AbstractBrooklynObjectSpec<?,?> spec = peekSpec();
         List<SpecParameter<?>> params = spec.getParameters();
         // should have another locally, simple in parent yaml type, and sample 
from parent java type
         assertEquals(params.size(), 
getNumDefaultConfigKeysFor(type.getSimpleName()) + 
NUM_CONFIG_KEYS_FROM_TEST_BLUEPRINT,
@@ -254,8 +249,7 @@ public class SpecParameterUnwrappingTest extends 
AbstractYamlTest {
                 "        label: override");
         final int NUM_CONFIG_KEYS_FROM_TEST_BLUEPRINT = 1;
 
-        CatalogItem<?, ?> item = catalog.getCatalogItem(SYMBOLIC_NAME, 
TEST_VERSION);
-        AbstractBrooklynObjectSpec<?,?> spec = catalog.peekSpec(item);
+        AbstractBrooklynObjectSpec<?,?> spec = peekSpec();
         List<SpecParameter<?>> params = spec.getParameters();
         // should have simple locally (and in parent yaml type) and sample 
from parent java type
         assertEquals(params.size(), 
getNumDefaultConfigKeysFor(type.getSimpleName()) + 
NUM_CONFIG_KEYS_FROM_TEST_BLUEPRINT,
@@ -286,8 +280,7 @@ public class SpecParameterUnwrappingTest extends 
AbstractYamlTest {
                 "      - name: simple",
                 "        default: rabbits");
 
-        CatalogItem<?, ?> item = catalog.getCatalogItem(SYMBOLIC_NAME, 
TEST_VERSION);
-        AbstractBrooklynObjectSpec<?,?> spec = catalog.peekSpec(item);
+        AbstractBrooklynObjectSpec<?,?> spec = peekSpec();
         List<SpecParameter<?>> params = spec.getParameters();
         assertTrue(Iterables.tryFind(params, 
nameEqualTo("simple")).isPresent());
         Optional<ConfigKey<?>> config = 
Iterables.tryFind(spec.getConfig().keySet(), 
ConfigPredicates.nameEqualTo("simple"));
@@ -312,8 +305,7 @@ public class SpecParameterUnwrappingTest extends 
AbstractYamlTest {
                 "        simple: value");
         final int NUM_CONFIG_KEYS_FROM_TEST_BLUEPRINT = 1;
 
-        CatalogItem<?, ?> item = catalog.getCatalogItem(SYMBOLIC_NAME, 
TEST_VERSION);
-        AbstractBrooklynObjectSpec<?,?> spec = catalog.peekSpec(item);
+        AbstractBrooklynObjectSpec<?, ?> spec = peekSpec();
         List<SpecParameter<?>> params = spec.getParameters();
         assertEquals(params.size(), NUM_ENTITY_DEFAULT_CONFIG_KEYS + 
ConfigEntityForTest.NUM_CONFIG_KEYS_DEFINED_HERE + 
NUM_CONFIG_KEYS_FROM_TEST_BLUEPRINT);
         assertTrue(Iterables.tryFind(params, 
nameEqualTo("simple")).isPresent());
@@ -323,6 +315,15 @@ public class SpecParameterUnwrappingTest extends 
AbstractYamlTest {
         assertEquals(value, "value");
     }
 
+    private AbstractBrooklynObjectSpec<?, ?> peekSpec() {
+        return peekSpec(SYMBOLIC_NAME, TEST_VERSION);
+    }
+
+    private AbstractBrooklynObjectSpec<?, ?> peekSpec(String name, String 
version) {
+        return mgmt().getTypeRegistry().createSpec(
+            mgmt().getTypeRegistry().get(name, version), null, null);
+    }
+
     @Test
     public void testDependantCatalogConfigReplacesParameters() {
         addCatalogItems(
@@ -341,8 +342,7 @@ public class SpecParameterUnwrappingTest extends 
AbstractYamlTest {
                 "      - name: simple",
                 "        default: rabbits");
 
-        CatalogItem<?, ?> item = catalog.getCatalogItem(SYMBOLIC_NAME, 
TEST_VERSION);
-        AbstractBrooklynObjectSpec<?,?> spec = catalog.peekSpec(item);
+        AbstractBrooklynObjectSpec<?,?> spec = peekSpec();
         List<SpecParameter<?>> params = spec.getParameters();
         assertTrue(Iterables.tryFind(params, 
nameEqualTo("simple")).isPresent());
         Optional<ConfigKey<?>> config = 
Iterables.tryFind(spec.getConfig().keySet(), 
ConfigPredicates.nameEqualTo("simple"));
@@ -365,8 +365,7 @@ public class SpecParameterUnwrappingTest extends 
AbstractYamlTest {
                 "      brooklyn.parameters:",
                 "      - simple");
 
-        CatalogItem<?, ?> item = catalog.getCatalogItem(SYMBOLIC_NAME, 
TEST_VERSION);
-        EntitySpec<?> parentSpec = (EntitySpec<?>) catalog.peekSpec(item);
+        EntitySpec<?> parentSpec = (EntitySpec<?>) peekSpec();
         EntitySpec<?> spec = parentSpec.getChildren().get(0);
         List<SpecParameter<?>> params = spec.getParameters();
         assertEquals(params.size(), NUM_ENTITY_DEFAULT_CONFIG_KEYS + 2, 
"params="+params);
@@ -550,8 +549,7 @@ public class SpecParameterUnwrappingTest extends 
AbstractYamlTest {
                 "              test: $brooklyn:config(\"num\")");
         final int NUM_CONFIG_KEYS_FROM_WITH_PARAMS_TEST_BLUEPRINT = 1;
 
-        CatalogItem<?, ?> item = 
catalog.getCatalogItem(ConfigEntityForTest.class.getSimpleName() + 
"WithParams", TEST_VERSION);
-        AbstractBrooklynObjectSpec<?,?> spec = catalog.peekSpec(item);
+        AbstractBrooklynObjectSpec<?,?> spec = 
peekSpec(ConfigEntityForTest.class.getSimpleName() + "WithParams", 
TEST_VERSION);
         List<SpecParameter<?>> params = spec.getParameters();
         assertEquals(params.size(), NUM_ENTITY_DEFAULT_CONFIG_KEYS + 
ConfigEntityForTest.NUM_CONFIG_KEYS_DEFINED_HERE + 
NUM_CONFIG_KEYS_FROM_WITH_PARAMS_TEST_BLUEPRINT,
             "params="+params);

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/b016e67e/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java
 
b/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java
index 2e1a1fa..f7f71e5 100644
--- 
a/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java
+++ 
b/core/src/main/java/org/apache/brooklyn/core/typereg/BasicBrooklynTypeRegistry.java
@@ -46,6 +46,7 @@ import org.apache.brooklyn.util.guava.Maybe;
 import org.apache.brooklyn.util.osgi.VersionedName;
 import org.apache.brooklyn.util.text.BrooklynVersionSyntax;
 import org.apache.brooklyn.util.text.Identifiers;
+import org.apache.brooklyn.util.text.Strings;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -97,7 +98,7 @@ public class BasicBrooklynTypeRegistry implements 
BrooklynTypeRegistry {
         RegisteredTypeLoadingContext context = contextFinal;
         if (context==null) context = RegisteredTypeLoadingContexts.any();
         String version = versionFinal;
-        if (version==null) version = BrooklynCatalog.DEFAULT_VERSION;
+        if (Strings.isBlank(version)) version = 
BrooklynCatalog.DEFAULT_VERSION;
 
         if (!BrooklynCatalog.DEFAULT_VERSION.equals(version)) {
             // normal code path when version is supplied
@@ -139,7 +140,7 @@ public class BasicBrooklynTypeRegistry implements 
BrooklynTypeRegistry {
             return Maybe.of( RegisteredTypes.CI_TO_RT.apply( item ) );
         
         return Maybe.absent("No matches for "+symbolicNameOrAliasIfNoVersion+
-            (versionFinal!=null ? ":"+versionFinal : "")+
+            (Strings.isNonBlank(versionFinal) ? ":"+versionFinal : "")+
             (contextFinal!=null ? " ("+contextFinal+")" : "") );
     }
 

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/b016e67e/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindCatalogItemTest.java
----------------------------------------------------------------------
diff --git 
a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindCatalogItemTest.java
 
b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindCatalogItemTest.java
index 2418a33..77d8919 100644
--- 
a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindCatalogItemTest.java
+++ 
b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindCatalogItemTest.java
@@ -26,7 +26,9 @@ import static org.testng.Assert.fail;
 
 import java.io.File;
 import java.util.Map;
+import java.util.Set;
 
+import org.apache.brooklyn.api.catalog.BrooklynCatalog;
 import org.apache.brooklyn.api.catalog.CatalogItem;
 import org.apache.brooklyn.api.catalog.CatalogItem.CatalogItemType;
 import org.apache.brooklyn.api.entity.EntitySpec;
@@ -40,6 +42,8 @@ import 
org.apache.brooklyn.core.catalog.internal.CatalogEntityItemDto;
 import org.apache.brooklyn.core.catalog.internal.CatalogItemBuilder;
 import org.apache.brooklyn.core.catalog.internal.CatalogLocationItemDto;
 import org.apache.brooklyn.core.catalog.internal.CatalogPolicyItemDto;
+import org.apache.brooklyn.core.catalog.internal.CatalogUtils;
+import org.apache.brooklyn.core.entity.EntityFunctions;
 import org.apache.brooklyn.core.internal.BrooklynProperties;
 import org.apache.brooklyn.core.mgmt.internal.LocalManagementContext;
 import org.apache.brooklyn.core.policy.AbstractPolicy;
@@ -58,7 +62,9 @@ import com.google.common.base.Joiner;
 import com.google.common.base.Optional;
 import com.google.common.base.Predicates;
 import com.google.common.base.Throwables;
+import com.google.common.collect.FluentIterable;
 import com.google.common.collect.Iterables;
+import com.google.common.collect.Sets;
 
 public class RebindCatalogItemTest extends RebindTestFixtureWithApp {
 
@@ -274,7 +280,7 @@ public class RebindCatalogItemTest extends 
RebindTestFixtureWithApp {
         assertFalse(itemPostRebind.isPresent(), "item="+itemPostRebind);
     }
 
-    @Test(invocationCount = 3)
+    @Test(invocationCount = 3)  // why three times?
     public void testCanTagCatalogItemAfterRebind() {
         String symbolicName = "rebind-yaml-catalog-item-test";
         String yaml = Joiner.on("\n").join(
@@ -292,9 +298,13 @@ public class RebindCatalogItemTest extends 
RebindTestFixtureWithApp {
                 .build();
         origManagementContext.getCatalog().addItem(item);
         LOG.info("Added item to catalog: {}, id={}", item, item.getId());
-
+        
+        
assertEquals(Iterables.size(origManagementContext.getTypeRegistry().getAll()), 
1);
         
assertEquals(Iterables.size(origManagementContext.getCatalog().getCatalogItems()),
 1);
+        // in OSGi/type registry you cannot edit tags directly (they won't be 
persisted as they come from BOM)
+        // RegisteredType origItem = 
origManagementContext.getTypeRegistry().get(symbolicName, TEST_VERSION);
         CatalogItem<?,?> origItem = 
origManagementContext.getCatalog().getCatalogItem(symbolicName, TEST_VERSION);
+        assertNotNull(origItem, "Item not in catalog (might be using new type 
registry where adding tags to items isn't supported as items come from BOM)");
         final String tag = "tag1";
         origItem.tags().addTag(tag);
         assertTrue(origItem.tags().containsTag(tag));
@@ -374,4 +384,37 @@ public class RebindCatalogItemTest extends 
RebindTestFixtureWithApp {
         }
         assertCatalogsEqual(newManagementContext.getCatalog(), 
origManagementContext.getCatalog());
     }
+    
+    protected void assertCatalogsEqual(BrooklynCatalog actual, BrooklynCatalog 
expected) {
+        Set<String> actualIds = getCatalogItemIds(actual.getCatalogItems());
+        Set<String> expectedIds = 
getCatalogItemIds(expected.getCatalogItems());
+        assertEquals(actualIds.size(), 
Iterables.size(actual.getCatalogItems()), "id keyset size != size of catalog. 
Are there duplicates in the catalog?");
+        assertEquals(actualIds, expectedIds);
+        for (String versionedId : actualIds) {
+            String id = 
CatalogUtils.getSymbolicNameFromVersionedId(versionedId);
+            String version = 
CatalogUtils.getVersionFromVersionedId(versionedId);
+            assertCatalogItemsEqual(actual.getCatalogItem(id, version), 
expected.getCatalogItem(id, version));
+        }
+    }
+
+    private Set<String> getCatalogItemIds(Iterable<CatalogItem<Object, 
Object>> catalogItems) {
+        return FluentIterable.from(catalogItems)
+                .transform(EntityFunctions.id())
+                .copyInto(Sets.<String>newHashSet());
+   }
+
+    protected void assertCatalogItemsEqual(CatalogItem<?, ?> actual, 
CatalogItem<?, ?> expected) {
+        assertEquals(actual.getClass(), expected.getClass());
+        assertEquals(actual.getId(), expected.getId());
+        assertEquals(actual.getDisplayName(), expected.getDisplayName());
+        assertEquals(actual.getVersion(), expected.getVersion());
+        assertEquals(actual.getDescription(), expected.getDescription());
+        assertEquals(actual.getIconUrl(), expected.getIconUrl());
+        assertEquals(actual.getVersion(), expected.getVersion());
+        assertEquals(actual.getCatalogItemJavaType(), 
expected.getCatalogItemJavaType());
+        assertEquals(actual.getCatalogItemType(), 
expected.getCatalogItemType());
+        assertEquals(actual.getSpecType(), expected.getSpecType());
+        assertEquals(actual.getSymbolicName(), expected.getSymbolicName());
+        assertEquals(actual.getLibraries(), expected.getLibraries());
+    }
 }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/b016e67e/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestFixture.java
----------------------------------------------------------------------
diff --git 
a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestFixture.java
 
b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestFixture.java
index c94b933..c7d97a9 100644
--- 
a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestFixture.java
+++ 
b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestFixture.java
@@ -361,39 +361,6 @@ public abstract class RebindTestFixture<T extends 
StartableApplication> {
         persister.stop(false);
         return mementoManifest;
     }
-
-    protected void assertCatalogsEqual(BrooklynCatalog actual, BrooklynCatalog 
expected) {
-        Set<String> actualIds = getCatalogItemIds(actual.getCatalogItems());
-        Set<String> expectedIds = 
getCatalogItemIds(expected.getCatalogItems());
-        assertEquals(actualIds.size(), 
Iterables.size(actual.getCatalogItems()), "id keyset size != size of catalog. 
Are there duplicates in the catalog?");
-        assertEquals(actualIds, expectedIds);
-        for (String versionedId : actualIds) {
-            String id = 
CatalogUtils.getSymbolicNameFromVersionedId(versionedId);
-            String version = 
CatalogUtils.getVersionFromVersionedId(versionedId);
-            assertCatalogItemsEqual(actual.getCatalogItem(id, version), 
expected.getCatalogItem(id, version));
-        }
-    }
-
-    private Set<String> getCatalogItemIds(Iterable<CatalogItem<Object, 
Object>> catalogItems) {
-        return FluentIterable.from(catalogItems)
-                .transform(EntityFunctions.id())
-                .copyInto(Sets.<String>newHashSet());
-   }
-
-    protected void assertCatalogItemsEqual(CatalogItem<?, ?> actual, 
CatalogItem<?, ?> expected) {
-        assertEquals(actual.getClass(), expected.getClass());
-        assertEquals(actual.getId(), expected.getId());
-        assertEquals(actual.getDisplayName(), expected.getDisplayName());
-        assertEquals(actual.getVersion(), expected.getVersion());
-        assertEquals(actual.getDescription(), expected.getDescription());
-        assertEquals(actual.getIconUrl(), expected.getIconUrl());
-        assertEquals(actual.getVersion(), expected.getVersion());
-        assertEquals(actual.getCatalogItemJavaType(), 
expected.getCatalogItemJavaType());
-        assertEquals(actual.getCatalogItemType(), 
expected.getCatalogItemType());
-        assertEquals(actual.getSpecType(), expected.getSpecType());
-        assertEquals(actual.getSymbolicName(), expected.getSymbolicName());
-        assertEquals(actual.getLibraries(), expected.getLibraries());
-    }
     
 //    protected void assertCatalogContains(BrooklynCatalog catalog, 
CatalogItem<?, ?> item) {
 //        CatalogItem<?, ?> found = 
catalog.getCatalogItem(item.getSymbolicName(), item.getVersion());

Reply via email to