This is an automated email from the ASF dual-hosted git repository.

heneveld pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brooklyn-server.git

commit c961ccbc85375004fb31191206789431cd5d3f33
Author: Alex Heneveld <[email protected]>
AuthorDate: Thu Dec 8 00:15:12 2022 +0000

    updates to tests where same-bundle and library wasn't used for searching
---
 .../catalog/CatalogMakeOsgiBundleTest.java         |  4 +--
 .../catalog/CatalogOsgiVersionMoreEntityTest.java  | 14 ++++----
 .../catalog/CatalogOsgiYamlLocationTest.java       |  5 +--
 .../camp/brooklyn/catalog/CatalogScanOsgiTest.java | 40 +++++++++-------------
 .../camp/brooklyn/test/lite/CampYamlLiteTest.java  | 22 +++++++-----
 .../catalog/internal/BasicBrooklynCatalog.java     |  6 +++-
 .../rest/resources/BundleAndTypeResourcesTest.java | 12 +++----
 .../rest/resources/CatalogResourceTest.java        |  4 +--
 .../rt/felix/EmbeddedFelixFrameworkTest.java       |  7 ++--
 9 files changed, 60 insertions(+), 54 deletions(-)

diff --git 
a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogMakeOsgiBundleTest.java
 
b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogMakeOsgiBundleTest.java
index 122c4a088d..975fa07336 100644
--- 
a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogMakeOsgiBundleTest.java
+++ 
b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogMakeOsgiBundleTest.java
@@ -149,8 +149,8 @@ public class CatalogMakeOsgiBundleTest extends 
AbstractYamlTest {
         
         RegisteredType item = mgmt().getTypeRegistry().get( 
basic1.getCatalogItemId() );
         Collection<OsgiBundleWithUrl> libs = item.getLibraries();
-        Asserts.assertSize(libs, 1);
-        Assert.assertEquals(Iterables.getOnlyElement(libs).getSymbolicName(), 
customName);
+        Asserts.assertSize(libs, 2);
+        Assert.assertEquals(MutableList.copyOf(libs).get(1).getSymbolicName(), 
customName);
     }
 
     private void installBundle(File jf) {
diff --git 
a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiVersionMoreEntityTest.java
 
b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiVersionMoreEntityTest.java
index 600e7d619e..ef2deb319d 100644
--- 
a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiVersionMoreEntityTest.java
+++ 
b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiVersionMoreEntityTest.java
@@ -101,7 +101,7 @@ public class CatalogOsgiVersionMoreEntityTest extends 
AbstractYamlTest implement
         Assert.assertNotNull(item);
         Assert.assertEquals(item.getVersion(), "1.0");
         Assert.assertTrue(RegisteredTypePredicates.IS_ENTITY.apply(item));
-        Assert.assertEquals(item.getLibraries().size(), 1);
+        Assert.assertEquals(item.getLibraries().size(), 2);
         
         Entity app = createAndStartApplication("services: [ { type: 
'more-entity:1.0' } ]");
         Entity moreEntity = Iterables.getOnlyElement(app.getChildren());
@@ -151,20 +151,20 @@ public class CatalogOsgiVersionMoreEntityTest extends 
AbstractYamlTest implement
     }
 
     @Test
-    /** Now assumes highest version wins regardless of install order */
-    public void testMoreEntityV1AndV2GivesV2() throws Exception {
+    /** Uses libraries to find references */
+    public void testMoreEntityV2ThenV1GivesV1() throws Exception {
         
TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), 
"/brooklyn/osgi/brooklyn-test-osgi-more-entities_0.1.0.jar");
         
TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), 
"/brooklyn/osgi/brooklyn-test-osgi-more-entities_0.2.0.jar");
         
TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), 
"/brooklyn/osgi/brooklyn-test-osgi-entities.jar");
 
-        addCatalogItems(getLocalResource("more-entity-v2-osgi-catalog.yaml"));
+        addCatalogItems(getLocalResource("more-entity-v2-osgi-catalog.yaml")); 
 // expects MoreEntity to come from 0.2.0 bundle, installed as more-entity:1.0
         forceCatalogUpdate();
