Search in sources :

Example 1 with ExportReference

use of org.osgi.service.remoteserviceadmin.ExportReference in project ecf by eclipse.

the class AbstractRemoteServiceRegisterTest method testRegisterAndUpdateProperties.

public void testRegisterAndUpdateProperties() throws Exception {
    remoteServiceAdminEvents.clear();
    // register RemoteServiceAdminListener
    ServiceRegistration listenerReg = getContext().registerService(RemoteServiceAdminListener.class.getName(), createRemoteServiceAdminListener(), null);
    // Create server container
    this.server = ContainerFactory.getDefault().createContainer(getServerContainerTypeName(), new Object[] { createServerID() });
    // Create props
    Properties props = getServiceProperties();
    // Put "1" for "testonekey"
    props.put("testonekey", "1");
    // Actually register with default service (IConcatService) as a remote service
    registration = registerDefaultService(props);
    ExportReference exportRef = null;
    Thread.sleep(15000);
    for (RemoteServiceAdminEvent e : remoteServiceAdminEvents) if (e.getType() == RemoteServiceAdminEvent.EXPORT_REGISTRATION)
        exportRef = e.getExportReference();
    assertTrue(exportRef != null);
    // remoteServiceAdminEvents should have the Export registration
    assertTrue(remoteServiceAdminEvents.size() > 0);
    // Get ExportReference
    EndpointDescription oldED = exportRef.getExportedEndpoint();
    assertNotNull(oldED);
    Map<String, ?> oldEDProperties = oldED.getProperties();
    assertNotNull(oldEDProperties);
    assertTrue("1".equals(oldEDProperties.get("testonekey")));
    assertTrue(oldEDProperties.get("testtwokey") == null);
    // Change testonekey value to "two" and set a new property "testtwokey" to "2"
    props.put("testonekey", "two");
    props.put("testtwokey", "2");
    // Set/update the properties on the registration
    this.registration.setProperties(props);
    // Now get new EndpointDescription and test that new properties have been changed in EndpointDescription
    EndpointDescription updatedED = exportRef.getExportedEndpoint();
    assertNotNull(updatedED);
    Map<String, ?> updatedEDProperties = updatedED.getProperties();
    assertNotNull(updatedEDProperties);
    assertTrue("two".equals(updatedEDProperties.get("testonekey")));
    assertTrue("2".equals(updatedEDProperties.get("testtwokey")));
    Thread.sleep(15000);
    listenerReg.unregister();
}
Also used : RemoteServiceAdminListener(org.osgi.service.remoteserviceadmin.RemoteServiceAdminListener) ExportReference(org.osgi.service.remoteserviceadmin.ExportReference) EndpointDescription(org.osgi.service.remoteserviceadmin.EndpointDescription) Properties(java.util.Properties) RemoteServiceAdminEvent(org.osgi.service.remoteserviceadmin.RemoteServiceAdminEvent) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Aggregations

Properties (java.util.Properties)1 ServiceRegistration (org.osgi.framework.ServiceRegistration)1 EndpointDescription (org.osgi.service.remoteserviceadmin.EndpointDescription)1 ExportReference (org.osgi.service.remoteserviceadmin.ExportReference)1 RemoteServiceAdminEvent (org.osgi.service.remoteserviceadmin.RemoteServiceAdminEvent)1 RemoteServiceAdminListener (org.osgi.service.remoteserviceadmin.RemoteServiceAdminListener)1