brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject [1/2] incubator-brooklyn git commit: added missing URI/URL to String coercions
Date Mon, 09 Nov 2015 12:30:00 GMT
Repository: incubator-brooklyn
Updated Branches:
  refs/heads/master 34142f939 -> 703354d68


added missing URI/URL to String coercions


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

Branch: refs/heads/master
Commit: 2700c406ead6c4fa2caad82c2c77cd9757f0e4f5
Parents: ae30539
Author: John McCabe <john@johnmccabe.net>
Authored: Mon Nov 9 11:42:09 2015 +0000
Committer: John McCabe <john@johnmccabe.net>
Committed: Mon Nov 9 11:42:09 2015 +0000

----------------------------------------------------------------------
 .../brooklyn/util/core/flags/TypeCoercions.java      | 12 ++++++++++++
 .../util/core/internal/TypeCoercionsTest.java        | 15 +++++++++++++++
 2 files changed, 27 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/2700c406/core/src/main/java/org/apache/brooklyn/util/core/flags/TypeCoercions.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/util/core/flags/TypeCoercions.java b/core/src/main/java/org/apache/brooklyn/util/core/flags/TypeCoercions.java
index ec49de7..f850fbd 100644
--- a/core/src/main/java/org/apache/brooklyn/util/core/flags/TypeCoercions.java
+++ b/core/src/main/java/org/apache/brooklyn/util/core/flags/TypeCoercions.java
@@ -586,12 +586,24 @@ public class TypeCoercions {
                 }
             }
         });
+        registerAdapter(URL.class, String.class, new Function<URL,String>() {
+            @Override
+            public String apply(URL input) {
+                return input.toString();
+            }
+        });
         registerAdapter(String.class, URI.class, new Function<String,URI>() {
             @Override
             public URI apply(String input) {
                 return URI.create(input);
             }
         });
+        registerAdapter(URI.class, String.class, new Function<URI,String>() {
+            @Override
+            public String apply(URI input) {
+                return input.toString();
+            }
+        });
         registerAdapter(Closure.class, ConfigurableEntityFactory.class, new Function<Closure,ConfigurableEntityFactory>()
{
             @SuppressWarnings("unchecked")
             @Override

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/2700c406/core/src/test/java/org/apache/brooklyn/util/core/internal/TypeCoercionsTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/util/core/internal/TypeCoercionsTest.java
b/core/src/test/java/org/apache/brooklyn/util/core/internal/TypeCoercionsTest.java
index ec89ebf..47d4c49 100644
--- a/core/src/test/java/org/apache/brooklyn/util/core/internal/TypeCoercionsTest.java
+++ b/core/src/test/java/org/apache/brooklyn/util/core/internal/TypeCoercionsTest.java
@@ -23,6 +23,9 @@ import static org.testng.Assert.assertNull;
 
 import java.math.BigDecimal;
 import java.math.BigInteger;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URL;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.List;
@@ -319,6 +322,18 @@ public class TypeCoercionsTest {
     }
 
     @Test
+    public void testURItoStringCoercion() {
+        String s = TypeCoercions.coerce(URI.create("http://localhost:1234/"), String.class);
+        Assert.assertEquals(s, "http://localhost:1234/");
+    }
+
+    @Test
+    public void testURLtoStringCoercion() throws MalformedURLException {
+        String s = TypeCoercions.coerce(new URL("http://localhost:1234/"), String.class);
+        Assert.assertEquals(s, "http://localhost:1234/");
+    }
+
+    @Test
     public void testAs() {
         Integer x = TypeCoercions.coerce(new WithAs("3"), Integer.class);
         Assert.assertEquals(x, (Integer)3);


Mime
View raw message