-        addCatalogItems(getLocalResource("more-entity-v1-osgi-catalog.yaml"));
+        addCatalogItems(getLocalResource("more-entity-v1-osgi-catalog.yaml")); 
 // expects MoreEntity to come from 0.1.0 bundle, installed as more-entity:1.0; 
replaces previous
         Entity app = createAndStartApplication("services: [ { type: 
'more-entity:1.0' } ]");
         Entity moreEntity = Iterables.getOnlyElement(app.getChildren());
         
-        OsgiVersionMoreEntityTest.assertV2EffectorCall(moreEntity);
-        OsgiVersionMoreEntityTest.assertV2MethodCall(moreEntity);
+        OsgiVersionMoreEntityTest.assertV1EffectorCall(moreEntity);
+        OsgiVersionMoreEntityTest.assertV1MethodCall(moreEntity);
     }
 
     /** unlike {@link #testMoreEntityV2ThenV1GivesV1()} this test should 
always work,
diff --git 
a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiYamlLocationTest.java
 
b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiYamlLocationTest.java
index 8f94f0e6f7..a7bf9407da 100644
--- 
a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiYamlLocationTest.java
+++ 
b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiYamlLocationTest.java
@@ -37,6 +37,7 @@ import org.apache.brooklyn.core.mgmt.osgi.OsgiStandaloneTest;
 import org.apache.brooklyn.core.typereg.RegisteredTypePredicates;
 import org.apache.brooklyn.core.typereg.RegisteredTypes;
 import org.apache.brooklyn.test.support.TestResourceUnavailableException;
+import org.apache.brooklyn.util.collections.MutableList;
 import org.apache.brooklyn.util.text.StringFunctions;
 import org.testng.Assert;
 import org.testng.annotations.AfterMethod;
@@ -99,8 +100,8 @@ public class CatalogOsgiYamlLocationTest extends 
AbstractYamlTest {
     private void assertOsgi(String symbolicName) {
         RegisteredType item = mgmt().getTypeRegistry().get(symbolicName, 
TEST_VERSION);
         Collection<OsgiBundleWithUrl> libs = item.getLibraries();
-        assertEquals(libs.size(), 1);
-        assertEquals(Iterables.getOnlyElement(libs).getUrl(), 
Iterables.getOnlyElement(getOsgiLibraries()));
+        assertEquals(libs.size(), 2);
+        assertEquals(MutableList.copyOf(libs).get(1).getUrl(), 
Iterables.getOnlyElement(getOsgiLibraries()));
     }
 
     private void assertAdded(String symbolicName, String expectedJavaType) {
diff --git 
a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogScanOsgiTest.java
 
b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogScanOsgiTest.java
index 97986514a7..796bfa0a16 100644
--- 
a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogScanOsgiTest.java
+++ 
b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogScanOsgiTest.java
@@ -18,32 +18,16 @@
  */
 package org.apache.brooklyn.camp.brooklyn.catalog;
 
-import java.util.function.Predicate;
+import com.google.common.collect.Iterables;
 import org.apache.brooklyn.api.entity.EntitySpec;
-import org.apache.brooklyn.core.config.ConfigKeys;
-import org.apache.brooklyn.core.mgmt.ha.OsgiBundleInstallationResult;
-import 
org.apache.brooklyn.core.mgmt.ha.OsgiBundleInstallationResult.ResultCode;
-import org.apache.brooklyn.util.exceptions.Exceptions;
-import org.apache.brooklyn.util.stream.InputStreamSource;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import static org.testng.Assert.assertEquals;
-
-import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-import java.util.Map;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipOutputStream;
-
 import org.apache.brooklyn.api.mgmt.ManagementContext;
 import org.apache.brooklyn.api.typereg.ManagedBundle;
 import org.apache.brooklyn.api.typereg.RegisteredType;
 import org.apache.brooklyn.camp.brooklyn.AbstractYamlTest;
 import org.apache.brooklyn.camp.brooklyn.test.lite.CampYamlLiteTest;
