Search in sources :

Example 1 with IServiceEvent

use of org.eclipse.ecf.discovery.IServiceEvent in project ecf by eclipse.

the class DiscoveryServiceTest method testAddServiceListenerIServiceTypeIDIServiceListenerOSGi.

public void testAddServiceListenerIServiceTypeIDIServiceListenerOSGi() throws ContainerConnectException {
    IServiceInfo[] services = discoveryLocator.getServices();
    assertTrue("No Services must be registerd at this point " + (services.length == 0 ? "" : services[0].toString()), services.length == 0);
    final TestServiceListener tsl = new TestServiceListener(eventsToExpect, discoveryLocator, getName(), getTestId());
    IServiceTypeID serviceTypeID = serviceInfo.getServiceID().getServiceTypeID();
    Properties props = new Properties();
    props.put("org.eclipse.ecf.discovery.services", serviceTypeID.getServices());
    props.put("org.eclipse.ecf.discovery.scopes", serviceTypeID.getScopes());
    props.put("org.eclipse.ecf.discovery.protocols", serviceTypeID.getProtocols());
    props.put("org.eclipse.ecf.discovery.namingauthority", serviceTypeID.getNamingAuthority());
    props.put(IDiscoveryLocator.CONTAINER_NAME, containerUnderTest);
    BundleContext ctxt = Activator.getDefault().getContext();
    ServiceRegistration registration = ctxt.registerService(IServiceListener.class.getName(), tsl, props);
    addListenerRegisterAndWait(tsl, serviceInfo);
    registration.unregister();
    IContainerEvent[] event = tsl.getEvent();
    assertNotNull("Test listener didn't receive discovery", event);
    assertEquals("Test listener received unexpected amount of discovery events: \n\t" + Arrays.asList(event), eventsToExpect, event.length);
    IServiceInfo serviceInfo2 = ((IServiceEvent) event[eventsToExpect - 1]).getServiceInfo();
    assertTrue("IServiceInfo should match, expected:\n\t" + serviceInfo + " but:\n\t" + serviceInfo2, comparator.compare(serviceInfo2, serviceInfo) == 0);
}
Also used : ThreadTestServiceListener(org.eclipse.ecf.tests.discovery.listener.ThreadTestServiceListener) TestServiceListener(org.eclipse.ecf.tests.discovery.listener.TestServiceListener) IServiceTypeID(org.eclipse.ecf.discovery.identity.IServiceTypeID) IServiceListener(org.eclipse.ecf.discovery.IServiceListener) IServiceInfo(org.eclipse.ecf.discovery.IServiceInfo) IContainerEvent(org.eclipse.ecf.core.events.IContainerEvent) Properties(java.util.Properties) IServiceEvent(org.eclipse.ecf.discovery.IServiceEvent) BundleContext(org.osgi.framework.BundleContext) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Example 2 with IServiceEvent

use of org.eclipse.ecf.discovery.IServiceEvent in project ecf by eclipse.

the class DiscoveryServiceTest method testAddServiceListenerIServiceTypeIDIServiceListenerOSGiWildcards.

