geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r787264 [2/2] - in /geronimo/sandbox/blueprint: blueprint-api/src/main/java/org/osgi/service/blueprint/container/ blueprint-cm/src/main/java/org/apache/geronimo/blueprint/compendium/cm/ blueprint-core/src/main/java/org/apache/geronimo/bluep...
Date Mon, 22 Jun 2009 15:03:55 GMT
Modified: geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/container/AggregateConverterTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/container/AggregateConverterTest.java?rev=787264&r1=787263&r2=787264&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/container/AggregateConverterTest.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/container/AggregateConverterTest.java
Mon Jun 22 15:03:53 2009
@@ -18,21 +18,23 @@
  */
 package org.apache.geronimo.blueprint.container;
 
+import java.io.ByteArrayOutputStream;
+import java.math.BigInteger;
 import java.net.URI;
 import java.net.URL;
-import java.math.BigInteger;
+import java.util.Arrays;
+import java.util.List;
 import java.util.Locale;
 import java.util.Properties;
-import java.io.ByteArrayOutputStream;
 
 import junit.framework.TestCase;
-
 import org.apache.geronimo.blueprint.TestBlueprintContainer;
+import org.osgi.service.blueprint.container.CollapsedType;
 import org.osgi.service.blueprint.container.Converter;
 
 public class AggregateConverterTest extends TestCase {
 
-    private Converter service;
+    private AggregateConverter service;
 
     protected void setUp() {
         service = new AggregateConverter(new TestBlueprintContainer(null));
@@ -132,6 +134,27 @@
     public void testConvertClass() throws Exception {
         assertEquals(this, service.convert(this, AggregateConverterTest.class));
         assertEquals(AggregateConverterTest.class, service.convert(this.getClass().getName(),
Class.class));
+        assertEquals(int[].class, service.convert("int[]", Class.class));
+    }
+
+    public void testConvertArray() throws Exception {
+        Object obj = service.convert(Arrays.asList(Arrays.asList(1, 2), Arrays.asList(3,
4)),
+                                     GenericType.parse("java.util.List<java.lang.Integer>[]",
getClass().getClassLoader()));
+        assertNotNull(obj);
+        assertTrue(obj.getClass().isArray());
+        Object[] o = (Object[]) obj;
+        assertEquals(2, o.length);
+        assertNotNull(o[0]);
+        assertTrue(o[0] instanceof List);
+        assertEquals(2, ((List) o[0]).size());
+        assertEquals(1, ((List) o[0]).get(0));
+        assertEquals(2, ((List) o[0]).get(1));
+        assertNotNull(o[0]);
+        assertTrue(o[1] instanceof List);
+        assertEquals(2, ((List) o[1]).size());
+        assertEquals(3, ((List) o[1]).get(0));
+        assertEquals(4, ((List) o[1]).get(1));
+        //assertEquals((Object) new int[] { 1, 2 }, (Object) service.convert(Arrays.asList(1,
2), int[].class));
     }
     
     public void testCustom() throws Exception {
@@ -165,28 +188,28 @@
     private interface AsianRegion extends Region {}
     
     private static class RegionConverter implements Converter {
-        public boolean canConvert(Object fromValue, Object toType) {
-            return Region.class == toType;
+        public boolean canConvert(Object fromValue, CollapsedType toType) {
+            return Region.class == toType.getRawClass();
         }
-        public Object convert(Object source, Object toType) throws Exception {
+        public Object convert(Object source, CollapsedType toType) throws Exception {
             return new Region() {} ;
         }
     }
     
     private static class EuRegionConverter implements Converter {
-        public boolean canConvert(Object fromValue, Object toType) {
-            return ((Class) toType).isAssignableFrom(EuRegion.class);
+        public boolean canConvert(Object fromValue, CollapsedType toType) {
+            return toType.getRawClass().isAssignableFrom(EuRegion.class);
         }
-        public Object convert(Object source, Object toType) throws Exception {
+        public Object convert(Object source, CollapsedType toType) throws Exception {
             return new EuRegion() {} ;
         }
     }
     
     private static class AsianRegionConverter implements Converter {
-        public boolean canConvert(Object fromValue, Object toType) {
-            return ((Class) toType).isAssignableFrom(AsianRegion.class);
+        public boolean canConvert(Object fromValue, CollapsedType toType) {
+            return toType.getRawClass().isAssignableFrom(AsianRegion.class);
         }
-        public Object convert(Object source, Object toType) throws Exception {
+        public Object convert(Object source, CollapsedType toType) throws Exception {
             return new AsianRegion() {} ;
         }
     }

Added: geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/container/GenericTypeTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/container/GenericTypeTest.java?rev=787264&view=auto
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/container/GenericTypeTest.java
(added)
+++ geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/container/GenericTypeTest.java
Mon Jun 22 15:03:53 2009
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.geronimo.blueprint.container;
+
+import java.lang.reflect.Type;
+
+import junit.framework.TestCase;
+import org.apache.geronimo.blueprint.utils.TypeUtils;
+
+public class GenericTypeTest extends TestCase {
+
+    public void testParseTypes() throws ClassNotFoundException {
+        GenericType type = GenericType.parse("java.util.List<java.lang.String[]>",
getClass().getClassLoader());
+        System.out.println(type);
+
+        type = GenericType.parse("java.util.Map<int, java.util.List<java.lang.Integer>[]>",
getClass().getClassLoader());
+        System.out.println(type);
+
+        Type t = TypeUtils.parseJavaType("java.util.List<java.lang.Integer>[]", getClass().getClassLoader());
+        type = new GenericType(t);
+        System.out.println(type.toString());
+    }
+
+}

Modified: geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/ConverterA.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/ConverterA.java?rev=787264&r1=787263&r2=787264&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/ConverterA.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/ConverterA.java
Mon Jun 22 15:03:53 2009
@@ -20,15 +20,16 @@
 
 import java.io.File;
 
+import org.osgi.service.blueprint.container.CollapsedType;
 import org.osgi.service.blueprint.container.Converter;
 
 public class ConverterA implements Converter {
 
-    public boolean canConvert(Object fromValue, Object toType) {
-        return fromValue instanceof String && toType == File.class;
+    public boolean canConvert(Object fromValue, CollapsedType toType) {
+        return fromValue instanceof String && toType.getRawClass() == File.class;
     }
 
-    public Object convert(Object source, Object toType) throws Exception {
+    public Object convert(Object source, CollapsedType toType) throws Exception {
         if (source instanceof String) {
             return new File((String) source);
         }

Modified: geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/ConverterB.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/ConverterB.java?rev=787264&r1=787263&r2=787264&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/ConverterB.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/ConverterB.java
Mon Jun 22 15:03:53 2009
@@ -18,18 +18,18 @@
  */
 package org.apache.geronimo.blueprint.pojos;
 
-import java.io.File;
 import java.net.URI;
 
+import org.osgi.service.blueprint.container.CollapsedType;
 import org.osgi.service.blueprint.container.Converter;
 
 public class ConverterB implements Converter {
 
-    public boolean canConvert(Object fromValue, Object toType) {
-        return fromValue instanceof String && toType == URI.class;
+    public boolean canConvert(Object fromValue, CollapsedType toType) {
+        return fromValue instanceof String && toType.getRawClass() == URI.class;
     }
 
-    public Object convert(Object source, Object toType) throws Exception {
+    public Object convert(Object source, CollapsedType toType) throws Exception {
         if (source instanceof String) {
             return new URI((String) source);
         }

Modified: geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/PojoA.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/PojoA.java?rev=787264&r1=787263&r2=787264&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/PojoA.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/pojos/PojoA.java
Mon Jun 22 15:03:53 2009
@@ -18,8 +18,8 @@
  */
 package org.apache.geronimo.blueprint.pojos;
 
-import java.util.Map;
 import java.util.List;
+import java.util.Map;
 import java.util.Properties;
 import java.util.Set;
 

Modified: geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/utils/HeaderParserTest.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/utils/HeaderParserTest.java?rev=787264&r1=787263&r2=787264&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/utils/HeaderParserTest.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/test/java/org/apache/geronimo/blueprint/utils/HeaderParserTest.java
Mon Jun 22 15:03:53 2009
@@ -21,9 +21,7 @@
 import java.util.List;
 
 import junit.framework.TestCase;
-
 import org.apache.geronimo.blueprint.utils.HeaderParser.PathElement;
-import org.apache.geronimo.blueprint.utils.HeaderParser;
 
 public class HeaderParserTest extends TestCase {
 

Modified: geronimo/sandbox/blueprint/blueprint-sample/src/main/java/org/apache/geronimo/blueprint/sample/CurrencyTypeConverter.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-sample/src/main/java/org/apache/geronimo/blueprint/sample/CurrencyTypeConverter.java?rev=787264&r1=787263&r2=787264&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-sample/src/main/java/org/apache/geronimo/blueprint/sample/CurrencyTypeConverter.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-sample/src/main/java/org/apache/geronimo/blueprint/sample/CurrencyTypeConverter.java
Mon Jun 22 15:03:53 2009
@@ -19,14 +19,15 @@
 import java.util.Currency;
 
 import org.osgi.service.blueprint.container.Converter;
+import org.osgi.service.blueprint.container.CollapsedType;
 
 public class CurrencyTypeConverter implements Converter {
 
-    public boolean canConvert(Object fromValue, Object toType) {
-        return Currency.class.isAssignableFrom((Class) toType);
+    public boolean canConvert(Object fromValue, CollapsedType toType) {
+        return Currency.class.isAssignableFrom(toType.getRawClass());
     }
 
-    public Object convert(Object source, Object toType) throws Exception {
+    public Object convert(Object source, CollapsedType toType) throws Exception {
         return Currency.getInstance(source.toString());
     }
 

Modified: geronimo/sandbox/blueprint/blueprint-sample/src/main/java/org/apache/geronimo/blueprint/sample/DateTypeConverter.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-sample/src/main/java/org/apache/geronimo/blueprint/sample/DateTypeConverter.java?rev=787264&r1=787263&r2=787264&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-sample/src/main/java/org/apache/geronimo/blueprint/sample/DateTypeConverter.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-sample/src/main/java/org/apache/geronimo/blueprint/sample/DateTypeConverter.java
Mon Jun 22 15:03:53 2009
@@ -21,6 +21,7 @@
 import java.util.Date;
 
 import org.osgi.service.blueprint.container.Converter;
+import org.osgi.service.blueprint.container.CollapsedType;
 
 public class DateTypeConverter implements Converter {
 
@@ -30,12 +31,12 @@
         dateFormat = new SimpleDateFormat(format);
     }
     
-    public Object convert(Object source, Object toType) throws Exception {
+    public Object convert(Object source, CollapsedType toType) throws Exception {
         return dateFormat.parse(source.toString());
     }
 
-    public boolean canConvert(Object fromValue, Object toType) {
-        return Date.class.isAssignableFrom((Class) toType);
+    public boolean canConvert(Object fromValue, CollapsedType toType) {
+        return Date.class.isAssignableFrom(toType.getRawClass());
     }
 
 }



Mime
View raw message