Refactor tests to be more readable

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

Branch: refs/heads/master
Commit: 1962b04e539d08154000c70559213e8b54c7191d
Parents: c5e4e29
Author: Duncan Grant <duncan.gr...@cloudsoftcorp.com>
Authored: Tue Jun 12 16:12:26 2018 +0100
Committer: Duncan Grant <duncan.gr...@cloudsoftcorp.com>
Committed: Tue Jun 12 16:21:35 2018 +0100

----------------------------------------------------------------------
 .../core/typereg/RegisteredTypesTest.java       | 133 ++++++++++---------
 1 file changed, 67 insertions(+), 66 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/1962b04e/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
index 7162f61..ae137c2 100644
--- 
a/core/src/test/java/org/apache/brooklyn/core/typereg/RegisteredTypesTest.java
+++ 
b/core/src/test/java/org/apache/brooklyn/core/typereg/RegisteredTypesTest.java
@@ -1,7 +1,27 @@
+/*
+ * 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 org.apache.brooklyn.api.typereg.BrooklynTypeRegistry;
 import org.apache.brooklyn.api.typereg.RegisteredType;
+import org.apache.brooklyn.util.text.Strings;
+import org.testng.Assert;
 import org.testng.annotations.Test;
 
 import javax.annotation.Nullable;
@@ -10,94 +30,75 @@ 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";
+    private static final String DRBD_YAML = Strings.lines(
+            "brooklyn.catalog:",
+            "  version: \"1.0.0-SNAPSHOT\" # BROOKLYN_DRBD_VERSION",
+            "  items:",
+            "  - 
\"https://github.com/brooklyncentral/common-catalog-utils/releases/download/v0.1.0/common.bom\"";,
+            "  - id: drbd-node");
+
+    private static final String DRBD_TESTS_YAML = Strings.lines(
+            "brooklyn.catalog:",
+            "  version: \"1.0.0-SNAPSHOT\" # BROOKLYN_DRBD_VERSION",
+            "  items:",
+            "  - 
https://github.com/brooklyncentral/common-catalog-utils/releases/download/v0.1.0/common.tests.bom\n";);
+
+    private static final String DRBR_YAML_WITH_COMMENTS = Strings.lines(
+            DRBD_YAML,
+            "# this is a comment");
+
+    private static final String DRBR_YAML_WITHOUT_QUOTES = Strings.lines(
+            "brooklyn.catalog:",
+            "  version: 1.0.0-SNAPSHOT # BROOKLYN_DRBD_VERSION",
+            "  items:",
+            "  - 
https://github.com/brooklyncentral/common-catalog-utils/releases/download/v0.1.0/common.bom";,
+            "  - id: drbd-node");
 
     @Test
     public void testIdenticalPlansAreEquivalent() {
-        BasicRegisteredType a = makeTypeWithYaml(DRBD_YAML);
+        BasicRegisteredType planA = makeTypeWithYaml(DRBD_YAML);
 
-        BasicRegisteredType b = makeTypeWithYaml(DRBD_YAML);
+        BasicRegisteredType planB = makeTypeWithYaml(DRBD_YAML);
 
-        boolean plansEquivalent = RegisteredTypes.arePlansEquivalent(
-                a, b);
-        assertTrue(plansEquivalent);
+        assertPlansEquivalent(planA, planB, "Identical plans");
     }
 
     @Test
     public void testDifferentPlansAreNotEquivalent() {
-        BasicRegisteredType a = makeTypeWithYaml(DRBD_YAML);
-        BasicRegisteredType b = makeTypeWithYaml(DRBD_TESTS_YAML);
+        BasicRegisteredType planA = makeTypeWithYaml(DRBD_YAML);
+        BasicRegisteredType planB = makeTypeWithYaml(DRBD_TESTS_YAML);
 
-        boolean plansEquivalent = RegisteredTypes.arePlansEquivalent(
-                a, b);
-        assertFalse(plansEquivalent);
+        assertPlansDifferent(planA, planB, "Completely different plans");
     }
 
     @Test
     public void testComparisonIgnoresComments() {
-        BasicRegisteredType a = makeTypeWithYaml(DRBD_YAML);
+        BasicRegisteredType planA = makeTypeWithYaml(DRBD_YAML);
 
-        BasicRegisteredType b = makeTypeWithYaml(DRBR_YAML_WITH_COMMENTS);
+        BasicRegisteredType planB = makeTypeWithYaml(DRBR_YAML_WITH_COMMENTS);
 
-        boolean plansEquivalent = RegisteredTypes.arePlansEquivalent(
-                a, b);
-        assertTrue(plansEquivalent);
+        assertPlansEquivalent(planA, planB, "Only difference comments");
     }
 
     @Test
     public void testComparisonIgnoresQuotedStrings() {
-        BasicRegisteredType a = makeTypeWithYaml(DRBD_YAML);
+        BasicRegisteredType planA = makeTypeWithYaml(DRBD_YAML);
 
-        BasicRegisteredType b = makeTypeWithYaml(DRBR_YAML_WITHOUT_QUOTES);
+        BasicRegisteredType planB = makeTypeWithYaml(DRBR_YAML_WITHOUT_QUOTES);
 
-        boolean plansEquivalent = RegisteredTypes.arePlansEquivalent(
-                a, b);
-        assertTrue(plansEquivalent);
+        assertPlansEquivalent(planA, planB, "Compares same yaml with and 
without quotes");
+    }
+
+    private void assertPlansDifferent(BasicRegisteredType planA, 
BasicRegisteredType planB, String messageOnError) {
+        assertFalse(RegisteredTypes.arePlansEquivalent(planA, planB), 
createErrorMessage("Plans equivalent: ", planA, planB, messageOnError));
+    }
+
+    private void assertPlansEquivalent(BasicRegisteredType planA, 
BasicRegisteredType planB, String messageOnError) {
+        assertTrue(RegisteredTypes.arePlansEquivalent(planA, planB), 
createErrorMessage("Plans differ: ",planA, planB, messageOnError));
+    }
+
+    private String createErrorMessage(String issue, BasicRegisteredType planA, 
BasicRegisteredType planB, String messageOnError) {
+        return Strings.lines(issue + messageOnError, planA.toString(), 
planB.toString());
     }
 
     BasicRegisteredType makeTypeWithYaml(final String yaml) {

Reply via email to