Search in sources :

Example 11 with Factory

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

the class TestUnacceptableConfiguration method testNull2.

/**
 * Null configuration (fail).
 */
@Test
public void testNull2() {
    Factory f = ipojoHelper.getFactory("Factories-FooProviderType-Dyn2");
    ComponentInstance ci;
    try {
        ci = f.createComponentInstance(null);
        ci.dispose();
    } catch (Exception e) {
        return;
    }
    fail("An unacceptable configuration is accepted");
}
Also used : ComponentInstance(org.apache.felix.ipojo.ComponentInstance) Factory(org.apache.felix.ipojo.Factory) Test(org.junit.Test)

Example 12 with Factory

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

the class TestUnacceptableConfiguration method testDynamicOKopt.

/**
 * Check dynamic properties.
 */
@Test
public void testDynamicOKopt() {
    Factory f = ipojoHelper.getFactory("Factories-FooProviderType-Dynopt");
    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());
    }
    p = new Properties();
    p.put("instance.name", "ok");
    p.put("boolean", true);
    p.put("strAProp", new String[] { "a" });
    p.put("intAProp", new int[] { 1, 2 });
    try {
        ci = f.createComponentInstance(p);
        ci.dispose();
    } catch (Exception e) {
        e.printStackTrace();
        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)

Example 13 with Factory

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

the class TestUnacceptableConfiguration method testUnicity4.

/**
 * Check instance name unicity.
 */
@Test
public void testUnicity4() {
    Factory f = ipojoHelper.getFactory("Factories-FooProviderType-2");
    Factory f2 = ipojoHelper.getFactory("Factories-FooProviderType-1");
    ComponentInstance ci1 = null, ci2;
    try {
        Properties p1 = new Properties();
        p1.put("instance.name", "name1");
        ci1 = f.createComponentInstance(p1);
        Properties p2 = new Properties();
        p2.put("instance.name", "name1");
        ci2 = f2.createComponentInstance(p2);
        assertThat("Check name ci1, ci2", ci1.getInstanceName(), not(ci2.getInstanceName()));
        ci1.dispose();
        ci2.dispose();
    } catch (Exception e) {
        if (ci1 != null) {
            ci1.dispose();
        }
        return;
    }
    fail("An unacceptable configuration is acceptable");
}
Also used : ComponentInstance(org.apache.felix.ipojo.ComponentInstance) Factory(org.apache.felix.ipojo.Factory) Properties(java.util.Properties) Test(org.junit.Test)

Example 14 with Factory

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

the class TestUnacceptableConfiguration method testWithoutNameOpt.

/**
 * Configuration without the name property.
 */
@Test
public void testWithoutNameOpt() {
    Factory f = ipojoHelper.getFactory("Factories-FooProviderType-2opt");
    Properties p = new Properties();
    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 refused : " + 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 15 with Factory

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

the class TestUnacceptableConfiguration method testEmptyConfigurationOpt.

/**
 * Empty configuration.
 */
@Test
public void testEmptyConfigurationOpt() {
    Factory f = ipojoHelper.getFactory("Factories-FooProviderType-2opt");
    Properties p = new Properties();
    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)

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