Commit API test suite (composite)
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@765176 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/api/pom.xml b/ipojo/api/pom.xml
index 371b0df..e4c4d3c 100644
--- a/ipojo/api/pom.xml
+++ b/ipojo/api/pom.xml
@@ -84,6 +84,7 @@
<configLocation>http://felix.apache.org/ipojo/dev/checkstyle_ipojo.xml</configLocation>
</configuration>
</plugin>
+
</plugins>
</build>
<dependencies>
diff --git a/ipojo/api/src/main/java/org/apache/felix/ipojo/api/composite/CompositeComponentType.java b/ipojo/api/src/main/java/org/apache/felix/ipojo/api/composite/CompositeComponentType.java
index 911a2f2..7186f26 100644
--- a/ipojo/api/src/main/java/org/apache/felix/ipojo/api/composite/CompositeComponentType.java
+++ b/ipojo/api/src/main/java/org/apache/felix/ipojo/api/composite/CompositeComponentType.java
@@ -99,7 +99,7 @@
*/
private void ensureValidity() {
if (m_context == null) {
- throw new IllegalStateException("The primitive component type has no bundle context");
+ throw new IllegalStateException("The composite component type has no bundle context");
}
}
@@ -223,6 +223,14 @@
InstantiatedService inst = (InstantiatedService) m_instantiated.get(i);
element.addElement(inst.getElement());
}
+ for (int i = 0; i < m_exported.size(); i++) {
+ ExportedService inst = (ExportedService) m_exported.get(i);
+ element.addElement(inst.getElement());
+ }
+ for (int i = 0; i < m_provided.size(); i++) {
+ ProvidedService inst = (ProvidedService) m_provided.get(i);
+ element.addElement(inst.getElement());
+ }
return element;
}
diff --git a/ipojo/api/src/test/java/org/apache/felix/ipojo/api/composite/ExportedServiceTest.java b/ipojo/api/src/test/java/org/apache/felix/ipojo/api/composite/ExportedServiceTest.java
new file mode 100644
index 0000000..ef665ed
--- /dev/null
+++ b/ipojo/api/src/test/java/org/apache/felix/ipojo/api/composite/ExportedServiceTest.java
@@ -0,0 +1,119 @@
+package org.apache.felix.ipojo.api.composite;
+
+
+import junit.framework.TestCase;
+
+import org.apache.felix.ipojo.metadata.Element;
+
+public class ExportedServiceTest extends TestCase {
+
+
+
+//
+//<comp:composite name="composite.export.5" architecture="true">
+// <subservice action="import"
+// specification="org.apache.felix.ipojo.test.composite.service.BazService"
+// aggregate="true" optional="true" filter="(!(instance.name=export))"
+// scope="composite" />
+// <comp:provides action="export"
+// specification="org.apache.felix.ipojo.test.composite.service.BazService"
+// filter="(instance.name=foo1)" />
+//</comp:composite>
+
+// <comp:provides action="export"
+// specification="org.apache.felix.ipojo.test.composite.service.BazService" />
+ public void testSimple() {
+ ExportedService svc = new ExportedService()
+ .setSpecification("org.apache.felix.ipojo.test.composite.service.BazService");
+
+ Element elem = svc.getElement();
+ String name = elem.getName();
+ String action = elem.getAttribute("action");
+ String spec = elem.getAttribute("specification");
+ assertEquals("spec", "org.apache.felix.ipojo.test.composite.service.BazService", spec);
+ }
+
+ public void testBad() {
+ ExportedService svc = new ExportedService()
+ //.setSpecification("org.apache.felix.ipojo.test.composite.service.BarService") NO SPEC
+ ;
+ try {
+ svc.getElement();
+ fail("Invalid element accepted");
+ } catch (IllegalStateException e) {
+ // OK
+ }
+ }
+
+
+// <comp:provides action="export"
+// specification="org.apache.felix.ipojo.test.composite.service.BazService"
+// aggregate="true" />
+ public void testAggregate() {
+ ExportedService svc = new ExportedService()
+ .setSpecification("org.apache.felix.ipojo.test.composite.service.BazService")
+ .setAggregate(true);
+
+
+ Element elem = svc.getElement();
+ String spec = elem.getAttribute("specification");
+ String agg = elem.getAttribute("aggregate");
+
+ assertEquals("spec", "org.apache.felix.ipojo.test.composite.service.BazService", spec);
+ assertEquals("aggregate", "true", agg);
+ }
+
+// <comp:provides action="export"
+// specification="org.apache.felix.ipojo.test.composite.service.BazService"
+// optional="true" />
+ public void testOptional() {
+ ExportedService svc = new ExportedService()
+ .setSpecification("org.apache.felix.ipojo.test.composite.service.BazService")
+ .setOptional(true);
+
+
+ Element elem = svc.getElement();
+ String spec = elem.getAttribute("specification");
+ String opt = elem.getAttribute("optional");
+
+ assertEquals("spec", "org.apache.felix.ipojo.test.composite.service.BazService", spec);
+ assertEquals("optional", "true", opt);
+ }
+// <comp:provides action="export"
+// specification="org.apache.felix.ipojo.test.composite.service.BazService"
+// aggregate="true" optional="true" />
+ public void testOptionalAndAggregate() {
+ ExportedService svc = new ExportedService()
+ .setSpecification("org.apache.felix.ipojo.test.composite.service.FooService")
+ .setOptional(true)
+ .setAggregate(true);
+
+
+ Element elem = svc.getElement();
+ String spec = elem.getAttribute("specification");
+ String opt = elem.getAttribute("optional");
+ String agg = elem.getAttribute("aggregate");
+
+
+ assertEquals("spec", "org.apache.felix.ipojo.test.composite.service.FooService", spec);
+ assertEquals("optional", "true", opt);
+ assertEquals("aggregate", "true", agg);
+ }
+
+// <comp:provides action="export"
+// specification="org.apache.felix.ipojo.test.composite.service.BazService"
+// filter="(instance.name=foo1)" />
+ public void testFilter() {
+ ExportedService svc = new ExportedService()
+ .setSpecification("org.apache.felix.ipojo.test.composite.service.FooService")
+ .setFilter("(&(int=2)(long=40))");
+
+ Element elem = svc.getElement();
+ String spec = elem.getAttribute("specification");
+ String filter = elem.getAttribute("filter");
+
+ assertEquals("spec", "org.apache.felix.ipojo.test.composite.service.FooService", spec);
+ assertEquals("filter", "(&(int=2)(long=40))", filter);
+ }
+
+}
diff --git a/ipojo/api/src/test/java/org/apache/felix/ipojo/api/composite/ImportedServiceTest.java b/ipojo/api/src/test/java/org/apache/felix/ipojo/api/composite/ImportedServiceTest.java
new file mode 100644
index 0000000..5cf580c
--- /dev/null
+++ b/ipojo/api/src/test/java/org/apache/felix/ipojo/api/composite/ImportedServiceTest.java
@@ -0,0 +1,143 @@
+package org.apache.felix.ipojo.api.composite;
+
+
+import junit.framework.TestCase;
+
+import org.apache.felix.ipojo.metadata.Element;
+
+public class ImportedServiceTest extends TestCase {
+
+// <comp:composite name="composite.requires.1" architecture="true">
+// <subservice action="import"
+// specification="org.apache.felix.ipojo.test.composite.service.FooService"
+// scope="composite" />
+//</comp:composite>
+ public void testSimple() {
+ ImportedService svc = new ImportedService()
+ .setSpecification("org.apache.felix.ipojo.test.composite.service.FooService");
+
+ Element elem = svc.getElement();
+ String spec = elem.getAttribute("specification");
+ assertEquals("spec", "org.apache.felix.ipojo.test.composite.service.FooService", spec);
+ }
+
+ public void testBad() {
+ ImportedService svc = new ImportedService()
+ //.setSpecification("org.apache.felix.ipojo.test.composite.service.BarService") NO SPEC
+ ;
+ try {
+ svc.getElement();
+ fail("Invalid element accepted");
+ } catch (IllegalStateException e) {
+ // OK
+ }
+ }
+
+ public void testScope() {
+ ImportedService svc = new ImportedService()
+ .setSpecification("org.apache.felix.ipojo.test.composite.service.FooService")
+ .setScope(ImportedService.COMPOSITE_SCOPE);
+
+
+ Element elem = svc.getElement();
+ String spec = elem.getAttribute("specification");
+ String scope = elem.getAttribute("scope");
+ assertEquals("spec", "org.apache.felix.ipojo.test.composite.service.FooService", spec);
+ assertEquals("scope", "composite", scope);
+
+ }
+
+//
+//<comp:composite name="composite.requires.2" architecture="true">
+// <subservice action="import"
+// specification="org.apache.felix.ipojo.test.composite.service.FooService"
+// aggregate="true" scope="composite" />
+//</comp:composite>
+ public void testAggregate() {
+ ImportedService svc = new ImportedService()
+ .setSpecification("org.apache.felix.ipojo.test.composite.service.FooService")
+ .setScope(ImportedService.COMPOSITE_SCOPE)
+ .setAggregate(true);
+
+
+ Element elem = svc.getElement();
+ String spec = elem.getAttribute("specification");
+ String scope = elem.getAttribute("scope");
+ String agg = elem.getAttribute("aggregate");
+
+ assertEquals("spec", "org.apache.felix.ipojo.test.composite.service.FooService", spec);
+ assertEquals("scope", "composite", scope);
+ assertEquals("aggregate", "true", agg);
+ }
+
+//
+//<comp:composite name="composite.requires.3" architecture="true">
+// <subservice action="import"
+// specification="org.apache.felix.ipojo.test.composite.service.FooService"
+// optional="true" scope="composite" />
+//</comp:composite>
+ public void testOptional() {
+ ImportedService svc = new ImportedService()
+ .setSpecification("org.apache.felix.ipojo.test.composite.service.FooService")
+ .setScope(ImportedService.COMPOSITE_SCOPE)
+ .setOptional(true);
+
+
+ Element elem = svc.getElement();
+ String spec = elem.getAttribute("specification");
+ String scope = elem.getAttribute("scope");
+ String opt = elem.getAttribute("optional");
+
+ assertEquals("spec", "org.apache.felix.ipojo.test.composite.service.FooService", spec);
+ assertEquals("scope", "composite", scope);
+ assertEquals("optional", "true", opt);
+ }
+//
+//<comp:composite name="composite.requires.4" architecture="true">
+// <subservice action="import"
+// specification="org.apache.felix.ipojo.test.composite.service.FooService"
+// optional="true" aggregate="true" scope="comp:composite" />
+//</comp:composite>
+ public void testOptionalAndAggregate() {
+ ImportedService svc = new ImportedService()
+ .setSpecification("org.apache.felix.ipojo.test.composite.service.FooService")
+ .setScope(ImportedService.COMPOSITE_SCOPE)
+ .setOptional(true)
+ .setAggregate(true);
+
+
+ Element elem = svc.getElement();
+ String spec = elem.getAttribute("specification");
+ String scope = elem.getAttribute("scope");
+ String opt = elem.getAttribute("optional");
+ String agg = elem.getAttribute("aggregate");
+
+
+ assertEquals("spec", "org.apache.felix.ipojo.test.composite.service.FooService", spec);
+ assertEquals("scope", "composite", scope);
+ assertEquals("optional", "true", opt);
+ assertEquals("aggregate", "true", agg);
+ }
+//
+//<comp:composite name="composite.requires.5" architecture="true">
+// <subservice action="import"
+// specification="org.apache.felix.ipojo.test.composite.service.FooService"
+// filter="(&(int=2)(long=40))" scope="composite" />
+//</comp:composite>
+ public void testFilter() {
+ ImportedService svc = new ImportedService()
+ .setSpecification("org.apache.felix.ipojo.test.composite.service.FooService")
+ .setScope(ImportedService.COMPOSITE_SCOPE)
+ .setFilter("(&(int=2)(long=40))");
+
+ Element elem = svc.getElement();
+ String spec = elem.getAttribute("specification");
+ String scope = elem.getAttribute("scope");
+ String filter = elem.getAttribute("filter");
+
+ assertEquals("spec", "org.apache.felix.ipojo.test.composite.service.FooService", spec);
+ assertEquals("scope", "composite", scope);
+ assertEquals("filter", "(&(int=2)(long=40))", filter);
+ }
+
+}
diff --git a/ipojo/api/src/test/java/org/apache/felix/ipojo/api/composite/InstantiatedServiceTest.java b/ipojo/api/src/test/java/org/apache/felix/ipojo/api/composite/InstantiatedServiceTest.java
new file mode 100644
index 0000000..7aed767
--- /dev/null
+++ b/ipojo/api/src/test/java/org/apache/felix/ipojo/api/composite/InstantiatedServiceTest.java
@@ -0,0 +1,170 @@
+package org.apache.felix.ipojo.api.composite;
+
+
+import junit.framework.TestCase;
+
+import org.apache.felix.ipojo.metadata.Element;
+
+public class InstantiatedServiceTest extends TestCase {
+
+// <comp:composite name="composite.bar.1" architecture="true">
+// <subservice action="instantiate" specification="org.apache.felix.ipojo.test.composite.service.BarService"/>
+//</comp:composite>
+
+ public void testSimple() {
+ InstantiatedService svc = new InstantiatedService()
+ .setSpecification("org.apache.felix.ipojo.test.composite.service.BarService");
+ Element elem = svc.getElement();
+ String spec = elem.getAttribute("specification");
+ String action = elem.getAttribute("action");
+
+ assertEquals("spec" , "org.apache.felix.ipojo.test.composite.service.BarService", spec);
+ assertEquals("action" , "instantiate", action);
+ }
+
+ public void testBad() {
+ InstantiatedService svc = new InstantiatedService()
+ //.setSpecification("org.apache.felix.ipojo.test.composite.service.BarService") NO SPEC
+ ;
+ try {
+ svc.getElement();
+ fail("Invalid element accepted");
+ } catch (IllegalStateException e) {
+ // OK
+ }
+ }
+
+
+
+
+//
+//<comp:composite name="composite.bar.2" architecture="true">
+// <subservice action="instantiate" specification="org.apache.felix.ipojo.test.composite.service.BarService" aggregate="true"/>
+//</comp:composite>
+
+ public void testAggregate() {
+ InstantiatedService svc = new InstantiatedService()
+ .setSpecification("org.apache.felix.ipojo.test.composite.service.BarService")
+ .setAggregate(true);
+ Element elem = svc.getElement();
+ String spec = elem.getAttribute("specification");
+ String action = elem.getAttribute("action");
+ String agg = elem.getAttribute("aggregate");
+
+
+ assertEquals("spec" , "org.apache.felix.ipojo.test.composite.service.BarService", spec);
+ assertEquals("action" , "instantiate", action);
+ assertEquals("aggregate" , "true", agg);
+
+ }
+
+//
+//<comp:composite name="composite.bar.3" architecture="true">
+// <subservice action="instantiate" specification="org.apache.felix.ipojo.test.composite.service.BarService" optional="true"/>
+//</comp:composite>
+ public void testOptional() {
+ InstantiatedService svc = new InstantiatedService()
+ .setSpecification("org.apache.felix.ipojo.test.composite.service.BarService")
+ .setOptional(true);
+ Element elem = svc.getElement();
+ String spec = elem.getAttribute("specification");
+ String action = elem.getAttribute("action");
+ String agg = elem.getAttribute("aggregate");
+ String opt = elem.getAttribute("optional");
+
+ assertEquals("spec" , "org.apache.felix.ipojo.test.composite.service.BarService", spec);
+ assertEquals("action" , "instantiate", action);
+ assertNull("aggregate" , agg);
+ assertEquals("optional" , "true", opt);
+ }
+
+//
+//<comp:composite name="composite.bar.4" architecture="true">
+// <subservice action="instantiate" specification="org.apache.felix.ipojo.test.composite.service.FooService" aggregate="true" optional="true"/>
+//</comp:composite>
+ public void testOptionalAndAggregate() {
+ InstantiatedService svc = new InstantiatedService()
+ .setSpecification("org.apache.felix.ipojo.test.composite.service.FooService")
+ .setOptional(true)
+ .setAggregate(true);
+ Element elem = svc.getElement();
+ String spec = elem.getAttribute("specification");
+ String action = elem.getAttribute("action");
+ String agg = elem.getAttribute("aggregate");
+ String opt = elem.getAttribute("optional");
+
+ assertEquals("spec" , "org.apache.felix.ipojo.test.composite.service.FooService", spec);
+ assertEquals("action" , "instantiate", action);
+ assertEquals("aggregate" , "true", agg);
+ assertEquals("optional" , "true", opt);
+ }
+
+//
+//<comp:composite name="composite.bar.5-accept" architecture="true">
+// <subservice action="instantiate" specification="org.apache.felix.ipojo.test.composite.service.FooService">
+// <property name="boolean" value="true"/>
+// <property name="string" value="foo"/>
+// <property name="strAprop" value="{foo, bar, baz}"/>
+// <property name="int" value="5"/>
+// </subservice>
+//</comp:composite>
+ public void testWithConfiguration() {
+ InstantiatedService svc = new InstantiatedService()
+ .setSpecification("org.apache.felix.ipojo.test.composite.service.FooService")
+ .addProperty("boolean", "true")
+ .addProperty("string", "foo")
+ .addProperty("stringAprop", new String[] {"foo", "bar", "baz" })
+ .addProperty("int", "5");
+ Element elem = svc.getElement();
+ String spec = elem.getAttribute("specification");
+ String action = elem.getAttribute("action");
+ String agg = elem.getAttribute("aggregate");
+ String opt = elem.getAttribute("optional");
+
+ assertEquals("spec" , "org.apache.felix.ipojo.test.composite.service.FooService", spec);
+ assertEquals("action" , "instantiate", action);
+ assertNull("aggregate" , agg);
+ assertNull("optional" , opt);
+
+ Element[] props = elem.getElements("property");
+ assertEquals("Number of properties", 4, props.length);
+ String n0 = props[0].getAttribute("name");
+ String v0 = props[0].getAttribute("value");
+ assertEquals("n0" , "boolean", n0);
+ assertEquals("v0" , "true", v0);
+
+ String n1 = props[1].getAttribute("name");
+ String v1 = props[1].getAttribute("value");
+ assertEquals("n1" , "string", n1);
+ assertEquals("v1" , "foo", v1);
+
+ String n2 = props[2].getAttribute("name");
+ String v2 = props[2].getAttribute("value");
+ String t2 = props[2].getAttribute("type");
+ Element[] sub = props[2].getElements();
+ assertEquals("Number of sub-properties", 3, sub.length);
+ assertEquals("n2", "stringAprop", n2);
+ assertNull("v2", v2);
+ assertEquals("t2", "array", t2);
+
+ String n20 = sub[0].getAttribute("name");
+ String v20 = sub[0].getAttribute("value");
+ assertNull("n20" , n20);
+ assertEquals("v20" , "foo", v20);
+ String n21 = sub[1].getAttribute("name");
+ String v21 = sub[1].getAttribute("value");
+ assertNull("n21" , n21);
+ assertEquals("v21" , "bar", v21);
+ String n22 = sub[2].getAttribute("name");
+ String v22 = sub[2].getAttribute("value");
+ assertNull("n22" , n22);
+ assertEquals("v22" , "baz", v22);
+
+ String n3 = props[3].getAttribute("name");
+ String v3 = props[3].getAttribute("value");
+ assertEquals("n3" , "int", n3);
+ assertEquals("v3" , "5", v3);
+ }
+
+
+}