Author: djencks
Date: Mon Dec 28 04:00:51 2015
New Revision: 1721870
URL: http://svn.apache.org/viewvc?rev=1721870&view=rev
Log:
FELIX-4607 test nested anno config
Added:
felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/components/annoconfig/NestedAnnoComponent.java
(with props)
Modified:
felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/helper/Annotations.java
felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/AnnoConfigTest.java
felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/components/annoconfig/AnnoComponent.java
felix/trunk/scr/src/test/resources/integration_test_annoconfig.xml
Modified:
felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/helper/Annotations.java
URL:
http://svn.apache.org/viewvc/felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/helper/Annotations.java?rev=1721870&r1=1721869&r2=1721870&view=diff
==============================================================================
---
felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/helper/Annotations.java
(original)
+++
felix/trunk/scr/src/main/java/org/apache/felix/scr/impl/helper/Annotations.java
Mon Dec 28 04:00:51 2015
@@ -24,6 +24,7 @@ import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -85,6 +86,10 @@ public class Annotations
for (Map.Entry<String, Method> entry: complexFields.entrySet())
{
List<Map<String, Object>> proplist =
nested.get(entry.getKey());
+ if (proplist == null)
+ {
+ proplist = Collections.emptyList();
+ }
Method method = entry.getValue();
Class<?> returnType = method.getReturnType();
if (returnType.isArray())
Modified:
felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/AnnoConfigTest.java
URL:
http://svn.apache.org/viewvc/felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/AnnoConfigTest.java?rev=1721870&r1=1721869&r2=1721870&view=diff
==============================================================================
---
felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/AnnoConfigTest.java
(original)
+++
felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/AnnoConfigTest.java
Mon Dec 28 04:00:51 2015
@@ -20,7 +20,6 @@ package org.apache.felix.scr.integration
import java.lang.reflect.Array;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
@@ -31,6 +30,10 @@ import org.apache.felix.scr.integration.
import org.apache.felix.scr.integration.components.annoconfig.AnnoComponent.A1;
import
org.apache.felix.scr.integration.components.annoconfig.AnnoComponent.A1Arrays;
import org.apache.felix.scr.integration.components.annoconfig.AnnoComponent.E1;
+import
org.apache.felix.scr.integration.components.annoconfig.NestedAnnoComponent;
+import
org.apache.felix.scr.integration.components.annoconfig.NestedAnnoComponent.A2;
+import
org.apache.felix.scr.integration.components.annoconfig.NestedAnnoComponent.B2;
+import
org.apache.felix.scr.integration.components.annoconfig.NestedAnnoComponent.E2;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.junit.JUnit4TestRunner;
@@ -253,4 +256,59 @@ public class AnnoConfigTest extends Comp
TestCase.assertEquals(null, a.shor());
TestCase.assertEquals(null, a.string());
}
+
+ @Test
+ public void testNestedAnnoConfig() throws Exception
+ {
+ String name =
"org.apache.felix.scr.integration.components.nestedannoconfig";
+ ComponentConfigurationDTO dto = findComponentConfigurationByName(name,
ComponentConfigurationDTO.SATISFIED);
+ NestedAnnoComponent ac = getServiceFromConfiguration(dto,
NestedAnnoComponent.class);
+ checkA2NoValues(ac.m_a2_activate);
+
+ Configuration c = configure(name, null, allNestedValues());
+ delay();
+
+ checkA2(ac.m_a2_modified);
+
+ ungetServiceFromConfiguration(dto, NestedAnnoComponent.class);
+ checkA2(ac.m_a2_deactivate);
+ ac = getServiceFromConfiguration(dto, NestedAnnoComponent.class);
+ checkA2(ac.m_a2_activate);
+
+
+ }
+ private Hashtable<String, Object> allNestedValues()
+ {
+ Hashtable<String, Object> values = new Hashtable<String, Object>();
+ values.put("b2.0.bool", "true");
+ values.put("b2.0.e2", E2.a.toString());
+ values.put("b2s.0.bool", "true");
+ values.put("b2s.0.e2", E2.a.toString());
+ values.put("b2s.1.bool", "true");
+ values.put("b2s.1.e2", E2.b.toString());
+ values.put("b2s.2.bool", "true");
+ values.put("b2s.2.e2", E2.c.toString());
+ return values;
+ }
+
+ private void checkA2NoValues(A2 a)
+ {
+ TestCase.assertEquals(0, a.b2s().length);
+ }
+ private void checkA2(A2 a)
+ {
+ checkB2(a.b2(), E2.a);
+ TestCase.assertNull(a.b2null());
+
+ TestCase.assertEquals(3, a.b2s().length);
+ checkB2(a.b2s()[0], E2.a);
+ checkB2(a.b2s()[1], E2.b);
+ checkB2(a.b2s()[2], E2.c);
+ }
+
+ private void checkB2(B2 b, E2 e2) {
+ TestCase.assertEquals(true, b.bool());
+ TestCase.assertEquals(e2, b.e2());
+ }
+
}
Modified:
felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/components/annoconfig/AnnoComponent.java
URL:
http://svn.apache.org/viewvc/felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/components/annoconfig/AnnoComponent.java?rev=1721870&r1=1721869&r2=1721870&view=diff
==============================================================================
---
felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/components/annoconfig/AnnoComponent.java
(original)
+++
felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/components/annoconfig/AnnoComponent.java
Mon Dec 28 04:00:51 2015
@@ -19,15 +19,8 @@
package org.apache.felix.scr.integration.components.annoconfig;
-import java.util.Dictionary;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.HashSet;
import java.util.Map;
-import java.util.Set;
-import org.apache.felix.scr.impl.helper.AnnotationTest.E1;
-import org.osgi.service.component.ComponentConstants;
import org.osgi.service.component.ComponentContext;
Added:
felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/components/annoconfig/NestedAnnoComponent.java
URL:
http://svn.apache.org/viewvc/felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/components/annoconfig/NestedAnnoComponent.java?rev=1721870&view=auto
==============================================================================
---
felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/components/annoconfig/NestedAnnoComponent.java
(added)
+++
felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/components/annoconfig/NestedAnnoComponent.java
Mon Dec 28 04:00:51 2015
@@ -0,0 +1,67 @@
+/*
+ * 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.scr.integration.components.annoconfig;
+
+
+
+
+public class NestedAnnoComponent
+{
+
+ public enum E2 {a, b, c}
+
+ public @interface A2 {
+ B2 b2();
+ B2 b2null();
+ B2[] b2s();
+ }
+
+ public @interface B2 {
+ boolean bool();
+ E2 e2();
+ }
+
+
+ public A2 m_a2_activate;
+ public A2 m_a2_modified;
+ public A2 m_a2_deactivate;
+
+
+ @SuppressWarnings("unused")
+ private void activate( A2 a1 )
+ {
+ m_a2_activate = a1;
+ }
+
+
+
+ @SuppressWarnings("unused")
+ private void modified( A2 a1)
+ {
+ m_a2_modified = a1;
+ }
+
+ @SuppressWarnings("unused")
+ private void deactivate( A2 a1 )
+ {
+ m_a2_deactivate = a1;
+ }
+
+
+}
Propchange:
felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/components/annoconfig/NestedAnnoComponent.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/components/annoconfig/NestedAnnoComponent.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange:
felix/trunk/scr/src/test/java/org/apache/felix/scr/integration/components/annoconfig/NestedAnnoComponent.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: felix/trunk/scr/src/test/resources/integration_test_annoconfig.xml
URL:
http://svn.apache.org/viewvc/felix/trunk/scr/src/test/resources/integration_test_annoconfig.xml?rev=1721870&r1=1721869&r2=1721870&view=diff
==============================================================================
--- felix/trunk/scr/src/test/resources/integration_test_annoconfig.xml
(original)
+++ felix/trunk/scr/src/test/resources/integration_test_annoconfig.xml Mon Dec
28 04:00:51 2015
@@ -9,7 +9,7 @@
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. -->
-<components xmlns:scr="http://www.osgi.org/xmlns/scr/v1.3.0">
+<components xmlns:scr="http://www.osgi.org/xmlns/scr/v1.3.0"
xmlns:ext="http://felix.apache.org/xmlns/scr/extensions/v1.0.0">
<scr:component
name='org.apache.felix.scr.integration.components.annoconfig'
pid='org.apache.felix.scr.integration.components.annoconfig'
@@ -22,5 +22,17 @@
</service>
</scr:component>
+ <scr:component ext:configureWithInterfaces="true"
+
name='org.apache.felix.scr.integration.components.nestedannoconfig'
+
pid='org.apache.felix.scr.integration.components.nestedannoconfig'
+ modified='modified'
+ >
+ <implementation
+
class='org.apache.felix.scr.integration.components.annoconfig.NestedAnnoComponent'
/>
+ <service>
+ <provide
interface='org.apache.felix.scr.integration.components.annoconfig.NestedAnnoComponent'
/>
+ </service>
+ </scr:component>
+
</components>