Search in sources :

Example 31 with PrimitiveInstanceDescription

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

the class TestManagedServiceFactoryTestForImmediate method testDelayedCreationAndReconfiguration2.

@Test
public void testDelayedCreationAndReconfiguration2() {
    factory.stop();
    // The reconfiguration happens before the service invocation
    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);
    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 object -1", 1, ((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", 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 32 with PrimitiveInstanceDescription

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

the class TestManagedServiceFactoryTestForServices method testMSFCreationAndReconfiguration.

@Test
public void testMSFCreationAndReconfiguration() {
    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);
    // 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);
    osgiHelper.waitForService(FooService.class.getName(), "(instance.name=" + pid + ")", 1000);
    ServiceReference refx = osgiHelper.getServiceReference(FooService.class.getName(), "(instance.name=" + pid + ")");
    assertNotNull("Check refx", refx);
    FooService fs = (FooService) osgiHelper.getServiceObject(FooService.class.getName(), "(instance.name=" + pid + ")");
    assertNotNull("Check fs", fs);
    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);
    // Wait for the processing of the first configuration.
    grace();
    Dictionary p2 = configuration.getProperties();
    p2.put("message", "message2");
    try {
        System.err.println("The configuration will be updated with message2");
        configuration.update(p2);
        // Update the configuration ...
        grace();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    System.err.println("The configuration should be updated with message2");
    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 33 with PrimitiveInstanceDescription

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

the class TestManagedServiceFactoryTestForServices method testMSFCreationAndReconfiguration2.

@Test
public void testMSFCreationAndReconfiguration2() {
    // 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();
    // 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 34 with PrimitiveInstanceDescription

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

the class TestManagedServiceFactoryTestForServices method testDelayedCreationAndReconfiguration.

@Test
public void testDelayedCreationAndReconfiguration() {
    factory.stop();
    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();
    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);
    osgiHelper.waitForService(FooService.class.getName(), "(instance.name=" + pid + ")", 1000);
    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);
    // Wait for the processing of the first configuration.
    grace();
    System.out.println("===");
    props.put("message", "message2");
    try {
        configuration.update(props);
        // Update the configuration ...
        grace();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    System.out.println("===");
    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 35 with PrimitiveInstanceDescription

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

the class TestManagedServiceTestForImmediate method testCreationUsingFactoryConfigurationSettingTheManagedServicePid.

/**
 * Creates an instance using a factory configuration.
 * The configuration specifies the managed.service.pid property
 * Reconfiguration is applied using the exposed managed service.
 */
@Test
public void testCreationUsingFactoryConfigurationSettingTheManagedServicePid() {
    Configuration conf = null;
    try {
        conf = admin.createFactoryConfiguration(factNameImm, getTestBundle().getLocation());
        Dictionary props = conf.getProperties();
        if (props == null) {
            props = new Properties();
        }
        props.put("managed.service.pid", msp);
        props.put("message", "message");
        conf.update(props);
        grace();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    Architecture arch = (Architecture) osgiHelper.getServiceObject(org.apache.felix.ipojo.architecture.Architecture.class.getName(), "(architecture.instance=" + conf.getPid() + ")");
    ServiceReference ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), conf.getPid());
    assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) arch.getInstanceDescription()).getCreatedObjects().length);
    assertNotNull("FS availability", ref);
    // arch = (Architecture) osgiHelper.getServiceObject( org.apache.felix.ipojo.architecture.Architecture.class.getName(), "(architecture.instance=" + conf.getPid() + ")");
    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) arch.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);
        grace();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    // arch = (Architecture) osgiHelper.getServiceObject( org.apache.felix.ipojo.architecture.Architecture.class.getName(), "(architecture.instance=" + conf.getPid() + ")");
    ref = ipojoHelper.getServiceReferenceByName(FooService.class.getName(), conf.getPid());
    assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) arch.getInstanceDescription()).getCreatedObjects().length);
    assertNotNull("FS availability", ref);
    // arch = (Architecture) osgiHelper.getServiceObject( org.apache.felix.ipojo.architecture.Architecture.class.getName(), "(architecture.instance=" + conf.getPid() + ")");
    fs = (FooService) bc.getService(ref);
    p = fs.fooProps();
    mes = p.getProperty("message");
    count = ((Integer) p.get("count")).intValue();
    assertEquals("Check 1 object", 1, ((PrimitiveInstanceDescription) arch.getInstanceDescription()).getCreatedObjects().length);
    if (mes.equals("message")) {
        System.out.println("Warning, configuration not yet applied");
        assertEquals("Check count - W", 1, count);
    } else {
        assertEquals("Check message", "message2", mes);
        assertEquals("Check count", 2, count);
    }
    try {
        conf.delete();
        grace();
    } catch (IOException e) {
        fail(e.getMessage());
    }
}
Also used : 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) IOException(java.io.IOException) PrimitiveInstanceDescription(org.apache.felix.ipojo.PrimitiveInstanceDescription) ServiceReference(org.osgi.framework.ServiceReference) FooService(org.apache.felix.ipojo.runtime.core.services.FooService) 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