felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject svn commit: r1794843 - in /felix/trunk/converter/converter/src: main/java/org/apache/felix/converter/impl/ test/java/org/apache/felix/converter/impl/ test/java/org/apache/felix/converter/impl/sub1/ test/java/org/apache/felix/converter/impl/sub2/
Date Thu, 11 May 2017 14:40:46 GMT
Author: davidb
Date: Thu May 11 14:40:46 2017
New Revision: 1794843

URL: http://svn.apache.org/viewvc?rev=1794843&view=rev
Log:
Felix converter - fix issue with converting from package protected annotations.

Added:
    felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/sub1/
    felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/sub1/TestAnn1.java
    felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/sub2/
    felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/sub2/TestAnn2.java
Modified:
    felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/Util.java
    felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/ConverterMapTest.java

Modified: felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/Util.java
URL: http://svn.apache.org/viewvc/felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/Util.java?rev=1794843&r1=1794842&r2=1794843&view=diff
==============================================================================
--- felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/Util.java
(original)
+++ felix/trunk/converter/converter/src/main/java/org/apache/felix/converter/impl/Util.java
Thu May 11 14:40:46 2017
@@ -79,8 +79,9 @@ class Util {
         Map<String, Method> keys = new LinkedHashMap<>();
         for (Method md : beanClass.getDeclaredMethods()) {
             String key = getBeanKey(md);
-            if (key != null && !keys.containsKey(key))
+            if (key != null && !keys.containsKey(key)) {
                 keys.put(key, md);
+            }
         }
         return keys;
     }
@@ -162,6 +163,7 @@ class Util {
                     set = new LinkedHashSet<>();
                     keys.put(name, set);
                 }
+                md.setAccessible(true);
                 set.add(md);
             }
         }

Modified: felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/ConverterMapTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/ConverterMapTest.java?rev=1794843&r1=1794842&r2=1794843&view=diff
==============================================================================
--- felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/ConverterMapTest.java
(original)
+++ felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/ConverterMapTest.java
Thu May 11 14:40:46 2017
@@ -17,6 +17,7 @@
 package org.apache.felix.converter.impl;
 
 import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
 import java.math.BigInteger;
 import java.net.URL;
 import java.text.SimpleDateFormat;
@@ -400,6 +401,34 @@ public class ConverterMapTest {
                 "{foo=bar, password=secret}", m.toString());
     }
 
+    @SuppressWarnings({ "unchecked", "rawtypes" })
+    @Test
+    public void testAnnotationDefaultMaterializer() throws Exception {
+        Map<String, Object> vals = new HashMap<>();
+        vals.put("bar", 99L);
+        vals.put("tar", true);
+        vals.put("za.za", false);
+
+        Class<?> ta1cls = getClass().getClassLoader().loadClass(getClass().getPackage().getName()
+ ".sub1.TestAnn1");
+        Object ta = converter.convert(vals).to(ta1cls);
+        Map vals2 = converter.convert(ta).to(Map.class);
+        vals2.putAll(vals);
+        Class<?> ta2cls = getClass().getClassLoader().loadClass(getClass().getPackage().getName()
+ ".sub2.TestAnn2");
+        Object ta2 = converter.convert(vals2).to(ta2cls);
+
+        Method m1 = ta2cls.getDeclaredMethod("foo");
+        m1.setAccessible(true);
+        assertEquals("fooo!", m1.invoke(ta2));
+
+        Method m2 = ta2cls.getDeclaredMethod("bar");
+        m2.setAccessible(true);
+        assertEquals(99, m2.invoke(ta2));
+
+        Method m3 = ta2cls.getDeclaredMethod("tar");
+        m3.setAccessible(true);
+        assertEquals(true, m3.invoke(ta2));
+    }
+
     interface TestInterface {
         String foo();
         int bar();

Added: felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/sub1/TestAnn1.java
URL: http://svn.apache.org/viewvc/felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/sub1/TestAnn1.java?rev=1794843&view=auto
==============================================================================
--- felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/sub1/TestAnn1.java
(added)
+++ felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/sub1/TestAnn1.java
Thu May 11 14:40:46 2017
@@ -0,0 +1,23 @@
+/*
+ * 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.felix.converter.impl.sub1;
+
+@interface TestAnn1 {
+    String foo() default "fooo!";
+    int bar() default 42;
+    boolean za_za();
+}

Added: felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/sub2/TestAnn2.java
URL: http://svn.apache.org/viewvc/felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/sub2/TestAnn2.java?rev=1794843&view=auto
==============================================================================
--- felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/sub2/TestAnn2.java
(added)
+++ felix/trunk/converter/converter/src/test/java/org/apache/felix/converter/impl/sub2/TestAnn2.java
Thu May 11 14:40:46 2017
@@ -0,0 +1,23 @@
+/*
+ * 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.felix.converter.impl.sub2;
+
+@interface TestAnn2 {
+    String foo();
+    int bar() default 42;
+    boolean tar();
+}



Mime
View raw message