use of org.apache.felix.ipojo.Factory in project felix by apache.
the class TestUnacceptableConfiguration method testStaticOKopt.
/**
* Check static properties.
*/
@Test
public void testStaticOKopt() {
Factory f = ipojoHelper.getFactory("Factories-FooProviderType-2opt");
Properties p = new Properties();
p.put("instance.name", "ok");
p.put("int", 3);
p.put("long", 42l);
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 testDynamicCompleteOpt.
/**
* Check good configuration (with overriding).
*/
@Test
public void testDynamicCompleteOpt() {
Factory f = ipojoHelper.getFactory("Factories-FooProviderType-Dyn2opt");
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) {
fail("An acceptable configuration is rejected : " + e.getMessage());
}
p = new Properties();
p.put("instance.name", "ok");
p.put("int", 3);
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 (2) : " + e.getMessage());
}
}
use of org.apache.felix.ipojo.Factory in project felix by apache.
the class TestUnacceptableConfiguration method testNull2Opt.
/**
* Null configuration (success).
*/
@Test
public void testNull2Opt() {
Factory f = ipojoHelper.getFactory("Factories-FooProviderType-Dyn2opt");
ComponentInstance ci;
try {
ci = f.createComponentInstance(null);
ci.dispose();
} catch (Exception e) {
fail("An acceptable configuration is refused");
}
}
use of org.apache.felix.ipojo.Factory in project felix by apache.
the class TestUnacceptableConfiguration method testDynamicUncomplete.
/**
* Check uncomplete configuration.
*/
@Test
public void testDynamicUncomplete() {
Factory f = ipojoHelper.getFactory("Factories-FooProviderType-Dyn2");
Properties 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 });
ComponentInstance ci;
try {
ci = f.createComponentInstance(p);
ci.dispose();
} catch (Exception e) {
return;
}
fail("An unacceptable configuration is accepted");
}
use of org.apache.felix.ipojo.Factory in project felix by apache.
the class TestErrorHandler method testErrorHandler.
@Test
public void testErrorHandler() throws InterruptedException, InvalidSyntaxException {
MyErrorHandler handler = new MyErrorHandler();
bc.registerService(ErrorHandler.class.getName(), handler, null);
Factory factory = ipojoHelper.getFactory("org.apache.felix.ipojo.runtime.core.components.MyErroneousComponent");
assertNotNull(factory);
try {
factory.createComponentInstance(null);
fail("Error expected");
} catch (Exception e) {
// Error expected.
}
System.out.println(handler.m_errors);
Assert.assertFalse(handler.m_errors.isEmpty());
Assert.assertTrue(handler.m_errors.contains("org.apache.felix.ipojo.runtime.core.components.MyErroneousComponent-0:[org.apache.felix.ipojo.runtime.core.components.MyErroneousComponent-0] createInstance -> Cannot invoke the constructor method - the constructor throws an exception : bad:bad"));
}
Aggregations