public void testAddServiceListenerIServiceTypeIDIServiceListenerOSGiWildcards() throws ContainerConnectException {
    IServiceInfo[] services = discoveryLocator.getServices();
    assertTrue("No Services must be registerd at this point " + (services.length == 0 ? "" : services[0].toString()), services.length == 0);
    final TestServiceListener tsl = new TestServiceListener(eventsToExpect, discoveryLocator, getName(), getTestId());
    Properties props = new Properties();
    props.put("org.eclipse.ecf.discovery.services", "*");
    props.put("org.eclipse.ecf.discovery.scopes", "*");
    props.put("org.eclipse.ecf.discovery.protocols", "*");
    props.put("org.eclipse.ecf.discovery.namingauthority", "*");
    props.put(IDiscoveryLocator.CONTAINER_NAME, containerUnderTest);
    BundleContext ctxt = Activator.getDefault().getContext();
    ServiceRegistration registration = ctxt.registerService(IServiceListener.class.getName(), tsl, props);
    addListenerRegisterAndWait(tsl, serviceInfo);
    registration.unregister();
    IContainerEvent[] event = tsl.getEvent();
    assertNotNull("Test listener didn't receive discovery", event);
    assertEquals("Test listener received unexpected amount of discovery events: \n\t" + Arrays.asList(event), eventsToExpect, event.length);
    IServiceInfo serviceInfo2 = ((IServiceEvent) event[eventsToExpect - 1]).getServiceInfo();
    assertTrue("IServiceInfo should match, expected:\n\t" + serviceInfo + " but:\n\t" + serviceInfo2, comparator.compare(serviceInfo2, serviceInfo) == 0);
}
Also used : ThreadTestServiceListener(org.eclipse.ecf.tests.discovery.listener.ThreadTestServiceListener) TestServiceListener(org.eclipse.ecf.tests.discovery.listener.TestServiceListener) IServiceListener(org.eclipse.ecf.discovery.IServiceListener) IServiceInfo(org.eclipse.ecf.discovery.IServiceInfo) IContainerEvent(org.eclipse.ecf.core.events.IContainerEvent) Properties(java.util.Properties) IServiceEvent(org.eclipse.ecf.discovery.IServiceEvent) BundleContext(org.osgi.framework.BundleContext) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Example 3 with IServiceEvent

use of org.eclipse.ecf.discovery.IServiceEvent in project ecf by eclipse.

the class DiscoveryTest method addServiceListener.

protected void addServiceListener(TestServiceListener serviceListener) {
    discoveryLocator.addServiceListener(serviceListener);
    addListenerRegisterAndWait(serviceListener, serviceInfo);
    discoveryLocator.removeServiceListener(serviceListener);
    IContainerEvent[] event = serviceListener.getEvent();
    assertNotNull("Test listener didn't receive any discovery event", event);
    assertEquals("Test listener received unexpected amount of discovery events: \n\t" + Arrays.asList(event), eventsToExpect, event.length);
    IServiceInfo serviceInfo2 = ((IServiceEvent) event[eventsToExpect - 1]).getServiceInfo();
    assertTrue("IServiceInfo should match, expected:\n\t" + serviceInfo + " but was \n\t" + serviceInfo2, comparator.compare(serviceInfo2, serviceInfo) == 0);
}
Also used : IServiceInfo(org.eclipse.ecf.discovery.IServiceInfo) IContainerEvent(org.eclipse.ecf.core.events.IContainerEvent) IServiceEvent(org.eclipse.ecf.discovery.IServiceEvent)

Example 4 with IServiceEvent

use of org.eclipse.ecf.discovery.IServiceEvent in project ecf by eclipse.

the class DiscoveryTest method testAddServiceListenerIServiceTypeIDIServiceListener.

/**
 * Test method for
 * {@link org.eclipse.ecf.discovery.IDiscoveryContainerAdapter#addServiceListener(org.eclipse.ecf.discovery.identity.IServiceTypeID, org.eclipse.ecf.discovery.IServiceListener)}.
 * @throws ContainerConnectException
 */
