Search in sources :

Example 16 with Factory

use of org.apache.felix.ipojo.Factory in project felix by apache.

the class TestUnacceptableConfiguration method testDynamicBadType.

/**
 * Check inconsistent types.
 */
@Test
public void testDynamicBadType() {
    Factory f = ipojoHelper.getFactory("Factories-FooProviderType-Dyn");
    Properties p = new Properties();
    p.put("instance.name", "ok");
    p.put("int", 3);
    p.put("long", (long) 42);
    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());
    }
}
Also used : ComponentInstance(org.apache.felix.ipojo.ComponentInstance) Factory(org.apache.felix.ipojo.Factory) Properties(java.util.Properties) Test(org.junit.Test)

Example 17 with Factory

use of org.apache.felix.ipojo.Factory in project felix by apache.

the class TestUnacceptableConfiguration method testDynamicComplete.

/**
 * Check good configuration (with overriding).
 */
@Test
public void testDynamicComplete() {
    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 });
    ComponentInstance ci;
    try {
        ci = f.createComponentInstance(p);
        ci.dispose();
    } catch (Exception e) {
        fail("An acceptable configuration is rejected : " + e.getMessage());
    }
}
Also used : ComponentInstance(org.apache.felix.ipojo.ComponentInstance) Factory(org.apache.felix.ipojo.Factory) Properties(java.util.Properties) Test(org.junit.Test)

Example 18 with Factory

use of org.apache.felix.ipojo.Factory in project felix by apache.

the class TestUnacceptableConfiguration method testDynamicMoreOpt.

/**
 * Check good configuration (more properties).
 */
@Test
public void testDynamicMoreOpt() {
    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 });
    p.put("tralala", "foo");
    ComponentInstance ci;
    try {
        ci = f.createComponentInstance(p);
        ci.dispose();
    } catch (Exception e) {
        fail("An acceptable configuration is rejected : " + e.getMessage());
    }
}
Also used : ComponentInstance(org.apache.felix.ipojo.ComponentInstance) Factory(org.apache.felix.ipojo.Factory) Properties(java.util.Properties) Test(org.junit.Test)

Example 19 with Factory

use of org.apache.felix.ipojo.Factory in project felix by apache.

the class TestUnacceptableConfiguration method testEmptyConfiguration2opt.

/**
 * Empty configuration (just the name).
 */
@Test
public void testEmptyConfiguration2opt() {
    Factory f = ipojoHelper.getFactory("Factories-FooProviderType-Dyn2opt");
    Properties p = new Properties();
    p.put("instance.name", "ko");
    ComponentInstance ci;
    try {
        ci = f.createComponentInstance(p);
        ci.dispose();
    } catch (Exception e) {
        fail("An acceptable configuration is refused");
    }
}
Also used : ComponentInstance(org.apache.felix.ipojo.ComponentInstance) Factory(org.apache.felix.ipojo.Factory) Properties(java.util.Properties) Test(org.junit.Test)

Example 20 with Factory

use of org.apache.felix.ipojo.Factory in project felix by apache.

the class TestUnacceptableConfiguration method testDynamicBadTypeOpt.

/**
 * Check inconsistent types.
 */
@Test
public void testDynamicBadTypeOpt() {
    Factory f = ipojoHelper.getFactory("Factories-FooProviderType-Dynopt");
    Properties p = new Properties();
    p.put("instance.name", "ok");
    p.put("int", 3);
    p.put("long", (long) 42);
    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());
    }
}
Also used : ComponentInstance(org.apache.felix.ipojo.ComponentInstance) Factory(org.apache.felix.ipojo.Factory) Properties(java.util.Properties) Test(org.junit.Test)

Aggregations

Factory (org.apache.felix.ipojo.Factory)111 Properties (java.util.Properties)88 Test (org.junit.Test)71 ComponentInstance (org.apache.felix.ipojo.ComponentInstance)53 Before (org.junit.Before)33 ServiceReference (org.osgi.framework.ServiceReference)29 FooService (org.apache.felix.ipojo.runtime.core.services.FooService)17 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)17 ComponentFactory (org.apache.felix.ipojo.ComponentFactory)14 ServiceContext (org.apache.felix.ipojo.ServiceContext)13 CheckService (org.apache.felix.ipojo.runtime.core.services.CheckService)11 IOException (java.io.IOException)6 HandlerFactory (org.apache.felix.ipojo.HandlerFactory)6 Architecture (org.apache.felix.ipojo.architecture.Architecture)4 HandlerDescription (org.apache.felix.ipojo.architecture.HandlerDescription)4 InstanceDescription (org.apache.felix.ipojo.architecture.InstanceDescription)4 CompositeInstanceDescription (org.apache.felix.ipojo.composite.CompositeInstanceDescription)4 CompositeManager (org.apache.felix.ipojo.composite.CompositeManager)4 ProvidedServiceDescription (org.apache.felix.ipojo.handlers.providedservice.ProvidedServiceDescription)4 ProvidedServiceHandlerDescription (org.apache.felix.ipojo.handlers.providedservice.ProvidedServiceHandlerDescription)4