Search in sources :

Example 1 with TestServiceTypeListener

use of org.eclipse.ecf.tests.discovery.listener.TestServiceTypeListener in project ecf by eclipse.

the class DiscoveryServiceTest method testAddServiceTypeListenerOSGi.

public void testAddServiceTypeListenerOSGi() 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 TestServiceTypeListener testTypeListener = new TestServiceTypeListener(eventsToExpect);
    Properties props = new Properties();
    props.put(IDiscoveryLocator.CONTAINER_NAME, containerUnderTest);
    BundleContext ctxt = Activator.getDefault().getContext();
    ServiceRegistration registration = ctxt.registerService(IServiceTypeListener.class.getName(), testTypeListener, props);
    synchronized (testTypeListener) {
        // register a service which we expect the test listener to get notified of
        registerService();
        try {
            testTypeListener.wait(waitTimeForProvider);
        } catch (final InterruptedException e) {
            Thread.currentThread().interrupt();
            fail("Some discovery unrelated threading issues?");
        }
    }
    registration.unregister();
    IContainerEvent[] event = testTypeListener.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);
}
Also used : TestServiceTypeListener(org.eclipse.ecf.tests.discovery.listener.TestServiceTypeListener) IServiceInfo(org.eclipse.ecf.discovery.IServiceInfo) IContainerEvent(org.eclipse.ecf.core.events.IContainerEvent) IServiceTypeListener(org.eclipse.ecf.discovery.IServiceTypeListener) Properties(java.util.Properties) BundleContext(org.osgi.framework.BundleContext) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Example 2 with TestServiceTypeListener

use of org.eclipse.ecf.tests.discovery.listener.TestServiceTypeListener in project ecf by eclipse.

the class DiscoveryTest method testAddServiceTypeListener.

/**
 * Test method for
 * {@link org.eclipse.ecf.discovery.IDiscoveryContainerAdapter#addServiceTypeListener(org.eclipse.ecf.discovery.IServiceTypeListener)}.
 * @throws ContainerConnectException
 */
public void testAddServiceTypeListener() 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 TestServiceTypeListener testTypeListener = new TestServiceTypeListener(eventsToExpect);
    discoveryLocator.addServiceTypeListener(testTypeListener);
    synchronized (testTypeListener) {
        // register a service which we expect the test listener to get notified of
        registerService();
        try {
            testTypeListener.wait(waitTimeForProvider);
        } catch (final InterruptedException e) {
            Thread.currentThread().interrupt();
            fail("Some discovery unrelated threading issues?");
        }
    }
    discoveryLocator.removeServiceTypeListener(testTypeListener);
    IContainerEvent[] event = testTypeListener.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);
}
Also used : TestServiceTypeListener(org.eclipse.ecf.tests.discovery.listener.TestServiceTypeListener) IServiceInfo(org.eclipse.ecf.discovery.IServiceInfo) IContainerEvent(org.eclipse.ecf.core.events.IContainerEvent)

Example 3 with TestServiceTypeListener

use of org.eclipse.ecf.tests.discovery.listener.TestServiceTypeListener in project ecf by eclipse.

the class DiscoveryTest method testRemoveServiceTypeListener.

/**
 * Test method for
 * {@link org.eclipse.ecf.discovery.IDiscoveryContainerAdapter#removeServiceTypeListener(org.eclipse.ecf.discovery.IServiceTypeListener)}.
 * @throws ContainerConnectException
 */
public void testRemoveServiceTypeListener() throws ContainerConnectException {
    assertTrue("No Services must be registerd at this point", discoveryLocator.getServices().length == 0);
    final TestServiceTypeListener testTypeListener = new TestServiceTypeListener(eventsToExpect);
    discoveryLocator.addServiceTypeListener(testTypeListener);
    synchronized (testTypeListener) {
        // register a service which we expect the test listener to get notified of
        registerService();
        try {
            testTypeListener.wait(waitTimeForProvider);
        } catch (final InterruptedException e) {
            Thread.currentThread().interrupt();
            fail("Some discovery unrelated threading issues?");
        }
    }
    discoveryLocator.removeServiceTypeListener(testTypeListener);
    IContainerEvent[] event = testTypeListener.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);
// TODO reregister and verify the listener doesn't receive any events any longer.
}
Also used : TestServiceTypeListener(org.eclipse.ecf.tests.discovery.listener.TestServiceTypeListener) IContainerEvent(org.eclipse.ecf.core.events.IContainerEvent)

Aggregations

IContainerEvent (org.eclipse.ecf.core.events.IContainerEvent)3 TestServiceTypeListener (org.eclipse.ecf.tests.discovery.listener.TestServiceTypeListener)3 IServiceInfo (org.eclipse.ecf.discovery.IServiceInfo)2 Properties (java.util.Properties)1 IServiceTypeListener (org.eclipse.ecf.discovery.IServiceTypeListener)1 BundleContext (org.osgi.framework.BundleContext)1 ServiceRegistration (org.osgi.framework.ServiceRegistration)1