Search in sources :

Example 11 with PrimitiveInstanceDescription

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

the class TestManagedServiceFactoryTestForImmediate method testDelayedCreationAndReconfiguration.

@Test
public void testDelayedCreationAndReconfiguration() {
    factory.stop();
    Configuration configuration = null;
    try {
        configuration = admin.createFactoryConfiguration("CA-ImmConfigurableProvider", "?");
    } catch (IOException e) {
        fail(e.getMessage());
    }
    Dictionary props = configuration.getProperties();
    if (props == null) {
        props = new Properties();
    }
    props.put("message", "message");
    try {
        configuration.update(props);
    } catch (IOException e) {
        fail(e.getMessage());
    }
    String pid = configuration.getPid();
    // Wait for the processing of the first configuration.
    grace();
    assertNull("check no instance", osgiHelper.getServiceObject(Architecture.class.getName(), "(architecture.instance=" + pid + ")"));
    factory.start();
    // Wait for the processing of the first configuration.
    grace();
    // The instance should be created, wait for the architecture service
    osgiHelper.waitForService(Architecture.class.getName(), "(architecture.instance=" + pid + ")", 1000);
    Architecture architecture = (Architecture) osgiHelper.getServiceObject(Architecture.class.getName(), "(architecture.instance=" + pid + ")");
    assertEquals("Check object", 1, ((PrimitiveInstanceDescription) architecture.getInstanceDescription()).getCreatedObjects().length);
    FooService fs = (FooService) osgiHelper.getServiceObject(FooService.class.getName(), "(instance.name=" + pid + ")");
    Properties p = fs.fooProps();
    String mes = p.getProperty("message");
    int count = (Integer) p.get("count");
    // architecture = (Architecture) osgiHelper.getServiceObject( Architecture.class.getName(), "(architecture.instance="+pid+")");
    assertEquals("Assert Message", "message", mes);
    assertEquals("Assert count", 1, count);
    assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) architecture.getInstanceDescription()).getCreatedObjects().length);
    props.put("message", "message2");
    try {
        configuration.update(props);
        // Update the configuration ...
        grace();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    fs = (FooService) osgiHelper.getServiceObject(FooService.class.getName(), "(instance.name=" + pid + ")");
    p = fs.fooProps();
    mes = p.getProperty("message");
    count = (Integer) p.get("count");
    // architecture = (Architecture) osgiHelper.getServiceObject( Architecture.class.getName(), "(architecture.instance="+pid+")");
    assertEquals("Assert Message", "message2", mes);
    // assertEquals("Assert count", 2, count);
    // This test was removed as the result can be 3.
    assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) architecture.getInstanceDescription()).getCreatedObjects().length);
    try {
        configuration.delete();
        grace();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    ServiceReference ref = osgiHelper.getServiceReference(FooService.class.getName(), "(instance.name=" + pid + ")");
    assertNull("Check unavailability", ref);
}
Also used : FooService(org.apache.felix.ipojo.runtime.core.services.FooService) Dictionary(java.util.Dictionary) Configuration(org.osgi.service.cm.Configuration) Architecture(org.apache.felix.ipojo.architecture.Architecture) IOException(java.io.IOException) Properties(java.util.Properties) PrimitiveInstanceDescription(org.apache.felix.ipojo.PrimitiveInstanceDescription) IOException(java.io.IOException) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 12 with PrimitiveInstanceDescription

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

the class TestManagedServiceFactoryTestForImmediate method testCreationAndReconfiguration.

