You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by al...@apache.org on 2019/01/16 16:40:12 UTC

[brooklyn-server] branch master updated (061057c -> da8bf93)

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

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


    from 061057c  This closes #1024
     new 890ef56  Bump assertj from 2.2.0 to 3.11.1
     new f08ed2c  [core] add assertj as test dependency
     new 2c0f0c2  [core] Refactor rebind test for clarity
     new 5d5a2dd  [core] rename excessively long private constant
     new 442a194  [common] add assertj as test dependency
     new 8f11da5  [common] Add unit tests for Reflections#findMappedName{AndLog,Maybe}()
     new 75f41da  [common] Add test for mapping classes from one bundle to another
     new c4234de  [common] fix typo in test
     new 2be6cd4  Extract nested tests for findMappedName into top level class
     new 170b351  fix typo
     new a0d2d84  Add assertj as test dependency
     new 8e91fbe  Coverage tests for existing CatalogUpgrades.getBundleUpgradedIfNecessary()
     new 0ec0418  Extract newMockBundle() utility methods to BundleTestUtil
     new 441213c  whenUpgradingAWrappedBundleThenUpdatedName()
     new 8419337  Add missing apache license headers
     new 748bfa0  Load all jars to find upgrades for wrapped bundles
     new 6127e03  Remove stopwatches
     new ef42313  Extract scanManagedBundles() and scanAllBundles()
     new 7328d9f  Extract RegisteredTypesSupplier to outer class
     new 64c869c  Extract CatalogUpgradeScanner
     new 0fc25b2  Extract overloaded typeSupplier() helpers
     new b6500ed  The presence of an OsgiManager is not the concern of CatalogUpgradeScanner
     new ab67707  Extract static methods as a constructor parameters
     new cdb298f  Limit violation of the law of demeter
     new 943f3b8  Make BundleUtilTest public
     new 9fe502a  Add unit tests for CatalogUpgradeSCanner
     new 09e65df  Remove previous attempt at failing test
     new aabab44  Add missing header
     new 2e025d1  Remove duplicated version for assertj
     new 5c22839  Changes requested on PR
     new da8bf93  This closes #1010

The 31 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 core/pom.xml                                       |   5 +
 .../catalog/internal/CatalogInitialization.java    |  62 ++--
 .../catalog/internal/CatalogUpgradeScanner.java    | 110 +++++++
 .../catalog/internal/RegisteredTypesSupplier.java  |  25 +-
 .../persist/DeserializingClassRenamesProvider.java |   5 +-
 .../brooklyn/core/typereg/BundleUpgradeParser.java |   2 +-
 .../internal/CatalogUpgradeScannerTest.java        | 322 +++++++++++++++++++++
 .../RebindWithDeserializingClassRenamesTest.java   | 152 +++++++---
 .../brooklyn/core/typereg/BundleTestUtil.java      |  57 ++++
 .../core/typereg/BundleUpgradeParserTest.java      |  27 +-
 ...ogUpgradesGetBundleUpgradedIfNecessaryTest.java | 246 ++++++++++++++++
 parent/pom.xml                                     |  41 +--
 pom.xml                                            |   6 +-
 utils/common/pom.xml                               |   6 +
 .../javalang/ReflectionsFindMappedNameTest.java    | 141 +++++++++
 15 files changed, 1053 insertions(+), 154 deletions(-)
 create mode 100644 core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogUpgradeScanner.java
 copy utils/common/dependencies/osgi/com-example-entities/src/main/java/com/example/brooklyn/test/osgi/PrefixedDummyExternalConfigSupplier.java => core/src/main/java/org/apache/brooklyn/core/catalog/internal/RegisteredTypesSupplier.java (58%)
 create mode 100644 core/src/test/java/org/apache/brooklyn/core/catalog/internal/CatalogUpgradeScannerTest.java
 create mode 100644 core/src/test/java/org/apache/brooklyn/core/typereg/BundleTestUtil.java
 create mode 100644 core/src/test/java/org/apache/brooklyn/core/typereg/CatalogUpgradesGetBundleUpgradedIfNecessaryTest.java
 create mode 100644 utils/common/src/test/java/org/apache/brooklyn/util/javalang/ReflectionsFindMappedNameTest.java


[brooklyn-server] 30/31: Changes requested on PR

Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 5c22839eeb63f6e9c1de16d6b1c6c7defa3a12b1
Author: Paul Campbell <pc...@kemitix.net>
AuthorDate: Wed Jan 16 14:55:53 2019 +0000

    Changes requested on PR
---
 .../catalog/internal/CatalogUpgradeScanner.java    | 16 +++++----
 .../internal/CatalogUpgradeScannerTest.java        | 24 ++++++-------
 .../RebindWithDeserializingClassRenamesTest.java   |  6 ++--
 ...ogUpgradesGetBundleUpgradedIfNecessaryTest.java |  2 +-
 parent/pom.xml                                     | 40 +++++++++++-----------
 pom.xml                                            |  2 --
 .../javalang/ReflectionsFindMappedNameTest.java    |  4 ---
 .../brooklyn/util/javalang/ReflectionsTest.java    |  4 +--
 8 files changed, 48 insertions(+), 50 deletions(-)

diff --git a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogUpgradeScanner.java b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogUpgradeScanner.java
index efe902d..a51c594 100644
--- a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogUpgradeScanner.java
+++ b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogUpgradeScanner.java
@@ -33,6 +33,8 @@ import java.util.Collection;
 import java.util.function.BiFunction;
 import java.util.function.Function;
 
+import static java.util.Objects.requireNonNull;
+
 /**
  * Scans managed bundles and other jar bundles to find upgrades for installed bundles.
  */
@@ -49,10 +51,12 @@ class CatalogUpgradeScanner {
             final Function<OsgiBundleWithUrl, Predicate<? super RegisteredType>> managedBundlePredicateSupplier,
             final Function<String, Predicate<? super RegisteredType>> unmanagedBundlePredicateSupplier
     ) {
-        this.managementContext = managementContext;
-        this.bundleUpgradeParser = bundleUpgradeParser;
-        this.managedBundlePredicateSupplier = managedBundlePredicateSupplier;
-        this.unmanagedBundlePredicateSupplier = unmanagedBundlePredicateSupplier;
+        this.managementContext = requireNonNull(managementContext, "managementContext");
+        this.bundleUpgradeParser = requireNonNull(bundleUpgradeParser, "bundleUpgradeParser");
+        this.managedBundlePredicateSupplier =
+                requireNonNull(managedBundlePredicateSupplier, "managedBundlePredicateSupplier");
+        this.unmanagedBundlePredicateSupplier =
+                requireNonNull(unmanagedBundlePredicateSupplier, "unmanagedBundlePredicateSupplier");
     }
 
     public CatalogUpgrades scan(
@@ -62,7 +66,7 @@ class CatalogUpgradeScanner {
     ) {
         final CatalogUpgrades.Builder catalogUpgradesBuilder = CatalogUpgrades.builder();
         scanManagedBundles(osgiManager, catalogUpgradesBuilder, rebindLogger);
-        scanUnmanagedBundles(catalogUpgradesBuilder, bundleContext);
+        scanAllBundles(catalogUpgradesBuilder, bundleContext);
         return catalogUpgradesBuilder.build();
     }
 
@@ -84,7 +88,7 @@ class CatalogUpgradeScanner {
         }
     }
 
