use of org.apache.felix.ipojo.Factory in project felix by apache.
the class TestUnacceptableConfiguration method testDoubleProps.
/**
* Check properties affecting services and component.
*/
@Test
public void testDoubleProps() {
Factory f = ipojoHelper.getFactory("Factories-FooProviderType-Dyn2");
Properties p = new Properties();
p.put("instance.name", "ok");
p.put("int", 3);
p.put("boolean", true);
p.put("string", "absdir");
p.put("strAProp", new String[] { "a" });
p.put("intAProp", new int[] { 1, 2 });
p.put("boolean", false);
p.put("string", "toto");
ComponentInstance ci;
try {
ci = f.createComponentInstance(p);
ci.dispose();
} catch (Exception e) {
fail("An acceptable configuration is rejected : " + e.getMessage());
}
}
use of org.apache.felix.ipojo.Factory in project felix by apache.
the class TestUnacceptableConfiguration method testDynamicMix.
/**
* Check good configuration.
*/
@Test
public void testDynamicMix() {
Factory f = ipojoHelper.getFactory("Factories-FooProviderType-Dyn2");
Properties p = new Properties();
p.put("instance.name", "ok");
p.put("boolean", true);
p.put("string", "absdir");
p.put("strAProp", new String[] { "a" });
p.put("intAProp", new int[] { 1, 2 });
ComponentInstance ci;
try {
ci = f.createComponentInstance(p);
ci.dispose();
} catch (Exception e) {
fail("An acceptable configuration is rejected : " + e.getMessage());
}
}
use of org.apache.felix.ipojo.Factory in project felix by apache.
the class TestUnacceptableConfiguration method testDynamicOK.
/**
* Check dynamic properties.
*/
@Test
public void testDynamicOK() {
Factory f = ipojoHelper.getFactory("Factories-FooProviderType-Dyn");
Properties p = new Properties();
p.put("instance.name", "ok");
p.put("int", 3);
p.put("boolean", true);
p.put("string", "absdir");
p.put("strAProp", new String[] { "a" });
p.put("intAProp", new int[] { 1, 2 });
ComponentInstance ci;
try {
ci = f.createComponentInstance(p);
ci.dispose();
} catch (Exception e) {
e.printStackTrace();
fail("An acceptable configuration is rejected : " + e.getMessage());
}
}
use of org.apache.felix.ipojo.Factory in project felix by apache.
the class TestUnacceptableConfiguration method testDynamicMixOpt.
/**
* Check good configuration.
*/
@Test
public void testDynamicMixOpt() {
Factory f = ipojoHelper.getFactory("Factories-FooProviderType-Dyn2opt");
Properties p = new Properties();
p.put("instance.name", "ok");
p.put("boolean", true);
p.put("string", "absdir");
p.put("strAProp", new String[] { "a" });
p.put("intAProp", new int[] { 1, 2 });
ComponentInstance ci;
try {
ci = f.createComponentInstance(p);
ci.dispose();
} catch (Exception e) {
fail("An acceptable configuration is rejected : " + e.getMessage());
}
p = new Properties();
p.put("instance.name", "ok");
p.put("string", "absdir");
p.put("strAProp", new String[] { "a" });
p.put("intAProp", new int[] { 1, 2 });
try {
ci = f.createComponentInstance(p);
ci.dispose();
} catch (Exception e) {
fail("An acceptable configuration is rejected : " + e.getMessage());
}
}
use of org.apache.felix.ipojo.Factory in project felix by apache.
the class EmptyCompositeTest method testInstanceCreation2.
@Test
public void testInstanceCreation2() {
Factory factory = ipojoHelper.getFactory("composite.empty");
Properties props = new Properties();
props.put("instance.name", "empty");
ComponentInstance ci = null;
try {
ci = factory.createComponentInstance(props);
} catch (Exception e) {
fail("Unacceptable configuration : " + e.getMessage());
}
assertTrue("Check composite manager", ci instanceof CompositeManager);
CompositeManager cm = (CompositeManager) ci;
ServiceContext sc = cm.getServiceContext();
try {
assertEquals("Check number of factories imported", sc.getServiceReferences(Factory.class.getName(), null).length, getContext().getServiceReferences(Factory.class.getName(), null).length);
} catch (InvalidSyntaxException e) {
fail("Invalid filter : " + e.getMessage());
}
Factory factory2 = ipojoHelper.getFactory(sc, "composite.empty");
assertNotNull("Check factory2 not null", factory2);
Properties props2 = new Properties();
props2.put("instance.name", "empty2");
ComponentInstance ci2 = null;
try {
ci2 = factory2.createComponentInstance(props2);
} catch (Exception e) {
fail("Unacceptable configuration : " + e.getMessage());
}
CompositeInstanceDescription id = (CompositeInstanceDescription) ci.getInstanceDescription();
assertEquals("Check composite instance name", id.getName(), "empty");
assertEquals("Check composite instance state", id.getState(), ComponentInstance.VALID);
assertEquals("Check contained instance", id.getContainedInstances().length, 1);
CompositeInstanceDescription id2 = (CompositeInstanceDescription) id.getContainedInstances()[0];
assertEquals("Check composite instance name", id2.getName(), "empty2");
assertEquals("Check composite instance state", id2.getState(), ComponentInstance.VALID);
assertEquals("Check contained instance", id2.getContainedInstances().length, 0);
ci2.dispose();
// id = ci.getInstanceDescription();
assertEquals("Check composite instance name", id.getName(), "empty");
assertEquals("Check composite instance state", id.getState(), ComponentInstance.VALID);
assertEquals("Check contained instance", id.getContainedInstances().length, 0);
ci.dispose();
}
Aggregations