@Test
public void testCreationAndReconfiguration() {
    Configuration configuration = null;
    try {
        configuration = admin.createFactoryConfiguration("CA-ImmConfigurableProvider", "?");
    } catch (IOException e) {
        fail(e.getMessage());
    }
    Dictionary props = configuration.getProperties();
    if (props == null) {
        props = new Properties();
    }
    props.put("message", "message");
    try {
        configuration.update(props);
    } catch (IOException e) {
        fail(e.getMessage());
    }
    String pid = configuration.getPid();
    // Wait for the processing of the first configuration.
    grace();
    // The instance should be created, wait for the architecture service
    osgiHelper.waitForService(Architecture.class.getName(), "(architecture.instance=" + pid + ")", 1000);
    Architecture architecture = (Architecture) osgiHelper.getServiceObject(Architecture.class.getName(), "(architecture.instance=" + pid + ")");
    assertEquals("Check object", 1, ((PrimitiveInstanceDescription) architecture.getInstanceDescription()).getCreatedObjects().length);
    FooService fs = (FooService) osgiHelper.getServiceObject(FooService.class.getName(), "(instance.name=" + pid + ")");
    Properties p = fs.fooProps();
    String mes = p.getProperty("message");
    int count = (Integer) p.get("count");
    // architecture = (Architecture) osgiHelper.getServiceObject( Architecture.class.getName(), "(architecture.instance="+pid+")");
    assertEquals("Assert Message", "message", mes);
    assertEquals("Assert count", 1, count);
    assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) architecture.getInstanceDescription()).getCreatedObjects().length);
    props.put("message", "message2");
    try {
        configuration.update(props);
        // Update the configuration ...
        grace();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    fs = (FooService) osgiHelper.getServiceObject(FooService.class.getName(), "(instance.name=" + pid + ")");
    p = fs.fooProps();
    mes = p.getProperty("message");
    count = (Integer) p.get("count");
    // architecture = (Architecture) osgiHelper.getServiceObject( Architecture.class.getName(), "(architecture.instance="+pid+")");
    assertEquals("Assert Message", "message2", mes);
    assertEquals("Assert count", 2, count);
    assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) architecture.getInstanceDescription()).getCreatedObjects().length);
    try {
        configuration.delete();
        grace();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    ServiceReference ref = osgiHelper.getServiceReference(FooService.class.getName(), "(instance.name=" + pid + ")");
    assertNull("Check unavailability", ref);
}
Also used : FooService(org.apache.felix.ipojo.runtime.core.services.FooService) Dictionary(java.util.Dictionary) Configuration(org.osgi.service.cm.Configuration) Architecture(org.apache.felix.ipojo.architecture.Architecture) IOException(java.io.IOException) Properties(java.util.Properties) PrimitiveInstanceDescription(org.apache.felix.ipojo.PrimitiveInstanceDescription) IOException(java.io.IOException) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 13 with PrimitiveInstanceDescription

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

the class TestManagedServiceFactoryTestForServices method testDelayedCreationAndReconfiguration2.

@Test
public void testDelayedCreationAndReconfiguration2() {
    factory.stop();
    // The reconfiguration happens before the service invocation
    Configuration configuration = null;
    try {
        configuration = admin.createFactoryConfiguration("CA-ConfigurableProvider", "?");
    } catch (IOException e) {
        fail(e.getMessage());
    }
    Dictionary props = configuration.getProperties();
    if (props == null) {
        props = new Properties();
    }
    props.put("message", "message");
    try {
        configuration.update(props);
    } catch (IOException e) {
        fail(e.getMessage());
    }
    String pid = configuration.getPid();
    System.out.println("PID : " + pid);
    assertNull("check no instance", osgiHelper.getServiceObject(Architecture.class.getName(), "(architecture.instance=" + pid + ")"));
    factory.start();
    // The instance should be created, wait for the architecture service
    osgiHelper.waitForService(Architecture.class.getName(), "(architecture.instance=" + pid + ")", 1000);
    Architecture architecture = (Architecture) osgiHelper.getServiceObject(Architecture.class.getName(), "(architecture.instance=" + pid + ")");
    assertEquals("Check no object", 0, ((PrimitiveInstanceDescription) architecture.getInstanceDescription()).getCreatedObjects().length);
    // Wait for the processing of the first configuration.
    grace();
    props.put("message", "message2");
    try {
        configuration.update(props);
        // Update the configuration ...
        grace();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    // architecture = (Architecture) osgiHelper.getServiceObject( Architecture.class.getName(), "(architecture.instance="+pid+")");
    assertEquals("Check no object -2", 0, ((PrimitiveInstanceDescription) architecture.getInstanceDescription()).getCreatedObjects().length);
    // Invoke
    FooService fs = (FooService) osgiHelper.getServiceObject(FooService.class.getName(), "(instance.name=" + pid + ")");
    Properties p = fs.fooProps();
    String mes = p.getProperty("message");
    int count = (Integer) p.get("count");
    // architecture = (Architecture) osgiHelper.getServiceObject( Architecture.class.getName(), "(architecture.instance="+pid+")");
    assertEquals("Assert Message", "message2", mes);
    assertEquals("Assert count", 1, count);
    assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) architecture.getInstanceDescription()).getCreatedObjects().length);
    try {
        configuration.delete();
        grace();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    ServiceReference ref = osgiHelper.getServiceReference(FooService.class.getName(), "(instance.name=" + pid + ")");
    assertNull("Check unavailability", ref);
}
Also used : FooService(org.apache.felix.ipojo.runtime.core.services.FooService) Dictionary(java.util.Dictionary) Configuration(org.osgi.service.cm.Configuration) Architecture(org.apache.felix.ipojo.architecture.Architecture) IOException(java.io.IOException) Properties(java.util.Properties) PrimitiveInstanceDescription(org.apache.felix.ipojo.PrimitiveInstanceDescription) IOException(java.io.IOException) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 14 with PrimitiveInstanceDescription

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

