use of org.eclipse.ecf.discovery.IServiceInfo in project ecf by eclipse.
the class JSLPServiceIDTest method testCreateByjSLPAndRemoveServicePrefix.
/* (non-Javadoc)
* @see org.eclipse.ecf.tests.discovery.identity.ServiceIDTest#testCreateServiceTypeIDFromInternalString()
*
* test from jSLP -> ECF discovery which needs to remove the first occurrence of "service:"
*/
public void testCreateByjSLPAndRemoveServicePrefix() throws ServiceLocationException {
final String internalRep = "service:foo.eclipse:bar";
final ServiceURL sUrl = new ServiceURL(internalRep + "://localhost:1234/a/path/to/something", ServiceURL.LIFETIME_PERMANENT);
final IServiceInfo serviceInfo = new JSLPServiceInfo(DiscoveryTestHelper.SERVICENAME, new ServiceURLAdapter(sUrl), DiscoveryTestHelper.PRIORITY, DiscoveryTestHelper.WEIGHT, new ServicePropertiesAdapter(new ArrayList()));
assertEquals(serviceInfo.getPriority(), DiscoveryTestHelper.PRIORITY);
assertEquals(serviceInfo.getWeight(), DiscoveryTestHelper.WEIGHT);
final IServiceID sid = serviceInfo.getServiceID();
assertEquals(serviceInfo.getServiceName(), DiscoveryTestHelper.SERVICENAME);
final IServiceTypeID stid = sid.getServiceTypeID();
String internal = stid.getInternal();
assertEquals(internalRep, internal);
assertEquals("_foo._bar._" + IServiceTypeID.DEFAULT_PROTO[0] + "." + IServiceTypeID.DEFAULT_SCOPE[0] + "._eclipse", stid.getName());
assertEquals("eclipse", stid.getNamingAuthority());
assertTrue(Arrays.equals(new String[] { "foo", "bar" }, stid.getServices()));
assertTrue(Arrays.equals(IServiceTypeID.DEFAULT_SCOPE, stid.getScopes()));
assertTrue(Arrays.equals(IServiceTypeID.DEFAULT_PROTO, stid.getProtocols()));
}
use of org.eclipse.ecf.discovery.IServiceInfo in project ecf by eclipse.
the class CompositeServiceInfoComporator method compare.
/* (non-Javadoc)
* @see org.eclipse.ecf.tests.discovery.ServiceInfoComparator#compare(java.lang.Object, java.lang.Object)
*/
public int compare(Object arg0, Object arg1) {
if (arg0 instanceof IServiceInfo && arg1 instanceof IServiceInfo) {
final IServiceInfo first = (IServiceInfo) arg0;
final IServiceInfo second = (IServiceInfo) arg1;
boolean priority = first.getPriority() == second.getPriority();
boolean weight = first.getWeight() == second.getWeight();
final URI uri1 = first.getLocation();
final URI uri2 = second.getLocation();
boolean port = uri1.getPort() == uri2.getPort();
boolean host = uri1.getHost().equals(uri2.getHost());
final IServiceID firstID = first.getServiceID();
final IServiceID secondID = second.getServiceID();
boolean serviceType = firstID.getServiceTypeID().equals(secondID.getServiceTypeID());
boolean serviceName = firstID.getServiceName().equals(secondID.getServiceName());
String firstName = firstID.getName();
String secondName = secondID.getName();
boolean name = firstName.equals(secondName);
boolean serviceProperties = compareServiceProperties(first.getServiceProperties(), second.getServiceProperties());
final boolean result = name && serviceType && serviceName && host && port && priority && weight && serviceProperties;
if (result == true) {
return 0;
}
}
return -1;
}
use of org.eclipse.ecf.discovery.IServiceInfo in project ecf by eclipse.
the class DiscoveryServiceRegistryTest method setUp.
protected void setUp() throws Exception {
super.setUp();
// override the service info with a _generic_ service info. Generic in
// the sense that its namespace if the parent DiscoveryNamespace and not
// a provider specific one. We need to use the parent DN because users of the
// whiteboard pattern do not interact with the IDA directly.
IServiceTypeID serviceTypeID = ServiceIDFactory.getDefault().createServiceTypeID(IDFactory.getDefault().getNamespaceByName(DiscoveryNamespace.NAME), services, new String[] { scope }, new String[] { protocol }, namingAuthority);
assertNotNull(serviceTypeID);
// Register a generic IServiceInfo (discovery generic) in the OSGi
// service registry. Let all comparison be done on the provider specific
// ("serviceInfo") super class member though Otherwise we would have to
// register a specific type ignoring ServiceInfoComparator (see below) because the
// generic IServiceInfo will never be equal to the (converted) discovery
// provider .
genericServiceInfo = new ServiceInfo(serviceInfo.getLocation(), DiscoveryTestHelper.SERVICENAME, serviceTypeID, 1, 1, serviceInfo.getServiceProperties(), ttl);
}
use of org.eclipse.ecf.discovery.IServiceInfo 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);
}
use of org.eclipse.ecf.discovery.IServiceInfo 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);
}
Aggregations