Search in sources :

Example 16 with IServiceInfo

use of org.eclipse.ecf.discovery.IServiceInfo 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 17 with IServiceInfo

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

the class DiscoveryTest method testAddServiceListenerIServiceListener.

/**
 * Test method for
 * {@link org.eclipse.ecf.discovery.IDiscoveryContainerAdapter#addServiceListener(org.eclipse.ecf.discovery.IServiceListener)}.
 * @throws ContainerConnectException
 */
public void testAddServiceListenerIServiceListener() 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());
    addServiceListener(tsl);
}
Also used : TestServiceListener(org.eclipse.ecf.tests.discovery.listener.TestServiceListener) IServiceInfo(org.eclipse.ecf.discovery.IServiceInfo)

Example 18 with IServiceInfo

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

the class DiscoveryTest method testGetServicesIServiceTypeID.

/**
 * Test method for
 * {@link org.eclipse.ecf.discovery.IDiscoveryContainerAdapter#getServices(org.eclipse.ecf.discovery.identity.IServiceTypeID)}.
 * @throws ContainerConnectException
 */
public void testGetServicesIServiceTypeID() throws ContainerConnectException {
    registerService();
    final IServiceInfo[] serviceInfos = discoveryLocator.getServices(serviceInfo.getServiceID().getServiceTypeID());
    assertTrue("IServiceInfo[] is empty", serviceInfos.length >= 1);
    for (int i = 0; i < serviceInfos.length; i++) {
        IServiceInfo iServiceInfo = serviceInfos[i];
        if (comparator.compare(iServiceInfo, serviceInfo) == 0) {
            return;
        }
    }
    fail("Self registered service not found");
}
Also used : IServiceInfo(org.eclipse.ecf.discovery.IServiceInfo)

Example 19 with IServiceInfo

use of org.eclipse.ecf.discovery.IServiceInfo 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 20 with IServiceInfo

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

the class DiscoveryTest method testUnregisterService.

/**
 * Test method for
 * {@link org.eclipse.ecf.discovery.IDiscoveryContainerAdapter#unregisterService(org.eclipse.ecf.discovery.IServiceInfo)}.
 * @throws ContainerConnectException
 */
public void testUnregisterService() throws ContainerConnectException {
    testRegisterService();
    unregisterService();
    final IServiceInfo[] services = discoveryLocator.getServices();
    for (int i = 0; i < services.length; i++) {
        final IServiceInfo service = services[i];
        if (comparator.compare(service, serviceInfo) == 0) {
            fail("Expected service to be not registered anymore");
        }
    }
}
Also used : IServiceInfo(org.eclipse.ecf.discovery.IServiceInfo)

Aggregations

IServiceInfo (org.eclipse.ecf.discovery.IServiceInfo)47 IContainerEvent (org.eclipse.ecf.core.events.IContainerEvent)8 IServiceTypeID (org.eclipse.ecf.discovery.identity.IServiceTypeID)8 Properties (java.util.Properties)7 URI (java.net.URI)6 IServiceEvent (org.eclipse.ecf.discovery.IServiceEvent)6 IServiceID (org.eclipse.ecf.discovery.identity.IServiceID)6 BundleContext (org.osgi.framework.BundleContext)6 ArrayList (java.util.ArrayList)5 ExecutionException (org.eclipse.core.commands.ExecutionException)5 ServiceRegistration (org.osgi.framework.ServiceRegistration)5 IServiceListener (org.eclipse.ecf.discovery.IServiceListener)4 ServiceInfo (org.eclipse.ecf.discovery.ServiceInfo)4 TestServiceListener (org.eclipse.ecf.tests.discovery.listener.TestServiceListener)4 ThreadTestServiceListener (org.eclipse.ecf.tests.discovery.listener.ThreadTestServiceListener)4 ServiceURL (ch.ethz.iks.slp.ServiceURL)3 List (java.util.List)3 IDCreateException (org.eclipse.ecf.core.identity.IDCreateException)3 IServiceProperties (org.eclipse.ecf.discovery.IServiceProperties)3 Iterator (java.util.Iterator)2