brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sjcorb...@apache.org
Subject [1/8] incubator-brooklyn git commit: Fix String -> Lifecycle coercion for ON_FIRE
Date Thu, 14 May 2015 09:59:52 GMT
Repository: incubator-brooklyn
Updated Branches:
  refs/heads/master 3fe40c7b5 -> d78c1725d


Fix String -> Lifecycle coercion for ON_FIRE


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

Branch: refs/heads/master
Commit: d7ff98a0711edfa194fc8d528818a97abc13f6ba
Parents: d0cbcf3
Author: Svetoslav Neykov <svetoslav.neykov@cloudsoftcorp.com>
Authored: Tue May 12 14:45:35 2015 +0300
Committer: Svetoslav Neykov <svetoslav.neykov@cloudsoftcorp.com>
Committed: Tue May 12 14:45:35 2015 +0300

----------------------------------------------------------------------
 .../java/brooklyn/entity/basic/Lifecycle.java    |  4 ++--
 .../entity/basic/LifecycleTransitionTest.java    | 19 ++++++++++++++++---
 2 files changed, 18 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/d7ff98a0/core/src/main/java/brooklyn/entity/basic/Lifecycle.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/entity/basic/Lifecycle.java b/core/src/main/java/brooklyn/entity/basic/Lifecycle.java
index 2c8c237..d4449a1 100644
--- a/core/src/main/java/brooklyn/entity/basic/Lifecycle.java
+++ b/core/src/main/java/brooklyn/entity/basic/Lifecycle.java
@@ -158,14 +158,14 @@ public enum Lifecycle {
     }
     
     protected static class TransitionCoalesceFunction implements Function<String, Transition>
{
-        private static final Pattern TRANSITION_PATTERN = Pattern.compile("^(\\w+)\\s+@\\s+(\\d+).*");
+        private static final Pattern TRANSITION_PATTERN = Pattern.compile("^([\\w-]+)\\s+@\\s+(\\d+).*");
 
         @Override
         public Transition apply(final String input) {
             if (input != null) {
                 Matcher m = TRANSITION_PATTERN.matcher(input);
                 if (m.matches()) {
-                    Lifecycle state = Lifecycle.valueOf(m.group(1).toUpperCase());
+                    Lifecycle state = Lifecycle.valueOf(m.group(1).toUpperCase().replace('-',
'_'));
                     long time = Long.parseLong(m.group(2));
                     return new Transition(state, new Date(time));
                 } else {

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/d7ff98a0/core/src/test/java/brooklyn/entity/basic/LifecycleTransitionTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/brooklyn/entity/basic/LifecycleTransitionTest.java b/core/src/test/java/brooklyn/entity/basic/LifecycleTransitionTest.java
index 7b5806e..686424d 100644
--- a/core/src/test/java/brooklyn/entity/basic/LifecycleTransitionTest.java
+++ b/core/src/test/java/brooklyn/entity/basic/LifecycleTransitionTest.java
@@ -22,15 +22,28 @@ import static org.testng.Assert.assertTrue;
 
 import java.util.Date;
 
+import org.testng.annotations.DataProvider;
 import org.testng.annotations.Test;
 
 import brooklyn.entity.basic.Lifecycle.Transition;
 import brooklyn.entity.basic.Lifecycle.TransitionCoalesceFunction;
 
 public class LifecycleTransitionTest {
-    @Test
-    public void testTransitionCoalesce() {
-        Transition t = new Transition(Lifecycle.RUNNING, new Date());
+    @DataProvider(name = "states")
+    public Object[][] generateLifecycleStates() {
+        Object[][] states = new Object[Lifecycle.values().length][];
+        int i = 0;
+        for (Lifecycle state : Lifecycle.values()) {
+            System.out.println(":" + state);
+            states[i] = new Object[] {state};
+            i++;
+        }
+        return states;
+    }
+
+    @Test(dataProvider="states")
+    public void testTransitionCoalesce(Lifecycle state) {
+        Transition t = new Transition(state, new Date());
         String serialized = t.toString();
         Transition t2 = new TransitionCoalesceFunction().apply(serialized);
         assertTrue(t.equals(t2), "Deserialized Lifecycle.Transition not equal to original");


Mime
View raw message