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 2017/04/06 11:08:44 UTC

[1/5] brooklyn-server git commit: Javadoc typo

Repository: brooklyn-server
Updated Branches:
  refs/heads/master b60863556 -> ff7cde116


Javadoc typo


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

Branch: refs/heads/master
Commit: 1962dda252164d79ed41a8d6e7d96c033e772d5d
Parents: ac89fbc
Author: Sam Corbett <sa...@cloudsoftcorp.com>
Authored: Tue Mar 21 17:10:48 2017 +0000
Committer: Sam Corbett <sa...@cloudsoftcorp.com>
Committed: Wed Apr 5 17:54:36 2017 +0100

----------------------------------------------------------------------
 .../src/main/java/org/apache/brooklyn/util/net/Networking.java     | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/1962dda2/utils/common/src/main/java/org/apache/brooklyn/util/net/Networking.java
----------------------------------------------------------------------
diff --git a/utils/common/src/main/java/org/apache/brooklyn/util/net/Networking.java b/utils/common/src/main/java/org/apache/brooklyn/util/net/Networking.java
index 79e3739..f944b77 100644
--- a/utils/common/src/main/java/org/apache/brooklyn/util/net/Networking.java
+++ b/utils/common/src/main/java/org/apache/brooklyn/util/net/Networking.java
@@ -406,7 +406,7 @@ public class Networking {
     
     /**
      * Gets an InetAddress using the given hostname or IP. If it is an IPv4 address, then this is equivalent
-     * to {@link getInetAddressWithFixedName(byte[])}. If it is a hostname, then this hostname will be used
+     * to {@link #getInetAddressWithFixedName(byte[])}. If it is a hostname, then this hostname will be used
      * in the returned InetAddress.
      */
     public static InetAddress getInetAddressWithFixedName(String hostnameOrIp) {


[5/5] brooklyn-server git commit: Closes #619

Posted by ge...@apache.org.
Closes #619

Add greaterThan and lessThan test framework assertions

Each relies on the two objects being compared being instances of the same `Comparable<T>`.

I also took the opportunity to simplify the logic in `TestAssertions`.


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

Branch: refs/heads/master
Commit: ff7cde11639e49684f4baf86e9000dfb24feffa5
Parents: b608635 c51c69a
Author: Geoff Macartney <ge...@cloudsoftcorp.com>
Authored: Thu Apr 6 12:08:34 2017 +0100
Committer: Geoff Macartney <ge...@cloudsoftcorp.com>
Committed: Thu Apr 6 12:08:34 2017 +0100

----------------------------------------------------------------------
 .../util/core/xstream/XmlSerializerTest.java    |   1 -
 .../test/framework/TestFrameworkAssertions.java | 197 +++++++------------
 .../framework/TestFrameworkAssertionsTest.java  |  24 ++-
 .../apache/brooklyn/util/net/Networking.java    |   2 +-
 4 files changed, 97 insertions(+), 127 deletions(-)
----------------------------------------------------------------------



[4/5] brooklyn-server git commit: Add greaterThan and lessThan test framework assertions

Posted by ge...@apache.org.
Add greaterThan and lessThan test framework assertions

Relies on the two objects being compared being instances of
Comparable<T>.


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

Branch: refs/heads/master
Commit: c51c69a2612adf3d10ae16f01b4e20d1f37e6297
Parents: 1578088
Author: Sam Corbett <sa...@cloudsoftcorp.com>
Authored: Thu Apr 6 10:16:54 2017 +0100
Committer: Sam Corbett <sa...@cloudsoftcorp.com>
Committed: Thu Apr 6 10:20:15 2017 +0100

----------------------------------------------------------------------
 .../test/framework/TestFrameworkAssertions.java | 27 +++++++++++++++++++-
 .../framework/TestFrameworkAssertionsTest.java  | 24 +++++++++++++++--
 2 files changed, 48 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/c51c69a2/test-framework/src/main/java/org/apache/brooklyn/test/framework/TestFrameworkAssertions.java
----------------------------------------------------------------------
diff --git a/test-framework/src/main/java/org/apache/brooklyn/test/framework/TestFrameworkAssertions.java b/test-framework/src/main/java/org/apache/brooklyn/test/framework/TestFrameworkAssertions.java
index c344557..68d51d8 100644
--- a/test-framework/src/main/java/org/apache/brooklyn/test/framework/TestFrameworkAssertions.java
+++ b/test-framework/src/main/java/org/apache/brooklyn/test/framework/TestFrameworkAssertions.java
@@ -66,6 +66,8 @@ public class TestFrameworkAssertions {
     public static final String IS_EMPTY = "isEmpty";
     public static final String NOT_EMPTY = "notEmpty";
     public static final String HAS_TRUTH_VALUE = "hasTruthValue";
+    public static final String GREATER_THAN = "greaterThan";
+    public static final String LESS_THAN = "lessThan";
     public static final String UNKNOWN_CONDITION = "unknown condition";
 
     public static class AssertionOptions {
@@ -334,6 +336,10 @@ public class TestFrameworkAssertions {
             return null != actual && actual.toString().matches(expected.toString());
         case HAS_TRUTH_VALUE:
             return isTrue(expected) == isTrue(actual);
+        case GREATER_THAN:
+            return canCompare(actual, expected) && compare(actual, expected) > 0;
+        case LESS_THAN:
+            return canCompare(actual, expected) && compare(actual, expected) < 0;
         default:
             return false;
         }
@@ -343,10 +349,29 @@ public class TestFrameworkAssertions {
         // Everything but UNKNOWN_CONDITION. The conditions should really be an enum!
         Set<String> allConditions = ImmutableSet.of(
                 IS_NULL, NOT_NULL, IS_EQUAL_TO, EQUAL_TO, EQUALS, NOT_EQUAL,
-                MATCHES, CONTAINS, IS_EMPTY, NOT_EMPTY, HAS_TRUTH_VALUE);
+                MATCHES, CONTAINS, IS_EMPTY, NOT_EMPTY, HAS_TRUTH_VALUE,
+                GREATER_THAN, LESS_THAN);
         return allConditions.contains(condition);
     }
 
+    /** @return True if actual and expected are both non-null instances of {@code Comparable<T>}. */
+    private static boolean canCompare(@Nullable Object actual, @Nullable Object expected) {
+        return actual != null
+                && expected != null
+                && actual instanceof Comparable
+                && actual.getClass().equals(expected.getClass());
+    }
+
+    @SuppressWarnings("unchecked")
+    private static int compare(@Nullable Object actual, @Nullable Object expected) {
+        if (!canCompare(actual, expected)) {
+            throw new IllegalArgumentException("Arguments are not comparable: " + actual + ", " + expected);
+        }
+        Comparable a = (Comparable) actual;
+        Comparable e = (Comparable) expected;
+        return a.compareTo(e);
+    }
+
     static void failAssertion(String target, String assertion, Object expected, Object actual) {
         throw new AssertionError(Joiner.on(' ').join(
             Objects.toString(target),

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/c51c69a2/test-framework/src/test/java/org/apache/brooklyn/test/framework/TestFrameworkAssertionsTest.java
----------------------------------------------------------------------
diff --git a/test-framework/src/test/java/org/apache/brooklyn/test/framework/TestFrameworkAssertionsTest.java b/test-framework/src/test/java/org/apache/brooklyn/test/framework/TestFrameworkAssertionsTest.java
index 3999952..360f072 100644
--- a/test-framework/src/test/java/org/apache/brooklyn/test/framework/TestFrameworkAssertionsTest.java
+++ b/test-framework/src/test/java/org/apache/brooklyn/test/framework/TestFrameworkAssertionsTest.java
@@ -21,6 +21,7 @@ package org.apache.brooklyn.test.framework;
 import static org.testng.Assert.assertTrue;
 
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -28,6 +29,7 @@ import java.util.Objects;
 
 import org.apache.brooklyn.test.Asserts;
 import org.apache.brooklyn.test.framework.TestFrameworkAssertions.AssertionOptions;
+import org.apache.brooklyn.util.collections.MutableMap;
 import org.apache.brooklyn.util.text.Identifiers;
 import org.apache.brooklyn.util.time.Duration;
 import org.slf4j.Logger;
@@ -71,6 +73,12 @@ public class TestFrameworkAssertionsTest {
                 {"some-non-null-value", Arrays.asList(ImmutableMap.of("notEmpty", Boolean.TRUE))},
                 {"true", Arrays.asList(ImmutableMap.of("hasTruthValue", Boolean.TRUE))},
                 {"false", Arrays.asList(ImmutableMap.of("hasTruthValue", Boolean.FALSE))},
+
+                {25, Collections.singletonList(ImmutableMap.of("greaterThan", 24))},
+                {"b", Collections.singletonList(ImmutableMap.of("greaterThan", "a"))},
+                {24, Collections.singletonList(ImmutableMap.of("lessThan", 25))},
+                {"a", Collections.singletonList(ImmutableMap.of("lessThan", "b"))},
+
                 {"some-non-null-value", Arrays.asList(ImmutableMap.of("hasTruthValue", Boolean.FALSE))},
         };
     }
@@ -137,6 +145,18 @@ public class TestFrameworkAssertionsTest {
                 {"<html><body><h1>Im a H1 tag!</h1></body></html>", "contains", "quack", Arrays.asList(ImmutableMap.of("contains", "quack"))},
                 {"{\"a\":\"b\",\"c\":\"d\",\"e\":123,\"g\":false}", "contains", "moo", Arrays.asList(ImmutableMap.of("contains", "moo"))},
 
+                {25, "lessThan", 24, Collections.singletonList(ImmutableMap.of("lessThan", 24))},
+                {"b", "lessThan", "a", Collections.singletonList(ImmutableMap.of("lessThan", "a"))},
+                {null, "lessThan", "a", Collections.singletonList(ImmutableMap.of("lessThan", "a"))},
+                {"a", "lessThan", null, Collections.singletonList(MutableMap.of("lessThan", null))},
+                {5, "lessThan", 5, Collections.singletonList(ImmutableMap.of("lessThan", 5))},
+
+                {24, "greaterThan", 25, Collections.singletonList(ImmutableMap.of("greaterThan", 25))},
+                {"a", "greaterThan", "b", Collections.singletonList(ImmutableMap.of("greaterThan", "b"))},
+                {null, "greaterThan", "a", Collections.singletonList(ImmutableMap.of("greaterThan", "a"))},
+                {"a", "greaterThan", null, Collections.singletonList(MutableMap.of("greaterThan", null))},
+                {5, "greaterThan", 5, Collections.singletonList(ImmutableMap.of("greaterThan", 5))},
+
                 {"true", "hasTruthValue", Boolean.FALSE, Arrays.asList(ImmutableMap.of("hasTruthValue", Boolean.FALSE))},
                 {"false", "hasTruthValue", Boolean.TRUE, Arrays.asList(ImmutableMap.of("hasTruthValue", Boolean.TRUE))},
                 {"some-not-null-value", "hasTruthValue", Boolean.TRUE, Arrays.asList(ImmutableMap.of("hasTruthValue", Boolean.TRUE))}
@@ -161,7 +181,7 @@ public class TestFrameworkAssertionsTest {
                     .timeout(timeout).assertions(assertions));
             Asserts.shouldHaveFailedPreviously();
         } catch (AssertionError e) {
-            Asserts.expectedFailureContains(e, Objects.toString(data), condition, expected.toString());
+            Asserts.expectedFailureContains(e, Objects.toString(data), condition, expected != null ? expected.toString() : "null");
         }
     }
 
@@ -187,7 +207,7 @@ public class TestFrameworkAssertionsTest {
                     .assertions(assertions));
             Asserts.shouldHaveFailedPreviously();
         } catch (AssertionError e) {
-            Asserts.expectedFailureContains(e, Objects.toString(data), condition, expected.toString());
+            Asserts.expectedFailureContains(e, Objects.toString(data), condition, expected != null ? expected.toString() : "null");
         }
     }
 


[2/5] brooklyn-server git commit: Delete System.out call in XmlSerializerTest.assertSerializeAndDeserialize

Posted by ge...@apache.org.
Delete System.out call in XmlSerializerTest.assertSerializeAndDeserialize

It breaks output in tmux


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

Branch: refs/heads/master
Commit: ac89fbcbde998227d971b35c6d5042ee1da6691f
Parents: 022be36
Author: Sam Corbett <sa...@cloudsoftcorp.com>
Authored: Tue Mar 21 15:40:25 2017 +0000
Committer: Sam Corbett <sa...@cloudsoftcorp.com>
Committed: Wed Apr 5 17:54:36 2017 +0100

----------------------------------------------------------------------
 .../org/apache/brooklyn/util/core/xstream/XmlSerializerTest.java    | 1 -
 1 file changed, 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/ac89fbcb/core/src/test/java/org/apache/brooklyn/util/core/xstream/XmlSerializerTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/util/core/xstream/XmlSerializerTest.java b/core/src/test/java/org/apache/brooklyn/util/core/xstream/XmlSerializerTest.java
index 13ccb38..bb55f87 100644
--- a/core/src/test/java/org/apache/brooklyn/util/core/xstream/XmlSerializerTest.java
+++ b/core/src/test/java/org/apache/brooklyn/util/core/xstream/XmlSerializerTest.java
@@ -102,7 +102,6 @@ public class XmlSerializerTest {
     protected void assertSerializeAndDeserialize(Object val) throws Exception {
         String xml = serializer.toString(val);
         Object result = serializer.fromString(xml);
-        System.out.println("val="+val+"'; xml="+xml+"; result="+result);
         LOG.debug("val="+val+"'; xml="+xml+"; result="+result);
         assertEquals(result, val);
     }


[3/5] brooklyn-server git commit: Simplify test case assertion handling

Posted by ge...@apache.org.
Simplify test case assertion handling


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

Branch: refs/heads/master
Commit: 1578088e7f1bece760f2d7843be8954cba1d5da2
Parents: 1962dda
Author: Sam Corbett <sa...@cloudsoftcorp.com>
Authored: Wed Apr 5 17:51:30 2017 +0100
Committer: Sam Corbett <sa...@cloudsoftcorp.com>
Committed: Thu Apr 6 10:20:15 2017 +0100

----------------------------------------------------------------------
 .../test/framework/TestFrameworkAssertions.java | 172 ++++++-------------
 1 file changed, 49 insertions(+), 123 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/1578088e/test-framework/src/main/java/org/apache/brooklyn/test/framework/TestFrameworkAssertions.java
----------------------------------------------------------------------
diff --git a/test-framework/src/main/java/org/apache/brooklyn/test/framework/TestFrameworkAssertions.java b/test-framework/src/main/java/org/apache/brooklyn/test/framework/TestFrameworkAssertions.java
index 9484ab5..c344557 100644
--- a/test-framework/src/main/java/org/apache/brooklyn/test/framework/TestFrameworkAssertions.java
+++ b/test-framework/src/main/java/org/apache/brooklyn/test/framework/TestFrameworkAssertions.java
@@ -23,7 +23,9 @@ import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
+import java.util.Set;
 import java.util.concurrent.Callable;
+import javax.annotation.Nullable;
 
 import org.apache.brooklyn.api.entity.Entity;
 import org.apache.brooklyn.config.ConfigKey;
@@ -44,6 +46,7 @@ import com.google.common.base.Predicate;
 import com.google.common.base.Predicates;
 import com.google.common.base.Supplier;
 import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
 import com.google.common.reflect.TypeToken;
 
 
@@ -287,140 +290,63 @@ public class TestFrameworkAssertions {
     protected static <T> void checkActualAgainstAssertions(Map<String, ?> assertions,
             String target, T actual) {
         for (Map.Entry<String, ?> assertion : assertions.entrySet()) {
-            String condition = assertion.getKey().toString();
+            String condition = assertion.getKey();
             Object expected = assertion.getValue();
-            switch (condition) {
-
-                case IS_EQUAL_TO :
-                case EQUAL_TO :
-                case EQUALS :
-                    if (null == actual || !actual.equals(expected)) {
-                        failAssertion(target, condition, expected, actual);
-                    }
-                    break;
-
-                case NOT_EQUAL :
-                    if (Objects.equals(actual, expected)) {
-                        failAssertion(target, condition, expected, actual);
-                    }
-                    break;
-                    
-                case IS_NULL :
-                    if (isTrue(expected) != (null == actual)) {
-                        failAssertion(target, condition, expected, actual);
-                    }
-                    break;
-
-                case NOT_NULL :
-                    if (isTrue(expected) != (null != actual)) {
-                        failAssertion(target, condition, expected, actual);
-                    }
-                    break;
-
-                case CONTAINS :
-                    if (null == actual || !actual.toString().contains(expected.toString())) {
-                        failAssertion(target, condition, expected, actual);
-                    }
-                    break;
-
-                case IS_EMPTY :
-                    if (isTrue(expected) != (null == actual || Strings.isEmpty(actual.toString()))) {
-                        failAssertion(target, condition, expected, actual);
-                    }
-                    break;
-
-                case NOT_EMPTY :
-                    if (isTrue(expected) != ((null != actual && Strings.isNonEmpty(actual.toString())))) {
-                        failAssertion(target, condition, expected, actual);
-                    }
-                    break;
-
-                case MATCHES :
-                    if (null == actual || !actual.toString().matches(expected.toString())) {
-                        failAssertion(target, condition, expected, actual);
-                    }
-                    break;
-
-                case HAS_TRUTH_VALUE :
-                    if (isTrue(expected) != isTrue(actual)) {
-                        failAssertion(target, condition, expected, actual);
-                    }
-                    break;
-
-                default:
-                    failAssertion(target, UNKNOWN_CONDITION, condition, actual);
+            if (!knownCondition(condition)) {
+                failAssertion(target, UNKNOWN_CONDITION, expected, actual);
+            } else if (!conditionHolds(condition, actual, expected)) {
+                failAssertion(target, condition, expected, actual);
             }
         }
     }
 
     protected static <T> void checkActualAgainstAbortConditions(Map<String, ?> assertions, String target, T actual) {
         for (Map.Entry<String, ?> assertion : assertions.entrySet()) {
-            String condition = assertion.getKey().toString();
+            String condition = assertion.getKey();
             Object expected = assertion.getValue();
-            switch (condition) {
-
-                case IS_EQUAL_TO :
-                case EQUAL_TO :
-                case EQUALS :
-                    if (null != actual && actual.equals(expected)) {
-                        abort(target, condition, expected, actual);
-                    }
-                    break;
-
-                case NOT_EQUAL :
-                    if (!Objects.equals(actual, expected)) {
-                        abort(target, condition, expected, actual);
-                    }
-                    break;
-                    
-                case IS_NULL :
-                    if (isTrue(expected) == (null == actual)) {
-                        abort(target, condition, expected, actual);
-                    }
-                    break;
-
-                case NOT_NULL :
-                    if (isTrue(expected) == (null != actual)) {
-                        abort(target, condition, expected, actual);
-                    }
-                    break;
-
-                case CONTAINS :
-                    if (null != actual && actual.toString().contains(expected.toString())) {
-                        abort(target, condition, expected, actual);
-                    }
-                    break;
-
-                case IS_EMPTY :
-                    if (isTrue(expected) == (null == actual || Strings.isEmpty(actual.toString()))) {
-                        abort(target, condition, expected, actual);
-                    }
-                    break;
-
-                case NOT_EMPTY :
-                    if (isTrue(expected) == ((null != actual && Strings.isNonEmpty(actual.toString())))) {
-                        abort(target, condition, expected, actual);
-                    }
-                    break;
-
-                case MATCHES :
-                    if (null != actual && actual.toString().matches(expected.toString())) {
-                        abort(target, condition, expected, actual);
-                    }
-                    break;
-
-                case HAS_TRUTH_VALUE :
-                    if (isTrue(expected) == isTrue(actual)) {
-                        abort(target, condition, expected, actual);
-                    }
-                    break;
-
-                default:
-                    abort(target, condition, expected, actual);
+            if (!knownCondition(condition)) {
+                abort(target, UNKNOWN_CONDITION, expected, actual);
+            } else if (conditionHolds(condition, actual, expected)) {
+                abort(target, condition, expected, actual);
             }
         }
     }
-    
+
+    private static boolean conditionHolds(String condition, Object actual, Object expected) {
+        switch (condition) {
+        case IS_EQUAL_TO:
+        case EQUAL_TO:
+        case EQUALS:
+            return null != actual && actual.equals(expected);
+        case NOT_EQUAL:
+            return !Objects.equals(actual, expected);
+        case IS_NULL:
+            return isTrue(expected) == (null == actual);
+        case NOT_NULL:
+            return isTrue(expected) == (null != actual);
+        case CONTAINS:
+            return null != actual && actual.toString().contains(expected.toString());
+        case IS_EMPTY:
+            return isTrue(expected) == (null == actual || Strings.isEmpty(actual.toString()));
+        case NOT_EMPTY:
+            return isTrue(expected) == ((null != actual && Strings.isNonEmpty(actual.toString())));
+        case MATCHES:
+            return null != actual && actual.toString().matches(expected.toString());
+        case HAS_TRUTH_VALUE:
+            return isTrue(expected) == isTrue(actual);
+        default:
+            return false;
+        }
+    }
+
+    private static boolean knownCondition(String condition) {
+        // Everything but UNKNOWN_CONDITION. The conditions should really be an enum!
+        Set<String> allConditions = ImmutableSet.of(
+                IS_NULL, NOT_NULL, IS_EQUAL_TO, EQUAL_TO, EQUALS, NOT_EQUAL,
+                MATCHES, CONTAINS, IS_EMPTY, NOT_EMPTY, HAS_TRUTH_VALUE);
+        return allConditions.contains(condition);
+    }
+
     static void failAssertion(String target, String assertion, Object expected, Object actual) {
         throw new AssertionError(Joiner.on(' ').join(
             Objects.toString(target),