Search in sources :

Example 81 with Factory

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());
    }
}
Also used : ComponentInstance(org.apache.felix.ipojo.ComponentInstance) Factory(org.apache.felix.ipojo.Factory) Properties(java.util.Properties) Test(org.junit.Test)

Example 82 with Factory

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());
    }
}
Also used : ComponentInstance(org.apache.felix.ipojo.ComponentInstance) Factory(org.apache.felix.ipojo.Factory) Properties(java.util.Properties) Test(org.junit.Test)

Example 83 with Factory

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());
    }
}
Also used : ComponentInstance(org.apache.felix.ipojo.ComponentInstance) Factory(org.apache.felix.ipojo.Factory) Properties(java.util.Properties) Test(org.junit.Test)

Example 84 with Factory

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());
    }
}
Also used : ComponentInstance(org.apache.felix.ipojo.ComponentInstance) Factory(org.apache.felix.ipojo.Factory) Properties(java.util.Properties) Test(org.junit.Test)

Example 85 with Factory

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();
}
Also used : ServiceContext(org.apache.felix.ipojo.ServiceContext) ComponentInstance(org.apache.felix.ipojo.ComponentInstance) CompositeManager(org.apache.felix.ipojo.composite.CompositeManager) Factory(org.apache.felix.ipojo.Factory) CompositeInstanceDescription(org.apache.felix.ipojo.composite.CompositeInstanceDescription) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) Properties(java.util.Properties) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) 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