Search in sources :

Example 71 with Factory

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

the class TestUnacceptableConfiguration method testUnicity1.

/**
 * Check instance name unicity.
 */
@Test
public void testUnicity1() {
    Factory f = ipojoHelper.getFactory("Factories-FooProviderType-2");
    ComponentInstance ci1, ci2, ci3;
    try {
        ci1 = f.createComponentInstance(null);
        ci2 = f.createComponentInstance(null);
        ci3 = f.createComponentInstance(null);
        assertThat("Check name ci1, ci2", ci1.getInstanceName(), not(ci2.getInstanceName()));
        assertThat("Check name ci1, ci3", ci1.getInstanceName(), not(ci3.getInstanceName()));
        assertThat("Check name ci3, ci2", ci3.getInstanceName(), not(ci2.getInstanceName()));
        ci1.dispose();
        ci2.dispose();
        ci3.dispose();
    } catch (Exception e) {
        fail("An acceptable configuration is refused");
    }
}
Also used : ComponentInstance(org.apache.felix.ipojo.ComponentInstance) Factory(org.apache.felix.ipojo.Factory) Test(org.junit.Test)

Example 72 with Factory

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

the class TestUnacceptableConfiguration method testStaticOK.

/**
 * Check static properties.
 */
@Test
public void testStaticOK() {
    Factory f = ipojoHelper.getFactory("Factories-FooProviderType-2");
    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());
    }
}
Also used : ComponentInstance(org.apache.felix.ipojo.ComponentInstance) Factory(org.apache.felix.ipojo.Factory) Properties(java.util.Properties) Test(org.junit.Test)

Example 73 with Factory

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

the class TestUnacceptableConfiguration method testDynamicMore.

/**
 * Check good configuration (more properties).
 */
@Test
public void testDynamicMore() {
    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("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 74 with Factory

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

the class TestUnacceptableConfiguration method testEmptyConfiguration.

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

Example 75 with Factory

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

the class TestUnacceptableConfiguration method testNullOpt.

/**
 * Null configuration (accept).
 */
@Test
public void testNullOpt() {
    Factory f = ipojoHelper.getFactory("Factories-FooProviderType-2opt");
    ComponentInstance ci;
    try {
        ci = f.createComponentInstance(null);
        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) 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