+import org.apache.brooklyn.core.config.ConfigKeys;
+import org.apache.brooklyn.core.mgmt.ha.OsgiBundleInstallationResult;
+import 
org.apache.brooklyn.core.mgmt.ha.OsgiBundleInstallationResult.ResultCode;
 import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
 import org.apache.brooklyn.entity.stock.BasicEntity;
 import org.apache.brooklyn.test.Asserts;
@@ -52,14 +36,24 @@ import org.apache.brooklyn.util.collections.MutableMap;
 import org.apache.brooklyn.util.collections.MutableSet;
 import org.apache.brooklyn.util.core.ResourceUtils;
 import org.apache.brooklyn.util.core.osgi.BundleMaker;
+import org.apache.brooklyn.util.exceptions.Exceptions;
 import org.apache.brooklyn.util.os.Os;
 import org.apache.brooklyn.util.osgi.OsgiTestResources;
+import org.apache.brooklyn.util.stream.InputStreamSource;
 import org.apache.brooklyn.util.stream.Streams;
 import org.apache.brooklyn.util.text.Strings;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.testng.Assert;
 import org.testng.annotations.Test;
 
-import com.google.common.collect.Iterables;
+import java.io.*;
+import java.nio.charset.StandardCharsets;
+import java.util.Map;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
+
+import static org.testng.Assert.assertEquals;
 
 public class CatalogScanOsgiTest extends AbstractYamlTest {
 
@@ -108,13 +102,13 @@ public class CatalogScanOsgiTest extends AbstractYamlTest 
{
 
         RegisteredType hereItem = mgmt().getTypeRegistry().get("here-item");
         assertEquals(hereItem.getVersion(), "2.0-test_java");
-        Asserts.assertSize(hereItem.getLibraries(), 2);
+        Asserts.assertSize(hereItem.getLibraries(), 3);
         assertEquals(hereItem.getContainingBundle(), 
"test-items:2.0-test_java");
         
         RegisteredType item = 
mgmt().getTypeRegistry().get(OsgiTestResources.BROOKLYN_TEST_MORE_ENTITIES_MORE_ENTITY);
         // versions and libraries _are_ inherited in this legacy mode
         assertEquals(item.getVersion(), "2.0-test_java");
-        Asserts.assertSize(hereItem.getLibraries(), 2);
+        Asserts.assertSize(hereItem.getLibraries(), 3);
         // and the containing bundle is recorded as the 
         assertEquals(item.getContainingBundle(), 
"test-items"+":"+"2.0-test_java");
     }
diff --git 
a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/test/lite/CampYamlLiteTest.java
 
b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/test/lite/CampYamlLiteTest.java
index 32114ebf86..3598913036 100644
--- 
a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/test/lite/CampYamlLiteTest.java
+++ 
b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/test/lite/CampYamlLiteTest.java
@@ -25,6 +25,7 @@ import java.io.IOException;
 import java.io.InputStreamReader;
 import java.io.Reader;
 import java.util.Collection;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
@@ -59,6 +60,7 @@ 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.osgi.VersionedName;
 import org.apache.brooklyn.util.stream.Streams;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -172,11 +174,7 @@ public class CampYamlLiteTest {
         RegisteredType retrievedItem = 
Iterables.getOnlyElement(retrievedItems);
         Assert.assertEquals(retrievedItem.getVersion(), "0.9");
 
-        Collection<OsgiBundleWithUrl> bundles = retrievedItem.getLibraries();
-        Asserts.assertSize(bundles, 1);
-        OsgiBundleWithUrl bundle = Iterables.getOnlyElement(bundles);
-        Assert.assertEquals(bundle.getUrl(), 
OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL);
-        Assert.assertEquals(bundle.getSuppliedVersionString(), "0.1.0");
+        assertTwoLibraries(retrievedItem.getLibraries(), 
VersionedName.fromString(retrievedItem.getContainingBundle()).toOsgiString(), 
OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL);
     }
 
     @Test
@@ -230,10 +228,7 @@ public class CampYamlLiteTest {
         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);
+        assertTwoLibraries(item.getLibraries(), "my.catalog.app.id:0.1.2", 
bundleUrl);
 
         // now let's check other things on the item
         assertEquals(item.getDisplayName(), "My Catalog App");
@@ -245,4 +240,13 @@ public class CampYamlLiteTest {
         assertEquals(iconData.length, 43);
     }
 
+    private void assertTwoLibraries(Collection<OsgiBundleWithUrl> libraries, 
String containingBundle, String bundleUrl) {
+        Iterator<OsgiBundleWithUrl> libi = libraries.iterator();
+        Asserts.assertEquals(libi.next().getVersionedName().toOsgiString(), 
containingBundle);
+        OsgiBundleWithUrl bundle = libi.next();
+        assertEquals(bundle.getVersionedName().toOsgiString(), 
"org.apache.brooklyn.test.resources.osgi.brooklyn-test-osgi-entities:0.1.0");
+        assertEquals(bundle.getUrl(), bundleUrl);
+        Asserts.assertFalse(libi.hasNext());
+    }
+
 }