the class TestManagedServiceTestForImmediate method testCreationAndReconfiguration3.

@Test
public void testCreationAndReconfiguration3() {
    // The configuration exists before the instance creation.
    // Update
    Configuration configuration;
    try {
        configuration = admin.getConfiguration(msp, getTestBundle().getLocation());
        Dictionary prc = configuration.getProperties();
        if (prc == null) {
            prc = new Properties();
        }
        prc.put("message", "message2");
        configuration.update(prc);
        grace();
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    Properties props = new Properties();
    props.put("managed.service.pid", msp);
    props.put("message", "message");
    ComponentInstance instance = null;
    try {
        instance = factImm.createComponentInstance(props);
        grace();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    ServiceReference ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance.getInstanceName());
    assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) instance.getInstanceDescription()).getCreatedObjects().length);
    assertNotNull("FS availability", ref);
    FooService fs = (FooService) bc.getService(ref);
    Properties p = fs.fooProps();
    String mes = p.getProperty("message");
    // int count = ((Integer) p.get("count")).intValue();
    assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) instance.getInstanceDescription()).getCreatedObjects().length);
    // Already reconfigured.
    assertEquals("Check message", "message2", mes);
    // Reconfiguration
    try {
        configuration = admin.getConfiguration(msp);
        Dictionary prc = configuration.getProperties();
        if (prc == null) {
            prc = new Properties();
        }
        prc.put("message", "message3");
        configuration.update(prc);
        grace();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    instance.dispose();
    // Recreation of the instance.
    props = new Properties();
    props.put("managed.service.pid", msp);
    props.put("message", "message");
    instance = null;
    try {
        instance = factImm.createComponentInstance(props);
    } catch (Exception e) {
        fail(e.getMessage());
    }
    // Wait until the configuration is delivered.
    grace();
    ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance.getInstanceName());
    assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) instance.getInstanceDescription()).getCreatedObjects().length);
    assertNotNull("FS availability", ref);
    fs = (FooService) bc.getService(ref);
    p = fs.fooProps();
    mes = p.getProperty("message");
    // count = ((Integer) p.get("count")).intValue();
    assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) instance.getInstanceDescription()).getCreatedObjects().length);
    // Already reconfigured.
    assertEquals("Check message", "message3", mes);
    // assertEquals("Check count", 1, count);
    instance.dispose();
}
Also used : FooService(org.apache.felix.ipojo.runtime.core.services.FooService) Dictionary(java.util.Dictionary) Configuration(org.osgi.service.cm.Configuration) ComponentInstance(org.apache.felix.ipojo.ComponentInstance) Properties(java.util.Properties) IOException(java.io.IOException) PrimitiveInstanceDescription(org.apache.felix.ipojo.PrimitiveInstanceDescription) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 15 with PrimitiveInstanceDescription

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

