You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by he...@apache.org on 2015/11/17 23:51:28 UTC
[13/14] incubator-brooklyn git commit: relatively simple test for
createSpec using the StaticTypePlanTransfomer
relatively simple test for createSpec using the StaticTypePlanTransfomer
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/c575708d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/c575708d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/c575708d
Branch: refs/heads/master
Commit: c575708d29f8a4577ce93536724454f3fa9ce736
Parents: 03aacd3
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Tue Nov 17 22:50:24 2015 +0000
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Tue Nov 17 22:50:24 2015 +0000
----------------------------------------------------------------------
.../internal/StaticTypePlanTransformer.java | 10 ++--
.../internal/StaticTypePlanTransformerTest.java | 63 ++++++++++++++++++++
2 files changed, 69 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c575708d/core/src/test/java/org/apache/brooklyn/core/catalog/internal/StaticTypePlanTransformer.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/catalog/internal/StaticTypePlanTransformer.java b/core/src/test/java/org/apache/brooklyn/core/catalog/internal/StaticTypePlanTransformer.java
index 613fe35..b7255e2 100644
--- a/core/src/test/java/org/apache/brooklyn/core/catalog/internal/StaticTypePlanTransformer.java
+++ b/core/src/test/java/org/apache/brooklyn/core/catalog/internal/StaticTypePlanTransformer.java
@@ -53,8 +53,10 @@ import org.apache.brooklyn.util.text.Identifiers;
*/
public class StaticTypePlanTransformer extends AbstractTypePlanTransformer {
+ public static final String FORMAT = "static-types";
+
public StaticTypePlanTransformer() {
- super("static-types", "Static Type", "Static transformer for use in tests");
+ super(FORMAT, "Static Type", "Static transformer for use in tests");
}
private static final Map<String, AbstractBrooklynObjectSpec<?, ?>> REGISTERED_SPECS = new ConcurrentHashMap<>();
@@ -101,9 +103,9 @@ public class StaticTypePlanTransformer extends AbstractTypePlanTransformer {
@Override
protected AbstractBrooklynObjectSpec<?, ?> createSpec(RegisteredType type, RegisteredTypeLoadingContext context) throws Exception {
- if (REGISTERED_SPECS.containsKey(type.getId()))
- return get(type.getId());
- if (REGISTERED_SPECS.containsKey(type.getPlan().getPlanData()))
+ if (REGISTERED_SPECS.containsKey(type.getSymbolicName()))
+ return get(type.getSymbolicName());
+ if (type.getPlan().getPlanData()!=null && REGISTERED_SPECS.containsKey(type.getPlan().getPlanData()))
return get((String)type.getPlan().getPlanData());
return null;
}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c575708d/core/src/test/java/org/apache/brooklyn/core/catalog/internal/StaticTypePlanTransformerTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/catalog/internal/StaticTypePlanTransformerTest.java b/core/src/test/java/org/apache/brooklyn/core/catalog/internal/StaticTypePlanTransformerTest.java
new file mode 100644
index 0000000..db292e0
--- /dev/null
+++ b/core/src/test/java/org/apache/brooklyn/core/catalog/internal/StaticTypePlanTransformerTest.java
@@ -0,0 +1,63 @@
+/*
+ * 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.entity.Entity;
+import org.apache.brooklyn.api.entity.EntitySpec;
+import org.apache.brooklyn.core.test.BrooklynMgmtUnitTestSupport;
+import org.apache.brooklyn.core.typereg.BasicTypeImplementationPlan;
+import org.apache.brooklyn.core.typereg.RegisteredTypes;
+import org.apache.brooklyn.entity.stock.BasicEntity;
+import org.testng.Assert;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+public class StaticTypePlanTransformerTest extends BrooklynMgmtUnitTestSupport {
+
+ final static String DISPLAY_NAME = "Static Test";
+ String specId;
+
+ @BeforeMethod(alwaysRun=true)
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ StaticTypePlanTransformer.forceInstall();
+ specId = StaticTypePlanTransformer.registerSpec(EntitySpec.create(BasicEntity.class).displayName(DISPLAY_NAME));
+ }
+
+ @AfterMethod(alwaysRun=true)
+ @Override
+ public void tearDown() throws Exception {
+ StaticTypePlanTransformer.clearForced();
+ super.tearDown();
+ }
+
+ @Test
+ public void testCreateSpec() {
+ EntitySpec<?> spec = mgmt.getTypeRegistry().createSpec(
+ RegisteredTypes.spec(specId, "1", new BasicTypeImplementationPlan(StaticTypePlanTransformer.FORMAT, null), Entity.class),
+ null, EntitySpec.class);
+ Assert.assertEquals(spec.getDisplayName(), DISPLAY_NAME);
+ Assert.assertEquals(spec.getType(), BasicEntity.class);
+ }
+
+ // there's a lot more which could be tested but at least we have a simple pathway asserting creation
+
+}