diff --git 
a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java
 
b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java
index fdfb87b253..69e0ff4c24 100644
--- 
a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java
+++ 
b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/BasicBrooklynCatalog.java
@@ -33,6 +33,7 @@ import java.util.Map;
 import java.util.NoSuchElementException;
 import java.util.Queue;
 import java.util.Set;
+import java.util.stream.Collectors;
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 import org.apache.brooklyn.api.catalog.BrooklynCatalog;
@@ -1886,7 +1887,10 @@ public class BasicBrooklynCatalog implements 
BrooklynCatalog {
 
         Map<RegisteredType, Collection<Throwable>> validation = 
validateTypes(result.keySet());
         if (Iterables.concat(validation.values()).iterator().hasNext()) {
-            throw new IllegalStateException("Could not validate one or more 
items: "+validation);
+            log.debug("Detail of failed validation:\n"+
+                    validation.entrySet().stream().map(en -> "  
"+en.getKey()+"\n"+en.getValue().stream().map(vv->"    
"+Exceptions.collapseText(vv)).collect(Collectors.joining("\n")))
+                            .collect(Collectors.joining("\n")));
+            throw Exceptions.propagate("Could not validate one or more items: 
"+validation.keySet(), 
validation.values().stream().flatMap(Collection::stream).collect(Collectors.toList()));
         }
         return result.keySet();
     }
diff --git 
a/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/BundleAndTypeResourcesTest.java
 
b/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/BundleAndTypeResourcesTest.java
index 96758c362c..c90e2ec3df 100644
--- 
a/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/BundleAndTypeResourcesTest.java
+++ 
b/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/BundleAndTypeResourcesTest.java
@@ -184,8 +184,8 @@ public class BundleAndTypeResourcesTest extends 
BrooklynRestResourceTest {
         RegisteredType item = 
getManagementContext().getTypeRegistry().get(symbolicName, TEST_VERSION);
         Assert.assertNotNull(item);
         Collection<OsgiBundleWithUrl> libs = item.getLibraries();
-        assertEquals(libs.size(), 1);
-        assertEquals(Iterables.getOnlyElement(libs).getUrl(), bundleUrl);
+        assertEquals(libs.size(), 2);
+        assertEquals(Iterables.get(libs, 1).getUrl(), bundleUrl);
 
         // now let's check other things on the item
         URI expectedIconUrl = URI.create(getEndpointAddress() + 
"/catalog/types/" + symbolicName + "/" + 
entityItem.getVersion()+"/icon").normalize();
@@ -727,8 +727,8 @@ public class BundleAndTypeResourcesTest extends 
BrooklynRestResourceTest {
         RegisteredType item = 
getManagementContext().getTypeRegistry().get(symbolicName, version);
         Assert.assertNotNull(item);
         Collection<OsgiBundleWithUrl> libs = item.getLibraries();
-        assertEquals(libs.size(), 1);
-        OsgiBundleWithUrl lib = Iterables.getOnlyElement(libs);
+        assertEquals(libs.size(), 2);
+        OsgiBundleWithUrl lib = Iterables.get(libs, 1);
         Assert.assertNull(lib.getUrl());
 
         assertEquals(lib.getSymbolicName(), 
"org.apache.brooklyn.test.resources.osgi.brooklyn-test-osgi-entities");
@@ -803,8 +803,8 @@ public class BundleAndTypeResourcesTest extends 
BrooklynRestResourceTest {
         RegisteredType item = 
getManagementContext().getTypeRegistry().get(symbolicName, version);
         Assert.assertNotNull(item);
         Collection<OsgiBundleWithUrl> libs = item.getLibraries();
-        assertEquals(libs.size(), 1);
-        OsgiBundleWithUrl lib = Iterables.getOnlyElement(libs);
+        assertEquals(libs.size(), 2);
+        OsgiBundleWithUrl lib = Iterables.get(libs, 1);
         Assert.assertNull(lib.getUrl());
 
         // check we can find it with ResourceUtils
diff --git 
a/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/CatalogResourceTest.java
 
b/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/CatalogResourceTest.java
index 9bbeb409cb..bbc7d0ff19 100644
--- 
a/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/CatalogResourceTest.java
+++ 
b/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/CatalogResourceTest.java
@@ -170,8 +170,8 @@ public class CatalogResourceTest extends 
BrooklynRestResourceTest {
                 .applyAsserts(() -> client());
 
         RegisteredTypeAsserts.newInstance(itemSymbolicName, TEST_VERSION)
-                .libraryNames(bundleName)
-                .libraryUrls(bundleUrl)
+                .libraryNames(new VersionedName("my.catalog.entity.id", 
"0.1.2"), bundleName)
+                .libraryUrls(null, bundleUrl)
                 
.iconUrl("classpath:/org/apache/brooklyn/test/osgi/entities/icon.gif")
                 .applyAsserts(getManagementContext().getTypeRegistry());
     }
diff --git 
a/utils/rt-felix/src/test/java/org/apache/brooklyn/rt/felix/EmbeddedFelixFrameworkTest.java
 
b/utils/rt-felix/src/test/java/org/apache/brooklyn/rt/felix/EmbeddedFelixFrameworkTest.java
index f75cf5d3f0..feb7aa2cd5 100644
--- 
a/utils/rt-felix/src/test/java/org/apache/brooklyn/rt/felix/EmbeddedFelixFrameworkTest.java
+++ 
b/utils/rt-felix/src/test/java/org/apache/brooklyn/rt/felix/EmbeddedFelixFrameworkTest.java
@@ -23,6 +23,7 @@ import java.util.List;
 import java.util.jar.JarInputStream;
 
 import org.apache.brooklyn.test.support.TestResourceUnavailableException;
+import org.apache.brooklyn.util.collections.MutableList;
 import org.apache.brooklyn.util.collections.MutableSet;
 import org.apache.brooklyn.util.io.FileUtil;
 import org.apache.brooklyn.util.os.Os;
@@ -72,14 +73,16 @@ public class EmbeddedFelixFrameworkTest {
         log.info("Bundles and exported packages:");
         MutableSet<String> allPackages = MutableSet.of();
         while (manifests.hasMoreElements()) {
-            String fullNameManifests = 
Streams.readFullyStringAndClose(manifests.nextElement().openStream());
+            URL mfUrl = manifests.nextElement();
+            String fullNameManifests = 
Streams.readFullyStringAndClose(mfUrl.openStream());
             ManifestHelper mf = null;
             try {
                 mf = ManifestHelper.forManifestContents(fullNameManifests);
                 List<String> mfPackages = mf.getExportedPackages();
-                log.info("  " + mf.getSymbolicNameVersion() + ": " + 
mfPackages);
+                log.info("   " + mfUrl+" / " + mf.getSymbolicNameVersion() + 
": " + mfPackages);
                 allPackages.addAll(mfPackages);
             } catch (BundleException e) {
+                log.info(" x " + mfUrl+": " + e);
                 // non valid manifest
             }
         }

Reply via email to