the class TestManagedServiceTestForImmediate method testFactoryCreationAndReconfigurationUsingManagedService.

@Test
public void testFactoryCreationAndReconfigurationUsingManagedService() {
    Properties props = new Properties();
    // Exposes a ManagedService.
    props.put("managed.service.pid", msp);
    props.put("message", "message");
    ComponentInstance instance = null;
    try {
        instance = factImm.createComponentInstance(props);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
    ServiceReference ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance.getInstanceName());
    assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) instance.getInstanceDescription()).getCreatedObjects().length);
    assertNotNull("FS availability", ref);
    FooService fs = (FooService) bc.getService(ref);
    Properties p = fs.fooProps();
    String mes = p.getProperty("message");
    int count = (Integer) p.get("count");
    assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) instance.getInstanceDescription()).getCreatedObjects().length);
    assertEquals("Check message", "message", mes);
    assertEquals("Check count", 1, count);
    // Update
    Configuration configuration;
    try {
        configuration = admin.getConfiguration(msp, getTestBundle().getLocation());
        Dictionary prc = configuration.getProperties();
        if (prc == null) {
            prc = new Properties();
        }
        prc.put("message", "message2");
        configuration.update(prc);
        System.err.println("updated ? ");
        grace();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), instance.getInstanceName());
    assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) instance.getInstanceDescription()).getCreatedObjects().length);
    assertNotNull("FS availability", ref);
    fs = (FooService) bc.getService(ref);
    p = fs.fooProps();
    mes = p.getProperty("message");
    count = (Integer) p.get("count");
    assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) instance.getInstanceDescription()).getCreatedObjects().length);
    assertEquals("Check message", "message2", mes);
    assertEquals("Check count", 2, count);
    instance.dispose();
}
Also used : FooService(org.apache.felix.ipojo.runtime.core.services.FooService) Dictionary(java.util.Dictionary) Configuration(org.osgi.service.cm.Configuration) ComponentInstance(org.apache.felix.ipojo.ComponentInstance) Properties(java.util.Properties) IOException(java.io.IOException) PrimitiveInstanceDescription(org.apache.felix.ipojo.PrimitiveInstanceDescription) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Aggregations

PrimitiveInstanceDescription (org.apache.felix.ipojo.PrimitiveInstanceDescription)40 Test (org.junit.Test)36 ServiceReference (org.osgi.framework.ServiceReference)36 FooService (org.apache.felix.ipojo.runtime.core.services.FooService)25 Architecture (org.apache.felix.ipojo.architecture.Architecture)20 Properties (java.util.Properties)18 IOException (java.io.IOException)16 Dictionary (java.util.Dictionary)16 Configuration (org.osgi.service.cm.Configuration)16 BaseTest (org.ow2.chameleon.testing.helpers.BaseTest)9 ComponentInstance (org.apache.felix.ipojo.ComponentInstance)8 CheckService (org.apache.felix.ipojo.runtime.core.services.CheckService)6 DependencyHandlerDescription (org.apache.felix.ipojo.handlers.dependency.DependencyHandlerDescription)5 ProvidedServiceHandlerDescription (org.apache.felix.ipojo.handlers.providedservice.ProvidedServiceHandlerDescription)5 CheckService (org.apache.felix.ipojo.runtime.core.test.services.CheckService)5 FooService (org.apache.felix.ipojo.runtime.core.test.services.FooService)5 PropertyDescription (org.apache.felix.ipojo.architecture.PropertyDescription)2 DependencyDescription (org.apache.felix.ipojo.handlers.dependency.DependencyDescription)2 ProvidedServiceDescription (org.apache.felix.ipojo.handlers.providedservice.ProvidedServiceDescription)2 CallbackCheckService (org.apache.felix.ipojo.runtime.core.services.CallbackCheckService)2