Author: rareddy
Date: 2010-08-11 15:56:01 -0400 (Wed, 11 Aug 2010)
New Revision: 2442
Modified:
trunk/client/src/test/java/org/teiid/adminapi/impl/TestVDBMetaData.java
trunk/common-core/src/main/java/org/teiid/core/util/StringUtil.java
trunk/common-core/src/test/java/org/teiid/core/util/TestStringUtil.java
Log:
TEIID-1201: Making the "StringUtil.valueOf" aware of the generation URL as the
object.
Modified: trunk/client/src/test/java/org/teiid/adminapi/impl/TestVDBMetaData.java
===================================================================
--- trunk/client/src/test/java/org/teiid/adminapi/impl/TestVDBMetaData.java 2010-08-11
19:55:00 UTC (rev 2441)
+++ trunk/client/src/test/java/org/teiid/adminapi/impl/TestVDBMetaData.java 2010-08-11
19:56:01 UTC (rev 2442)
@@ -45,6 +45,7 @@
import org.teiid.adminapi.Model;
import org.teiid.adminapi.Translator;
import org.teiid.adminapi.impl.DataPolicyMetadata.PermissionMetaData;
+import org.teiid.core.util.PropertiesUtils;
@SuppressWarnings("nls")
public class TestVDBMetaData {
@@ -182,4 +183,13 @@
}
}
}
+
+ @Test
+ public void testAdminMOCreation() {
+ VDBMetaData vdb = new VDBMetaData();
+
+ PropertiesUtils.setBeanProperty(vdb, "url",
"http://teiid.org/myvdb.vdb");
+
+
assertEquals("http://teiid.org/myvdb.vdb", vdb.getUrl());
+ }
}
Modified: trunk/common-core/src/main/java/org/teiid/core/util/StringUtil.java
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/util/StringUtil.java 2010-08-11
19:55:00 UTC (rev 2441)
+++ trunk/common-core/src/main/java/org/teiid/core/util/StringUtil.java 2010-08-11
19:56:01 UTC (rev 2442)
@@ -18,6 +18,8 @@
import java.io.PrintWriter;
import java.io.StringReader;
import java.lang.reflect.Array;
+import java.net.MalformedURLException;
+import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
@@ -990,7 +992,13 @@
else if (type.isEnum()) {
return (T)Enum.valueOf(type, value);
}
-
+ else if (type == URL.class) {
+ try {
+ return (T)new URL(value);
+ } catch (MalformedURLException e) {
+ // fall through and end up in error
+ }
+ }
else if (type.isAssignableFrom(Map.class)) {
List<String> l = Arrays.asList(value.split(",")); //$NON-NLS-1$
Map m = new HashMap<String, String>();
Modified: trunk/common-core/src/test/java/org/teiid/core/util/TestStringUtil.java
===================================================================
--- trunk/common-core/src/test/java/org/teiid/core/util/TestStringUtil.java 2010-08-11
19:55:00 UTC (rev 2441)
+++ trunk/common-core/src/test/java/org/teiid/core/util/TestStringUtil.java 2010-08-11
19:56:01 UTC (rev 2442)
@@ -22,12 +22,11 @@
package org.teiid.core.util;
+import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
-import org.teiid.core.util.StringUtil;
-
import junit.framework.TestCase;
/**
@@ -394,7 +393,7 @@
WORLD
}
- public void testValueOf() {
+ public void testValueOf() throws Exception {
assertEquals(Integer.valueOf(21), StringUtil.valueOf("21",
Integer.class)); //$NON-NLS-1$
assertEquals(Boolean.valueOf(true), StringUtil.valueOf("true",
Boolean.class)); //$NON-NLS-1$
assertEquals("Foo", StringUtil.valueOf("Foo", String.class));
//$NON-NLS-1$ //$NON-NLS-2$
@@ -417,5 +416,7 @@
assertEquals(m.get("foo"), "bar"); //$NON-NLS-1$ //$NON-NLS-2$
assertEquals(m.get("x"), ""); //$NON-NLS-1$ //$NON-NLS-2$
assertEquals(Test.HELLO, StringUtil.valueOf("HELLO", Test.class));
//$NON-NLS-1$
+
+ assertEquals(new URL("http://teiid.org"),
StringUtil.valueOf("http://teiid.org", URL.class)); //$NON-NLS-1$ //$NON-NLS-2$
}
}