Search in sources :

Example 1 with TestServiceListener

use of org.eclipse.ecf.tests.discovery.listener.TestServiceListener 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 TestServiceListener

use of org.eclipse.ecf.tests.discovery.listener.TestServiceListener 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 TestServiceListener

use of org.eclipse.ecf.tests.discovery.listener.TestServiceListener 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 4 with TestServiceListener

use of org.eclipse.ecf.tests.discovery.listener.TestServiceListener 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 5 with TestServiceListener

use of org.eclipse.ecf.tests.discovery.listener.TestServiceListener 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

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