SfcGeniusDpnIfWriter { public CompletableFuture<Optional<BigInteger>> addInterface(BigInteger dpnId, String interfaceName) { Set<String> interfaces = dpnInterfaces.computeIfAbsent(dpnId, k -> new HashSet<>()); return interfaces.add(interfaceName) && interfaces.size() == 1 ? CompletableFuture.completedFuture(Optional.of(dpnId)) : CompletableFuture.completedFuture(Optional.empty()); } SfcGeniusDpnIfWriter(Map<BigInteger, Set<String>> dpnInterfaces); CompletableFuture<Optional<BigInteger>> addInterface(BigInteger dpnId, String interfaceName); CompletableFuture<Optional<BigInteger>> removeInterfaceFromDpn(BigInteger dpnId, String interfaceName);  }
@Test public void addInterfaceFirstOfDpn() throws Exception { BigInteger dpnId = BigInteger.valueOf(999); String interfaceName = "IF7"; int oldSize = dpnInterfaces.size(); CompletableFuture<Optional<BigInteger>> newDpnId = sfcGeniusDpnIfWriter.addInterface(dpnId, interfaceName); assertThat(dpnInterfaces.get(dpnId), is(Collections.singleton(interfaceName))); assertThat(dpnInterfaces.size(), is(oldSize + 1)); assertThat(newDpnId.get().isPresent(), is(true)); assertThat(newDpnId.get().get(), is(dpnId)); }
@Test public void addInterfaceNotFirstOfDpn() throws Exception { String interfaceName = "IF7"; int oldSize = dpnInterfaces.size(); CompletableFuture<Optional<BigInteger>> newDpnId = sfcGeniusDpnIfWriter.addInterface(dpnIdWithOneInterface, interfaceName); assertThat(dpnInterfaces.get(dpnIdWithOneInterface).contains(interfaceName), is(true)); assertThat(dpnInterfaces.size(), is(oldSize)); assertThat(newDpnId.get().isPresent(), is(false)); }
@Test public void addInterfaceExistingNotFirstOfDpn() throws Exception { int oldSize = dpnInterfaces.size(); CompletableFuture<Optional<BigInteger>> newDpnId = sfcGeniusDpnIfWriter.addInterface(dpnIdWithOneInterface, existingInterface); assertThat(dpnInterfaces.get(dpnIdWithOneInterface).contains(existingInterface), is(true)); assertThat(dpnInterfaces.size(), is(oldSize)); assertThat(newDpnId.get().isPresent(), is(false)); }