CassandraConnectionLinker implements EntityLinker<CassandraConnection> { @Override public void link(CassandraConnection entity, Bundle bundle, Bundle targetBundle) { if (entity.getPasswordId() == null) { return; } StoredPassword storedPassword = bundle.getEntities(StoredPassword.class).values().stream().filter(s -> entity.getPasswordId().equals(s.getId())).findFirst().orElse(null); if (storedPassword == null) { throw new LinkerException("Could not find Stored Password for Cassandra Connection: " + entity.getName() + ". Password ID: " + entity.getPasswordId()); } entity.setStoredPasswordName(storedPassword.getName()); }  @Override void link(CassandraConnection entity, Bundle bundle, Bundle targetBundle); @Override Class<CassandraConnection> getEntityClass();  }
@Test void testLinkNoPasswordId() { CassandraConnection cassandraConnection = new CassandraConnection(); linker.link(cassandraConnection, null, null); assertNull(cassandraConnection.getStoredPasswordName()); }
@Test void testLinkPasswordNotFound() { CassandraConnection cassandraConnection = new CassandraConnection.Builder().passwordId("123").build(); assertThrows(LinkerException.class, () -> linker.link(cassandraConnection, new Bundle(), null)); }
@Test void testLinkWithPassword() { CassandraConnection cassandraConnection = new CassandraConnection.Builder().passwordId("123").build(); Bundle bundle = new Bundle(); bundle.addEntity(new StoredPassword.Builder().name("name").id("123").build()); linker.link(cassandraConnection, bundle, null); assertNotNull(cassandraConnection.getStoredPasswordName()); assertEquals("name", cassandraConnection.getStoredPasswordName()); }