tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From antel...@apache.org
Subject svn commit: r808939 - in /tuscany/java/sca/modules/domain-node/src: main/java/org/apache/tuscany/sca/node/DomainNode.java test/java/org/apache/tuscany/sca/node/ConfigTestCase.java
Date Fri, 28 Aug 2009 16:12:45 GMT
Author: antelder
Date: Fri Aug 28 16:12:44 2009
New Revision: 808939

URL: http://svn.apache.org/viewvc?rev=808939&view=rev
Log:
Automatically change : to :// in domain node config uri to make it easier to type

Modified:
    tuscany/java/sca/modules/domain-node/src/main/java/org/apache/tuscany/sca/node/DomainNode.java
    tuscany/java/sca/modules/domain-node/src/test/java/org/apache/tuscany/sca/node/ConfigTestCase.java

Modified: tuscany/java/sca/modules/domain-node/src/main/java/org/apache/tuscany/sca/node/DomainNode.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/domain-node/src/main/java/org/apache/tuscany/sca/node/DomainNode.java?rev=808939&r1=808938&r2=808939&view=diff
==============================================================================
--- tuscany/java/sca/modules/domain-node/src/main/java/org/apache/tuscany/sca/node/DomainNode.java
(original)
+++ tuscany/java/sca/modules/domain-node/src/main/java/org/apache/tuscany/sca/node/DomainNode.java
Fri Aug 28 16:12:44 2009
@@ -115,7 +115,7 @@
     }
     
     protected void parseConfigURI(String configURI) {
-        URI uri = URI.create(configURI);
+        URI uri = URI.create(fixScheme(configURI));
         String dn = uri.getHost();
         if (dn == null || dn.length() < 1) {
             dn = DEFAULT_DOMAIN_NAME;
@@ -136,4 +136,19 @@
             }
         }
     }
+    
+    /**
+     * I keep typing the scheme part with just a colon instead of colon slash slash
+     * which URI doesn't parse properly which irritates me so fix it up here
+     */
+    private String fixScheme(String uri) {
+        int i = uri.indexOf(":");
+        if (i > -1 && uri.charAt(i+1) != '/') {
+            uri = uri.replaceFirst(":", ":/");
+        }
+        if (i > -1 && uri.charAt(i+2) != '/') {
+            uri = uri.replaceFirst(":/", "://");
+        }
+        return uri;
+    }
 }

Modified: tuscany/java/sca/modules/domain-node/src/test/java/org/apache/tuscany/sca/node/ConfigTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/domain-node/src/test/java/org/apache/tuscany/sca/node/ConfigTestCase.java?rev=808939&r1=808938&r2=808939&view=diff
==============================================================================
--- tuscany/java/sca/modules/domain-node/src/test/java/org/apache/tuscany/sca/node/ConfigTestCase.java
(original)
+++ tuscany/java/sca/modules/domain-node/src/test/java/org/apache/tuscany/sca/node/ConfigTestCase.java
Fri Aug 28 16:12:44 2009
@@ -39,4 +39,25 @@
         assertEquals("y", domain.getConfigAttributes().getAttributes().get("p2"));
     }
 
+    @Test
+    public void testConfig1() throws Exception {
+        DomainNode domain = new DomainNode("foo:someDomain:1234?p1=x&p2=y");
+        assertEquals(4,  domain.getConfigAttributes().getAttributes().size());
+        assertEquals("someDomain", domain.getDomainName());
+        assertEquals("foo", domain.getConfigAttributes().getAttributes().get("domainScheme"));
+        assertEquals("someDomain", domain.getConfigAttributes().getAttributes().get("domainName"));
+        assertEquals("x", domain.getConfigAttributes().getAttributes().get("p1"));
+        assertEquals("y", domain.getConfigAttributes().getAttributes().get("p2"));
+    }
+
+    @Test
+    public void testConfig2() throws Exception {
+        DomainNode domain = new DomainNode("foo:/someDomain:1234?p1=x&p2=y");
+        assertEquals(4,  domain.getConfigAttributes().getAttributes().size());
+        assertEquals("someDomain", domain.getDomainName());
+        assertEquals("foo", domain.getConfigAttributes().getAttributes().get("domainScheme"));
+        assertEquals("someDomain", domain.getConfigAttributes().getAttributes().get("domainName"));
+        assertEquals("x", domain.getConfigAttributes().getAttributes().get("p1"));
+        assertEquals("y", domain.getConfigAttributes().getAttributes().get("p2"));
+    }
 }



Mime
View raw message