brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject [1/9] brooklyn-server git commit: Split CatalogYamlLocationTest for non-osgi and osgi
Date Mon, 13 Feb 2017 06:26:41 GMT
Repository: brooklyn-server
Updated Branches:
  refs/heads/master 6571bab4a -> 0f649fe17


Split CatalogYamlLocationTest for non-osgi and osgi


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

Branch: refs/heads/master
Commit: 7ff81869bbc6dbef9f7baf0c9211c75f2b0ea7e5
Parents: 6571bab
Author: Aled Sage <aled.sage@gmail.com>
Authored: Fri Feb 10 14:21:11 2017 +0000
Committer: Aled Sage <aled.sage@gmail.com>
Committed: Fri Feb 10 14:51:43 2017 +0000

----------------------------------------------------------------------
 .../camp/brooklyn/AbstractYamlTest.java         |  16 ++
 .../catalog/CatalogOsgiYamlLocationTest.java    | 198 +++++++++++++++++++
 .../catalog/CatalogYamlLocationTest.java        |  81 +-------
 3 files changed, 220 insertions(+), 75 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/7ff81869/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/AbstractYamlTest.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/AbstractYamlTest.java
b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/AbstractYamlTest.java
index a919aba..376fb5c 100644
--- a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/AbstractYamlTest.java
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/AbstractYamlTest.java
@@ -28,6 +28,7 @@ import org.apache.brooklyn.api.entity.Entity;
 import org.apache.brooklyn.api.entity.EntitySpec;
 import org.apache.brooklyn.api.mgmt.ManagementContext;
 import org.apache.brooklyn.api.mgmt.Task;
+import org.apache.brooklyn.api.typereg.RegisteredType;
 import org.apache.brooklyn.camp.brooklyn.spi.creation.CampTypePlanTransformer;
 import org.apache.brooklyn.core.catalog.internal.CatalogUtils;
 import org.apache.brooklyn.core.entity.Entities;
@@ -38,6 +39,7 @@ import org.apache.brooklyn.core.mgmt.internal.LocalManagementContext;
 import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests;
 import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests.Builder;
 import org.apache.brooklyn.core.typereg.RegisteredTypeLoadingContexts;
+import org.apache.brooklyn.core.typereg.RegisteredTypePredicates;
 import org.apache.brooklyn.util.collections.MutableMap;
 import org.apache.brooklyn.util.core.ResourceUtils;
 import org.apache.brooklyn.util.net.Urls;
