You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by ge...@apache.org on 2018/06/15 08:45:51 UTC
[2/4] brooklyn-server git commit: Add tests to
RegisteredTypes.arePlansEquivilant
Add tests to RegisteredTypes.arePlansEquivilant
Hopefully these show that we now ignore things like comments and strings
with surrounding quotes
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/c5e4e299
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/c5e4e299
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/c5e4e299
Branch: refs/heads/master
Commit: c5e4e2993e8f2448286cbf08295cd7eebb006daf
Parents: 066cbbf
Author: Duncan Grant <du...@cloudsoftcorp.com>
Authored: Tue Jun 5 16:24:23 2018 +0100
Committer: Duncan Grant <du...@cloudsoftcorp.com>
Committed: Tue Jun 5 16:24:23 2018 +0100
----------------------------------------------------------------------
.../brooklyn/core/typereg/RegisteredTypes.java | 2 +
.../core/typereg/RegisteredTypesTest.java | 123 +++++++++++++++++++
2 files changed, 125 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/c5e4e299/core/src/main/java/org/apache/brooklyn/core/typereg/RegisteredTypes.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/typereg/RegisteredTypes.java b/core/src/main/java/org/apache/brooklyn/core/typereg/RegisteredTypes.java
index 83e7f05..f76fcb1 100644
--- a/core/src/main/java/org/apache/brooklyn/core/typereg/RegisteredTypes.java
+++ b/core/src/main/java/org/apache/brooklyn/core/typereg/RegisteredTypes.java
@@ -25,10 +25,12 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.stream.StreamSupport;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
+import com.google.common.collect.Iterators;
import org.apache.brooklyn.api.catalog.CatalogItem;
import org.apache.brooklyn.api.catalog.CatalogItem.CatalogItemType;
import org.apache.brooklyn.api.internal.AbstractBrooklynObjectSpec;
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/c5e4e299/core/src/test/java/org/apache/brooklyn/core/typereg/RegisteredTypesTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/typereg/RegisteredTypesTest.java b/core/src/test/java/org/apache/brooklyn/core/typereg/RegisteredTypesTest.java
new file mode 100644
index 0000000..7162f61
--- /dev/null
+++ b/core/src/test/java/org/apache/brooklyn/core/typereg/RegisteredTypesTest.java
@@ -0,0 +1,123 @@
+package org.apache.brooklyn.core.typereg;
+
+import org.apache.brooklyn.api.typereg.BrooklynTypeRegistry;
+import org.apache.brooklyn.api.typereg.RegisteredType;
+import org.testng.annotations.Test;
+
+import javax.annotation.Nullable;
+
+import static org.testng.Assert.*;
+
+public class RegisteredTypesTest {
+
+ public static final String DRBD_YAML = "brooklyn.catalog:\n" +
+ " version: \"1.0.0-SNAPSHOT\" # BROOKLYN_DRBD_VERSION\n" +
+ " publish:\n" +
+ " description: |\n" +
+ " DRBD is a distributed replicated storage system for the Linux platform. It is implemented as a kernel driver, \n" +
+ " several userspace management applications, and some shell scripts. DRBD is traditionally used in high availability (HA) computer clusters to provide a\n" +
+ " RAID 1 like configuration over a network.\n" +
+ " license_code: Apache-2.0\n" +
+ " defaults:\n" +
+ " drbdIconUrl: \"https://s3.eu-central-1.amazonaws.com/misc-csft/drbd.jpg\"\n" +
+ " classpathIconUrl: &drbdIconUrl 'classpath://io.brooklyn.drbd.brooklyn-drbd:drbd.png'\n" +
+ " items:\n" +
+ " - \"https://github.com/brooklyncentral/common-catalog-utils/releases/download/v0.1.0/common.bom\"\n" +
+ " - id: drbd-node\n";
+
+ public static final String DRBD_TESTS_YAML = "brooklyn.catalog:\n" +
+ " version: \"1.0.0-SNAPSHOT\" # BROOKLYN_DRBD_VERSION\n" +
+ " items:\n" +
+ " - https://github.com/brooklyncentral/common-catalog-utils/releases/download/v0.1.0/common.tests.bom\n" +
+ " - id: drbd-test\n" +
+ " name: DRBD Test\n" +
+ " itemType: template\n" +
+ " iconUrl: https://s3.eu-central-1.amazonaws.com/misc-csft/drbd.jpg\n" +
+ " license: Apache-2.0\n" +
+ " item:\n" +
+ " booklyn.config:\n" +
+ " defaultDisplayName: DRBD Test\n" +
+ " services:\n" +
+ " - type: drbd-webapp\n";
+
+ public static final String DRBR_YAML_WITH_COMMENTS = DRBD_YAML + "\n" +
+ "# this is a comment";
+ private static final String DRBR_YAML_WITHOUT_QUOTES = "brooklyn.catalog:\n" +
+ " version: 1.0.0-SNAPSHOT # BROOKLYN_DRBD_VERSION\n" +
+ " publish:\n" +
+ " description: |\n" +
+ " DRBD is a distributed replicated storage system for the Linux platform. It is implemented as a kernel driver, \n" +
+ " several userspace management applications, and some shell scripts. DRBD is traditionally used in high availability (HA) computer clusters to provide a\n" +
+ " RAID 1 like configuration over a network.\n" +
+ " license_code: Apache-2.0\n" +
+ " defaults:\n" +
+ " drbdIconUrl: https://s3.eu-central-1.amazonaws.com/misc-csft/drbd.jpg\n" +
+ " classpathIconUrl: &drbdIconUrl 'classpath://io.brooklyn.drbd.brooklyn-drbd:drbd.png'\n" +
+ " items:\n" +
+ " - https://github.com/brooklyncentral/common-catalog-utils/releases/download/v0.1.0/common.bom\n" +
+ " - id: drbd-node\n";
+
+ @Test
+ public void testIdenticalPlansAreEquivalent() {
+ BasicRegisteredType a = makeTypeWithYaml(DRBD_YAML);
+
+ BasicRegisteredType b = makeTypeWithYaml(DRBD_YAML);
+
+ boolean plansEquivalent = RegisteredTypes.arePlansEquivalent(
+ a, b);
+ assertTrue(plansEquivalent);
+ }
+
+ @Test
+ public void testDifferentPlansAreNotEquivalent() {
+ BasicRegisteredType a = makeTypeWithYaml(DRBD_YAML);
+ BasicRegisteredType b = makeTypeWithYaml(DRBD_TESTS_YAML);
+
+ boolean plansEquivalent = RegisteredTypes.arePlansEquivalent(
+ a, b);
+ assertFalse(plansEquivalent);
+ }
+
+ @Test
+ public void testComparisonIgnoresComments() {
+ BasicRegisteredType a = makeTypeWithYaml(DRBD_YAML);
+
+ BasicRegisteredType b = makeTypeWithYaml(DRBR_YAML_WITH_COMMENTS);
+
+ boolean plansEquivalent = RegisteredTypes.arePlansEquivalent(
+ a, b);
+ assertTrue(plansEquivalent);
+ }
+
+ @Test
+ public void testComparisonIgnoresQuotedStrings() {
+ BasicRegisteredType a = makeTypeWithYaml(DRBD_YAML);
+
+ BasicRegisteredType b = makeTypeWithYaml(DRBR_YAML_WITHOUT_QUOTES);
+
+ boolean plansEquivalent = RegisteredTypes.arePlansEquivalent(
+ a, b);
+ assertTrue(plansEquivalent);
+ }
+
+ BasicRegisteredType makeTypeWithYaml(final String yaml) {
+ return new BasicRegisteredType(
+ BrooklynTypeRegistry.RegisteredTypeKind.SPEC,
+ "B",
+ "1",
+ new RegisteredType.TypeImplementationPlan() {
+ @Nullable
+ @Override
+ public String getPlanFormat() {
+ return null;
+ }
+
+ @Override
+ public Object getPlanData() {
+ return yaml;
+ }
+ });
+ }
+
+
+}
\ No newline at end of file