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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations