Search in sources :

Example 11 with IServiceInfo

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

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

the class DiscoveryTest method testGetAsyncServicesIServiceTypeID.

/**
 * Test method for
 * {@link org.eclipse.ecf.discovery.IDiscoveryLocator#getAsyncServices(org.eclipse.ecf.discovery.identity.IServiceTypeID)}.
 * @throws ContainerConnectException
 * @throws InterruptedException
 * @throws OperationCanceledException
 */
public void testGetAsyncServicesIServiceTypeID() throws ContainerConnectException, OperationCanceledException, InterruptedException {
    registerService();
    final IFuture aFuture = discoveryLocator.getAsyncServices(serviceInfo.getServiceID().getServiceTypeID());
    final Object object = aFuture.get();
    assertTrue(object instanceof IServiceInfo[]);
    final IServiceInfo[] services = (IServiceInfo[]) object;
    assertTrue("Found: " + services.length + Arrays.asList(services), services.length == eventsToExpect);
    for (int i = 0; i < services.length; i++) {
        IServiceInfo iServiceInfo = services[i];
        if (comparator.compare(iServiceInfo, serviceInfo) == 0) {
            return;
        }
    }
    fail("Self registered service not found");
}
Also used : IServiceInfo(org.eclipse.ecf.discovery.IServiceInfo) IFuture(org.eclipse.equinox.concurrent.future.IFuture)

Example 13 with IServiceInfo

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

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

the class DiscoveryTest method testGetAsyncServiceInfo.

/**
 * Test method for
 * {@link org.eclipse.ecf.discovery.IDiscoveryLocator#getAsyncServiceInfo(org.eclipse.ecf.discovery.identity.IServiceID)}.
 * @throws InterruptedException
 * @throws OperationCanceledException
 * @throws ContainerConnectException
 */
public void testGetAsyncServiceInfo() throws OperationCanceledException, InterruptedException, ContainerConnectException {
    registerService();
    final IFuture aFuture = discoveryLocator.getAsyncServiceInfo(serviceInfo.getServiceID());
    final Object object = aFuture.get();
    assertTrue(object instanceof IServiceInfo);
    final IServiceInfo info = (IServiceInfo) object;
    assertTrue("IServiceInfo should match, expected:\n\t" + serviceInfo + " but:\n\t" + info, comparator.compare(info, serviceInfo) == 0);
}
Also used : IServiceInfo(org.eclipse.ecf.discovery.IServiceInfo) IFuture(org.eclipse.equinox.concurrent.future.IFuture)

Example 15 with IServiceInfo

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

the class DiscoveryTest method testRegisterService.

/**
 * Test method for
 * {@link org.eclipse.ecf.discovery.IDiscoveryContainerAdapter#registerService(org.eclipse.ecf.discovery.IServiceInfo)}.
 * @throws ContainerConnectException
 */
public void testRegisterService() throws ContainerConnectException {
    registerService();
    final IServiceInfo[] services = discoveryLocator.getServices();
    assertTrue("IServiceInfo[] is empty", services.length >= 1);
    for (int i = 0; i < services.length; i++) {
        final IServiceInfo service = services[i];
        if (comparator.compare(service, serviceInfo) == 0) {
            return;
        }
    }
    fail("Self registered service not found");
}
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