コード例 #1
0
  public void testSetServiceBindingSets() throws Exception {
    Set<ServiceBindingMetadata> set = new HashSet<ServiceBindingMetadata>();
    set.addAll(Arrays.asList(AA, AB, Anull));

    Set<ServiceBindingSet> sbs = new HashSet<ServiceBindingSet>();
    ServiceBindingSet setA = new ServiceBindingSet(A, null, 10);
    sbs.add(setA);
    ServiceBindingSet setB = new ServiceBindingSet(B, "localhost", 20);
    sbs.add(setB);

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

    Set<ServiceBindingSet> updated = new HashSet<ServiceBindingSet>(store.getServiceBindingSets());

    Set<ServiceBindingMetadata> overrides = new HashSet<ServiceBindingMetadata>();
    overrides.add(BA);
    ServiceBindingSet newSet = new ServiceBindingSet(C, "192.168.0.10", 30, overrides);
    updated.add(newSet);
    ServiceBindingSet replaced = new ServiceBindingSet(B, "localhost", 50);
    updated.remove(setB);
    updated.add(replaced);
    assertEquals(3, updated.size());

    store.setServiceBindingSets(updated);

    Set<ServiceBindingSet> result = store.getServiceBindingSets();
    assertNotNull(result);
    assertTrue("has setA", result.contains(setA));
    assertTrue("has setB", result.contains(replaced));
    assertTrue("has newSet", result.contains(newSet));

    Set<ServiceBinding> bindings = store.getServiceBindings(C);
    assertNotNull(bindings);
    Map<String, ServiceBinding> byFQN = new HashMap<String, ServiceBinding>();
    for (ServiceBinding binding : bindings) {
      byFQN.put(binding.getFullyQualifiedName(), binding);
    }

    ServiceBinding aa = byFQN.get(AA.getFullyQualifiedName());
    assertNotNull(aa);
    assertEquals(AA.getServiceName(), aa.getServiceName());
    assertEquals(AA.getBindingName(), aa.getBindingName());
    assertEquals(AA.getDescription(), aa.getDescription());
    assertEquals("192.168.0.10", aa.getHostName());
    assertEquals(AA.getPort() + 30, aa.getPort());

    ServiceBinding ab = byFQN.get(AB.getFullyQualifiedName());
    assertNotNull(aa);
    assertEquals(AB.getServiceName(), ab.getServiceName());
    assertEquals(AB.getBindingName(), ab.getBindingName());
    assertEquals(AB.getDescription(), ab.getDescription());
    assertEquals("192.168.0.10", ab.getHostName());
    assertEquals(AB.getPort() + 30, ab.getPort());

    ServiceBinding anull = byFQN.get(Anull.getFullyQualifiedName());
    assertNotNull(anull);
    assertEquals(Anull.getServiceName(), anull.getServiceName());
    assertEquals(Anull.getBindingName(), anull.getBindingName());
    assertEquals(Anull.getDescription(), anull.getDescription());
    assertEquals("192.168.0.10", anull.getHostName());
    assertEquals(Anull.getPort() + 30, anull.getPort());

    ServiceBinding newOne = byFQN.get(BA.getFullyQualifiedName());
    assertNotNull(newOne);
    assertEquals(BA.getServiceName(), newOne.getServiceName());
    assertEquals(BA.getBindingName(), newOne.getBindingName());
    assertEquals(BA.getDescription(), newOne.getDescription());
    assertEquals("192.168.0.10", newOne.getHostName());
    assertEquals(BA.getPort() + 30, newOne.getPort());

    bindings = store.getServiceBindings(B);
    assertNotNull(bindings);
    byFQN = new HashMap<String, ServiceBinding>();
    for (ServiceBinding binding : bindings) {
      byFQN.put(binding.getFullyQualifiedName(), binding);
    }

    aa = byFQN.get(AA.getFullyQualifiedName());
    assertNotNull(aa);
    assertEquals(AA.getServiceName(), aa.getServiceName());
    assertEquals(AA.getBindingName(), aa.getBindingName());
    assertEquals(AA.getDescription(), aa.getDescription());
    assertEquals("localhost", aa.getHostName());
    assertEquals(AA.getPort() + 50, aa.getPort());

    ab = byFQN.get(AB.getFullyQualifiedName());
    assertNotNull(aa);
    assertEquals(AB.getServiceName(), ab.getServiceName());
    assertEquals(AB.getBindingName(), ab.getBindingName());
    assertEquals(AB.getDescription(), ab.getDescription());
    assertEquals("localhost", ab.getHostName());
    assertEquals(AB.getPort() + 50, ab.getPort());

    anull = byFQN.get(Anull.getFullyQualifiedName());
    assertNotNull(anull);
    assertEquals(Anull.getServiceName(), anull.getServiceName());
    assertEquals(Anull.getBindingName(), anull.getBindingName());
    assertEquals(Anull.getDescription(), anull.getDescription());
    assertEquals("localhost", anull.getHostName());
    assertEquals(Anull.getPort() + 50, anull.getPort());
  }
コード例 #2
0
  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());
    }
  }