You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by al...@apache.org on 2015/12/09 10:17:05 UTC

[1/2] incubator-brooklyn git commit: Fix assertions for 'succeeds eventually' behaviour.

Repository: incubator-brooklyn
Updated Branches:
  refs/heads/master 89440c303 -> b39ef3a82


Fix assertions for 'succeeds eventually' behaviour.

The following test case will not work with the code as currently defined:

```yaml
name: testcase1
location:
  mylocation
services:
- type: org.apache.brooklyn.entity.webapp.tomcat.TomcatServer
  id: tomcatServer
  timeout: 15m
- type: org.apache.brooklyn.test.framework.TestCase
  name: TomServTest
  brooklyn.children:
  - type: org.apache.brooklyn.test.framework.TestSensor
    target: $brooklyn:component("tomcatServer")
    sensor: service.isUp
    timeout: 1m
    assert:
    - equals: true
```

With the two entities (server and test) deployed independently instead of
within the same test case, the "checkAssertions" code will fail as it collects
all failures in AssertionSupport, when it should only collect those that
occur from the "Asserts.succeedsEventually".

Changing this code in this commit to allow tests to work.  The effect will
be that only one failed assertion will be reported on, even if many
assertions might fail. We can come back to this in order to see if multiple
assertion failures may be collected, but this is not necessary now.


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

Branch: refs/heads/master
Commit: 92cb905de2f621a88cf1713ff273c354954de0dd
Parents: 89440c3
Author: Geoff Macartney <ge...@cloudsoftcorp.com>
Authored: Tue Dec 8 14:35:59 2015 +0000
Committer: Geoff Macartney <ge...@cloudsoftcorp.com>
Committed: Tue Dec 8 18:26:17 2015 +0000

----------------------------------------------------------------------
 .../test/framework/TestFrameworkAssertions.java | 29 ++++++++++++--------
 1 file changed, 18 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/92cb905d/usage/test-framework/src/main/java/org/apache/brooklyn/test/framework/TestFrameworkAssertions.java
----------------------------------------------------------------------
diff --git a/usage/test-framework/src/main/java/org/apache/brooklyn/test/framework/TestFrameworkAssertions.java b/usage/test-framework/src/main/java/org/apache/brooklyn/test/framework/TestFrameworkAssertions.java
index fee68e6..0e61419 100644
--- a/usage/test-framework/src/main/java/org/apache/brooklyn/test/framework/TestFrameworkAssertions.java
+++ b/usage/test-framework/src/main/java/org/apache/brooklyn/test/framework/TestFrameworkAssertions.java
@@ -144,7 +144,7 @@ public class TestFrameworkAssertions {
                 @Override
                 public void run() {
                     T actual = actualSupplier.get();
-                    checkActualAgainstAssertions(support, assertions, target, actual);
+                    checkActualAgainstAssertions(assertions, target, actual);
                 }
             });
         } catch (Throwable t) {
@@ -152,7 +152,7 @@ public class TestFrameworkAssertions {
         }
     }
 
-    private static <T> void checkActualAgainstAssertions(AssertionSupport support, Map<String, Object> assertions,
+    private static <T> void checkActualAgainstAssertions(Map<String, Object> assertions,
                                                          String target, T actual) {
         for (Map.Entry<String, Object> assertion : assertions.entrySet()) {
             String condition = assertion.getKey().toString();
@@ -163,58 +163,65 @@ public class TestFrameworkAssertions {
                 case EQUAL_TO :
                 case EQUALS :
                     if (null == actual || !actual.equals(expected)) {
-                        support.fail(target, EQUALS, expected);
+                        failAssertion(target, EQUALS, expected);
                     }
                     break;
 
                 case IS_NULL :
                     if (isTrue(expected) != (null == actual)) {
-                        support.fail(target, IS_NULL, expected);
+                        failAssertion(target, IS_NULL, expected);
                     }
                     break;
 
                 case NOT_NULL :
                     if (isTrue(expected) != (null != actual)) {
-                        support.fail(target, NOT_NULL, expected);
+                        failAssertion(target, NOT_NULL, expected);
                     }
                     break;
 
                 case CONTAINS :
                     if (null == actual || !actual.toString().contains(expected.toString())) {
-                        support.fail(target, CONTAINS, expected);
+                        failAssertion(target, CONTAINS, expected);
                     }
                     break;
 
                 case IS_EMPTY :
                     if (isTrue(expected) != (null == actual || Strings.isEmpty(actual.toString()))) {
-                        support.fail(target, IS_EMPTY, expected);
+                        failAssertion(target, IS_EMPTY, expected);
                     }
                     break;
 
                 case NOT_EMPTY :
                     if (isTrue(expected) != ((null != actual && Strings.isNonEmpty(actual.toString())))) {
-                        support.fail(target, NOT_EMPTY, expected);
+                        failAssertion(target, NOT_EMPTY, expected);
                     }
                     break;
 
                 case MATCHES :
                     if (null == actual || !actual.toString().matches(expected.toString())) {
-                        support.fail(target, MATCHES, expected);
+                        failAssertion(target, MATCHES, expected);
                     }
                     break;
 
                 case HAS_TRUTH_VALUE :
                     if (isTrue(expected) != isTrue(actual)) {
-                        support.fail(target, HAS_TRUTH_VALUE, expected);
+                        failAssertion(target, HAS_TRUTH_VALUE, expected);
                     }
                     break;
 
                 default:
-                    support.fail(target, UNKNOWN_CONDITION, condition);
+                    failAssertion(target, UNKNOWN_CONDITION, condition);
             }
         }
     }
 
+    static void failAssertion(String target, String assertion, Object expected) {
+        throw new AssertionError(Joiner.on(' ').join(
+            null != target ? target : "null",
+            null != assertion ? assertion : "null",
+            null != expected ? expected : "null"));
+    }
+
     private static boolean isTrue(Object object) {
         return null != object && Boolean.valueOf(object.toString());
     }


[2/2] incubator-brooklyn git commit: This closes #1094

Posted by al...@apache.org.
This closes #1094


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

Branch: refs/heads/master
Commit: b39ef3a8270c7729e9b68e5ac9ec6161478ab0c2
Parents: 89440c3 92cb905
Author: Aled Sage <al...@gmail.com>
Authored: Wed Dec 9 09:16:51 2015 +0000
Committer: Aled Sage <al...@gmail.com>
Committed: Wed Dec 9 09:16:51 2015 +0000

----------------------------------------------------------------------
 .../test/framework/TestFrameworkAssertions.java | 29 ++++++++++++--------
 1 file changed, 18 insertions(+), 11 deletions(-)
----------------------------------------------------------------------