@SuppressWarnings("unchecked")
  public void test5NoSuitableEndpointFound() throws Exception {
    ServiceResolverRegistry registry =
        OsgiSupport.getReference(bundleContext, ServiceResolverRegistry.class);
    registry.register(resolverMock, resolverProps);

    EndpointDescription endpointMock = createMock(EndpointDescription.class);
    ServiceDescription serviceMock = createMock(ServiceDescription.class);

    List<EndpointDescription> endpoints = new ArrayList<EndpointDescription>();
    endpoints.add(endpointMock);

    expect(resolverMock.getEndpointsFor(service2Interface, null)).andReturn(endpoints).once();
    expect(endpointMock.getServiceName()).andReturn(new QName("dummy", "dummy")).times(2);
    expect(endpointMock.getAddress()).andReturn("non-existing-one").once();
    expect(endpointMock.getName()).andReturn("endpoint-name").once();

    replay(resolverMock);
    replay(endpointMock);
    replay(serviceMock);

    try {
      setExchangeThroughNMR();
      fail("The routing of exchange must fail");
    } catch (RuntimeException e) {
      // expected result
    }

    verify(resolverMock);
    verify(endpointMock);
    verify(serviceMock);
  }
  /** @throws Exception */
  public void test3SuccessfullResolverSequence() throws Exception {
    ServiceResolverRegistry registry =
        OsgiSupport.getReference(bundleContext, ServiceResolverRegistry.class);
    registry.register(resolverMock, resolverProps);

    EndpointDescription endpointMock = createMock(EndpointDescription.class);
    ServiceDescription<?> serviceMock = createMock(ServiceDescription.class);

    List<EndpointDescription> endpoints = new ArrayList<EndpointDescription>();
    endpoints.add(endpointMock);

    expect(resolverMock.getEndpointsFor(service2Interface, null)).andReturn(endpoints).once();
    expect(endpointMock.getMetadata()).andReturn(null);
    expect(endpointMock.getServiceName()).andReturn(service2).once();

    replay(resolverMock);
    replay(endpointMock);
    replay(serviceMock);

    setExchangeThroughNMR();

    verify(resolverMock);
    verify(endpointMock);
    verify(serviceMock);
  }
  /**
   * Tests if the serviceReolver is actually present(registered as the osgi service) in the
   * Swordfish Runtime Platform
   */
  public void test1ResolverInitialization() throws Exception {
    Collection<ServiceResolverRegistry> registries =
        OsgiSupport.getReferences(bundleContext, ServiceResolverRegistry.class);
    assertEquals("Thre must be only one ServiceResolver registry", registries.size(), 1);

    ServiceResolverRegistry registry = registries.iterator().next();
    assertTrue("No ServiceResolver instances are registered", registry.getKeys().size() > 0);
  }
  @Override
  protected void tearDown() throws Exception {
    NMR nmr = OsgiSupport.getReference(bundleContext, NMR.class);
    assertNotNull(nmr);

    ServiceMixSupport.unregisterEndpoints(nmr, endpointService1, endpointService2);

    ServiceResolverRegistry registry =
        OsgiSupport.getReference(bundleContext, ServiceResolverRegistry.class);
    registry.unregister(resolverMock, resolverProps);
    assertFalse(registry.getKeys().get(0).equals(resolverMock));

    super.tearDown();
  }
  public void test7ServiceResolverNoPolicyMatching() throws Exception {
    ServiceResolverRegistry registry =
        OsgiSupport.getReference(bundleContext, ServiceResolverRegistry.class);
    ServiceResolver resolver = registry.getKeys().get(0);
    assertNotNull("Couldn't find the ServiceResolver service", resolver);

    Collection<EndpointDescription> c =
        resolver.getEndpointsFor(
            new QName("http://service.dynamic.samples.swordfish.eclipse.org/", "FlightService"));
    assertNotNull("No endpoints resolved. ", c);
    assertEquals(c.size(), 1);
    assertEquals(
        c.iterator().next().getServiceName(),
        new QName("http://service.dynamic.samples.swordfish.eclipse.org/", "FlightServiceImpl"));
  }
  public void test4FailedNoServiceDescription() throws Exception {
    ServiceResolverRegistry registry =
        OsgiSupport.getReference(bundleContext, ServiceResolverRegistry.class);
    registry.register(resolverMock, resolverProps);

    List<EndpointDescription> endpointsEmpty = new ArrayList<EndpointDescription>();

    expect(resolverMock.getEndpointsFor(service2Interface, null)).andReturn(endpointsEmpty).once();
    replay(resolverMock);

    try {
      setExchangeThroughNMR();
      fail("The routing of exchange must fail");
    } catch (RuntimeException e) {
      // expected result
    }
    verify(resolverMock);
  }
  /**
   * The testcase sends the messageExchange through the nmr. Checks if the serviceResolver was
   * actually invoked inside the nmr
   */
  public void test2SuccessfullResolverUsingStub() throws Exception {
    ServiceDescriptionStub stubDescr = new ServiceDescriptionStub(service2);
    EndpointDescriptionStub stubEndp = new EndpointDescriptionStub(stubDescr);

    List<EndpointDescription> stubEndpoints = new ArrayList<EndpointDescription>();
    stubEndpoints.add(stubEndp);

    ServiceResolverRegistry registry =
        OsgiSupport.getReference(bundleContext, ServiceResolverRegistry.class);
    registry.register(resolverMock, resolverProps);

    expect(resolverMock.getEndpointsFor(service2Interface, null)).andStubReturn(stubEndpoints);
    replay(resolverMock);

    setExchangeThroughNMR();

    verify(resolverMock);
  }