public void testAddServiceListenerIServiceTypeIDIServiceListener() throws ContainerConnectException {
    IServiceInfo[] services = discoveryLocator.getServices();
    assertTrue("No Services must be registerd at this point " + (services.length == 0 ? "" : services[0].toString()), services.length == 0);
    final TestServiceListener tsl = new TestServiceListener(eventsToExpect, discoveryLocator, getName(), getTestId());
    discoveryLocator.addServiceListener(serviceInfo.getServiceID().getServiceTypeID(), tsl);
    addListenerRegisterAndWait(tsl, serviceInfo);
    discoveryLocator.removeServiceListener(serviceInfo.getServiceID().getServiceTypeID(), tsl);
    IContainerEvent[] event = tsl.getEvent();
    assertNotNull("Test listener didn't receive discovery", event);
    assertEquals("Test listener received unexpected amount of discovery events: \n\t" + Arrays.asList(event), eventsToExpect, event.length);
    IServiceInfo serviceInfo2 = ((IServiceEvent) event[eventsToExpect - 1]).getServiceInfo();
    assertTrue("IServiceInfo should match, expected:\n\t" + serviceInfo + " but:\n\t" + serviceInfo2, comparator.compare(serviceInfo2, serviceInfo) == 0);
}
Also used : TestServiceListener(org.eclipse.ecf.tests.discovery.listener.TestServiceListener) IServiceInfo(org.eclipse.ecf.discovery.IServiceInfo) IContainerEvent(org.eclipse.ecf.core.events.IContainerEvent) IServiceEvent(org.eclipse.ecf.discovery.IServiceEvent)

Example 5 with IServiceEvent

use of org.eclipse.ecf.discovery.IServiceEvent in project ecf by eclipse.

the class DiscoveryServiceTest method testAddServiceListenerIServiceListenerOSGi.

public void testAddServiceListenerIServiceListenerOSGi() throws ContainerConnectException {
    IServiceInfo[] services = discoveryLocator.getServices();
    assertTrue("No Services must be registerd at this point " + (services.length == 0 ? "" : services[0].toString()), services.length == 0);
    final TestServiceListener tsl = new TestServiceListener(eventsToExpect, discoveryLocator, getName(), getTestId());
    Properties props = new Properties();
    props.put(IDiscoveryLocator.CONTAINER_NAME, containerUnderTest);
    BundleContext ctxt = Activator.getDefault().getContext();
    ServiceRegistration registration = ctxt.registerService(IServiceListener.class.getName(), tsl, props);
    addListenerRegisterAndWait(tsl, serviceInfo);
    registration.unregister();
    IContainerEvent[] event = tsl.getEvent();
    assertNotNull("Test listener didn't receive any discovery event", event);
    assertEquals("Test listener received unexpected amount of discovery events: \n\t" + Arrays.asList(event), eventsToExpect, event.length);
    IServiceInfo serviceInfo2 = ((IServiceEvent) event[eventsToExpect - 1]).getServiceInfo();
    assertTrue("IServiceInfo should match, expected:\n\t" + serviceInfo + " but was \n\t" + serviceInfo2, comparator.compare(serviceInfo2, serviceInfo) == 0);
}
Also used : ThreadTestServiceListener(org.eclipse.ecf.tests.discovery.listener.ThreadTestServiceListener) TestServiceListener(org.eclipse.ecf.tests.discovery.listener.TestServiceListener) IServiceListener(org.eclipse.ecf.discovery.IServiceListener) IServiceInfo(org.eclipse.ecf.discovery.IServiceInfo) IContainerEvent(org.eclipse.ecf.core.events.IContainerEvent) Properties(java.util.Properties) IServiceEvent(org.eclipse.ecf.discovery.IServiceEvent) BundleContext(org.osgi.framework.BundleContext) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Aggregations

IContainerEvent (org.eclipse.ecf.core.events.IContainerEvent)6 IServiceEvent (org.eclipse.ecf.discovery.IServiceEvent)6 IServiceInfo (org.eclipse.ecf.discovery.IServiceInfo)6 Properties (java.util.Properties)4 IServiceListener (org.eclipse.ecf.discovery.IServiceListener)4 TestServiceListener (org.eclipse.ecf.tests.discovery.listener.TestServiceListener)4 ThreadTestServiceListener (org.eclipse.ecf.tests.discovery.listener.ThreadTestServiceListener)4 BundleContext (org.osgi.framework.BundleContext)4 ServiceRegistration (org.osgi.framework.ServiceRegistration)4 HashSet (java.util.HashSet)1 Set (java.util.Set)1 IServiceTypeID (org.eclipse.ecf.discovery.identity.IServiceTypeID)1