-    private void scanUnmanagedBundles(
+    private void scanAllBundles(
             final CatalogUpgrades.Builder catalogUpgradesBuilder,
             final BundleContext bundleContext
     ) {
diff --git a/core/src/test/java/org/apache/brooklyn/core/catalog/internal/CatalogUpgradeScannerTest.java b/core/src/test/java/org/apache/brooklyn/core/catalog/internal/CatalogUpgradeScannerTest.java
index 5eba4f1..a91dca6 100644
--- a/core/src/test/java/org/apache/brooklyn/core/catalog/internal/CatalogUpgradeScannerTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/catalog/internal/CatalogUpgradeScannerTest.java
@@ -190,12 +190,12 @@ public class CatalogUpgradeScannerTest implements WithAssertions {
                 final OsgiManager osgiManager,
                 final BiFunction<Bundle, RegisteredTypesSupplier, CatalogUpgrades> bundleUpgradeParser
         ) {
-            final Map<String, ManagedBundle> managedBundlesWithNoUpgrades =
+            final Map<String, ManagedBundle> bundles =
                     ImmutableMap.of(
                             "managed1", findableManagedBundle(osgiManager, CatalogUpgrades.EMPTY, bundleUpgradeParser),
                             "managed2", findableManagedBundle(osgiManager, CatalogUpgrades.EMPTY, bundleUpgradeParser)
                     );
-            doReturn(managedBundlesWithNoUpgrades).when(osgiManager).getManagedBundles();
+            doReturn(bundles).when(osgiManager).getManagedBundles();
         }
 
         static void givenManagedBundlesWithUpgrades(
@@ -203,9 +203,9 @@ public class CatalogUpgradeScannerTest implements WithAssertions {
                 final OsgiManager osgiManager,
                 final BiFunction<Bundle, RegisteredTypesSupplier, CatalogUpgrades> bundleUpgradeParser
         ) {
-            final Map<String, ManagedBundle> managedBundlesWithNoUpgrades =
+            final Map<String, ManagedBundle> bundles =
                     ImmutableMap.of("managed", findableManagedBundle(osgiManager, upgrades, bundleUpgradeParser));
-            doReturn(managedBundlesWithNoUpgrades).when(osgiManager).getManagedBundles();
+            doReturn(bundles).when(osgiManager).getManagedBundles();
         }
 
         static void givenManagedBundleWithNoUpgrades(
@@ -215,20 +215,20 @@ public class CatalogUpgradeScannerTest implements WithAssertions {
         ) {
             final ManagedBundle managedBundle =
                     findableManagedBundle(osgiManager, CatalogUpgrades.EMPTY, bundleUpgradeParser);
-            final Map<String, ManagedBundle> managedBundlesWithNoUpgrades =
+            final Map<String, ManagedBundle> bundles =
                     ImmutableMap.of(bundleName, managedBundle);
-            doReturn(managedBundlesWithNoUpgrades).when(osgiManager).getManagedBundles();
+            doReturn(bundles).when(osgiManager).getManagedBundles();
         }
 
         static void givenUnmanagedBundlesWithNoUpgrades(
                 final BundleContext bundleContext,
                 final BiFunction<Bundle, RegisteredTypesSupplier, CatalogUpgrades> bundleUpgradeParser
         ) {
-            final Bundle[] unmanagedBundlesWithNoUpgrades = new Bundle[]{
+            final Bundle[] bundles = new Bundle[]{
                     unmanagedBundle(bundleName("unmanaged1", "1.1.0"), CatalogUpgrades.EMPTY, bundleUpgradeParser),
                     unmanagedBundle(bundleName("unmanaged2", "1.1.0"), CatalogUpgrades.EMPTY, bundleUpgradeParser)
             };
-            doReturn(unmanagedBundlesWithNoUpgrades).when(bundleContext).getBundles();
+            doReturn(bundles).when(bundleContext).getBundles();
         }
 
         static void givenUnmanagedBundleWithNoUpgrades(
@@ -236,10 +236,10 @@ public class CatalogUpgradeScannerTest implements WithAssertions {
                 final BundleContext bundleContext,
                 final BiFunction<Bundle, RegisteredTypesSupplier, CatalogUpgrades> bundleUpgradeParser
         ) {
-            final Bundle[] unmanagedBundlesWithNoUpgrades = new Bundle[]{
+            final Bundle[] bundles = new Bundle[]{
                     unmanagedBundle(bundleName, CatalogUpgrades.EMPTY, bundleUpgradeParser)
             };
-            doReturn(unmanagedBundlesWithNoUpgrades).when(bundleContext).getBundles();
+            doReturn(bundles).when(bundleContext).getBundles();
         }
 
         static void givenUnmanagedBundleWithUpgrades(
@@ -247,10 +247,10 @@ public class CatalogUpgradeScannerTest implements WithAssertions {
                 final BundleContext bundleContext,
                 final BiFunction<Bundle, RegisteredTypesSupplier, CatalogUpgrades> bundleUpgradeParser
         ) {
-            final Bundle[] unmanagedBundlesWithNoUpgrades = new Bundle[]{
+            final Bundle[] bundles = new Bundle[]{
                     unmanagedBundle(bundleName("unmanaged", "1.1.0"), upgrades, bundleUpgradeParser)
             };
-            doReturn(unmanagedBundlesWithNoUpgrades).when(bundleContext).getBundles();
+            doReturn(bundles).when(bundleContext).getBundles();
         }
 
     }
diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindWithDeserializingClassRenamesTest.java b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindWithDeserializingClassRenamesTest.java
index 40b4a3f..6e3b74e 100644
--- a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindWithDeserializingClassRenamesTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindWithDeserializingClassRenamesTest.java
@@ -142,10 +142,10 @@ public class RebindWithDeserializingClassRenamesTest extends RebindTestFixtureWi
         }
 
         static Transform of(final String legacyClassName,
-                            final ConfigInheritance configInheritance,
+                            final ConfigInheritance inheritanceMode,
                             final String configKey) {
-            final Class<? extends ConfigInheritance> configInheritanceClass = configInheritance.getClass();
-            return new Transform(legacyClassName, configInheritanceClass.getName(), configInheritance, configKey);
+            final Class<? extends ConfigInheritance> configInheritanceClass = inheritanceMode.getClass();
+            return new Transform(legacyClassName, configInheritanceClass.getName(), inheritanceMode, configKey);
         }
     }
 }
diff --git a/core/src/test/java/org/apache/brooklyn/core/typereg/CatalogUpgradesGetBundleUpgradedIfNecessaryTest.java b/core/src/test/java/org/apache/brooklyn/core/typereg/CatalogUpgradesGetBundleUpgradedIfNecessaryTest.java
index 126a1ef..5799804 100644
--- a/core/src/test/java/org/apache/brooklyn/core/typereg/CatalogUpgradesGetBundleUpgradedIfNecessaryTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/typereg/CatalogUpgradesGetBundleUpgradedIfNecessaryTest.java
@@ -58,7 +58,7 @@ public class CatalogUpgradesGetBundleUpgradedIfNecessaryTest implements WithAsse
 
     private CatalogUpgrades.Builder catalogUpgradesBuilder;
 
-    @BeforeMethod
+    @BeforeMethod(alwaysRun = true)
     public void setUp() {
         Mockito.reset(managementContext, osgiManager, managedBundle, typeRegistry);
         catalogUpgradesBuilder = CatalogUpgrades.builder();
diff --git a/parent/pom.xml b/parent/pom.xml
index e0e2633..2b94015 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -561,34 +561,34 @@
                 <artifactId>cxf-rt-rs-client</artifactId>
                 <version>${cxf.version}</version>
             </dependency>
-			<dependency>
-				<groupId>io.fabric8</groupId>
-				<artifactId>kubernetes-client</artifactId>
-				<version>${kubernetes-client.version}</version>
-				<exclusions>
-					<exclusion>
-						<groupId>com.squareup.okio</groupId>
-						<artifactId>okio</artifactId>
-					</exclusion>
-				</exclusions>
-			</dependency>
-			<dependency>
-				<groupId>io.fabric8</groupId>
-				<artifactId>openshift-client</artifactId>
-				<version>${kubernetes-client.version}</version>
-			</dependency>
+            <dependency>
+                <groupId>io.fabric8</groupId>
+                <artifactId>kubernetes-client</artifactId>
+                <version>${kubernetes-client.version}</version>
+                <exclusions>
+                    <exclusion>
+                        <groupId>com.squareup.okio</groupId>
+                        <artifactId>okio</artifactId>
+                    </exclusion>
+                </exclusions>
+            </dependency>
+            <dependency>
+                <groupId>io.fabric8</groupId>
+                <artifactId>openshift-client</artifactId>
+                <version>${kubernetes-client.version}</version>
+            </dependency>
             <dependency>
                 <groupId>org.ops4j.pax.web</groupId>
                 <artifactId>pax-web-spi</artifactId>
                 <version>${pax-web.version}</version>
-			</dependency>
-			<dependency>
+            </dependency>
+            <dependency>
                 <groupId>org.assertj</groupId>
                 <artifactId>assertj-core</artifactId>
                 <version>${assertj.version}</version>
             </dependency>
-		</dependencies>
-	</dependencyManagement>
+        </dependencies>
+    </dependencyManagement>
 
     <build>
         <testSourceDirectory>src/test/java</testSourceDirectory>
diff --git a/pom.xml b/pom.xml
index ed1ad6e..1b776da 100644
--- a/pom.xml
+++ b/pom.xml
@@ -188,8 +188,6 @@
         <assertj.version>3.11.1</assertj.version>
         <cobertura.plugin.version>2.7</cobertura.plugin.version>
         <surefire.version>2.19.1</surefire.version>
-        <testng.version>6.10</testng.version>
-        <mockito.version>2.7.12</mockito.version>
         <hamcrest.version>1.1</hamcrest.version>
         <mockwebserver.version>20121111</mockwebserver.version>
 
diff --git a/utils/common/src/test/java/org/apache/brooklyn/util/javalang/ReflectionsFindMappedNameTest.java b/utils/common/src/test/java/org/apache/brooklyn/util/javalang/ReflectionsFindMappedNameTest.java
index 76642df..6e88977 100644
--- a/utils/common/src/test/java/org/apache/brooklyn/util/javalang/ReflectionsFindMappedNameTest.java
+++ b/utils/common/src/test/java/org/apache/brooklyn/util/javalang/ReflectionsFindMappedNameTest.java
@@ -25,10 +25,6 @@ import java.util.HashMap;
 import java.util.Map;
 import java.util.UUID;
 
-/**
- * Tests for {@link Reflections#findMappedNameAndLog(Map, String)} and
- * {@link Reflections#findMappedNameMaybe(Map, String)} methods.
- */
 public class ReflectionsFindMappedNameTest  implements WithAssertions {
 
     @Test
diff --git a/utils/common/src/test/java/org/apache/brooklyn/util/javalang/ReflectionsTest.java b/utils/common/src/test/java/org/apache/brooklyn/util/javalang/ReflectionsTest.java
index a46f6ee..3c628a9 100644
--- a/utils/common/src/test/java/org/apache/brooklyn/util/javalang/ReflectionsTest.java
+++ b/utils/common/src/test/java/org/apache/brooklyn/util/javalang/ReflectionsTest.java
@@ -24,12 +24,12 @@ import static org.testng.Assert.assertTrue;
 
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
-import java.util.*;
+import java.util.Arrays;
+import java.util.List;
 
 import org.apache.brooklyn.util.javalang.coerce.CommonAdaptorTypeCoercions;
 import org.apache.brooklyn.util.javalang.coerce.TypeCoercer;
 import org.apache.brooklyn.util.javalang.coerce.TypeCoercerExtensible;
-import org.assertj.core.api.WithAssertions;
 import org.testng.Assert;
 import org.testng.annotations.Test;
 


[brooklyn-server] 08/31: [common] fix typo in test

Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit c4234deb76d718fa2a39725cefd76e7e6764d5ad
Author: Paul Campbell <pa...@cloudsoft.io>
AuthorDate: Tue Oct 9 17:13:20 2018 +0100

    [common] fix typo in test
---
 .../java/org/apache/brooklyn/util/javalang/ReflectionsTest.java     | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/utils/common/src/test/java/org/apache/brooklyn/util/javalang/ReflectionsTest.java b/utils/common/src/test/java/org/apache/brooklyn/util/javalang/ReflectionsTest.java
index c95d439..06c5f47 100644
--- a/utils/common/src/test/java/org/apache/brooklyn/util/javalang/ReflectionsTest.java
+++ b/utils/common/src/test/java/org/apache/brooklyn/util/javalang/ReflectionsTest.java
@@ -346,16 +346,16 @@ public class ReflectionsTest implements WithAssertions {
         @Test
         public void allClassesInOneBundleAreNowInOtherBundle() {
             //given
-            final Map<String, String> rename = new HashMap<>();
+            final Map<String, String> renames = new HashMap<>();
             final String wildcard = "*";
             final String originalBundle = "wrap_blah_aws-java-sdk-bundle-1.11.245.jar:";
             final String updatedBundle = "wrap_blah_aws-java-sdk-bundle-1.11.411.jar:";
-            rename.put(originalBundle + wildcard, updatedBundle + wildcard);
+            renames.put(originalBundle + wildcard, updatedBundle + wildcard);
             final String className = createAName();
             final String originalName = originalBundle + className;
             final String updatedName = updatedBundle + className;
             //when
-            final String result = Reflections.findMappedNameAndLog(rename, originalName);
+            final String result = Reflections.findMappedNameAndLog(renames, originalName);
             //then
             assertThat(result).isSameAs(updatedName);
         }


[brooklyn-server] 04/31: [core] rename excessively long private constant

Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 5d5a2dd0e5392a05f1b155371d30d45f4e7d74cb
Author: Paul Campbell <pa...@cloudsoft.io>
AuthorDate: Tue Oct 9 15:43:13 2018 +0100

    [core] rename excessively long private constant
    
    The constant is private to the class, there are not other constants. There is no
    need to repeat most of the classname in the constants name.
---
 .../core/mgmt/persist/DeserializingClassRenamesProvider.java         | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/persist/DeserializingClassRenamesProvider.java b/core/src/main/java/org/apache/brooklyn/core/mgmt/persist/DeserializingClassRenamesProvider.java
index 49f4bce..78cff25 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/persist/DeserializingClassRenamesProvider.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/persist/DeserializingClassRenamesProvider.java
@@ -38,12 +38,13 @@ import org.apache.brooklyn.util.javalang.Reflections;
 @Beta
 public class DeserializingClassRenamesProvider extends DeserializingProvider{
 
-    private static final String DESERIALIZING_CLASS_RENAMES_PROPERTIES_PATH = "classpath://org/apache/brooklyn/core/mgmt/persist/deserializingClassRenames.properties";
+    private static final String RENAMES_PROPERTIES =
+            "classpath://org/apache/brooklyn/core/mgmt/persist/deserializingClassRenames.properties";
 
     public static final DeserializingClassRenamesProvider INSTANCE = new DeserializingClassRenamesProvider();
 
     private DeserializingClassRenamesProvider(){
-        super(ImmutableList.of(new PropertiesConfigLoader(DESERIALIZING_CLASS_RENAMES_PROPERTIES_PATH)));
+        super(ImmutableList.of(new PropertiesConfigLoader(RENAMES_PROPERTIES)));
     }
 
     /**


[brooklyn-server] 22/31: The presence of an OsgiManager is not the concern of CatalogUpgradeScanner

Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit b6500edf082ccc207a892d0cd2889d3c8935bc6e
Author: Paul Campbell <pc...@kemitix.net>
AuthorDate: Wed Oct 24 10:54:46 2018 +0100

    The presence of an OsgiManager is not the concern of CatalogUpgradeScanner
    
    CatalogUgradeScanner requires an OsgiManager. Branching for special case is
    pushed out to the (single) caller, where it is clear that the ManagementContext
    is being set to an empty set of CatalogUpgrades.
---
 .../core/catalog/internal/CatalogInitialization.java       | 10 ++++++++--
 .../core/catalog/internal/CatalogUpgradeScanner.java       | 14 ++++++--------
 2 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogInitialization.java b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogInitialization.java
index 9dcaa4b..e284479 100644
--- a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogInitialization.java
+++ b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogInitialization.java
@@ -254,8 +254,14 @@ public class CatalogInitialization implements ManagementContextInjectable {
             
             populateInitialCatalogImpl(true);
 
-            final CatalogUpgrades catalogUpgrades = catalogUpgradeScanner.scan(rebindLogger);
-            CatalogUpgrades.storeInManagementContext(catalogUpgrades, managementContext);
+            final Maybe<OsgiManager> osgiManager = managementContext.getOsgiManager();
+            if (osgiManager.isAbsent()) {
+                // Can't find any bundles to tell if there are upgrades. Could be running tests; do no filtering.
+                CatalogUpgrades.storeInManagementContext(CatalogUpgrades.EMPTY, managementContext);
+            } else {
+                final CatalogUpgrades catalogUpgrades = catalogUpgradeScanner.scan(osgiManager.get(), rebindLogger);
+                CatalogUpgrades.storeInManagementContext(catalogUpgrades, managementContext);
+            }
             PersistedCatalogState filteredPersistedState = filterBundlesAndCatalogInPersistedState(persistedState, rebindLogger);
             addPersistedCatalogImpl(filteredPersistedState, exceptionHandler, rebindLogger);
             
diff --git a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogUpgradeScanner.java b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogUpgradeScanner.java
index 342e3af..446c083 100644
--- a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogUpgradeScanner.java
+++ b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogUpgradeScanner.java
@@ -42,15 +42,13 @@ class CatalogUpgradeScanner {
         this.managementContext = managementContext;
     }
 
-    public CatalogUpgrades scan(final CatalogInitialization.RebindLogger rebindLogger) {
-        Maybe<OsgiManager> osgiManager = managementContext.getOsgiManager();
-        if (osgiManager.isAbsent()) {
-            // Can't find any bundles to tell if there are upgrades. Could be running tests; do no filtering.
-            return CatalogUpgrades.EMPTY;
-        }
+    public CatalogUpgrades scan(
+            final OsgiManager osgiManager,
+            final CatalogInitialization.RebindLogger rebindLogger
+    ) {
         final CatalogUpgrades.Builder catalogUpgradesBuilder = CatalogUpgrades.builder();
-        scanManagedBundles(osgiManager.get(), catalogUpgradesBuilder, rebindLogger);
-        scanAllBundles(osgiManager.get(), catalogUpgradesBuilder);
+        scanManagedBundles(osgiManager, catalogUpgradesBuilder, rebindLogger);
+        scanAllBundles(osgiManager, catalogUpgradesBuilder);
         return catalogUpgradesBuilder.build();
     }
 


[brooklyn-server] 27/31: Remove previous attempt at failing test

Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 09e65df7d46b5177b14c1e4565d4c5249697aee0
Author: Paul Campbell <pc...@kemitix.net>
AuthorDate: Wed Oct 24 17:48:41 2018 +0100

    Remove previous attempt at failing test
    
    Solution wasn't found from this test, so removing it again.
---
 .../util/javalang/ReflectionsFindMappedNameTest.java   | 18 ------------------
 1 file changed, 18 deletions(-)

diff --git a/utils/common/src/test/java/org/apache/brooklyn/util/javalang/ReflectionsFindMappedNameTest.java b/utils/common/src/test/java/org/apache/brooklyn/util/javalang/ReflectionsFindMappedNameTest.java
index 173d0a9..76642df 100644
--- a/utils/common/src/test/java/org/apache/brooklyn/util/javalang/ReflectionsFindMappedNameTest.java
+++ b/utils/common/src/test/java/org/apache/brooklyn/util/javalang/ReflectionsFindMappedNameTest.java
@@ -138,24 +138,6 @@ public class ReflectionsFindMappedNameTest  implements WithAssertions {
         assertThat(result).isEqualTo(updatedName);
     }
 
-    //wrap_blah_aws-java-sdk-bundle-1.11.245.jar\:*  : wrap_blah_aws-java-sdk-bundle-1.11.411.jar\:*
-    @Test
-    public void allClassesInOneBundleAreNowInOtherBundle() {
-        //given
-        final Map<String, String> renames = new HashMap<>();
-        final String wildcard = "*";
-        final String originalBundle = "wrap_blah_aws-java-sdk-bundle-1.11.245.jar:";
-        final String updatedBundle = "wrap_blah_aws-java-sdk-bundle-1.11.411.jar:";
-        renames.put(originalBundle + wildcard, updatedBundle + wildcard);
-        final String className = createAName();
-        final String originalName = originalBundle + className;
-        final String updatedName = updatedBundle + className;
-        //when
-        final String result = Reflections.findMappedNameAndLog(renames, originalName);
-        //then
-        assertThat(result).isSameAs(updatedName);
-    }
-
     private String createAName() {
         return UUID.randomUUID().toString();
     }


[brooklyn-server] 25/31: Make BundleUtilTest public

Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 943f3b8ab7ce4a17235d10072c0d5ec00e6e2e86
Author: Paul Campbell <pc...@kemitix.net>
AuthorDate: Wed Oct 24 13:05:59 2018 +0100

    Make BundleUtilTest public
---
 .../java/org/apache/brooklyn/core/typereg/BundleTestUtil.java     | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/core/src/test/java/org/apache/brooklyn/core/typereg/BundleTestUtil.java b/core/src/test/java/org/apache/brooklyn/core/typereg/BundleTestUtil.java
index a869514..04a2376 100644
--- a/core/src/test/java/org/apache/brooklyn/core/typereg/BundleTestUtil.java
+++ b/core/src/test/java/org/apache/brooklyn/core/typereg/BundleTestUtil.java
@@ -28,17 +28,17 @@ import java.util.Dictionary;
 import java.util.Hashtable;
 import java.util.Map;
 
-class BundleTestUtil {
+public class BundleTestUtil {
 
-    static Bundle newMockBundle(Map<String, String> rawHeaders) {
+    public static Bundle newMockBundle(Map<String, String> rawHeaders) {
         return newMockBundle(VersionedName.fromString("do.no.care:1.2.3"), rawHeaders);
     }
 
-    static Bundle newMockBundle(VersionedName name) {
+    public static Bundle newMockBundle(VersionedName name) {
         return newMockBundle(name, ImmutableMap.of());
     }
 
-    static Bundle newMockBundle(VersionedName name, Map<String, String> rawHeaders) {
+    public static Bundle newMockBundle(VersionedName name, Map<String, String> rawHeaders) {
         Dictionary<String, String> headers = new Hashtable<>(rawHeaders);
         Bundle result;
         try {


[brooklyn-server] 09/31: Extract nested tests for findMappedName into top level class

Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 2be6cd47f906d0806486d2e00216a2d064ca65d0
Author: Paul Campbell <pc...@kemitix.net>
AuthorDate: Thu Oct 11 16:53:32 2018 +0100

    Extract nested tests for findMappedName into top level class
    
    TestNG isn't good at running a subset of tests without a log of ceremony
    attached (e.g. config files and annotations).
---
 .../javalang/ReflectionsFindMappedNameTest.java    | 145 +++++++++++++++++++++
 .../brooklyn/util/javalang/ReflectionsTest.java    | 139 +-------------------
 2 files changed, 146 insertions(+), 138 deletions(-)

diff --git a/utils/common/src/test/java/org/apache/brooklyn/util/javalang/ReflectionsFindMappedNameTest.java b/utils/common/src/test/java/org/apache/brooklyn/util/javalang/ReflectionsFindMappedNameTest.java
new file mode 100644
index 0000000..d4bb0f6
--- /dev/null
+++ b/utils/common/src/test/java/org/apache/brooklyn/util/javalang/ReflectionsFindMappedNameTest.java
@@ -0,0 +1,145 @@
+package org.apache.brooklyn.util.javalang;
+
+import org.assertj.core.api.WithAssertions;
+import org.testng.annotations.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+/**
+ * Tests for {@link Reflections#findMappedNameAndLog(Map, String)} and
+ * {@link Reflections#findMappedNameMaybe(Map, String)} methods.
+ */
+public class ReflectionsFindMappedNameTest  implements WithAssertions {
+
+    @Test
+    public void givenRenamesIsNullThenReturnOriginalName() {
+        //given
+        final Map<String, String> renames = null;
+        final String originalName = createAName();
+        //when
+        final String result = Reflections.findMappedNameAndLog(renames, originalName);
+        //then
+        assertThat(result).isEqualTo(originalName);
+    }
+
+    @Test
+    public void givenRenamesIsEmptyThenReturnOriginalName() {
+        //given
+        final Map<String, String> renames = new HashMap<>();
+        final String originalName = createAName();
+        //when
+        final String result = Reflections.findMappedNameAndLog(renames, originalName);
+        //then
+        assertThat(result).isEqualTo(originalName);
+    }
+
+    @Test
+    public void givenRenamesHasNoMatchThenReturnOriginalName() {
+        //given
+        final Map<String, String> renames = new HashMap<>();
+        renames.put(createAName(), createAName());
+        final String originalName = createAName();
+        //when
+        final String result = Reflections.findMappedNameAndLog(renames, originalName);
+        //then
+        assertThat(result).isEqualTo(originalName);
+    }
+
+    @Test
+    public void givenRenamesHasMatchThenReturnUpdatedName() {
+        //given
+        final Map<String, String> renames = new HashMap<>();
+        final String originalName = createAName();
+        final String updatedName = createAName();
+        renames.put(originalName, updatedName);
+        //when
+        final String result = Reflections.findMappedNameAndLog(renames, originalName);
+        //then
+        assertThat(result).isEqualTo(updatedName);
+    }
+
+    @Test
+    public void givenInnerClassHasNoMatchThenReturnOriginalName() {
+        //given
+        final Map<String, String> renames = new HashMap<>();
+        final String originalName = createAName() + "$" + createAName();
+        //when
+        final String result = Reflections.findMappedNameAndLog(renames, originalName);
+        //then
+        assertThat(result).isEqualTo(originalName);
+    }
+
+    @Test
+    public void givenInnerClassHasMatchThenReturnUpdatedName() {
+        //given
+        final Map<String, String> renames = new HashMap<>();
+        final String originalName = createAName() + "$" + createAName();
+        final String updatedName = createAName();
+        renames.put(originalName, updatedName);
+        //when
+        final String result = Reflections.findMappedNameAndLog(renames, originalName);
+        //then
+        assertThat(result).isEqualTo(updatedName);
+    }
+
+    @Test
+    public void givenInnerClassWhenOnlyOuterClassHasMatchThenReturnUpdatedName() {
+        //given
+        final Map<String, String> renames = new HashMap<>();
+        final String originalOuterClass = createAName();
+        final String originalInnerClass = createAName();
+        final String originalName = originalOuterClass + "$" + originalInnerClass;
+        final String updatedOuterClass = createAName();
+        final String updatedName = updatedOuterClass + "$" + originalInnerClass;
+        renames.put(originalOuterClass, updatedOuterClass);
+        //when
+        final String result = Reflections.findMappedNameAndLog(renames, originalName);
+        //then
+        assertThat(result).isEqualTo(updatedName);
+    }
+
+    @Test
+    public void givenInnerClassWhenOuterAndInnerClassHasMatchThenReturnInnerClassUpdatedName() {
+        //given
+        final Map<String, String> renames = new HashMap<>();
+        // the outer class has been renamed
+        final String originalOuterClass = createAName();
+        final String updatedOuterClass = createAName();
+        renames.put(originalOuterClass, updatedOuterClass);
+        // the inner class has an explicit rename to a different outer class
+        final String originalInnerClass = createAName();
+        final String originalName = originalOuterClass + "$" + originalInnerClass;
+        final String updatedName = createAName() + "$" + createAName();
+        renames.put(originalName, updatedName);
+        //when
+        final String result = Reflections.findMappedNameAndLog(renames, originalName);
+        //then
+        // the explicit rename overrides the outer class rename
+        assertThat(result).isEqualTo(updatedName);
+    }
+
+    //wrap_blah_aws-java-sdk-bundle-1.11.245.jar\:*  : wrap_blah_aws-java-sdk-bundle-1.11.411.jar\:*
+    @Test
+    public void allClassesInOneBundleAreNowInOtherBundle() {
+        //given
+        final Map<String, String> renames = new HashMap<>();
+        final String wildcard = "*";
+        final String originalBundle = "wrap_blah_aws-java-sdk-bundle-1.11.245.jar:";
+        final String updatedBundle = "wrap_blah_aws-java-sdk-bundle-1.11.411.jar:";
+        renames.put(originalBundle + wildcard, updatedBundle + wildcard);
+        final String className = createAName();
+        final String originalName = originalBundle + className;
+        final String updatedName = updatedBundle + className;
+        //when
+        final String result = Reflections.findMappedNameAndLog(renames, originalName);
+        //then
+        assertThat(result).isSameAs(updatedName);
+    }
+
+    private String createAName() {
+        return UUID.randomUUID().toString();
+    }
+
+}
diff --git a/utils/common/src/test/java/org/apache/brooklyn/util/javalang/ReflectionsTest.java b/utils/common/src/test/java/org/apache/brooklyn/util/javalang/ReflectionsTest.java
index 06c5f47..a46f6ee 100644
--- a/utils/common/src/test/java/org/apache/brooklyn/util/javalang/ReflectionsTest.java
+++ b/utils/common/src/test/java/org/apache/brooklyn/util/javalang/ReflectionsTest.java
@@ -38,7 +38,7 @@ import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Sets;
 
-public class ReflectionsTest implements WithAssertions {
+public class ReflectionsTest {
 
     @Test
     public void testFindPublicMethodsOrderedBySuper() throws Exception {
@@ -229,143 +229,6 @@ public class ReflectionsTest implements WithAssertions {
         Assert.assertEquals(Reflections.getAllInterfaces(C.class), ImmutableList.of(M.class, K.class, I.class, J.class, L.class));
     }
 
-    /**
-     * Tests for {@link Reflections#findMappedNameAndLog(Map, String)} and
-     * {@link Reflections#findMappedNameMaybe(Map, String)} methods.
-     */
-    public class FindMappedName {
-
-        @Test
-        public void givenRenamesIsNullThenReturnOriginalName() {
-            //given
-            final Map<String, String> renames = null;
-            final String originalName = createAName();
-            //when
-            final String result = Reflections.findMappedNameAndLog(renames, originalName);
-            //then
-            assertThat(result).isEqualTo(originalName);
-        }
-
-        @Test
-        public void givenRenamesIsEmptyThenReturnOriginalName() {
-            //given
-            final Map<String, String> renames = new HashMap<>();
-            final String originalName = createAName();
-            //when
-            final String result = Reflections.findMappedNameAndLog(renames, originalName);
-            //then
-            assertThat(result).isEqualTo(originalName);
-        }
-
-        @Test
-        public void givenRenamesHasNoMatchThenReturnOriginalName() {
-            //given
-            final Map<String, String> renames = new HashMap<>();
-            renames.put(createAName(), createAName());
-            final String originalName = createAName();
-            //when
-            final String result = Reflections.findMappedNameAndLog(renames, originalName);
-            //then
-            assertThat(result).isEqualTo(originalName);
-        }
-
-        @Test
-        public void givenRenamesHasMatchThenReturnUpdatedName() {
-            //given
-            final Map<String, String> renames = new HashMap<>();
-            final String originalName = createAName();
-            final String updatedName = createAName();
-            renames.put(originalName, updatedName);
-            //when
-            final String result = Reflections.findMappedNameAndLog(renames, originalName);
-            //then
-            assertThat(result).isEqualTo(updatedName);
-        }
-
-        @Test
-        public void givenInnerClassHasNoMatchThenReturnOriginalName() {
-            //given
-            final Map<String, String> renames = new HashMap<>();
-            final String originalName = createAName() + "$" + createAName();
-            //when
-            final String result = Reflections.findMappedNameAndLog(renames, originalName);
-            //then
-            assertThat(result).isEqualTo(originalName);
-        }
-
-        @Test
-        public void givenInnerClassHasMatchThenReturnUpdatedName() {
-            //given
-            final Map<String, String> renames = new HashMap<>();
-            final String originalName = createAName() + "$" + createAName();
-            final String updatedName = createAName();
-            renames.put(originalName, updatedName);
-            //when
-            final String result = Reflections.findMappedNameAndLog(renames, originalName);
-            //then
-            assertThat(result).isEqualTo(updatedName);
-        }
-
-        @Test
-        public void givenInnerClassWhenOnlyOuterClassHasMatchThenReturnUpdatedName() {
-            //given
-            final Map<String, String> renames = new HashMap<>();
-            final String originalOuterClass = createAName();
-            final String originalInnerClass = createAName();
-            final String originalName = originalOuterClass + "$" + originalInnerClass;
-            final String updatedOuterClass = createAName();
-            final String updatedName = updatedOuterClass + "$" + originalInnerClass;
-            renames.put(originalOuterClass, updatedOuterClass);
-            //when
-            final String result = Reflections.findMappedNameAndLog(renames, originalName);
-            //then
-            assertThat(result).isEqualTo(updatedName);
-        }
-
-        @Test
-        public void givenInnerClassWhenOuterAndInnerClassHasMatchThenReturnInnerClassUpdatedName() {
-            //given
-            final Map<String, String> renames = new HashMap<>();
-            // the outer class has been renamed
-            final String originalOuterClass = createAName();
-            final String updatedOuterClass = createAName();
-            renames.put(originalOuterClass, updatedOuterClass);
-            // the inner class has an explicit rename to a different outer class
-            final String originalInnerClass = createAName();
-            final String originalName = originalOuterClass + "$" + originalInnerClass;
-            final String updatedName = createAName() + "$" + createAName();
-            renames.put(originalName, updatedName);
-            //when
-            final String result = Reflections.findMappedNameAndLog(renames, originalName);
-            //then
-            // the explicit rename overrides the outer class rename
-            assertThat(result).isEqualTo(updatedName);
-        }
-
-        //wrap_blah_aws-java-sdk-bundle-1.11.245.jar\:*  : wrap_blah_aws-java-sdk-bundle-1.11.411.jar\:*
-        @Test
-        public void allClassesInOneBundleAreNowInOtherBundle() {
-            //given
-            final Map<String, String> renames = new HashMap<>();
-            final String wildcard = "*";
-            final String originalBundle = "wrap_blah_aws-java-sdk-bundle-1.11.245.jar:";
-            final String updatedBundle = "wrap_blah_aws-java-sdk-bundle-1.11.411.jar:";
-            renames.put(originalBundle + wildcard, updatedBundle + wildcard);
-            final String className = createAName();
-            final String originalName = originalBundle + className;
-            final String updatedName = updatedBundle + className;
-            //when
-            final String result = Reflections.findMappedNameAndLog(renames, originalName);
-            //then
-            assertThat(result).isSameAs(updatedName);
-        }
-
-        private String createAName() {
-            return UUID.randomUUID().toString();
-        }
-
-    }
-
     public static abstract class PublicSuperClass {
         public abstract void methodOnSuperClass();
     }


[brooklyn-server] 13/31: Extract newMockBundle() utility methods to BundleTestUtil

Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 0ec04184d60ea00ecd0f4cea2d8faac2529dae93
Author: Paul Campbell <pc...@kemitix.net>
AuthorDate: Mon Oct 22 14:20:45 2018 +0100

    Extract newMockBundle() utility methods to BundleTestUtil
---
 .../brooklyn/core/typereg/BundleTestUtil.java      | 39 ++++++++++++++++++++++
 .../core/typereg/BundleUpgradeParserTest.java      | 27 +--------------
 2 files changed, 40 insertions(+), 26 deletions(-)

diff --git a/core/src/test/java/org/apache/brooklyn/core/typereg/BundleTestUtil.java b/core/src/test/java/org/apache/brooklyn/core/typereg/BundleTestUtil.java
new file mode 100644
index 0000000..2a5c3d7
--- /dev/null
+++ b/core/src/test/java/org/apache/brooklyn/core/typereg/BundleTestUtil.java
@@ -0,0 +1,39 @@
+package org.apache.brooklyn.core.typereg;
+
+import com.google.common.collect.ImmutableMap;
+import org.apache.brooklyn.util.osgi.VersionedName;
+import org.mockito.Mockito;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.Version;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.Map;
+
+class BundleTestUtil {
+
+    static Bundle newMockBundle(Map<String, String> rawHeaders) {
+        return newMockBundle(VersionedName.fromString("do.no.care:1.2.3"), rawHeaders);
+    }
+
+    static Bundle newMockBundle(VersionedName name) {
+        return newMockBundle(name, ImmutableMap.of());
+    }
+
+    static Bundle newMockBundle(VersionedName name, Map<String, String> rawHeaders) {
+        Dictionary<String, String> headers = new Hashtable<>(rawHeaders);
+        Bundle result;
+        try {
+            result = Mockito.mock(Bundle.class);
+        } catch (Exception e) {
+            throw new IllegalStateException("Java too old.  There is a bug in really early java 1.8.0 "
+                    + "that causes mocks to fail, and has probably caused this.", e);
+        }
+        Mockito.when(result.getHeaders()).thenReturn(headers);
+        Mockito.when(result.getSymbolicName()).thenReturn(name.getSymbolicName());
+        Mockito.when(result.getVersion()).thenReturn(Version.valueOf(name.getOsgiVersionString()));
+        return result;
+    }
+
+
+}
diff --git a/core/src/test/java/org/apache/brooklyn/core/typereg/BundleUpgradeParserTest.java b/core/src/test/java/org/apache/brooklyn/core/typereg/BundleUpgradeParserTest.java
index 8803294..1b437b3 100644
--- a/core/src/test/java/org/apache/brooklyn/core/typereg/BundleUpgradeParserTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/typereg/BundleUpgradeParserTest.java
@@ -18,14 +18,12 @@
  */
 package org.apache.brooklyn.core.typereg;
 
+import static org.apache.brooklyn.core.typereg.BundleTestUtil.newMockBundle;
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertFalse;
 import static org.testng.Assert.assertTrue;
 
-import java.util.Dictionary;
-import java.util.Hashtable;
 import java.util.List;
-import java.util.Map;
 import java.util.Set;
 
 import org.apache.brooklyn.api.catalog.CatalogItem;
@@ -401,29 +399,6 @@ public class BundleUpgradeParserTest {
         assertEquals(BundleUpgradeParser.stripQuotes("''"), "");
     }
     
-    private Bundle newMockBundle(Map<String, String> rawHeaders) {
-        return newMockBundle(VersionedName.fromString("do.no.care:1.2.3"), rawHeaders);
-    }
-
-    private Bundle newMockBundle(VersionedName name) {
-        return newMockBundle(name, ImmutableMap.of());
-    }
-    
-    private Bundle newMockBundle(VersionedName name, Map<String, String> rawHeaders) {
-        Dictionary<String, String> headers = new Hashtable<>(rawHeaders);
-        Bundle result;
-        try {
-            result = Mockito.mock(Bundle.class);
-        } catch (Exception e) {
-            throw new IllegalStateException("Java too old.  There is a bug in really early java 1.8.0 "
-                + "that causes mocks to fail, and has probably caused this.", e);
-        }
-        Mockito.when(result.getHeaders()).thenReturn(headers);
-        Mockito.when(result.getSymbolicName()).thenReturn(name.getSymbolicName());
-        Mockito.when(result.getVersion()).thenReturn(Version.valueOf(name.getOsgiVersionString()));
-        return result;
-    }
-
     private RegisteredType newMockRegisteredType(String symbolicName, String version) {
         RegisteredType result = Mockito.mock(RegisteredType.class);
         Mockito.when(result.getSymbolicName()).thenReturn(symbolicName);


[brooklyn-server] 28/31: Add missing header

Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit aabab44f869669abea6911e82bbf00a04d1bb4e4
Author: Paul Campbell <pc...@kemitix.net>
AuthorDate: Wed Oct 24 19:52:34 2018 +0100

    Add missing header
---
 .../catalog/internal/CatalogUpgradeScannerTest.java    | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/core/src/test/java/org/apache/brooklyn/core/catalog/internal/CatalogUpgradeScannerTest.java b/core/src/test/java/org/apache/brooklyn/core/catalog/internal/CatalogUpgradeScannerTest.java
index a03a54e..5eba4f1 100644
--- a/core/src/test/java/org/apache/brooklyn/core/catalog/internal/CatalogUpgradeScannerTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/catalog/internal/CatalogUpgradeScannerTest.java
@@ -1,3 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
 package org.apache.brooklyn.core.catalog.internal;
 
 import com.google.common.base.Predicate;


[brooklyn-server] 06/31: [common] Add unit tests for Reflections#findMappedName{AndLog, Maybe}()

Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 8f11da59c266f885a1223e509230d89fb7ab96e3
Author: Paul Campbell <pa...@cloudsoft.io>
AuthorDate: Tue Oct 9 16:38:52 2018 +0100

    [common] Add unit tests for Reflections#findMappedName{AndLog,Maybe}()
    
    Full coverage unit tests for these two methods.
---
 .../brooklyn/util/javalang/ReflectionsTest.java    | 125 ++++++++++++++++++++-
 1 file changed, 122 insertions(+), 3 deletions(-)

diff --git a/utils/common/src/test/java/org/apache/brooklyn/util/javalang/ReflectionsTest.java b/utils/common/src/test/java/org/apache/brooklyn/util/javalang/ReflectionsTest.java
index 3c628a9..554ad96 100644
--- a/utils/common/src/test/java/org/apache/brooklyn/util/javalang/ReflectionsTest.java
+++ b/utils/common/src/test/java/org/apache/brooklyn/util/javalang/ReflectionsTest.java
@@ -24,12 +24,12 @@ import static org.testng.Assert.assertTrue;
 
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
-import java.util.Arrays;
-import java.util.List;
+import java.util.*;
 
 import org.apache.brooklyn.util.javalang.coerce.CommonAdaptorTypeCoercions;
 import org.apache.brooklyn.util.javalang.coerce.TypeCoercer;
 import org.apache.brooklyn.util.javalang.coerce.TypeCoercerExtensible;
+import org.assertj.core.api.WithAssertions;
 import org.testng.Assert;
 import org.testng.annotations.Test;
 
@@ -38,7 +38,7 @@ import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Sets;
 
-public class ReflectionsTest {
+public class ReflectionsTest implements WithAssertions {
 
     @Test
     public void testFindPublicMethodsOrderedBySuper() throws Exception {
@@ -229,6 +229,125 @@ public class ReflectionsTest {
         Assert.assertEquals(Reflections.getAllInterfaces(C.class), ImmutableList.of(M.class, K.class, I.class, J.class, L.class));
     }
 
+    /**
+     * Tests for {@link Reflections#findMappedNameAndLog(Map, String)} and
+     * {@link Reflections#findMappedNameMaybe(Map, String)} methods.
+     */
+    public class FindMappedName {
+
+        @Test
+        public void givenRenamesIsNullThenReturnOriginalName() {
+            //given
+            final Map<String, String> renames = null;
+            final String originalName = createAName();
+            //when
+            final String result = Reflections.findMappedNameAndLog(renames, originalName);
+            //then
+            assertThat(result).isEqualTo(originalName);
+        }
+
+        @Test
+        public void givenRenamesIsEmptyThenReturnOriginalName() {
+            //given
+            final Map<String, String> renames = new HashMap<>();
+            final String originalName = createAName();
+            //when
+            final String result = Reflections.findMappedNameAndLog(renames, originalName);
+            //then
+            assertThat(result).isEqualTo(originalName);
+        }
+
+        @Test
+        public void givenRenamesHasNoMatchThenReturnOriginalName() {
+            //given
+            final Map<String, String> renames = new HashMap<>();
+            renames.put(createAName(), createAName());
+            final String originalName = createAName();
+            //when
+            final String result = Reflections.findMappedNameAndLog(renames, originalName);
+            //then
+            assertThat(result).isEqualTo(originalName);
+        }
+
+        @Test
+        public void givenRenamesHasMatchThenReturnUpdatedName() {
+            //given
+            final Map<String, String> renames = new HashMap<>();
+            final String originalName = createAName();
+            final String updatedName = createAName();
+            renames.put(originalName, updatedName);
+            //when
+            final String result = Reflections.findMappedNameAndLog(renames, originalName);
+            //then
+            assertThat(result).isEqualTo(updatedName);
+        }
+
+        @Test
+        public void givenInnerClassHasNoMatchThenReturnOriginalName() {
+            //given
+            final Map<String, String> renames = new HashMap<>();
+            final String originalName = createAName() + "$" + createAName();
+            //when
+            final String result = Reflections.findMappedNameAndLog(renames, originalName);
+            //then
+            assertThat(result).isEqualTo(originalName);
+        }
+
+        @Test
+        public void givenInnerClassHasMatchThenReturnUpdatedName() {
+            //given
+            final Map<String, String> renames = new HashMap<>();
+            final String originalName = createAName() + "$" + createAName();
+            final String updatedName = createAName();
+            renames.put(originalName, updatedName);
+            //when
+            final String result = Reflections.findMappedNameAndLog(renames, originalName);
+            //then
+            assertThat(result).isEqualTo(updatedName);
+        }
+
+        @Test
+        public void givenInnerClassWhenOnlyOuterClassHasMatchThenReturnUpdatedName() {
+            //given
+            final Map<String, String> renames = new HashMap<>();
+            final String originalOuterClass = createAName();
+            final String originalInnerClass = createAName();
+            final String originalName = originalOuterClass + "$" + originalInnerClass;
+            final String updatedOuterClass = createAName();
+            final String updatedName = updatedOuterClass + "$" + originalInnerClass;
+            renames.put(originalOuterClass, updatedOuterClass);
+            //when
+            final String result = Reflections.findMappedNameAndLog(renames, originalName);
+            //then
+            assertThat(result).isEqualTo(updatedName);
+        }
+
+        @Test
+        public void givenInnerClassWhenOuterAndInnerClassHasMatchThenReturnInnerClassUpdatedName() {
+            //given
+            final Map<String, String> renames = new HashMap<>();
+            // the outer class has been renamed
+            final String originalOuterClass = createAName();
+            final String updatedOuterClass = createAName();
+            renames.put(originalOuterClass, updatedOuterClass);
+            // the inner class has an explicit rename to a different outer class
+            final String originalInnerClass = createAName();
+            final String originalName = originalOuterClass + "$" + originalInnerClass;
+            final String updatedName = createAName() + "$" + createAName();
+            renames.put(originalName, updatedName);
+            //when
+            final String result = Reflections.findMappedNameAndLog(renames, originalName);
+            //then
+            // the explicit rename overrides the outer class rename
+            assertThat(result).isEqualTo(updatedName);
+        }
+
+        private String createAName() {
+            return UUID.randomUUID().toString();
+        }
+
+    }
+
     public static abstract class PublicSuperClass {
         public abstract void methodOnSuperClass();
     }


[brooklyn-server] 24/31: Limit violation of the law of demeter

Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit cdb298faafada153bcd1e81f1a65b983d0752611
Author: Paul Campbell <pc...@kemitix.net>
AuthorDate: Wed Oct 24 11:48:39 2018 +0100

    Limit violation of the law of demeter
    
    Push out drilling into the orgimanager,framework.bundlecontext.bundles to
    callers.
---
 .../core/catalog/internal/CatalogInitialization.java        | 10 +++++++---
 .../core/catalog/internal/CatalogUpgradeScanner.java        | 13 +++++++------
 2 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogInitialization.java b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogInitialization.java
index fe57f41..29a9601 100644
--- a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogInitialization.java
+++ b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogInitialization.java
@@ -68,6 +68,7 @@ import org.apache.brooklyn.util.os.Os;
 import org.apache.brooklyn.util.osgi.VersionedName;
 import org.apache.brooklyn.util.text.Strings;
 import org.apache.brooklyn.util.time.Duration;
+import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -256,12 +257,15 @@ public class CatalogInitialization implements ManagementContextInjectable {
             
             populateInitialCatalogImpl(true);
 
-            final Maybe<OsgiManager> osgiManager = managementContext.getOsgiManager();
-            if (osgiManager.isAbsent()) {
+            final Maybe<OsgiManager> maybesOsgiManager = managementContext.getOsgiManager();
+            if (maybesOsgiManager.isAbsent()) {
                 // Can't find any bundles to tell if there are upgrades. Could be running tests; do no filtering.
                 CatalogUpgrades.storeInManagementContext(CatalogUpgrades.EMPTY, managementContext);
             } else {
-                final CatalogUpgrades catalogUpgrades = catalogUpgradeScanner.scan(osgiManager.get(), rebindLogger);
+                final OsgiManager osgiManager = maybesOsgiManager.get();
+                final BundleContext bundleContext = osgiManager.getFramework().getBundleContext();
+                final CatalogUpgrades catalogUpgrades =
+                        catalogUpgradeScanner.scan(osgiManager, bundleContext, rebindLogger);
                 CatalogUpgrades.storeInManagementContext(catalogUpgrades, managementContext);
             }
             PersistedCatalogState filteredPersistedState = filterBundlesAndCatalogInPersistedState(persistedState, rebindLogger);
diff --git a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogUpgradeScanner.java b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogUpgradeScanner.java
index b48bbf8..efe902d 100644
--- a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogUpgradeScanner.java
+++ b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogUpgradeScanner.java
@@ -25,9 +25,9 @@ import org.apache.brooklyn.api.typereg.RegisteredType;
 import org.apache.brooklyn.core.mgmt.ha.OsgiManager;
 import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
 import org.apache.brooklyn.core.typereg.BundleUpgradeParser.CatalogUpgrades;
-import org.apache.brooklyn.core.typereg.RegisteredTypePredicates;
 import org.apache.brooklyn.util.guava.Maybe;
 import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
 
 import java.util.Collection;
 import java.util.function.BiFunction;
@@ -57,11 +57,12 @@ class CatalogUpgradeScanner {
 
     public CatalogUpgrades scan(
             final OsgiManager osgiManager,
+            final BundleContext bundleContext,
             final CatalogInitialization.RebindLogger rebindLogger
     ) {
         final CatalogUpgrades.Builder catalogUpgradesBuilder = CatalogUpgrades.builder();
         scanManagedBundles(osgiManager, catalogUpgradesBuilder, rebindLogger);
-        scanAllBundles(osgiManager, catalogUpgradesBuilder);
+        scanUnmanagedBundles(catalogUpgradesBuilder, bundleContext);
         return catalogUpgradesBuilder.build();
     }
 
@@ -83,11 +84,11 @@ class CatalogUpgradeScanner {
         }
     }
 
-    private void scanAllBundles(
-            final OsgiManager osgiManager,
-            final CatalogUpgrades.Builder catalogUpgradesBuilder
+    private void scanUnmanagedBundles(
+            final CatalogUpgrades.Builder catalogUpgradesBuilder,
+            final BundleContext bundleContext
     ) {
-        for (Bundle bundle : osgiManager.getFramework().getBundleContext().getBundles()) {
+        for (Bundle bundle : bundleContext.getBundles()) {
             final CatalogUpgrades catalogUpgrades = bundleUpgradeParser.apply(bundle, typeSupplier(bundle));
             catalogUpgradesBuilder.addAll(catalogUpgrades);
         }


[brooklyn-server] 17/31: Remove stopwatches

Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 6127e032294180f324de961c272c3abad0cbe767
Author: Paul Campbell <pc...@kemitix.net>
AuthorDate: Tue Oct 23 17:06:41 2018 +0100

    Remove stopwatches
---
 .../brooklyn/core/catalog/internal/CatalogInitialization.java      | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogInitialization.java b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogInitialization.java
index 18e1f27..b355b97 100644
--- a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogInitialization.java
+++ b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogInitialization.java
@@ -29,7 +29,6 @@ import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import java.util.concurrent.TimeUnit;
 
 import org.apache.brooklyn.api.catalog.BrooklynCatalog;
 import org.apache.brooklyn.api.catalog.CatalogItem;
@@ -618,7 +617,6 @@ public class CatalogInitialization implements ManagementContextInjectable {
         
         CatalogUpgrades.Builder catalogUpgradesBuilder = CatalogUpgrades.builder();
         Collection<ManagedBundle> managedBundles = osgiManager.get().getManagedBundles().values();
-        final Stopwatch started = Stopwatch.createStarted();
         for (ManagedBundle managedBundle : managedBundles) {
             Maybe<Bundle> bundle = osgiManager.get().findBundle(managedBundle);
             if (bundle.isPresent()) {
@@ -631,10 +629,7 @@ public class CatalogInitialization implements ManagementContextInjectable {
                         + "ignoring when calculating persisted state catalog upgrades");
             }
         }
-        started.stop();
-        log.info("Loaded managed bundles in " + started.elapsed(TimeUnit.MILLISECONDS) + "ms");
 
-        final Stopwatch allbundleStopWatch = Stopwatch.createStarted();
         for (Bundle bundle : osgiManager.get().getFramework().getBundleContext().getBundles()) {
             final RegisteredTypesSupplier typeSupplier =
                     new RegisteredTypesSupplier(managementContext,
@@ -643,8 +638,6 @@ public class CatalogInitialization implements ManagementContextInjectable {
                     BundleUpgradeParser.parseBundleManifestForCatalogUpgrades(bundle, typeSupplier);
             catalogUpgradesBuilder.addAll(catalogUpgrades);
         }
-        allbundleStopWatch.stop();
-        log.info("Loaded all bundles in " + allbundleStopWatch.elapsed(TimeUnit.MILLISECONDS) + "ms");
 
         return catalogUpgradesBuilder.build();
     }


[brooklyn-server] 23/31: Extract static methods as a constructor parameters

Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit ab67707f3b3728f3e2a12728e77fd8f5541c6c2f
Author: Paul Campbell <pc...@kemitix.net>
AuthorDate: Wed Oct 24 11:05:46 2018 +0100

    Extract static methods as a constructor parameters
    
    Providing the static method call as a function to the constructor makes unit
    testing for this class much simpler as it allows the static method to be
    mocked, improving the clarity of the unit tests.
---
 .../catalog/internal/CatalogInitialization.java    |  6 +++--
 .../catalog/internal/CatalogUpgradeScanner.java    | 28 +++++++++++++++-------
 2 files changed, 23 insertions(+), 11 deletions(-)

diff --git a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogInitialization.java b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogInitialization.java
index e284479..fe57f41 100644
--- a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogInitialization.java
+++ b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogInitialization.java
@@ -68,7 +68,6 @@ import org.apache.brooklyn.util.os.Os;
 import org.apache.brooklyn.util.osgi.VersionedName;
 import org.apache.brooklyn.util.text.Strings;
 import org.apache.brooklyn.util.time.Duration;
-import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -135,7 +134,10 @@ public class CatalogInitialization implements ManagementContextInjectable {
         if (this.managementContext!=null && managementContext!=this.managementContext)
             throw new IllegalStateException("Cannot switch management context, from "+this.managementContext+" to "+managementContext);
         this.managementContext = (ManagementContextInternal) managementContext;
-        catalogUpgradeScanner = new CatalogUpgradeScanner(this.managementContext);
+        catalogUpgradeScanner = new CatalogUpgradeScanner(this.managementContext,
+                BundleUpgradeParser::parseBundleManifestForCatalogUpgrades,
+                RegisteredTypePredicates::containingBundle,
+                RegisteredTypePredicates::containingBundle);
     }
     
     /** Called by the framework to set true while starting up, and false afterwards,
diff --git a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogUpgradeScanner.java b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogUpgradeScanner.java
index 446c083..b48bbf8 100644
--- a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogUpgradeScanner.java
+++ b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogUpgradeScanner.java
@@ -18,16 +18,20 @@
  */
 package org.apache.brooklyn.core.catalog.internal;
 
+import com.google.common.base.Predicate;
 import org.apache.brooklyn.api.typereg.ManagedBundle;
+import org.apache.brooklyn.api.typereg.OsgiBundleWithUrl;
+import org.apache.brooklyn.api.typereg.RegisteredType;
 import org.apache.brooklyn.core.mgmt.ha.OsgiManager;
 import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
-import org.apache.brooklyn.core.typereg.BundleUpgradeParser;
 import org.apache.brooklyn.core.typereg.BundleUpgradeParser.CatalogUpgrades;
 import org.apache.brooklyn.core.typereg.RegisteredTypePredicates;
 import org.apache.brooklyn.util.guava.Maybe;
 import org.osgi.framework.Bundle;
 
 import java.util.Collection;
+import java.util.function.BiFunction;
+import java.util.function.Function;
 
 /**
  * Scans managed bundles and other jar bundles to find upgrades for installed bundles.
@@ -35,11 +39,20 @@ import java.util.Collection;
 class CatalogUpgradeScanner {
 
     private final ManagementContextInternal managementContext;
+    private final BiFunction<Bundle, RegisteredTypesSupplier, CatalogUpgrades> bundleUpgradeParser;
+    private final Function<OsgiBundleWithUrl, Predicate<? super RegisteredType>> managedBundlePredicateSupplier;
+    private final Function<String, Predicate<? super RegisteredType>> unmanagedBundlePredicateSupplier;
 
     CatalogUpgradeScanner(
-            final ManagementContextInternal managementContext
+            final ManagementContextInternal managementContext,
+            final BiFunction<Bundle, RegisteredTypesSupplier, CatalogUpgrades> bundleUpgradeParser,
+            final Function<OsgiBundleWithUrl, Predicate<? super RegisteredType>> managedBundlePredicateSupplier,
+            final Function<String, Predicate<? super RegisteredType>> unmanagedBundlePredicateSupplier
     ) {
         this.managementContext = managementContext;
+        this.bundleUpgradeParser = bundleUpgradeParser;
+        this.managedBundlePredicateSupplier = managedBundlePredicateSupplier;
+        this.unmanagedBundlePredicateSupplier = unmanagedBundlePredicateSupplier;
     }
 
     public CatalogUpgrades scan(
@@ -61,8 +74,7 @@ class CatalogUpgradeScanner {
         for (ManagedBundle managedBundle : managedBundles) {
             Maybe<Bundle> bundle = osgiManager.findBundle(managedBundle);
             if (bundle.isPresent()) {
-                CatalogUpgrades catalogUpgrades = BundleUpgradeParser.parseBundleManifestForCatalogUpgrades(
-                        bundle.get(), typeSupplier(managedBundle));
+                CatalogUpgrades catalogUpgrades = bundleUpgradeParser.apply(bundle.get(), typeSupplier(managedBundle));
                 catalogUpgradesBuilder.addAll(catalogUpgrades);
             } else {
                 rebindLogger.info("Managed bundle "+managedBundle.getId()+" not found by OSGi Manager; "
@@ -76,20 +88,18 @@ class CatalogUpgradeScanner {
             final CatalogUpgrades.Builder catalogUpgradesBuilder
     ) {
         for (Bundle bundle : osgiManager.getFramework().getBundleContext().getBundles()) {
-            final CatalogUpgrades catalogUpgrades =
-                    BundleUpgradeParser.parseBundleManifestForCatalogUpgrades(bundle, typeSupplier(bundle));
+            final CatalogUpgrades catalogUpgrades = bundleUpgradeParser.apply(bundle, typeSupplier(bundle));
             catalogUpgradesBuilder.addAll(catalogUpgrades);
         }
     }
 
     private RegisteredTypesSupplier typeSupplier(final ManagedBundle managedBundle) {
-        return new RegisteredTypesSupplier(managementContext,
-                RegisteredTypePredicates.containingBundle(managedBundle));
+        return new RegisteredTypesSupplier(managementContext, managedBundlePredicateSupplier.apply(managedBundle));
     }
 
     private RegisteredTypesSupplier typeSupplier(final Bundle bundle) {
         return new RegisteredTypesSupplier(managementContext,
-                RegisteredTypePredicates.containingBundle(bundle.getSymbolicName()));
+                unmanagedBundlePredicateSupplier.apply(bundle.getSymbolicName()));
     }
 
 }


[brooklyn-server] 12/31: Coverage tests for existing CatalogUpgrades.getBundleUpgradedIfNecessary()

Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 8e91fbee540b1fec025606bacc4540ae8c2ea180
Author: Paul Campbell <pc...@kemitix.net>
AuthorDate: Thu Oct 18 11:16:58 2018 +0100

    Coverage tests for existing CatalogUpgrades.getBundleUpgradedIfNecessary()
---
 ...ogUpgradesGetBundleUpgradedIfNecessaryTest.java | 219 +++++++++++++++++++++
 1 file changed, 219 insertions(+)

diff --git a/core/src/test/java/org/apache/brooklyn/core/typereg/CatalogUpgradesGetBundleUpgradedIfNecessaryTest.java b/core/src/test/java/org/apache/brooklyn/core/typereg/CatalogUpgradesGetBundleUpgradedIfNecessaryTest.java
new file mode 100644
index 0000000..70cd926
--- /dev/null
+++ b/core/src/test/java/org/apache/brooklyn/core/typereg/CatalogUpgradesGetBundleUpgradedIfNecessaryTest.java
@@ -0,0 +1,219 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.brooklyn.core.typereg;
+
+import com.google.common.collect.ImmutableListMultimap;
+import org.apache.brooklyn.api.mgmt.ManagementContext;
+import org.apache.brooklyn.api.typereg.BrooklynTypeRegistry;
+import org.apache.brooklyn.api.typereg.ManagedBundle;
+import org.apache.brooklyn.core.mgmt.ha.OsgiManager;
+import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
+import org.apache.brooklyn.util.guava.Maybe;
+import org.apache.brooklyn.util.osgi.VersionedName;
+import org.assertj.core.api.WithAssertions;
+import org.mockito.Mockito;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import java.util.UUID;
+
+import static org.apache.brooklyn.core.typereg.BundleUpgradeParser.*;
+import static org.mockito.BDDMockito.given;
+import static org.mockito.Mockito.mock;
+
+public class CatalogUpgradesGetBundleUpgradedIfNecessaryTest implements WithAssertions {
+
+    private final ManagementContextInternal managementContext = mock(ManagementContextInternal.class);
+    private final OsgiManager osgiManager = mock(OsgiManager.class);
+    private final ManagedBundle managedBundle = mock(ManagedBundle.class);
+    private final BasicBrooklynTypeRegistry typeRegistry = mock(BasicBrooklynTypeRegistry.class);
+
+    private final String originalName = createAName("original", "1.0.0");
+    private final String updatedName = createAName("updated", "2.0.0");
+    private final VersionedName originalVersionedName = VersionedName.fromString(originalName);
+    private final VersionedName updatedVersionedName = VersionedName.fromString(updatedName);
+    private final VersionRangedName originalVersionRangedName =
+            VersionRangedName.fromString(originalName, true);
+
+    private CatalogUpgrades.Builder catalogUpgradesBuilder;
+
+    @BeforeMethod
+    public void setUp() {
+        Mockito.reset(managementContext, osgiManager, managedBundle, typeRegistry);
+        catalogUpgradesBuilder = CatalogUpgrades.builder();
+    }
+
+    @Test
+    public void whenContextIsNullThenNull() {
+        //given
+        final ManagementContext managementContext = null;
+        //when
+        final String result = CatalogUpgrades.getBundleUpgradedIfNecessary(managementContext, originalName);
+        //then
+        assertThat(result).isNull();
+    }
+
+    @Test
+    public void whenNameIsNullThenNull() {
+        //given
+        final String originalName = null;
+        //when
+        final String result = CatalogUpgrades.getBundleUpgradedIfNecessary(managementContext, originalName);
+        //then
+        assertThat(result).isNull();
+    }
+
+    @Test
+    public void whenNonOSGIEnvironmentThenOriginalName() {
+        //given
+        givenANonOsgiEnvironment(managementContext);
+        //when
+        final String result = CatalogUpgrades.getBundleUpgradedIfNecessary(managementContext, originalName);
+        //then
+        assertThat(result).isEqualTo(originalName);
+    }
+
+    @Test
+    public void whenAlreadyInstalledThenOriginalName() {
+        //given
+        givenAnOsgiEnvironment(managementContext, osgiManager);
+        givenBundleIsAlreadyInstalled(osgiManager, originalVersionedName, managedBundle);
+        //when
+        final String result = CatalogUpgrades.getBundleUpgradedIfNecessary(managementContext, originalName);
+        //then
+        assertThat(result).isEqualTo(originalName);
+    }
+
+    @Test
+    public void whenNotInstalledAndNoRenameFoundThenOriginalName() {
+        //given
+        givenAnOsgiEnvironment(managementContext, osgiManager);
+        givenBundleIsNotAlreadyInstalled(osgiManager, originalVersionedName);
+        givenNoRenameFound(managementContext, typeRegistry, catalogUpgradesBuilder);
+        //when
+        final String result = CatalogUpgrades.getBundleUpgradedIfNecessary(managementContext, originalName);
+        //then
+        assertThat(result).isEqualTo(originalName);
+    }
+
+    @Test
+    public void whenNotInstalledAndNoCatalogUpgradesThenOriginalName() {
+        //given
+        givenAnOsgiEnvironment(managementContext, osgiManager);
+        givenBundleIsNotAlreadyInstalled(osgiManager, originalVersionedName);
+        givenNoCatalogUpgrades(managementContext, typeRegistry);
+        //when
+        final String result = CatalogUpgrades.getBundleUpgradedIfNecessary(managementContext, originalName);
+        //then
+        assertThat(result).isEqualTo(originalName);
+    }
+
+    @Test
+    public void whenNotAlreadyInstalledAndRenameIsFoundThenUpdatedName() {
+        //given
+        givenAnOsgiEnvironment(managementContext, osgiManager);
+        givenBundleIsNotAlreadyInstalled(osgiManager, originalVersionedName);
+        givenRenameIsFound(managementContext, typeRegistry, catalogUpgradesBuilder,
+                updatedVersionedName, originalVersionRangedName);
+        //when
+        final String result = CatalogUpgrades.getBundleUpgradedIfNecessary(managementContext, originalName);
+        //then
+        assertThat(result).isEqualTo(updatedName);
+    }
+
+    private static void givenANonOsgiEnvironment(
+            final ManagementContextInternal managementContext
+    ) {
+        given(managementContext.getOsgiManager()).willReturn(Maybe.absent());
+    }
+
+    private static void givenNoRenameFound(
+            final ManagementContextInternal managementContext,
+            final BasicBrooklynTypeRegistry typeRegistry,
+            final CatalogUpgrades.Builder catalogUpgradesBuilder
+    ) {
+        givenCatalogUpgrades(managementContext, typeRegistry, catalogUpgradesBuilder);
+    }
+
+    private static void givenRenameIsFound(
+            final ManagementContextInternal managementContext,
+            final BasicBrooklynTypeRegistry typeRegistry,
+            final CatalogUpgrades.Builder catalogUpgradesBuilder,
+            final VersionedName updatedVersionedName,
+            final VersionRangedName originalVersionRangedName
+    ) {
+        catalogUpgradesBuilder.upgradeBundles(
+                ImmutableListMultimap.of(updatedVersionedName, originalVersionRangedName));
+        givenCatalogUpgrades(managementContext, typeRegistry, catalogUpgradesBuilder);
+    }
+
+    private static void givenNoCatalogUpgrades(
+            final ManagementContextInternal managementContext,
+            final BasicBrooklynTypeRegistry typeRegistry
+    ) {
+        givenManagementContextHasTypeRegistry(managementContext, typeRegistry);
+        given(typeRegistry.getCatalogUpgradesInstructions()).willReturn(null);
+    }
+
+    private static void givenCatalogUpgrades(
+            final ManagementContextInternal managementContext,
+            final BasicBrooklynTypeRegistry typeRegistry,
+            final CatalogUpgrades.Builder catalogUpgradesBuilder
+    ) {
+        givenManagementContextHasTypeRegistry(managementContext, typeRegistry);
+        given(typeRegistry.getCatalogUpgradesInstructions()).willReturn(catalogUpgradesBuilder.build());
+    }
+
+    private static void givenManagementContextHasTypeRegistry(
+            final ManagementContextInternal managementContext,
+            final BrooklynTypeRegistry typeRegistry
+    ) {
+        given(managementContext.getTypeRegistry()).willReturn(typeRegistry);
+    }
+
+    private static void givenBundleIsAlreadyInstalled(
+            final OsgiManager osgiManager,
+            final VersionedName originalVersionedName,
+            final ManagedBundle managedBundle
+    ) {
+        given(osgiManager.getManagedBundle(originalVersionedName)).willReturn(managedBundle);
+    }
+
+    private static void givenBundleIsNotAlreadyInstalled(
+            final OsgiManager osgiManager,
+            final VersionedName originalVersionedName
+    ) {
+        given(osgiManager.getManagedBundle(originalVersionedName)).willReturn(null);
+    }
+
+    private static void givenAnOsgiEnvironment(
+            final ManagementContextInternal managementContext,
+            final OsgiManager osgiManager
+    ) {
+        given(managementContext.getOsgiManager()).willReturn(Maybe.of(osgiManager));
+    }
+
+    private static String createAName(
+            final String prefix,
+            final String version
+    ) {
+        return prefix + ":" + version;
+    }
+
+}
\ No newline at end of file


[brooklyn-server] 19/31: Extract RegisteredTypesSupplier to outer class

Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 7328d9f7005be178170721d566e6073858939972
Author: Paul Campbell <pc...@kemitix.net>
AuthorDate: Wed Oct 24 10:38:03 2018 +0100

    Extract RegisteredTypesSupplier to outer class
    
    Will be required in the CatalogUpgradeScanner that is about to be extracted.
---
 .../catalog/internal/CatalogInitialization.java    | 16 ---------
 .../catalog/internal/RegisteredTypesSupplier.java  | 38 ++++++++++++++++++++++
 2 files changed, 38 insertions(+), 16 deletions(-)

diff --git a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogInitialization.java b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogInitialization.java
index da7f1f6..4588119 100644
--- a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogInitialization.java
+++ b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogInitialization.java
@@ -75,9 +75,7 @@ import org.slf4j.LoggerFactory;
 
 import com.google.common.annotations.Beta;
 import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Predicate;
 import com.google.common.base.Stopwatch;
-import com.google.common.base.Supplier;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Iterables;
 
@@ -647,20 +645,6 @@ public class CatalogInitialization implements ManagementContextInjectable {
         }
     }
 
-    private static class RegisteredTypesSupplier implements Supplier<Iterable<RegisteredType>> {
-        private final ManagementContext mgmt;
-        private final Predicate<? super RegisteredType> filter;
-        
-        RegisteredTypesSupplier(ManagementContext mgmt, Predicate<? super RegisteredType> predicate) {
-            this.mgmt = mgmt;
-            this.filter = predicate;
-        }
-        @Override
-        public Iterable<RegisteredType> get() {
-            return mgmt.getTypeRegistry().getMatching(filter);
-        }
-    }
-
     public interface RebindLogger {
         void debug(String message, Object... args);
         void info(String message, Object... args);
diff --git a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/RegisteredTypesSupplier.java b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/RegisteredTypesSupplier.java
new file mode 100644
index 0000000..5c32164
--- /dev/null
+++ b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/RegisteredTypesSupplier.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.brooklyn.core.catalog.internal;
+
+import com.google.common.base.Predicate;
+import com.google.common.base.Supplier;
+import org.apache.brooklyn.api.mgmt.ManagementContext;
+import org.apache.brooklyn.api.typereg.RegisteredType;
+
+class RegisteredTypesSupplier implements Supplier<Iterable<RegisteredType>> {
+    private final ManagementContext mgmt;
+    private final Predicate<? super RegisteredType> filter;
+
+    RegisteredTypesSupplier(ManagementContext mgmt, Predicate<? super RegisteredType> predicate) {
+        this.mgmt = mgmt;
+        this.filter = predicate;
+    }
+    @Override
+    public Iterable<RegisteredType> get() {
+        return mgmt.getTypeRegistry().getMatching(filter);
+    }
+}


[brooklyn-server] 16/31: Load all jars to find upgrades for wrapped bundles

Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 748bfa0d8a22895749f8c7cfe3203f43a8dc7abe
Author: Paul Campbell <pc...@kemitix.net>
AuthorDate: Tue Oct 23 16:34:03 2018 +0100

    Load all jars to find upgrades for wrapped bundles
---
 .../core/catalog/internal/CatalogInitialization.java    | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogInitialization.java b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogInitialization.java
index f35e8a9..18e1f27 100644
--- a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogInitialization.java
+++ b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogInitialization.java
@@ -29,6 +29,7 @@ import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.brooklyn.api.catalog.BrooklynCatalog;
 import org.apache.brooklyn.api.catalog.CatalogItem;
@@ -617,6 +618,7 @@ public class CatalogInitialization implements ManagementContextInjectable {
         
         CatalogUpgrades.Builder catalogUpgradesBuilder = CatalogUpgrades.builder();
         Collection<ManagedBundle> managedBundles = osgiManager.get().getManagedBundles().values();
+        final Stopwatch started = Stopwatch.createStarted();
         for (ManagedBundle managedBundle : managedBundles) {
             Maybe<Bundle> bundle = osgiManager.get().findBundle(managedBundle);
             if (bundle.isPresent()) {
@@ -629,6 +631,21 @@ public class CatalogInitialization implements ManagementContextInjectable {
                         + "ignoring when calculating persisted state catalog upgrades");
             }
         }
+        started.stop();
+        log.info("Loaded managed bundles in " + started.elapsed(TimeUnit.MILLISECONDS) + "ms");
+
+        final Stopwatch allbundleStopWatch = Stopwatch.createStarted();
+        for (Bundle bundle : osgiManager.get().getFramework().getBundleContext().getBundles()) {
+            final RegisteredTypesSupplier typeSupplier =
+                    new RegisteredTypesSupplier(managementContext,
+                            RegisteredTypePredicates.containingBundle(bundle.getSymbolicName()));
+            final CatalogUpgrades catalogUpgrades =
+                    BundleUpgradeParser.parseBundleManifestForCatalogUpgrades(bundle, typeSupplier);
+            catalogUpgradesBuilder.addAll(catalogUpgrades);
+        }
+        allbundleStopWatch.stop();
+        log.info("Loaded all bundles in " + allbundleStopWatch.elapsed(TimeUnit.MILLISECONDS) + "ms");
+
         return catalogUpgradesBuilder.build();
     }
 


[brooklyn-server] 11/31: Add assertj as test dependency

Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit a0d2d8451b7d92fbdf77d7e27a2a254d20a18f4b
Author: Paul Campbell <pc...@kemitix.net>
AuthorDate: Wed Oct 17 17:20:45 2018 +0100

    Add assertj as test dependency
---
 pom.xml | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/pom.xml b/pom.xml
index 8b5f56b..4016730 100644
--- a/pom.xml
+++ b/pom.xml
@@ -183,6 +183,9 @@
         <plantuml.version>6121</plantuml.version>
 
         <!-- Test dependencies -->
+        <testng.version>6.10</testng.version>
+        <mockito.version>2.7.12</mockito.version>
+        <assertj.version>3.11.1</assertj.version>
         <cobertura.plugin.version>2.7</cobertura.plugin.version>
         <surefire.version>2.19.1</surefire.version>
         <testng.version>6.10</testng.version>


[brooklyn-server] 15/31: Add missing apache license headers

Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 84193370c09f201186d6bfca19738382dbf565c9
Author: Paul Campbell <pc...@kemitix.net>
AuthorDate: Tue Oct 23 16:19:36 2018 +0100

    Add missing apache license headers
---
 .../apache/brooklyn/core/typereg/BundleTestUtil.java   | 18 ++++++++++++++++++
 .../util/javalang/ReflectionsFindMappedNameTest.java   | 18 ++++++++++++++++++
 2 files changed, 36 insertions(+)

diff --git a/core/src/test/java/org/apache/brooklyn/core/typereg/BundleTestUtil.java b/core/src/test/java/org/apache/brooklyn/core/typereg/BundleTestUtil.java
index 2a5c3d7..a869514 100644
--- a/core/src/test/java/org/apache/brooklyn/core/typereg/BundleTestUtil.java
+++ b/core/src/test/java/org/apache/brooklyn/core/typereg/BundleTestUtil.java
@@ -1,3 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
 package org.apache.brooklyn.core.typereg;
 
 import com.google.common.collect.ImmutableMap;
diff --git a/utils/common/src/test/java/org/apache/brooklyn/util/javalang/ReflectionsFindMappedNameTest.java b/utils/common/src/test/java/org/apache/brooklyn/util/javalang/ReflectionsFindMappedNameTest.java
index d4bb0f6..173d0a9 100644
--- a/utils/common/src/test/java/org/apache/brooklyn/util/javalang/ReflectionsFindMappedNameTest.java
+++ b/utils/common/src/test/java/org/apache/brooklyn/util/javalang/ReflectionsFindMappedNameTest.java
@@ -1,3 +1,21 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
 package org.apache.brooklyn.util.javalang;
 
 import org.assertj.core.api.WithAssertions;


[brooklyn-server] 18/31: Extract scanManagedBundles() and scanAllBundles()

Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit ef42313efc3b4d88beb540bacef82f9f7e3fc71e
Author: Paul Campbell <pc...@kemitix.net>
AuthorDate: Tue Oct 23 17:16:39 2018 +0100

    Extract scanManagedBundles() and scanAllBundles()
---
 .../core/catalog/internal/CatalogInitialization.java  | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogInitialization.java b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogInitialization.java
index b355b97..da7f1f6 100644
--- a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogInitialization.java
+++ b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogInitialization.java
@@ -614,11 +614,16 @@ public class CatalogInitialization implements ManagementContextInjectable {
             // Can't find any bundles to tell if there are upgrades. Could be running tests; do no filtering.
             return CatalogUpgrades.EMPTY;
         }
-        
-        CatalogUpgrades.Builder catalogUpgradesBuilder = CatalogUpgrades.builder();
-        Collection<ManagedBundle> managedBundles = osgiManager.get().getManagedBundles().values();
+        final CatalogUpgrades.Builder catalogUpgradesBuilder = CatalogUpgrades.builder();
+        scanManagedBundles(osgiManager.get(), catalogUpgradesBuilder, rebindLogger);
+        scanAllBundles(osgiManager.get(), catalogUpgradesBuilder);
+        return catalogUpgradesBuilder.build();
+    }
+
+    private void scanManagedBundles(OsgiManager osgiManager, CatalogUpgrades.Builder catalogUpgradesBuilder, RebindLogger rebindLogger) {
+        Collection<ManagedBundle> managedBundles = osgiManager.getManagedBundles().values();
         for (ManagedBundle managedBundle : managedBundles) {
-            Maybe<Bundle> bundle = osgiManager.get().findBundle(managedBundle);
+            Maybe<Bundle> bundle = osgiManager.findBundle(managedBundle);
             if (bundle.isPresent()) {
                 CatalogUpgrades catalogUpgrades = BundleUpgradeParser.parseBundleManifestForCatalogUpgrades(
                         bundle.get(),
@@ -629,8 +634,10 @@ public class CatalogInitialization implements ManagementContextInjectable {
                         + "ignoring when calculating persisted state catalog upgrades");
             }
         }
+    }
 
-        for (Bundle bundle : osgiManager.get().getFramework().getBundleContext().getBundles()) {
+    private void scanAllBundles(OsgiManager osgiManager, CatalogUpgrades.Builder catalogUpgradesBuilder) {
+        for (Bundle bundle : osgiManager.getFramework().getBundleContext().getBundles()) {
             final RegisteredTypesSupplier typeSupplier =
                     new RegisteredTypesSupplier(managementContext,
                             RegisteredTypePredicates.containingBundle(bundle.getSymbolicName()));
@@ -638,8 +645,6 @@ public class CatalogInitialization implements ManagementContextInjectable {
                     BundleUpgradeParser.parseBundleManifestForCatalogUpgrades(bundle, typeSupplier);
             catalogUpgradesBuilder.addAll(catalogUpgrades);
         }
-
-        return catalogUpgradesBuilder.build();
     }
 
     private static class RegisteredTypesSupplier implements Supplier<Iterable<RegisteredType>> {


[brooklyn-server] 03/31: [core] Refactor rebind test for clarity

Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 2c0f0c25fcbdc52272fb25e6c0e689bbfec91a6f
Author: Paul Campbell <pa...@cloudsoft.io>
AuthorDate: Tue Oct 9 13:04:16 2018 +0100

    [core] Refactor rebind test for clarity
    
    * Uses assertj for better error messages and soft assertions (lists all
      failures, not just the first found)
    * Replace use of com.google.common with pure JDK
---
 .../RebindWithDeserializingClassRenamesTest.java   | 152 ++++++++++++++-------
 1 file changed, 105 insertions(+), 47 deletions(-)

diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindWithDeserializingClassRenamesTest.java b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindWithDeserializingClassRenamesTest.java
index a66c7d9..40b4a3f 100644
--- a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindWithDeserializingClassRenamesTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindWithDeserializingClassRenamesTest.java
@@ -18,10 +18,14 @@
  */
 package org.apache.brooklyn.core.mgmt.rebind;
 
-import static org.testng.Assert.assertEquals;
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.assertj.core.api.SoftAssertions.assertSoftly;
 
 import java.io.File;
-import java.util.Map;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.util.*;
+import java.util.stream.Collectors;
 
 import org.apache.brooklyn.config.ConfigInheritance;
 import org.apache.brooklyn.config.ConfigKey;
@@ -29,65 +33,119 @@ import org.apache.brooklyn.core.config.BasicConfigInheritance;
 import org.apache.brooklyn.core.config.ConfigKeys.InheritanceContext;
 import org.apache.brooklyn.core.config.ConfigPredicates;
 import org.apache.brooklyn.core.entity.EntityInternal;
-import org.apache.brooklyn.test.Asserts;
 import org.apache.brooklyn.util.core.ResourceUtils;
 import org.apache.brooklyn.util.os.Os;
+import org.assertj.core.api.WithAssertions;
 import org.testng.annotations.Test;
 
-import com.google.common.base.Charsets;
-import com.google.common.base.Joiner;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Iterables;
-import com.google.common.io.Files;
+public class RebindWithDeserializingClassRenamesTest extends RebindTestFixtureWithApp implements WithAssertions {
 
-public class RebindWithDeserializingClassRenamesTest extends RebindTestFixtureWithApp {
+    private static final String LEGACY_INHERITANCE_NONE = "org.apache.brooklyn.config.ConfigInheritance$None";
+    private static final String LEGACY_INHERITANCE_ALWAYS = "org.apache.brooklyn.config.ConfigInheritance$Always";
+    private static final String LEGACY_INHERITANCE_MERGED = "org.apache.brooklyn.config.ConfigInheritance$Merged";
+    private static final String RESOURCE_PATH = "org/apache/brooklyn/core/test/rebind/deserializing-class-names/";
+    private static final String ENTITY_ID = "toruf2wxg4";
 
     /** also see {@link RebindConfigInheritanceTest} */
     @Test
     public void testRebindWillRenameLegacyConfigInheritance() throws Exception {
-        Map<String, String> expectedTransforms = ImmutableMap.<String, String>builder()
-                .put("org.apache.brooklyn.config.ConfigInheritance$None", BasicConfigInheritance.NOT_REINHERITED.getClass().getName())
-                .put("org.apache.brooklyn.config.ConfigInheritance$Always", BasicConfigInheritance.OVERWRITE.getClass().getName())
-                .put("org.apache.brooklyn.config.ConfigInheritance$Merged", BasicConfigInheritance.DEEP_MERGE.getClass().getName())
-                .build();
-        
-        String entityId = "toruf2wxg4";
-        String entityResource = "org/apache/brooklyn/core/test/rebind/deserializing-class-names/"+entityId;
-        String persistedEntity = ResourceUtils.create(RebindWithDeserializingClassRenamesTest.class).getResourceAsString(entityResource);
-
-        // Orig state contains the old names (and not the new names)
-        for (Map.Entry<String, String> entry : expectedTransforms.entrySet()) {
-            Asserts.assertStringContains(persistedEntity, entry.getKey());
-            Asserts.assertStringDoesNotContain(persistedEntity, entry.getValue());
-        }
-        
-        File persistedEntityFile = new File(mementoDir, Os.mergePaths("entities", entityId));
-        Files.write(persistedEntity.getBytes(), persistedEntityFile);
-        
+        //given
+        final List<Transform> expectedTransforms = Collections.unmodifiableList(Arrays.asList(
+                Transform.of(LEGACY_INHERITANCE_NONE, BasicConfigInheritance.NOT_REINHERITED, "my.config.inheritanceNone"),
+                Transform.of(LEGACY_INHERITANCE_ALWAYS, BasicConfigInheritance.OVERWRITE, "my.config.inheritanceAlways"),
+                Transform.of(LEGACY_INHERITANCE_MERGED, BasicConfigInheritance.DEEP_MERGE, "my.config.inheritanceMerged")
+        ));
+        // a legacy brooklyn 0.10.0 entity
+        final File persistedEntityFile = givenLegacyEntityFile(ENTITY_ID);
+        // verify that the entity has not been updated and is still using the old names
+        final String persistedEntity = readFile(persistedEntityFile);
+        assertSoftly(s -> expectedTransforms
+                .forEach(transform -> {
+                    s.assertThat(persistedEntity)
+                            .as("existing persisted entity uses legacy classnames")
+                            .contains(transform.legacyClassName);
+                    s.assertThat(persistedEntity)
+                            .as("existing persisted entity does not use current classnames")
+                            .doesNotContain(transform.currentClassName);
+                }));
+        //when
+        // reload and rewrite the configuration
         rebind();
-        
+        //then
         // After rebind, we've re-written the persisted state so it contains the new names (and not old names)
         RebindTestUtils.waitForPersisted(mgmt());
-        String newPersistedEntity = Joiner.on("\n").join(Files.readLines(persistedEntityFile, Charsets.UTF_8));
-        for (Map.Entry<String, String> entry : expectedTransforms.entrySet()) {
-            Asserts.assertStringDoesNotContain(newPersistedEntity, entry.getKey());
-            Asserts.assertStringContains(newPersistedEntity, entry.getValue());
-        }
+        final String reboundPersistedEntity = readFile(persistedEntityFile);
+        final Map<ConfigKey<?>, Object> config = getEntityConfig(ENTITY_ID);
+        // verify that the new config file has been updated and is using the new classnames
+        assertSoftly(s -> expectedTransforms
+                .forEach(transform -> {
+                    s.assertThat(reboundPersistedEntity)
+                            .as("rebound persisted entity does not use legacy classnames")
+                            .doesNotContain(transform.legacyClassName);
+                    s.assertThat(reboundPersistedEntity)
+                            .as("rebound persisted entity uses current classnames")
+                            .contains(transform.currentClassName);
+                    s.assertThat(inheritanceModeByKeyName(config, transform.configKeyName))
+                            .as("config keys are as expected")
+                            .isEqualTo(transform.inheritanceMode);
+                }));
+    }
+
+    private File givenLegacyEntityFile(final String entityId) throws IOException {
+        // load template entity config file
+        final String persistedEntity = ResourceUtils.create(RebindWithDeserializingClassRenamesTest.class)
+                .getResourceAsString(RESOURCE_PATH + entityId);
+        // create a private/writable copy of the legacy config file
+        final File persistedEntityFile = new File(mementoDir, Os.mergePaths("entities", entityId));
+        Files.write(persistedEntityFile.toPath(), persistedEntity.getBytes());
+        return persistedEntityFile;
+    }
+
+    private String readFile(final File legacyEntityFile) throws IOException {
+        return Files.readAllLines(legacyEntityFile.toPath(), UTF_8)
+                .stream().collect(Collectors.joining(System.lineSeparator()));
+    }
+
+    private Map<ConfigKey<?>, Object> getEntityConfig(final String entityId) {
+        final EntityInternal entity = (EntityInternal) mgmt().getEntityManager().getEntity(entityId);
+        assertThat(entity).isNotNull();
+        return entity.config().getAllLocalRaw();
+    }
 
-        // Check the config keys are as expected 
-        EntityInternal entity = (EntityInternal) mgmt().getEntityManager().getEntity(entityId);
-        Map<ConfigKey<?>, Object> config = entity.config().getAllLocalRaw();
-        ConfigKey<?> keyWithInheritanceNone = Iterables.find(config.keySet(), ConfigPredicates.nameEqualTo("my.config.inheritanceNone"));
-        ConfigKey<?> keyWithInheritanceAlways = Iterables.find(config.keySet(), ConfigPredicates.nameEqualTo("my.config.inheritanceAlways"));
-        ConfigKey<?> keyWithInheritanceMerged = Iterables.find(config.keySet(), ConfigPredicates.nameEqualTo("my.config.inheritanceMerged"));
-        
-        assertConfigRuntimeInheritanceMode(keyWithInheritanceNone, BasicConfigInheritance.NOT_REINHERITED);
-        assertConfigRuntimeInheritanceMode(keyWithInheritanceAlways, BasicConfigInheritance.OVERWRITE);
-        assertConfigRuntimeInheritanceMode(keyWithInheritanceMerged, BasicConfigInheritance.DEEP_MERGE);
+    private ConfigInheritance inheritanceModeByKeyName(final Map<ConfigKey<?>, Object> config, final String keyName) {
+        return inheritanceMode(configKeyByName(config, keyName));
     }
 
-    private void assertConfigRuntimeInheritanceMode(ConfigKey<?> key, ConfigInheritance expected) throws Exception {
-        ConfigInheritance val = key.getInheritanceByContext().get(InheritanceContext.RUNTIME_MANAGEMENT);
-        assertEquals(val, expected);
+    private ConfigInheritance inheritanceMode(ConfigKey<?> key) {
+        return key.getInheritanceByContext().get(InheritanceContext.RUNTIME_MANAGEMENT);
+    }
+
+    private ConfigKey<?> configKeyByName(final Map<ConfigKey<?>, Object> config, final String keyName) {
+        return config.keySet().stream().filter(ConfigPredicates.nameEqualTo(keyName)::apply).findFirst().get();
+    }
+
+    private static class Transform {
+
+        private String legacyClassName;
+        private String currentClassName;
+        private ConfigInheritance inheritanceMode;
+        private String configKeyName;
+
+        private Transform(final String legacyClassName,
+                          final String currentClassName,
+                          final ConfigInheritance inheritanceMode,
+                          final String configKeyName) {
+            this.legacyClassName = legacyClassName;
+            this.currentClassName = currentClassName;
+            this.inheritanceMode = inheritanceMode;
+            this.configKeyName = configKeyName;
+        }
+
+        static Transform of(final String legacyClassName,
+                            final ConfigInheritance configInheritance,
+                            final String configKey) {
+            final Class<? extends ConfigInheritance> configInheritanceClass = configInheritance.getClass();
+            return new Transform(legacyClassName, configInheritanceClass.getName(), configInheritance, configKey);
+        }
     }
 }


[brooklyn-server] 20/31: Extract CatalogUpgradeScanner

Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 64c869c8ee7f5a25f4f0b7cd02f9a2c1e53db5bb
Author: Paul Campbell <pc...@kemitix.net>
AuthorDate: Wed Oct 24 10:41:39 2018 +0100

    Extract CatalogUpgradeScanner
---
 .../catalog/internal/CatalogInitialization.java    | 45 +----------
 .../catalog/internal/CatalogUpgradeScanner.java    | 91 ++++++++++++++++++++++
 2 files changed, 95 insertions(+), 41 deletions(-)

diff --git a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogInitialization.java b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogInitialization.java
index 4588119..9dcaa4b 100644
--- a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogInitialization.java
+++ b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogInitialization.java
@@ -112,6 +112,7 @@ public class CatalogInitialization implements ManagementContextInjectable {
     private boolean hasRunFinalInitialization = false;
 
     private ManagementContextInternal managementContext;
+    private CatalogUpgradeScanner catalogUpgradeScanner;
     private boolean isStartingUp = false;
     private boolean failOnStartupErrors = false;
     
@@ -134,6 +135,7 @@ public class CatalogInitialization implements ManagementContextInjectable {
         if (this.managementContext!=null && managementContext!=this.managementContext)
             throw new IllegalStateException("Cannot switch management context, from "+this.managementContext+" to "+managementContext);
         this.managementContext = (ManagementContextInternal) managementContext;
+        catalogUpgradeScanner = new CatalogUpgradeScanner(this.managementContext);
     }
     
     /** Called by the framework to set true while starting up, and false afterwards,
@@ -251,8 +253,8 @@ public class CatalogInitialization implements ManagementContextInjectable {
             }
             
             populateInitialCatalogImpl(true);
-            
-            CatalogUpgrades catalogUpgrades = gatherCatalogUpgradesInstructions(rebindLogger);
+
+            final CatalogUpgrades catalogUpgrades = catalogUpgradeScanner.scan(rebindLogger);
             CatalogUpgrades.storeInManagementContext(catalogUpgrades, managementContext);
             PersistedCatalogState filteredPersistedState = filterBundlesAndCatalogInPersistedState(persistedState, rebindLogger);
             addPersistedCatalogImpl(filteredPersistedState, exceptionHandler, rebindLogger);
@@ -606,45 +608,6 @@ public class CatalogInitialization implements ManagementContextInjectable {
         return new PersistedCatalogState(bundles, legacyCatalogItems);
     }
 
-    private CatalogUpgrades gatherCatalogUpgradesInstructions(RebindLogger rebindLogger) {
-        Maybe<OsgiManager> osgiManager = ((ManagementContextInternal)managementContext).getOsgiManager();
-        if (osgiManager.isAbsent()) {
-            // Can't find any bundles to tell if there are upgrades. Could be running tests; do no filtering.
-            return CatalogUpgrades.EMPTY;
-        }
-        final CatalogUpgrades.Builder catalogUpgradesBuilder = CatalogUpgrades.builder();
-        scanManagedBundles(osgiManager.get(), catalogUpgradesBuilder, rebindLogger);
-        scanAllBundles(osgiManager.get(), catalogUpgradesBuilder);
-        return catalogUpgradesBuilder.build();
-    }
-
-    private void scanManagedBundles(OsgiManager osgiManager, CatalogUpgrades.Builder catalogUpgradesBuilder, RebindLogger rebindLogger) {
-        Collection<ManagedBundle> managedBundles = osgiManager.getManagedBundles().values();
-        for (ManagedBundle managedBundle : managedBundles) {
-            Maybe<Bundle> bundle = osgiManager.findBundle(managedBundle);
-            if (bundle.isPresent()) {
-                CatalogUpgrades catalogUpgrades = BundleUpgradeParser.parseBundleManifestForCatalogUpgrades(
-                        bundle.get(),
-                        new RegisteredTypesSupplier(managementContext, RegisteredTypePredicates.containingBundle(managedBundle)));
-                catalogUpgradesBuilder.addAll(catalogUpgrades);
-            } else {
-                rebindLogger.info("Managed bundle "+managedBundle.getId()+" not found by OSGi Manager; "
-                        + "ignoring when calculating persisted state catalog upgrades");
-            }
-        }
-    }
-
-    private void scanAllBundles(OsgiManager osgiManager, CatalogUpgrades.Builder catalogUpgradesBuilder) {
-        for (Bundle bundle : osgiManager.getFramework().getBundleContext().getBundles()) {
-            final RegisteredTypesSupplier typeSupplier =
-                    new RegisteredTypesSupplier(managementContext,
-                            RegisteredTypePredicates.containingBundle(bundle.getSymbolicName()));
-            final CatalogUpgrades catalogUpgrades =
-                    BundleUpgradeParser.parseBundleManifestForCatalogUpgrades(bundle, typeSupplier);
-            catalogUpgradesBuilder.addAll(catalogUpgrades);
-        }
-    }
-
     public interface RebindLogger {
         void debug(String message, Object... args);
         void info(String message, Object... args);
diff --git a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogUpgradeScanner.java b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogUpgradeScanner.java
new file mode 100644
index 0000000..afb181f
--- /dev/null
+++ b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogUpgradeScanner.java
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.brooklyn.core.catalog.internal;
+
+import org.apache.brooklyn.api.typereg.ManagedBundle;
+import org.apache.brooklyn.core.mgmt.ha.OsgiManager;
+import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
+import org.apache.brooklyn.core.typereg.BundleUpgradeParser;
+import org.apache.brooklyn.core.typereg.BundleUpgradeParser.CatalogUpgrades;
+import org.apache.brooklyn.core.typereg.RegisteredTypePredicates;
+import org.apache.brooklyn.util.guava.Maybe;
+import org.osgi.framework.Bundle;
+
+import java.util.Collection;
+
+/**
+ * Scans managed bundles and other jar bundles to find upgrades for installed bundles.
+ */
+class CatalogUpgradeScanner {
+
+    private final ManagementContextInternal managementContext;
+
+    CatalogUpgradeScanner(
+            final ManagementContextInternal managementContext
+    ) {
+        this.managementContext = managementContext;
+    }
+
+    public CatalogUpgrades scan(final CatalogInitialization.RebindLogger rebindLogger) {
+        Maybe<OsgiManager> osgiManager = managementContext.getOsgiManager();
+        if (osgiManager.isAbsent()) {
+            // Can't find any bundles to tell if there are upgrades. Could be running tests; do no filtering.
+            return CatalogUpgrades.EMPTY;
+        }
+        final CatalogUpgrades.Builder catalogUpgradesBuilder = CatalogUpgrades.builder();
+        scanManagedBundles(osgiManager.get(), catalogUpgradesBuilder, rebindLogger);
+        scanAllBundles(osgiManager.get(), catalogUpgradesBuilder);
+        return catalogUpgradesBuilder.build();
+    }
+
+    private void scanManagedBundles(
+            final OsgiManager osgiManager,
+            final CatalogUpgrades.Builder catalogUpgradesBuilder,
+            final CatalogInitialization.RebindLogger rebindLogger
+    ) {
+        Collection<ManagedBundle> managedBundles = osgiManager.getManagedBundles().values();
+        for (ManagedBundle managedBundle : managedBundles) {
+            Maybe<Bundle> bundle = osgiManager.findBundle(managedBundle);
+            if (bundle.isPresent()) {
+                CatalogUpgrades catalogUpgrades = BundleUpgradeParser.parseBundleManifestForCatalogUpgrades(
+                        bundle.get(),
+                        new RegisteredTypesSupplier(managementContext, RegisteredTypePredicates.containingBundle(managedBundle)));
+                catalogUpgradesBuilder.addAll(catalogUpgrades);
+            } else {
+                rebindLogger.info("Managed bundle "+managedBundle.getId()+" not found by OSGi Manager; "
+                        + "ignoring when calculating persisted state catalog upgrades");
+            }
+        }
+    }
+
+    private void scanAllBundles(
+            final OsgiManager osgiManager,
+            final CatalogUpgrades.Builder catalogUpgradesBuilder
+    ) {
+        for (Bundle bundle : osgiManager.getFramework().getBundleContext().getBundles()) {
+            final RegisteredTypesSupplier typeSupplier =
+                    new RegisteredTypesSupplier(managementContext,
+                            RegisteredTypePredicates.containingBundle(bundle.getSymbolicName()));
+            final CatalogUpgrades catalogUpgrades =
+                    BundleUpgradeParser.parseBundleManifestForCatalogUpgrades(bundle, typeSupplier);
+            catalogUpgradesBuilder.addAll(catalogUpgrades);
+        }
+    }
+
+}


[brooklyn-server] 07/31: [common] Add test for mapping classes from one bundle to another

Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 75f41da62d737ea6ca0b315efece9fbe2d8e59c7
Author: Paul Campbell <pa...@cloudsoft.io>
AuthorDate: Tue Oct 9 17:07:58 2018 +0100

    [common] Add test for mapping classes from one bundle to another
---
 .../apache/brooklyn/util/javalang/ReflectionsTest.java | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/utils/common/src/test/java/org/apache/brooklyn/util/javalang/ReflectionsTest.java b/utils/common/src/test/java/org/apache/brooklyn/util/javalang/ReflectionsTest.java
index 554ad96..c95d439 100644
--- a/utils/common/src/test/java/org/apache/brooklyn/util/javalang/ReflectionsTest.java
+++ b/utils/common/src/test/java/org/apache/brooklyn/util/javalang/ReflectionsTest.java
@@ -342,6 +342,24 @@ public class ReflectionsTest implements WithAssertions {
             assertThat(result).isEqualTo(updatedName);
         }
 
+        //wrap_blah_aws-java-sdk-bundle-1.11.245.jar\:*  : wrap_blah_aws-java-sdk-bundle-1.11.411.jar\:*
+        @Test
+        public void allClassesInOneBundleAreNowInOtherBundle() {
+            //given
+            final Map<String, String> rename = new HashMap<>();
+            final String wildcard = "*";
+            final String originalBundle = "wrap_blah_aws-java-sdk-bundle-1.11.245.jar:";
+            final String updatedBundle = "wrap_blah_aws-java-sdk-bundle-1.11.411.jar:";
+            rename.put(originalBundle + wildcard, updatedBundle + wildcard);
+            final String className = createAName();
+            final String originalName = originalBundle + className;
+            final String updatedName = updatedBundle + className;
+            //when
+            final String result = Reflections.findMappedNameAndLog(rename, originalName);
+            //then
+            assertThat(result).isSameAs(updatedName);
+        }
+
         private String createAName() {
             return UUID.randomUUID().toString();
         }


[brooklyn-server] 31/31: This closes #1010

Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit da8bf93b73f4f5bf91197d5b5290d9abe763419f
Merge: 061057c 5c22839
Author: Aled Sage <al...@gmail.com>
AuthorDate: Wed Jan 16 16:38:57 2019 +0000

    This closes #1010

 core/pom.xml                                       |   5 +
 .../catalog/internal/CatalogInitialization.java    |  62 ++--
 .../catalog/internal/CatalogUpgradeScanner.java    | 110 +++++++
 .../catalog/internal/RegisteredTypesSupplier.java  |  38 +++
 .../persist/DeserializingClassRenamesProvider.java |   5 +-
 .../brooklyn/core/typereg/BundleUpgradeParser.java |   2 +-
 .../internal/CatalogUpgradeScannerTest.java        | 322 +++++++++++++++++++++
 .../RebindWithDeserializingClassRenamesTest.java   | 152 +++++++---
 .../brooklyn/core/typereg/BundleTestUtil.java      |  57 ++++
 .../core/typereg/BundleUpgradeParserTest.java      |  27 +-
 ...ogUpgradesGetBundleUpgradedIfNecessaryTest.java | 246 ++++++++++++++++
 parent/pom.xml                                     |  41 +--
 pom.xml                                            |   6 +-
 utils/common/pom.xml                               |   6 +
 .../javalang/ReflectionsFindMappedNameTest.java    | 141 +++++++++
 15 files changed, 1079 insertions(+), 141 deletions(-)


[brooklyn-server] 05/31: [common] add assertj as test dependency

Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 442a1944ee752944e42916fb3d22ef2a1628b861
Author: Paul Campbell <pa...@cloudsoft.io>
AuthorDate: Tue Oct 9 16:38:27 2018 +0100

    [common] add assertj as test dependency
---
 utils/common/pom.xml | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/utils/common/pom.xml b/utils/common/pom.xml
index e547842..d2a3b3a 100644
--- a/utils/common/pom.xml
+++ b/utils/common/pom.xml
@@ -117,6 +117,12 @@
             <version>${org.osgi.core.version}</version>
             <type>jar</type>
         </dependency>
+        <dependency>
+            <groupId>org.assertj</groupId>
+            <artifactId>assertj-core</artifactId>
+            <scope>test</scope>
+        </dependency>
+
     </dependencies>
 
     <build>


[brooklyn-server] 21/31: Extract overloaded typeSupplier() helpers

Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 0fc25b22589e9af0e5f825f07fb477c7d6bd96e2
Author: Paul Campbell <pc...@kemitix.net>
AuthorDate: Wed Oct 24 10:48:39 2018 +0100

    Extract overloaded typeSupplier() helpers
---
 .../core/catalog/internal/CatalogUpgradeScanner.java   | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogUpgradeScanner.java b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogUpgradeScanner.java
index afb181f..342e3af 100644
--- a/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogUpgradeScanner.java
+++ b/core/src/main/java/org/apache/brooklyn/core/catalog/internal/CatalogUpgradeScanner.java
@@ -64,8 +64,7 @@ class CatalogUpgradeScanner {
             Maybe<Bundle> bundle = osgiManager.findBundle(managedBundle);
             if (bundle.isPresent()) {
                 CatalogUpgrades catalogUpgrades = BundleUpgradeParser.parseBundleManifestForCatalogUpgrades(
-                        bundle.get(),
-                        new RegisteredTypesSupplier(managementContext, RegisteredTypePredicates.containingBundle(managedBundle)));
+                        bundle.get(), typeSupplier(managedBundle));
                 catalogUpgradesBuilder.addAll(catalogUpgrades);
             } else {
                 rebindLogger.info("Managed bundle "+managedBundle.getId()+" not found by OSGi Manager; "
@@ -79,13 +78,20 @@ class CatalogUpgradeScanner {
             final CatalogUpgrades.Builder catalogUpgradesBuilder
     ) {
         for (Bundle bundle : osgiManager.getFramework().getBundleContext().getBundles()) {
-            final RegisteredTypesSupplier typeSupplier =
-                    new RegisteredTypesSupplier(managementContext,
-                            RegisteredTypePredicates.containingBundle(bundle.getSymbolicName()));
             final CatalogUpgrades catalogUpgrades =
-                    BundleUpgradeParser.parseBundleManifestForCatalogUpgrades(bundle, typeSupplier);
+                    BundleUpgradeParser.parseBundleManifestForCatalogUpgrades(bundle, typeSupplier(bundle));
             catalogUpgradesBuilder.addAll(catalogUpgrades);
         }
     }
 
+    private RegisteredTypesSupplier typeSupplier(final ManagedBundle managedBundle) {
+        return new RegisteredTypesSupplier(managementContext,
+                RegisteredTypePredicates.containingBundle(managedBundle));
+    }
+
+    private RegisteredTypesSupplier typeSupplier(final Bundle bundle) {
+        return new RegisteredTypesSupplier(managementContext,
+                RegisteredTypePredicates.containingBundle(bundle.getSymbolicName()));
+    }
+
 }


[brooklyn-server] 02/31: [core] add assertj as test dependency

Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit f08ed2c94908f8592cfdc20a73276706e613ae6d
Author: Paul Campbell <pa...@cloudsoft.io>
AuthorDate: Tue Oct 9 09:48:26 2018 +0100

    [core] add assertj as test dependency
---
 core/pom.xml | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/core/pom.xml b/core/pom.xml
index 28de44e..69f8772 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -237,6 +237,11 @@
             <classifier>tests</classifier>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.assertj</groupId>
+            <artifactId>assertj-core</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <build>


[brooklyn-server] 29/31: Remove duplicated version for assertj

Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 2e025d10328609148ceae766a4f7e4f6cc2c62af
Author: Paul Campbell <pc...@kemitix.net>
AuthorDate: Wed Oct 24 23:10:14 2018 +0100

    Remove duplicated version for assertj
---
 pom.xml | 1 -
 1 file changed, 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index 4016730..ed1ad6e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -190,7 +190,6 @@
         <surefire.version>2.19.1</surefire.version>
         <testng.version>6.10</testng.version>
         <mockito.version>2.7.12</mockito.version>
-        <assertj.version>3.11.1</assertj.version>
         <hamcrest.version>1.1</hamcrest.version>
         <mockwebserver.version>20121111</mockwebserver.version>
 


[brooklyn-server] 01/31: Bump assertj from 2.2.0 to 3.11.1

Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 890ef568a1a710d62f0cbd160a8d0123b4655536
Author: Paul Campbell <pa...@cloudsoft.io>
AuthorDate: Mon Oct 8 17:06:58 2018 +0100

    Bump assertj from 2.2.0 to 3.11.1
    
    As brooklyn is now built with Java 8 (brooklyn-server/pom.xml java.version =
    1.8) there is no reason not to take advantage of the improved fluent assertions
    in assertj 3.x.
---
 parent/pom.xml | 5 +++++
 pom.xml        | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/parent/pom.xml b/parent/pom.xml
index 971c76e..e0e2633 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -581,6 +581,11 @@
                 <groupId>org.ops4j.pax.web</groupId>
                 <artifactId>pax-web-spi</artifactId>
                 <version>${pax-web.version}</version>
+			</dependency>
+			<dependency>
+                <groupId>org.assertj</groupId>
+                <artifactId>assertj-core</artifactId>
+                <version>${assertj.version}</version>
             </dependency>
 		</dependencies>
 	</dependencyManagement>
diff --git a/pom.xml b/pom.xml
index 20c0bc8..8b5f56b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -187,7 +187,7 @@
         <surefire.version>2.19.1</surefire.version>
         <testng.version>6.10</testng.version>
         <mockito.version>2.7.12</mockito.version>
-        <assertj.version>2.2.0</assertj.version> <!-- v 2.2.0 is being used as v 3.20 introduces Java8 dependencies-->
+        <assertj.version>3.11.1</assertj.version>
         <hamcrest.version>1.1</hamcrest.version>
         <mockwebserver.version>20121111</mockwebserver.version>
 


[brooklyn-server] 26/31: Add unit tests for CatalogUpgradeSCanner

Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 9fe502a2d67835d60a23a0bbf5aa27f9c7a3caef
Author: Paul Campbell <pc...@kemitix.net>
AuthorDate: Wed Oct 24 17:06:24 2018 +0100

    Add unit tests for CatalogUpgradeSCanner
---
 .../internal/CatalogUpgradeScannerTest.java        | 304 +++++++++++++++++++++
 1 file changed, 304 insertions(+)

diff --git a/core/src/test/java/org/apache/brooklyn/core/catalog/internal/CatalogUpgradeScannerTest.java b/core/src/test/java/org/apache/brooklyn/core/catalog/internal/CatalogUpgradeScannerTest.java
new file mode 100644
index 0000000..a03a54e
--- /dev/null
+++ b/core/src/test/java/org/apache/brooklyn/core/catalog/internal/CatalogUpgradeScannerTest.java
@@ -0,0 +1,304 @@
+package org.apache.brooklyn.core.catalog.internal;
+
+import com.google.common.base.Predicate;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableMultimap;
+import com.google.common.collect.Multimap;
+import org.apache.brooklyn.api.typereg.ManagedBundle;
+import org.apache.brooklyn.api.typereg.OsgiBundleWithUrl;
+import org.apache.brooklyn.api.typereg.RegisteredType;
+import org.apache.brooklyn.core.mgmt.ha.OsgiManager;
+import org.apache.brooklyn.core.mgmt.internal.LocalManagementContext;
+import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
+import org.apache.brooklyn.core.typereg.BasicManagedBundle;
+import org.apache.brooklyn.core.typereg.BundleUpgradeParser.CatalogUpgrades;
+import org.apache.brooklyn.core.typereg.BundleUpgradeParser.VersionRangedName;
+import org.apache.brooklyn.util.guava.Maybe;
+import org.apache.brooklyn.util.osgi.VersionedName;
+import org.assertj.core.api.WithAssertions;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.function.BiFunction;
+import java.util.function.Function;
+
+import static org.apache.brooklyn.core.catalog.internal.CatalogUpgradeScannerTest.Givens.*;
+import static org.apache.brooklyn.core.catalog.internal.CatalogUpgradeScannerTest.Utils.*;
+import static org.apache.brooklyn.core.typereg.BundleTestUtil.newMockBundle;
+import static org.assertj.core.api.SoftAssertions.assertSoftly;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.BDDMockito.given;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+
+public class CatalogUpgradeScannerTest implements WithAssertions {
+
+    // collaborators
+    private final ManagementContextInternal managementContext = new LocalManagementContext();
+    @Mock
+    private BiFunction<Bundle, RegisteredTypesSupplier, CatalogUpgrades> bundleUpgradeParser;
+    @Mock
+    private Function<OsgiBundleWithUrl, Predicate<? super RegisteredType>> managedBundlePredicateSupplier;
+    @Mock
+    private Function<String, Predicate<? super RegisteredType>> unmanagedBundlePredicateSupplier;
+
+    // subject under test
+    private CatalogUpgradeScanner scanner;
+
+    // parameters
+    private final OsgiManager osgiManager = mock(OsgiManager.class);
+    private final CatalogInitialization.RebindLogger rebindLogger = mock(CatalogInitialization.RebindLogger.class);
+    private final BundleContext bundleContext = mock(BundleContext.class);
+
+    @BeforeClass
+    public void setUp() {
+        MockitoAnnotations.initMocks(this);
+        scanner = new CatalogUpgradeScanner(managementContext, bundleUpgradeParser, managedBundlePredicateSupplier,
+                        unmanagedBundlePredicateSupplier);
+    }
+
+    private CatalogUpgrades invoke() {
+        return scanner.scan(osgiManager, bundleContext, rebindLogger);
+    }
+
+    @Test
+    public void whenNoUnmanagedOrManagedBundlesThenNoUpgrades() {
+        //given
+        givenNoManagedBundles(osgiManager);
+        givenNoUnmanagedBundles(bundleContext);
+        //when
+        final CatalogUpgrades result = invoke();
+        //then
+        assertThatThereAreNoUpgrades(result);
+    }
+
+    @Test
+    public void whenUnmanagedAndManagedBundlesWithNoUpgradesThenNoUpgrades() {
+        //given
+        givenManagedBundlesWithNoUpgrades(osgiManager, bundleUpgradeParser);
+        givenUnmanagedBundlesWithNoUpgrades(bundleContext, bundleUpgradeParser);
+        //when
+        final CatalogUpgrades result = invoke();
+        //then
+        assertThatThereAreNoUpgrades(result);
+    }
+
+    @Test
+    public void whenOnlyManagedBundleHasUpgradesThenUpgradesForManagedBundle() {
+        //given
+        final String upgradeFrom = bundleName("managed", "1.0.0");
+        final String upgradeTo = bundleName("managed", "2.0.0");
+        final CatalogUpgrades catalogUpgrades = CatalogUpgrades.builder()
+                .upgradeBundles(upgradeMapping(upgradeFrom, upgradeTo))
+                .build();
+        givenManagedBundlesWithUpgrades(catalogUpgrades, osgiManager, bundleUpgradeParser);
+        givenUnmanagedBundlesWithNoUpgrades(bundleContext, bundleUpgradeParser);
+        //when
+        final CatalogUpgrades result = invoke();
+        //then
+        assertThatBundleHasUpgrades(result, upgradeFrom, upgradeTo);
+    }
+
+    @Test
+    public void whenOnlyManagedBundleHasUpgradesThenNoUpgradesForUnmanagedBundles() {
+        //given
+        final String upgradeFrom = bundleName("managed", "1.0.0");
+        final String upgradeTo = bundleName("managed", "2.0.0");
+        final CatalogUpgrades catalogUpgrades = CatalogUpgrades.builder()
+                .upgradeBundles(upgradeMapping(upgradeFrom, upgradeTo))
+                .build();
+        givenManagedBundlesWithUpgrades(catalogUpgrades, osgiManager, bundleUpgradeParser);
+        final String unmanagedBundle = bundleName("unmanaged", "1.1.0");
+        givenUnmanagedBundleWithNoUpgrades(unmanagedBundle, bundleContext, bundleUpgradeParser);
+        //when
+        final CatalogUpgrades result = invoke();
+        //then
+        assertThatBundleHasNoUpgrades(result, unmanagedBundle);
+    }
+
+    @Test
+    public void whenOnlyUnmanagedBundleHasUpgradesThenUpgradesForUnmanagedBundle() {
+        //given
+        final String upgradeFrom = bundleName("unmanaged", "1.0.0");
+        final String upgradeTo = bundleName("unmanaged", "2.0.0");
+        final CatalogUpgrades catalogUpgrades = CatalogUpgrades.builder()
+                .upgradeBundles(upgradeMapping(upgradeFrom, upgradeTo))
+                .build();
+        givenManagedBundlesWithNoUpgrades(osgiManager, bundleUpgradeParser);
+        givenUnmanagedBundleWithUpgrades(catalogUpgrades, bundleContext, bundleUpgradeParser);
+        //when
+        final CatalogUpgrades result = invoke();
+        //then
+        assertThatBundleHasUpgrades(result, upgradeFrom, upgradeTo);
+    }
+
+    @Test
+    public void whenOnlyUnmanagedBundleHasUpgradesThenNoUpgradesForManagedBundles() {
+        //given
+        final String upgradeFrom = bundleName("unmanaged", "1.0.0");
+        final String upgradeTo = bundleName("unmanaged", "2.0.0");
+        final CatalogUpgrades catalogUpgrades = CatalogUpgrades.builder()
+                .upgradeBundles(upgradeMapping(upgradeFrom, upgradeTo))
+                .build();
+        final String managedBundle = bundleName("managed", "1.1.0");
+        givenManagedBundleWithNoUpgrades(managedBundle, osgiManager, bundleUpgradeParser);
+        givenUnmanagedBundleWithUpgrades(catalogUpgrades, bundleContext, bundleUpgradeParser);
+        //when
+        final CatalogUpgrades result = invoke();
+        //then
+        assertThatBundleHasNoUpgrades(result, managedBundle);
+    }
+
+    static class Givens {
+
+        static void givenNoManagedBundles(final OsgiManager osgiManager) {
+            final Map<String, ManagedBundle> noBundles = Collections.emptyMap();
+            given(osgiManager.getManagedBundles()).willReturn(noBundles);
+        }
+
+        static void givenNoUnmanagedBundles(BundleContext bundleContext) {
+            final Bundle[] noBundles = new Bundle[0];
+            given(bundleContext.getBundles()).willReturn(noBundles);
+        }
+
+        static void givenManagedBundlesWithNoUpgrades(
+                final OsgiManager osgiManager,
+                final BiFunction<Bundle, RegisteredTypesSupplier, CatalogUpgrades> bundleUpgradeParser
+        ) {
+            final Map<String, ManagedBundle> managedBundlesWithNoUpgrades =
+                    ImmutableMap.of(
+                            "managed1", findableManagedBundle(osgiManager, CatalogUpgrades.EMPTY, bundleUpgradeParser),
+                            "managed2", findableManagedBundle(osgiManager, CatalogUpgrades.EMPTY, bundleUpgradeParser)
+                    );
+            doReturn(managedBundlesWithNoUpgrades).when(osgiManager).getManagedBundles();
+        }
+
+        static void givenManagedBundlesWithUpgrades(
+                final CatalogUpgrades upgrades,
+                final OsgiManager osgiManager,
+                final BiFunction<Bundle, RegisteredTypesSupplier, CatalogUpgrades> bundleUpgradeParser
+        ) {
+            final Map<String, ManagedBundle> managedBundlesWithNoUpgrades =
+                    ImmutableMap.of("managed", findableManagedBundle(osgiManager, upgrades, bundleUpgradeParser));
+            doReturn(managedBundlesWithNoUpgrades).when(osgiManager).getManagedBundles();
+        }
+
+        static void givenManagedBundleWithNoUpgrades(
+                final String bundleName,
+                final OsgiManager osgiManager,
+                final BiFunction<Bundle, RegisteredTypesSupplier, CatalogUpgrades> bundleUpgradeParser
+        ) {
+            final ManagedBundle managedBundle =
+                    findableManagedBundle(osgiManager, CatalogUpgrades.EMPTY, bundleUpgradeParser);
+            final Map<String, ManagedBundle> managedBundlesWithNoUpgrades =
+                    ImmutableMap.of(bundleName, managedBundle);
+            doReturn(managedBundlesWithNoUpgrades).when(osgiManager).getManagedBundles();
+        }
+
+        static void givenUnmanagedBundlesWithNoUpgrades(
+                final BundleContext bundleContext,
+                final BiFunction<Bundle, RegisteredTypesSupplier, CatalogUpgrades> bundleUpgradeParser
+        ) {
+            final Bundle[] unmanagedBundlesWithNoUpgrades = new Bundle[]{
+                    unmanagedBundle(bundleName("unmanaged1", "1.1.0"), CatalogUpgrades.EMPTY, bundleUpgradeParser),
+                    unmanagedBundle(bundleName("unmanaged2", "1.1.0"), CatalogUpgrades.EMPTY, bundleUpgradeParser)
+            };
+            doReturn(unmanagedBundlesWithNoUpgrades).when(bundleContext).getBundles();
+        }
+
+        static void givenUnmanagedBundleWithNoUpgrades(
+                final String bundleName,
+                final BundleContext bundleContext,
+                final BiFunction<Bundle, RegisteredTypesSupplier, CatalogUpgrades> bundleUpgradeParser
+        ) {
+            final Bundle[] unmanagedBundlesWithNoUpgrades = new Bundle[]{
+                    unmanagedBundle(bundleName, CatalogUpgrades.EMPTY, bundleUpgradeParser)
+            };
+            doReturn(unmanagedBundlesWithNoUpgrades).when(bundleContext).getBundles();
+        }
+
+        static void givenUnmanagedBundleWithUpgrades(
+                final CatalogUpgrades upgrades,
+                final BundleContext bundleContext,
+                final BiFunction<Bundle, RegisteredTypesSupplier, CatalogUpgrades> bundleUpgradeParser
+        ) {
+            final Bundle[] unmanagedBundlesWithNoUpgrades = new Bundle[]{
+                    unmanagedBundle(bundleName("unmanaged", "1.1.0"), upgrades, bundleUpgradeParser)
+            };
+            doReturn(unmanagedBundlesWithNoUpgrades).when(bundleContext).getBundles();
+        }
+
+    }
+
+    void assertThatThereAreNoUpgrades(final CatalogUpgrades result) {
+        assertSoftly(s -> {
+            s.assertThat(result.getUpgradesProvidedByBundles().size()).isZero();
+            s.assertThat(result.getUpgradesProvidedByTypes().size()).isZero();
+        });
+    }
+
+    void assertThatBundleHasUpgrades(
+            final CatalogUpgrades result,
+            final String upgradeFrom,
+            final String upgradeTo
+    ) {
+        assertThat(result.getUpgradesForBundle(VersionedName.fromString(upgradeFrom)))
+                .contains(VersionedName.fromString(upgradeTo));
+    }
+
+    void assertThatBundleHasNoUpgrades(
+            final CatalogUpgrades result,
+            final String unmanagedBundle
+    ) {
+        assertThat(result.getUpgradesForBundle(VersionedName.fromString(unmanagedBundle))).isEmpty();
+    }
+
+    static class Utils {
+
+        static Bundle unmanagedBundle(
+                String bundleName, final CatalogUpgrades catalogUpgrades,
+                final BiFunction<Bundle, RegisteredTypesSupplier, CatalogUpgrades> bundleUpgradeParser
+        ) {
+            final Bundle bundle = newMockBundle(VersionedName.fromString(bundleName), ImmutableMap.of());
+            given(bundleUpgradeParser.apply(eq(bundle), any())).willReturn(catalogUpgrades);
+            return bundle;
+        }
+
+        static ManagedBundle findableManagedBundle(
+                final OsgiManager osgiManager,
+                final CatalogUpgrades catalogUpgrades,
+                final BiFunction<Bundle, RegisteredTypesSupplier, CatalogUpgrades> bundleUpgradeParser
+        ) {
+            final ManagedBundle managedBundle = new BasicManagedBundle();
+            final Bundle bundle = mock(Bundle.class);
+            given(osgiManager.findBundle(managedBundle)).willReturn(Maybe.of(bundle));
+            given(bundleUpgradeParser.apply(eq(bundle), any())).willReturn(catalogUpgrades);
+            return managedBundle;
+        }
+
+        static String bundleName(
+                final String name,
+                final String version
+        ) {
+            return name + ":" + version;
+        }
+
+        static Multimap<VersionedName, VersionRangedName> upgradeMapping(
+                final String upgradeFrom,
+                final String upgradeTo
+        ) {
+            return ImmutableMultimap.of(
+                    VersionedName.fromString(upgradeTo),
+                    VersionRangedName.fromString(upgradeFrom, true));
+        }
+
+    }
+
+}
\ No newline at end of file


[brooklyn-server] 14/31: whenUpgradingAWrappedBundleThenUpdatedName()

Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 441213c8980ae7181760fffedb177042346cfcb1
Author: Paul Campbell <pc...@kemitix.net>
AuthorDate: Mon Oct 22 14:28:44 2018 +0100

    whenUpgradingAWrappedBundleThenUpdatedName()
---
 ...ogUpgradesGetBundleUpgradedIfNecessaryTest.java | 29 +++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)

diff --git a/core/src/test/java/org/apache/brooklyn/core/typereg/CatalogUpgradesGetBundleUpgradedIfNecessaryTest.java b/core/src/test/java/org/apache/brooklyn/core/typereg/CatalogUpgradesGetBundleUpgradedIfNecessaryTest.java
index 70cd926..126a1ef 100644
--- a/core/src/test/java/org/apache/brooklyn/core/typereg/CatalogUpgradesGetBundleUpgradedIfNecessaryTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/typereg/CatalogUpgradesGetBundleUpgradedIfNecessaryTest.java
@@ -18,21 +18,26 @@
  */
 package org.apache.brooklyn.core.typereg;
 
+import com.google.common.base.Supplier;
 import com.google.common.collect.ImmutableListMultimap;
+import com.google.common.collect.ImmutableMap;
 import org.apache.brooklyn.api.mgmt.ManagementContext;
 import org.apache.brooklyn.api.typereg.BrooklynTypeRegistry;
 import org.apache.brooklyn.api.typereg.ManagedBundle;
+import org.apache.brooklyn.api.typereg.RegisteredType;
 import org.apache.brooklyn.core.mgmt.ha.OsgiManager;
 import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
 import org.apache.brooklyn.util.guava.Maybe;
 import org.apache.brooklyn.util.osgi.VersionedName;
 import org.assertj.core.api.WithAssertions;
 import org.mockito.Mockito;
+import org.osgi.framework.Bundle;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
-import java.util.UUID;
+import java.util.*;
 
+import static org.apache.brooklyn.core.typereg.BundleTestUtil.newMockBundle;
 import static org.apache.brooklyn.core.typereg.BundleUpgradeParser.*;
 import static org.mockito.BDDMockito.given;
 import static org.mockito.Mockito.mock;
@@ -137,6 +142,28 @@ public class CatalogUpgradesGetBundleUpgradedIfNecessaryTest implements WithAsse
         assertThat(result).isEqualTo(updatedName);
     }
 
+    @Test
+    public void whenUpgradingAWrappedBundleThenUpdatedName() {
+        //given
+        givenAnOsgiEnvironment(managementContext, osgiManager);
+        givenBundleIsNotAlreadyInstalled(osgiManager, originalVersionedName);
+        givenManagementContextHasTypeRegistry(managementContext, typeRegistry);
+        givenRenameIsFound(managementContext, typeRegistry, catalogUpgradesBuilder, updatedVersionedName, originalVersionRangedName);
+
+        final Bundle bundle = newMockBundle(updatedVersionedName, ImmutableMap.of(
+                BundleUpgradeParser.MANIFEST_HEADER_UPGRADE_FOR_BUNDLES, "original:[1.0.0,2.0.0)" + "=" + updatedName));
+
+        final CatalogUpgrades catalogUpgrades = BundleUpgradeParser.parseBundleManifestForCatalogUpgrades(
+                bundle, (Supplier<Iterable<RegisteredType>>) ArrayList::new
+        );
+        System.out.println("catalogUpgrades = " + catalogUpgrades);
+
+        //when
+        final String result = CatalogUpgrades.getBundleUpgradedIfNecessary(managementContext, originalName);
+        //then
+        assertThat(result).isEqualTo(updatedName);
+    }
+
     private static void givenANonOsgiEnvironment(
             final ManagementContextInternal managementContext
     ) {


[brooklyn-server] 10/31: fix typo

Posted by al...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 170b3510b422970e10dbedea018b7f979ffb3af8
Author: Paul Campbell <pc...@kemitix.net>
AuthorDate: Mon Oct 15 15:34:41 2018 +0100

    fix typo
---
 .../main/java/org/apache/brooklyn/core/typereg/BundleUpgradeParser.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/core/src/main/java/org/apache/brooklyn/core/typereg/BundleUpgradeParser.java b/core/src/main/java/org/apache/brooklyn/core/typereg/BundleUpgradeParser.java
index 8b16d69..007c5da 100644
--- a/core/src/main/java/org/apache/brooklyn/core/typereg/BundleUpgradeParser.java
+++ b/core/src/main/java/org/apache/brooklyn/core/typereg/BundleUpgradeParser.java
@@ -137,7 +137,7 @@ public class BundleUpgradeParser {
      * 
      * The format is a comma separate list of {@code key=value} pairs, where each key is a name with a version range
      * (as per {@link #MANIFEST_HEADER_FORCE_REMOVE_BUNDLES}) specifying what should be upgraded, and {@code value} is a name and
-     * version specifying what it should be ugpraded to. The {@code =value} can be omitted, and usually is,
+     * version specifying what it should be upgraded to. The {@code =value} can be omitted, and usually is,
      * to mean this bundle at this version. (The {@code =value} is available if one bundle is defining upgrades for other bundles.)  
      * 
      * A wildcard can be given as the key, without a version ({@code *}) or with ({@code *:[0,1)}) to refer to