@@ -48,6 +50,8 @@ import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 
 import com.google.common.base.Joiner;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterables;
 
 public abstract class AbstractYamlTest {
 
@@ -228,6 +232,18 @@ public abstract class AbstractYamlTest {
         return CatalogUtils.getVersionedId(id, TEST_VERSION);
     }
 
+    protected String ver(String id, String version) {
+        return CatalogUtils.getVersionedId(id, version);
+    }
+    
+    protected int countCatalogLocations() {
+        return countCatalogItemsMatching(RegisteredTypePredicates.IS_LOCATION);
+    }
+
+    protected int countCatalogItemsMatching(Predicate<? super RegisteredType> filter)
{
+        return Iterables.size(mgmt().getTypeRegistry().getMatching(filter));
+    }
+    
     public void forceCatalogUpdate() {
         forceUpdate = true;
     }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/7ff81869/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiYamlLocationTest.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiYamlLocationTest.java
b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiYamlLocationTest.java
new file mode 100644
index 0000000..94b2c50
--- /dev/null
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiYamlLocationTest.java
@@ -0,0 +1,198 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.brooklyn.camp.brooklyn.catalog;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNull;
+
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.brooklyn.api.entity.Entity;
+import org.apache.brooklyn.api.location.Location;
+import org.apache.brooklyn.api.location.LocationDefinition;
+import org.apache.brooklyn.api.location.LocationSpec;
+import org.apache.brooklyn.api.typereg.OsgiBundleWithUrl;
+import org.apache.brooklyn.api.typereg.RegisteredType;
+import org.apache.brooklyn.camp.brooklyn.AbstractYamlTest;
+import org.apache.brooklyn.core.config.BasicConfigKey;
+import org.apache.brooklyn.core.entity.Entities;
+import org.apache.brooklyn.core.mgmt.osgi.OsgiStandaloneTest;
+import org.apache.brooklyn.core.typereg.RegisteredTypePredicates;
+import org.apache.brooklyn.core.typereg.RegisteredTypes;
+import org.apache.brooklyn.test.support.TestResourceUnavailableException;
+import org.apache.brooklyn.util.text.StringFunctions;
+import org.testng.Assert;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
+
+public class CatalogOsgiYamlLocationTest extends AbstractYamlTest {
+    private static final String SIMPLE_LOCATION_TYPE = "org.apache.brooklyn.test.osgi.entities.SimpleLocation";
+
+    @Override
+    protected boolean disableOsgi() {
+        return false;
+    }
+
+    @AfterMethod(alwaysRun=true)
+    @Override
+    public void tearDown() throws Exception {
+        try {
+            for (RegisteredType ci : mgmt().getTypeRegistry().getMatching(RegisteredTypePredicates.IS_LOCATION))
{
+                mgmt().getCatalog().deleteCatalogItem(ci.getSymbolicName(), ci.getVersion());
+            }
+        } finally {
+            super.tearDown();
+        }
+    }
+    
+    @Test
+    public void testAddCatalogItemOsgi() throws Exception {
+        assertEquals(countCatalogLocations(), 0);
+
+        String symbolicName = "my.catalog.location.id.load";
+        addCatalogLocation(symbolicName, SIMPLE_LOCATION_TYPE, getOsgiLibraries());
+        assertAdded(symbolicName, SIMPLE_LOCATION_TYPE);
+        assertOsgi(symbolicName);
+        removeAndAssert(symbolicName);
+    }
+
+    @Test
+    public void testAddCatalogItemOsgiLegacySyntax() throws Exception {
+        assertEquals(countCatalogLocations(), 0);
+
+        String symbolicName = "my.catalog.location.id.load";
+        addCatalogLocationLegacySyntax(symbolicName, SIMPLE_LOCATION_TYPE, getOsgiLibraries());
+        assertAdded(symbolicName, SIMPLE_LOCATION_TYPE);
+        assertOsgi(symbolicName);
+        removeAndAssert(symbolicName);
+    }
+
+    private void assertOsgi(String symbolicName) {
+        RegisteredType item = mgmt().getTypeRegistry().get(symbolicName, TEST_VERSION);
+        Collection<OsgiBundleWithUrl> libs = item.getLibraries();
+        assertEquals(libs.size(), 1);
+        assertEquals(Iterables.getOnlyElement(libs).getUrl(), Iterables.getOnlyElement(getOsgiLibraries()));
+    }
+
+    private void assertAdded(String symbolicName, String expectedJavaType) {
+        RegisteredType item = mgmt().getTypeRegistry().get(symbolicName, TEST_VERSION);
+        assertEquals(item.getSymbolicName(), symbolicName);
+        Assert.assertTrue(RegisteredTypes.isSubtypeOf(item, Location.class), "Expected Location,
not "+item.getSuperTypes());
+        assertEquals(countCatalogLocations(), 1);
+
+        // Item added to catalog should automatically be available in location registry
+        LocationDefinition def = mgmt().getLocationRegistry().getDefinedLocationByName(symbolicName);
+        assertEquals(def.getId(), symbolicName);
+        assertEquals(def.getName(), symbolicName);
+        
+        LocationSpec<?> spec = mgmt().getTypeRegistry().createSpec(item, null, LocationSpec.class);
+        assertEquals(spec.getType().getName(), expectedJavaType);
+    }
+    
+    private void removeAndAssert(String symbolicName) {
+        // Deleting item: should be gone from catalog, and from location registry
+        deleteCatalogEntity(symbolicName);
+
+        assertEquals(countCatalogLocations(), 0);
+        assertNull(mgmt().getLocationRegistry().getDefinedLocationByName(symbolicName));
+    }
+
+    @Test
+    public void testLaunchApplicationReferencingOsgiLocation() throws Exception {
+        String symbolicName = "my.catalog.location.id.launch";
+        addCatalogLocation(symbolicName, SIMPLE_LOCATION_TYPE, getOsgiLibraries());
+        runLaunchApplicationReferencingLocation(symbolicName, SIMPLE_LOCATION_TYPE);
+        
+        deleteCatalogEntity(symbolicName);
+    }
+    
+    protected void runLaunchApplicationReferencingLocation(String locTypeInYaml, String locType)
throws Exception {
+        Entity app = createAndStartApplication(
+            "name: simple-app-yaml",
+            "location: ",
+            "  "+locTypeInYaml+":",
+            "    config2: config2 override",
+            "    config3: config3",
+            "services: ",
+            "  - type: org.apache.brooklyn.entity.stock.BasicStartable");
+
+        Entity simpleEntity = Iterables.getOnlyElement(app.getChildren());
+        Location location = Iterables.getOnlyElement(Entities.getAllInheritedLocations(simpleEntity));
+        assertEquals(location.getClass().getName(), locType);
+        assertEquals(location.getConfig(new BasicConfigKey<String>(String.class, "config1")),
"config1");
+        assertEquals(location.getConfig(new BasicConfigKey<String>(String.class, "config2")),
"config2 override");
+        assertEquals(location.getConfig(new BasicConfigKey<String>(String.class, "config3")),
"config3");
+    }
+
+    private List<String> getOsgiLibraries() {
+        TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH);
+        return ImmutableList.of(OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL);
+    }
+    
+    private void addCatalogLocation(String symbolicName, String locationType, List<String>
libraries) {
+        ImmutableList.Builder<String> yaml = ImmutableList.<String>builder().add(
+                "brooklyn.catalog:",
+                "  id: " + symbolicName,
+                "  version: " + TEST_VERSION,
+                "  itemType: location",
+                "  name: My Catalog Location",
+                "  description: My description");
+        if (libraries!=null && libraries.size() > 0) {
+            yaml.add("  libraries:")
+                .addAll(Lists.transform(libraries, StringFunctions.prepend("  - url: ")));
+        }
+        yaml.add(
+                "  item:",
+                "    type: " + locationType,
+                "    brooklyn.config:",
+                "      config1: config1",
+                "      config2: config2");
+        
+        
+        addCatalogItems(yaml.build());
+    }
+
+    private void addCatalogLocationLegacySyntax(String symbolicName, String locationType,
List<String> libraries) {
+        ImmutableList.Builder<String> yaml = ImmutableList.<String>builder().add(
+                "brooklyn.catalog:",
+                "  id: " + symbolicName,
+                "  name: My Catalog Location",
+                "  description: My description",
+                "  version: " + TEST_VERSION);
+        if (libraries!=null && libraries.size() > 0) {
+            yaml.add("  libraries:")
+                .addAll(Lists.transform(libraries, StringFunctions.prepend("  - url: ")));
+        }
+        yaml.add(
+                "",
+                "brooklyn.locations:",
+                "- type: " + locationType,
+                "  brooklyn.config:",
+                "    config1: config1",
+                "    config2: config2");
+        
+        
+        addCatalogItems(yaml.build());
+    }
+}

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/7ff81869/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlLocationTest.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlLocationTest.java
b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlLocationTest.java
index df00c6c..01fb484 100644
--- a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlLocationTest.java
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlLocationTest.java
@@ -23,7 +23,6 @@ import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertNull;
 import static org.testng.Assert.assertTrue;
 
-import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 
@@ -31,20 +30,16 @@ import org.apache.brooklyn.api.entity.Entity;
 import org.apache.brooklyn.api.location.Location;
 import org.apache.brooklyn.api.location.LocationDefinition;
 import org.apache.brooklyn.api.location.LocationSpec;
-import org.apache.brooklyn.api.typereg.OsgiBundleWithUrl;
 import org.apache.brooklyn.api.typereg.RegisteredType;
 import org.apache.brooklyn.camp.brooklyn.AbstractYamlTest;
 import org.apache.brooklyn.core.config.BasicConfigKey;
 import org.apache.brooklyn.core.entity.Entities;
-import org.apache.brooklyn.core.mgmt.osgi.OsgiStandaloneTest;
 import org.apache.brooklyn.core.typereg.RegisteredTypePredicates;
 import org.apache.brooklyn.core.typereg.RegisteredTypes;
 import org.apache.brooklyn.entity.stock.BasicEntity;
 import org.apache.brooklyn.location.localhost.LocalhostMachineProvisioningLocation;
 import org.apache.brooklyn.test.Asserts;
-import org.apache.brooklyn.test.support.TestResourceUnavailableException;
 import org.apache.brooklyn.util.collections.CollectionFunctionals;
-import org.apache.brooklyn.util.text.StringFunctions;
 import org.testng.Assert;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.Test;
@@ -53,17 +48,10 @@ import com.google.common.base.Joiner;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
 
 public class CatalogYamlLocationTest extends AbstractYamlTest {
     private static final String LOCALHOST_LOCATION_SPEC = "localhost";
     private static final String LOCALHOST_LOCATION_TYPE = LocalhostMachineProvisioningLocation.class.getName();
-    private static final String SIMPLE_LOCATION_TYPE = "org.apache.brooklyn.test.osgi.entities.SimpleLocation";
-
-    @Override
-    protected boolean disableOsgi() {
-        return false;
-    }
 
     @AfterMethod(alwaysRun=true)
     @Override
@@ -88,44 +76,15 @@ public class CatalogYamlLocationTest extends AbstractYamlTest {
     }
 
     @Test
-    public void testAddCatalogItemOsgi() throws Exception {
-        assertEquals(countCatalogLocations(), 0);
-
-        String symbolicName = "my.catalog.location.id.load";
-        addCatalogLocation(symbolicName, SIMPLE_LOCATION_TYPE, getOsgiLibraries());
-        assertAdded(symbolicName, SIMPLE_LOCATION_TYPE);
-        assertOsgi(symbolicName);
-        removeAndAssert(symbolicName);
-    }
-
-    @Test
     public void testAddCatalogItemLegacySyntax() throws Exception {
         assertEquals(countCatalogLocations(), 0);
 
         String symbolicName = "my.catalog.location.id.load";
-        addCatalogLocationLegacySyntax(symbolicName, LOCALHOST_LOCATION_TYPE, null);
+        addCatalogLocationLegacySyntax(symbolicName, LOCALHOST_LOCATION_TYPE);
         assertAdded(symbolicName, LOCALHOST_LOCATION_TYPE);
         removeAndAssert(symbolicName);
     }
 
-    @Test
-    public void testAddCatalogItemOsgiLegacySyntax() throws Exception {
-        assertEquals(countCatalogLocations(), 0);
-
-        String symbolicName = "my.catalog.location.id.load";
-        addCatalogLocationLegacySyntax(symbolicName, SIMPLE_LOCATION_TYPE, getOsgiLibraries());
-        assertAdded(symbolicName, SIMPLE_LOCATION_TYPE);
-        assertOsgi(symbolicName);
-        removeAndAssert(symbolicName);
-    }
-
-    private void assertOsgi(String symbolicName) {
-        RegisteredType item = mgmt().getTypeRegistry().get(symbolicName, TEST_VERSION);
-        Collection<OsgiBundleWithUrl> libs = item.getLibraries();
-        assertEquals(libs.size(), 1);
-        assertEquals(Iterables.getOnlyElement(libs).getUrl(), Iterables.getOnlyElement(getOsgiLibraries()));
-    }
-
     @SuppressWarnings({ "rawtypes" })
     private void assertAdded(String symbolicName, String expectedJavaType) {
         RegisteredType item = mgmt().getTypeRegistry().get(symbolicName, TEST_VERSION);
@@ -171,7 +130,7 @@ public class CatalogYamlLocationTest extends AbstractYamlTest {
     @Test
     public void testLaunchApplicationReferencingLocationClassLegacySyntax() throws Exception
{
         String symbolicName = "my.catalog.location.id.launch";
-        addCatalogLocationLegacySyntax(symbolicName, LOCALHOST_LOCATION_TYPE, null);
+        addCatalogLocationLegacySyntax(symbolicName, LOCALHOST_LOCATION_TYPE);
         runLaunchApplicationReferencingLocation(symbolicName, LOCALHOST_LOCATION_TYPE);
 
         deleteCatalogEntity(symbolicName);
@@ -180,21 +139,12 @@ public class CatalogYamlLocationTest extends AbstractYamlTest {
     @Test
     public void testLaunchApplicationReferencingLocationSpecLegacySyntax() throws Exception
{
         String symbolicName = "my.catalog.location.id.launch";
-        addCatalogLocationLegacySyntax(symbolicName, LOCALHOST_LOCATION_SPEC, null);
+        addCatalogLocationLegacySyntax(symbolicName, LOCALHOST_LOCATION_SPEC);
         runLaunchApplicationReferencingLocation(symbolicName, LOCALHOST_LOCATION_TYPE);
 
         deleteCatalogEntity(symbolicName);
     }
 
-    @Test
-    public void testLaunchApplicationReferencingOsgiLocation() throws Exception {
-        String symbolicName = "my.catalog.location.id.launch";
-        addCatalogLocation(symbolicName, SIMPLE_LOCATION_TYPE, getOsgiLibraries());
-        runLaunchApplicationReferencingLocation(symbolicName, SIMPLE_LOCATION_TYPE);
-        
-        deleteCatalogEntity(symbolicName);
-    }
-    
     // See https://issues.apache.org/jira/browse/BROOKLYN-248
     @Test
     public void testTypeInheritance() throws Exception {
@@ -380,11 +330,6 @@ public class CatalogYamlLocationTest extends AbstractYamlTest {
         assertEquals(location.getConfig(new BasicConfigKey<String>(String.class, "config3")),
"config3");
     }
 
-    private List<String> getOsgiLibraries() {
-        TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH);
-        return ImmutableList.of(OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL);
-    }
-    
     private void addCatalogLocation(String symbolicName, String locationType, List<String>
libraries) {
         ImmutableList.Builder<String> yaml = ImmutableList.<String>builder().add(
                 "brooklyn.catalog:",
@@ -392,12 +337,7 @@ public class CatalogYamlLocationTest extends AbstractYamlTest {
                 "  version: " + TEST_VERSION,
                 "  itemType: location",
                 "  name: My Catalog Location",
-                "  description: My description");
-        if (libraries!=null && libraries.size() > 0) {
-            yaml.add("  libraries:")
-                .addAll(Lists.transform(libraries, StringFunctions.prepend("  - url: ")));
-        }
-        yaml.add(
+                "  description: My description",
                 "  item:",
                 "    type: " + locationType,
                 "    brooklyn.config:",
@@ -408,18 +348,13 @@ public class CatalogYamlLocationTest extends AbstractYamlTest {
         addCatalogItems(yaml.build());
     }
 
-    private void addCatalogLocationLegacySyntax(String symbolicName, String locationType,
List<String> libraries) {
+    private void addCatalogLocationLegacySyntax(String symbolicName, String locationType)
{
         ImmutableList.Builder<String> yaml = ImmutableList.<String>builder().add(
                 "brooklyn.catalog:",
                 "  id: " + symbolicName,
                 "  name: My Catalog Location",
                 "  description: My description",
-                "  version: " + TEST_VERSION);
-        if (libraries!=null && libraries.size() > 0) {
-            yaml.add("  libraries:")
-                .addAll(Lists.transform(libraries, StringFunctions.prepend("  - url: ")));
-        }
-        yaml.add(
+                "  version: " + TEST_VERSION,
                 "",
                 "brooklyn.locations:",
                 "- type: " + locationType,
@@ -431,10 +366,6 @@ public class CatalogYamlLocationTest extends AbstractYamlTest {
         addCatalogItems(yaml.build());
     }
 
-    private int countCatalogLocations() {
-        return Iterables.size(mgmt().getTypeRegistry().getMatching(RegisteredTypePredicates.IS_LOCATION));
-    }
-
     @Test
     public void testManagedLocationsCreateAndCleanup() {
         assertLocationRegistryCount(0);


Mime
View raw message