You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by sv...@apache.org on 2017/02/13 06:26:42 UTC
[2/9] brooklyn-server git commit: Split CatalogYamlPolicyTest for
non-osgi and osgi
Split CatalogYamlPolicyTest 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/f2ea02d5
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/f2ea02d5
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/f2ea02d5
Branch: refs/heads/master
Commit: f2ea02d5ac653a5b0d3db80c8e582cf0b096cf20
Parents: 7ff8186
Author: Aled Sage <al...@gmail.com>
Authored: Fri Feb 10 14:34:56 2017 +0000
Committer: Aled Sage <al...@gmail.com>
Committed: Fri Feb 10 22:15:49 2017 +0000
----------------------------------------------------------------------
.../camp/brooklyn/AbstractYamlTest.java | 4 +
.../catalog/CatalogOsgiYamlPolicyTest.java | 165 +++++++++++++++++++
.../brooklyn/catalog/CatalogYamlPolicyTest.java | 73 +++-----
3 files changed, 191 insertions(+), 51 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/f2ea02d5/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 376fb5c..5581aba 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
@@ -240,6 +240,10 @@ public abstract class AbstractYamlTest {
return countCatalogItemsMatching(RegisteredTypePredicates.IS_LOCATION);
}
+ protected int countCatalogPolicies() {
+ return countCatalogItemsMatching(RegisteredTypePredicates.IS_POLICY);
+ }
+
protected int countCatalogItemsMatching(Predicate<? super RegisteredType> filter) {
return Iterables.size(mgmt().getTypeRegistry().getMatching(filter));
}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/f2ea02d5/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiYamlPolicyTest.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiYamlPolicyTest.java b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiYamlPolicyTest.java
new file mode 100644
index 0000000..e26aca6
--- /dev/null
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogOsgiYamlPolicyTest.java
@@ -0,0 +1,165 @@
+/*
+ * 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 org.apache.brooklyn.api.entity.Entity;
+import org.apache.brooklyn.api.policy.Policy;
+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.mgmt.osgi.OsgiStandaloneTest;
+import org.apache.brooklyn.entity.stock.BasicEntity;
+import org.apache.brooklyn.test.support.TestResourceUnavailableException;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.Iterables;
+
+public class CatalogOsgiYamlPolicyTest extends AbstractYamlTest {
+ private static final String SIMPLE_POLICY_TYPE = "org.apache.brooklyn.test.osgi.entities.SimplePolicy";
+
+ @Override
+ protected boolean disableOsgi() {
+ return false;
+ }
+
+ @Test
+ public void testAddCatalogItemOsgi() throws Exception {
+ assertEquals(countCatalogPolicies(), 0);
+
+ String symbolicName = "my.catalog.policy.id.load";
+ addCatalogOsgiPolicy(symbolicName, SIMPLE_POLICY_TYPE);
+
+ RegisteredType item = mgmt().getTypeRegistry().get(symbolicName, TEST_VERSION);
+ assertEquals(item.getSymbolicName(), symbolicName);
+ assertEquals(countCatalogPolicies(), 1);
+
+ deleteCatalogEntity(symbolicName);
+ }
+
+ @Test
+ public void testAddCatalogItemTopLevelLegacySyntaxOsgi() throws Exception {
+ assertEquals(countCatalogPolicies(), 0);
+
+ String symbolicName = "my.catalog.policy.id.load";
+ addCatalogOsgiPolicyLegacySyntax(symbolicName, SIMPLE_POLICY_TYPE);
+
+ RegisteredType item = mgmt().getTypeRegistry().get(symbolicName, TEST_VERSION);
+ assertEquals(item.getSymbolicName(), symbolicName);
+ assertEquals(countCatalogPolicies(), 1);
+
+ deleteCatalogEntity(symbolicName);
+ }
+
+ @Test
+ public void testLaunchApplicationReferencingPolicy() throws Exception {
+ String symbolicName = "my.catalog.policy.id.launch";
+ addCatalogOsgiPolicy(symbolicName, SIMPLE_POLICY_TYPE);
+ Entity app = createAndStartApplication(
+ "name: simple-app-yaml",
+ "location: localhost",
+ "services: ",
+ " - type: " + BasicEntity.class.getName(),
+ " brooklyn.policies:\n" +
+ " - type: " + ver(symbolicName),
+ " brooklyn.config:",
+ " config2: config2 override",
+ " config3: config3");
+
+ Entity simpleEntity = Iterables.getOnlyElement(app.getChildren());
+ Policy policy = Iterables.getOnlyElement(simpleEntity.policies());
+ assertEquals(policy.getPolicyType().getName(), SIMPLE_POLICY_TYPE);
+ assertEquals(policy.getConfig(new BasicConfigKey<String>(String.class, "config1")), "config1");
+ assertEquals(policy.getConfig(new BasicConfigKey<String>(String.class, "config2")), "config2 override");
+ assertEquals(policy.getConfig(new BasicConfigKey<String>(String.class, "config3")), "config3");
+
+ deleteCatalogEntity(symbolicName);
+ }
+
+ @Test
+ public void testLaunchApplicationWithCatalogReferencingOtherCatalog() throws Exception {
+ String referencedSymbolicName = "my.catalog.policy.id.referenced";
+ String referrerSymbolicName = "my.catalog.policy.id.referring";
+ addCatalogOsgiPolicy(referencedSymbolicName, SIMPLE_POLICY_TYPE);
+
+ addCatalogItems(
+ "brooklyn.catalog:",
+ " id: " + referrerSymbolicName,
+ " version: " + TEST_VERSION,
+ " itemType: entity",
+ " name: My Catalog App",
+ " description: My description",
+ " icon_url: classpath://path/to/myicon.jpg",
+ " item:",
+ " type: " + BasicEntity.class.getName(),
+ " brooklyn.policies:",
+ " - type: " + ver(referencedSymbolicName));
+
+ Entity app = createAndStartApplication(
+ "services:",
+ "- type: "+ ver(referrerSymbolicName));
+
+ Entity entity = Iterables.getOnlyElement(app.getChildren());
+ Policy policy = Iterables.getOnlyElement(entity.policies());
+ assertEquals(policy.getPolicyType().getName(), SIMPLE_POLICY_TYPE);
+
+ deleteCatalogEntity(referencedSymbolicName);
+ }
+
+ private void addCatalogOsgiPolicy(String symbolicName, String policyType) {
+ TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH);
+
+ addCatalogItems(
+ "brooklyn.catalog:",
+ " id: " + symbolicName,
+ " version: " + TEST_VERSION,
+ " itemType: policy",
+ " name: My Catalog Policy",
+ " description: My description",
+ " icon_url: classpath://path/to/myicon.jpg",
+ " libraries:",
+ " - url: " + OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL,
+ " item:",
+ " type: " + policyType,
+ " brooklyn.config:",
+ " config1: config1",
+ " config2: config2");
+ }
+
+ private void addCatalogOsgiPolicyLegacySyntax(String symbolicName, String policyType) {
+ TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH);
+
+ addCatalogItems(
+ "brooklyn.catalog:",
+ " id: " + symbolicName,
+ " name: My Catalog Policy",
+ " description: My description",
+ " icon_url: classpath://path/to/myicon.jpg",
+ " version: " + TEST_VERSION,
+ " libraries:",
+ " - url: " + OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL,
+ "",
+ "brooklyn.policies:",
+ "- type: " + policyType,
+ " brooklyn.config:",
+ " config1: config1",
+ " config2: config2");
+ }
+}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/f2ea02d5/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlPolicyTest.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlPolicyTest.java b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlPolicyTest.java
index 573bb7c..e1cbbb7 100644
--- a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlPolicyTest.java
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/CatalogYamlPolicyTest.java
@@ -24,29 +24,22 @@ import org.apache.brooklyn.api.entity.Entity;
import org.apache.brooklyn.api.policy.Policy;
import org.apache.brooklyn.api.typereg.RegisteredType;
import org.apache.brooklyn.camp.brooklyn.AbstractYamlTest;
-import org.apache.brooklyn.core.catalog.CatalogPredicates;
import org.apache.brooklyn.core.config.BasicConfigKey;
-import org.apache.brooklyn.core.mgmt.osgi.OsgiStandaloneTest;
-import org.apache.brooklyn.test.support.TestResourceUnavailableException;
+import org.apache.brooklyn.core.test.policy.TestPolicy;
+import org.apache.brooklyn.entity.stock.BasicEntity;
import org.testng.annotations.Test;
import com.google.common.collect.Iterables;
public class CatalogYamlPolicyTest extends AbstractYamlTest {
- private static final String SIMPLE_POLICY_TYPE = "org.apache.brooklyn.test.osgi.entities.SimplePolicy";
- private static final String SIMPLE_ENTITY_TYPE = "org.apache.brooklyn.test.osgi.entities.SimpleEntity";
-
- @Override
- protected boolean disableOsgi() {
- return false;
- }
+ private static final String POLICY_TYPE = TestPolicy.class.getName();
@Test
public void testAddCatalogItem() throws Exception {
assertEquals(countCatalogPolicies(), 0);
String symbolicName = "my.catalog.policy.id.load";
- addCatalogOsgiPolicy(symbolicName, SIMPLE_POLICY_TYPE);
+ addCatalogPolicy(symbolicName, POLICY_TYPE);
RegisteredType item = mgmt().getTypeRegistry().get(symbolicName, TEST_VERSION);
assertEquals(item.getSymbolicName(), symbolicName);
@@ -56,11 +49,11 @@ public class CatalogYamlPolicyTest extends AbstractYamlTest {
}
@Test
- public void testAddCatalogItemTopLevelSyntax() throws Exception {
+ public void testAddCatalogItemTopLevelLegacySyntax() throws Exception {
assertEquals(countCatalogPolicies(), 0);
String symbolicName = "my.catalog.policy.id.load";
- addCatalogOsgiPolicyLegacySyntax(symbolicName, SIMPLE_POLICY_TYPE);
+ addCatalogPolicyLegacySyntax(symbolicName, POLICY_TYPE);
RegisteredType item = mgmt().getTypeRegistry().get(symbolicName, TEST_VERSION);
assertEquals(item.getSymbolicName(), symbolicName);
@@ -72,13 +65,11 @@ public class CatalogYamlPolicyTest extends AbstractYamlTest {
@Test
public void testLaunchApplicationReferencingPolicy() throws Exception {
String symbolicName = "my.catalog.policy.id.launch";
- addCatalogOsgiPolicy(symbolicName, SIMPLE_POLICY_TYPE);
+ addCatalogPolicy(symbolicName, POLICY_TYPE);
Entity app = createAndStartApplication(
- "name: simple-app-yaml",
- "location: localhost",
"services: ",
- " - type: org.apache.brooklyn.entity.stock.BasicEntity\n" +
- " brooklyn.policies:\n" +
+ " - type: " + BasicEntity.class.getName(),
+ " brooklyn.policies:",
" - type: " + ver(symbolicName),
" brooklyn.config:",
" config2: config2 override",
@@ -86,7 +77,7 @@ public class CatalogYamlPolicyTest extends AbstractYamlTest {
Entity simpleEntity = Iterables.getOnlyElement(app.getChildren());
Policy policy = Iterables.getOnlyElement(simpleEntity.policies());
- assertEquals(policy.getPolicyType().getName(), SIMPLE_POLICY_TYPE);
+ assertEquals(policy.getPolicyType().getName(), POLICY_TYPE);
assertEquals(policy.getConfig(new BasicConfigKey<String>(String.class, "config1")), "config1");
assertEquals(policy.getConfig(new BasicConfigKey<String>(String.class, "config2")), "config2 override");
assertEquals(policy.getConfig(new BasicConfigKey<String>(String.class, "config3")), "config3");
@@ -97,13 +88,11 @@ public class CatalogYamlPolicyTest extends AbstractYamlTest {
@Test
public void testLaunchApplicationReferencingPolicyTopLevelSyntax() throws Exception {
String symbolicName = "my.catalog.policy.id.launch";
- addCatalogOsgiPolicyLegacySyntax(symbolicName, SIMPLE_POLICY_TYPE);
+ addCatalogPolicyLegacySyntax(symbolicName, POLICY_TYPE);
Entity app = createAndStartApplication(
- "name: simple-app-yaml",
- "location: localhost",
"services: ",
- " - type: org.apache.brooklyn.entity.stock.BasicEntity\n" +
- " brooklyn.policies:\n" +
+ " - type: " + BasicEntity.class.getName(),
+ " brooklyn.policies:",
" - type: " + ver(symbolicName),
" brooklyn.config:",
" config2: config2 override",
@@ -111,7 +100,7 @@ public class CatalogYamlPolicyTest extends AbstractYamlTest {
Entity simpleEntity = Iterables.getOnlyElement(app.getChildren());
Policy policy = Iterables.getOnlyElement(simpleEntity.policies());
- assertEquals(policy.getPolicyType().getName(), SIMPLE_POLICY_TYPE);
+ assertEquals(policy.getPolicyType().getName(), POLICY_TYPE);
assertEquals(policy.getConfig(new BasicConfigKey<String>(String.class, "config1")), "config1");
assertEquals(policy.getConfig(new BasicConfigKey<String>(String.class, "config2")), "config2 override");
assertEquals(policy.getConfig(new BasicConfigKey<String>(String.class, "config3")), "config3");
@@ -123,7 +112,7 @@ public class CatalogYamlPolicyTest extends AbstractYamlTest {
public void testLaunchApplicationWithCatalogReferencingOtherCatalog() throws Exception {
String referencedSymbolicName = "my.catalog.policy.id.referenced";
String referrerSymbolicName = "my.catalog.policy.id.referring";
- addCatalogOsgiPolicy(referencedSymbolicName, SIMPLE_POLICY_TYPE);
+ addCatalogPolicy(referencedSymbolicName, POLICY_TYPE);
addCatalogItems(
"brooklyn.catalog:",
@@ -133,30 +122,23 @@ public class CatalogYamlPolicyTest extends AbstractYamlTest {
" name: My Catalog App",
" description: My description",
" icon_url: classpath://path/to/myicon.jpg",
- " libraries:",
- " - url: " + OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL,
" item:",
- " type: " + SIMPLE_ENTITY_TYPE,
+ " type: " + BasicEntity.class.getName(),
" brooklyn.policies:",
" - type: " + ver(referencedSymbolicName));
- String yaml = "name: simple-app-yaml\n" +
- "location: localhost\n" +
- "services: \n" +
- "- type: "+ ver(referrerSymbolicName);
-
- Entity app = createAndStartApplication(yaml);
+ Entity app = createAndStartApplication(
+ "services:",
+ "- type: "+ ver(referrerSymbolicName));
Entity simpleEntity = Iterables.getOnlyElement(app.getChildren());
Policy policy = Iterables.getOnlyElement(simpleEntity.policies());
- assertEquals(policy.getPolicyType().getName(), SIMPLE_POLICY_TYPE);
+ assertEquals(policy.getPolicyType().getName(), POLICY_TYPE);
deleteCatalogEntity(referencedSymbolicName);
}
- private void addCatalogOsgiPolicy(String symbolicName, String policyType) {
- TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH);
-
+ private void addCatalogPolicy(String symbolicName, String policyType) {
addCatalogItems(
"brooklyn.catalog:",
" id: " + symbolicName,
@@ -165,8 +147,6 @@ public class CatalogYamlPolicyTest extends AbstractYamlTest {
" name: My Catalog Policy",
" description: My description",
" icon_url: classpath://path/to/myicon.jpg",
- " libraries:",
- " - url: " + OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL,
" item:",
" type: " + policyType,
" brooklyn.config:",
@@ -174,9 +154,7 @@ public class CatalogYamlPolicyTest extends AbstractYamlTest {
" config2: config2");
}
- private void addCatalogOsgiPolicyLegacySyntax(String symbolicName, String policyType) {
- TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH);
-
+ private void addCatalogPolicyLegacySyntax(String symbolicName, String policyType) {
addCatalogItems(
"brooklyn.catalog:",
" id: " + symbolicName,
@@ -184,8 +162,6 @@ public class CatalogYamlPolicyTest extends AbstractYamlTest {
" description: My description",
" icon_url: classpath://path/to/myicon.jpg",
" version: " + TEST_VERSION,
- " libraries:",
- " - url: " + OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL,
"",
"brooklyn.policies:",
"- type: " + policyType,
@@ -193,9 +169,4 @@ public class CatalogYamlPolicyTest extends AbstractYamlTest {
" config1: config1",
" config2: config2");
}
-
- private int countCatalogPolicies() {
- return Iterables.size(mgmt().getCatalog().getCatalogItems(CatalogPredicates.IS_POLICY));
- }
-
}