@Override
  protected void setUp() throws Exception {
    super.setUp();

    AA = new ServiceBindingMetadata(A, A, null, 1, false, false);
    bindings.add(AA);
    AB = new ServiceBindingMetadata(A, B, null, 1, false, false);
    bindings.add(AB);
    Anull = new ServiceBindingMetadata(A, null, null, 1, false, false);
    bindings.add(Anull);

    // This one doesn't go in the standard bindings set
    BA = new ServiceBindingMetadata(B, A, null, 1, false, false);

    SET_A = new ServiceBindingSet(A);
    SET_A.setDefaultHostName("localhost");
    bindingSets.add(SET_A);
    SET_B = new ServiceBindingSet(B);
    SET_B.setDefaultHostName("localhost");
    bindingSets.add(SET_B);
    SET_C = new ServiceBindingSet(C);
    SET_C.setDefaultHostName("localhost");
    bindingSets.add(SET_C);
  }
 private static ServiceBinding getServiceBinding(ServiceBindingMetadata md, ServiceBindingSet set)
     throws UnknownHostException {
   return new ServiceBinding(md, set.getDefaultHostName(), set.getPortOffset());
 }
  public void testSetStandardBindings() throws Exception {
    Set<ServiceBindingMetadata> set = new HashSet<ServiceBindingMetadata>();
    set.addAll(Arrays.asList(AA, AB, Anull));

    Set<ServiceBindingSet> sbs = new HashSet<ServiceBindingSet>();
    ServiceBindingSet setB = new ServiceBindingSet(B, "localhost", 20);
    sbs.add(setB);
    ServiceBindingSet setC = new ServiceBindingSet(C, "192.168.0.10", 30);
    sbs.add(setC);

    PojoServiceBindingStore store = new PojoServiceBindingStore(sbs, set);
    store.start();

    Set<ServiceBindingMetadata> updatedSet =
        new HashSet<ServiceBindingMetadata>(store.getStandardBindings());
    assertEquals(3, updatedSet.size());
    ServiceBindingMetadata updated = new ServiceBindingMetadata(AA);
    updated.setPort(9999);
    updated.setDescription("updated");
    updatedSet.remove(AA);
    updatedSet.add(updated);
    updatedSet.add(BA);
    assertEquals(4, updatedSet.size());

    store.setStandardBindings(updatedSet);

    Set<ServiceBindingMetadata> result = store.getStandardBindings();
    assertNotNull(result);
    assertTrue("has updated", result.contains(updated));
    assertTrue("has AB", result.contains(AB));
    assertTrue("has Anull", result.contains(Anull));
    assertTrue("has BA", result.contains(BA));

    for (ServiceBindingSet bindingSet : sbs) {
      String setName = bindingSet.getName();
      Set<ServiceBinding> bindings = store.getServiceBindings(setName);
      assertNotNull(bindings);
      assertEquals(4, bindings.size());
      Map<String, ServiceBinding> byFQN = new HashMap<String, ServiceBinding>();
      for (ServiceBinding binding : bindings) {
        byFQN.put(binding.getFullyQualifiedName(), binding);
      }

      ServiceBinding aa = byFQN.get(updated.getFullyQualifiedName());
      assertNotNull(aa);
      assertEquals(setName + "/updated/serviceName", updated.getServiceName(), aa.getServiceName());
      assertEquals(setName + "/updated/bindingName", updated.getBindingName(), aa.getBindingName());
      assertEquals(setName + "/updated/description", updated.getDescription(), aa.getDescription());
      assertEquals(
          setName + "/updated/hostName", bindingSet.getDefaultHostName(), aa.getHostName());
      assertEquals(
          setName + "/updated/port", updated.getPort() + bindingSet.getPortOffset(), aa.getPort());

      ServiceBinding ab = byFQN.get(AB.getFullyQualifiedName());
      assertNotNull(aa);
      assertEquals(setName + "/AB/serviceName", AB.getServiceName(), ab.getServiceName());
      assertEquals(setName + "/AB/bindingName", AB.getBindingName(), ab.getBindingName());
      assertEquals(setName + "/AB/description", AB.getDescription(), ab.getDescription());
      assertEquals(setName + "/AB/hostName", bindingSet.getDefaultHostName(), ab.getHostName());
      assertEquals(setName + "/AB/port", AB.getPort() + bindingSet.getPortOffset(), ab.getPort());

      ServiceBinding anull = byFQN.get(Anull.getFullyQualifiedName());
      assertNotNull(anull);
      assertEquals(setName + "/Anull/serviceName", Anull.getServiceName(), anull.getServiceName());
      assertEquals(setName + "/Anull/bindingName", Anull.getBindingName(), anull.getBindingName());
      assertEquals(setName + "/Anull/description", Anull.getDescription(), anull.getDescription());
      assertEquals(
          setName + "/Anull/hostName", bindingSet.getDefaultHostName(), anull.getHostName());
      assertEquals(
          setName + "/Anull/port", Anull.getPort() + bindingSet.getPortOffset(), anull.getPort());

      ServiceBinding newOne = byFQN.get(BA.getFullyQualifiedName());
      assertNotNull(newOne);
      assertEquals(setName + "/BA/serviceName", BA.getServiceName(), newOne.getServiceName());
      assertEquals(setName + "/BA/bindingName", BA.getBindingName(), newOne.getBindingName());
      assertEquals(setName + "/BA/description", BA.getDescription(), newOne.getDescription());
      assertEquals(setName + "/BA/hostName", bindingSet.getDefaultHostName(), newOne.getHostName());
      assertEquals(
          setName + "/BA/port", BA.getPort() + bindingSet.getPortOffset(), newOne.getPort());
    }
  }