@Test public void shouldNotComputeConnectorConfiguredPropertiesAsMissing() { final ConnectionUpdateHandler updateHandler = new ConnectionUpdateHandler(dataManager, null, validator); final Connection connection = new Connection.Builder() .id("connection") .putConfiguredProperty("req2", "value2") .build(); final ConfigurationProperty required = new ConfigurationProperty.Builder().required(true).build(); final Connector sameConnector = new Connector.Builder() .id("new-connector") .putProperty("req1", required) .putProperty("req2", required) .putConfiguredProperty("req1", "value1") .build(); when(dataManager.fetchByPropertyValue(ConnectionBulletinBoard.class, "targetResourceId", "connection")) .thenReturn(Optional.empty()); final ConnectionBulletinBoard board = updateHandler.computeBoard(connection, sameConnector, sameConnector); assertThat(board.getMessages()).isEmpty(); }
ConnectionBulletinBoard computeBoard(Connection connection, Connector oldConnector, Connector newConnector) { final DataManager dataManager = getDataManager(); final String id = connection.getId().get(); final ConnectionBulletinBoard board = dataManager.fetchByPropertyValue(ConnectionBulletinBoard.class, "targetResourceId", id).orElse(null); final ConnectionBulletinBoard.Builder builder; if (board != null) { builder = new ConnectionBulletinBoard.Builder() .createFrom(board); } else { builder = new ConnectionBulletinBoard.Builder() .id(KeyGenerator.createKey()) .targetResourceId(id) .createdAt(System.currentTimeMillis()); } List<LeveledMessage> messages = new ArrayList<>(); messages.addAll(computeValidatorMessages(LeveledMessage.Builder::new, connection)); messages.addAll(computePropertiesDiffMessages(LeveledMessage.Builder::new, oldConnector.getProperties(), newConnector.getProperties())); if (!connection.isDerived()) { messages.addAll(computeMissingMandatoryPropertiesMessages( LeveledMessage.Builder::new, newConnector.getProperties(), merge(newConnector.getConfiguredProperties(), connection.getConfiguredProperties())) ); } messages.addAll(computeSecretsUpdateMessages(LeveledMessage.Builder::new, newConnector.getProperties(), connection.getConfiguredProperties())); builder.errors(countMessagesWithLevel(LeveledMessage.Level.ERROR, messages)); builder.warnings(countMessagesWithLevel(LeveledMessage.Level.WARN, messages)); builder.notices(countMessagesWithLevel(LeveledMessage.Level.INFO, messages)); builder.putMetadata("connector-id", newConnector.getId().get()); builder.putMetadata("connector-version-latest", Integer.toString(newConnector.getVersion())); builder.putMetadata("connector-version-connection", Integer.toString(oldConnector.getVersion())); builder.messages(messages); ConnectionBulletinBoard updated = builder.build(); if (!updated.equals(board)) { return builder.updatedAt(System.currentTimeMillis()).build(); } return null; }
ConnectionUpdateHandler extends AbstractResourceUpdateHandler<ConnectionBulletinBoard> { ConnectionBulletinBoard computeBoard(Connection connection, Connector oldConnector, Connector newConnector) { final DataManager dataManager = getDataManager(); final String id = connection.getId().get(); final ConnectionBulletinBoard board = dataManager.fetchByPropertyValue(ConnectionBulletinBoard.class, "targetResourceId", id).orElse(null); final ConnectionBulletinBoard.Builder builder; if (board != null) { builder = new ConnectionBulletinBoard.Builder() .createFrom(board); } else { builder = new ConnectionBulletinBoard.Builder() .id(KeyGenerator.createKey()) .targetResourceId(id) .createdAt(System.currentTimeMillis()); } List<LeveledMessage> messages = new ArrayList<>(); messages.addAll(computeValidatorMessages(LeveledMessage.Builder::new, connection)); messages.addAll(computePropertiesDiffMessages(LeveledMessage.Builder::new, oldConnector.getProperties(), newConnector.getProperties())); if (!connection.isDerived()) { messages.addAll(computeMissingMandatoryPropertiesMessages( LeveledMessage.Builder::new, newConnector.getProperties(), merge(newConnector.getConfiguredProperties(), connection.getConfiguredProperties())) ); } messages.addAll(computeSecretsUpdateMessages(LeveledMessage.Builder::new, newConnector.getProperties(), connection.getConfiguredProperties())); builder.errors(countMessagesWithLevel(LeveledMessage.Level.ERROR, messages)); builder.warnings(countMessagesWithLevel(LeveledMessage.Level.WARN, messages)); builder.notices(countMessagesWithLevel(LeveledMessage.Level.INFO, messages)); builder.putMetadata("connector-id", newConnector.getId().get()); builder.putMetadata("connector-version-latest", Integer.toString(newConnector.getVersion())); builder.putMetadata("connector-version-connection", Integer.toString(oldConnector.getVersion())); builder.messages(messages); ConnectionBulletinBoard updated = builder.build(); if (!updated.equals(board)) { return builder.updatedAt(System.currentTimeMillis()).build(); } return null; } }
ConnectionUpdateHandler extends AbstractResourceUpdateHandler<ConnectionBulletinBoard> { ConnectionBulletinBoard computeBoard(Connection connection, Connector oldConnector, Connector newConnector) { final DataManager dataManager = getDataManager(); final String id = connection.getId().get(); final ConnectionBulletinBoard board = dataManager.fetchByPropertyValue(ConnectionBulletinBoard.class, "targetResourceId", id).orElse(null); final ConnectionBulletinBoard.Builder builder; if (board != null) { builder = new ConnectionBulletinBoard.Builder() .createFrom(board); } else { builder = new ConnectionBulletinBoard.Builder() .id(KeyGenerator.createKey()) .targetResourceId(id) .createdAt(System.currentTimeMillis()); } List<LeveledMessage> messages = new ArrayList<>(); messages.addAll(computeValidatorMessages(LeveledMessage.Builder::new, connection)); messages.addAll(computePropertiesDiffMessages(LeveledMessage.Builder::new, oldConnector.getProperties(), newConnector.getProperties())); if (!connection.isDerived()) { messages.addAll(computeMissingMandatoryPropertiesMessages( LeveledMessage.Builder::new, newConnector.getProperties(), merge(newConnector.getConfiguredProperties(), connection.getConfiguredProperties())) ); } messages.addAll(computeSecretsUpdateMessages(LeveledMessage.Builder::new, newConnector.getProperties(), connection.getConfiguredProperties())); builder.errors(countMessagesWithLevel(LeveledMessage.Level.ERROR, messages)); builder.warnings(countMessagesWithLevel(LeveledMessage.Level.WARN, messages)); builder.notices(countMessagesWithLevel(LeveledMessage.Level.INFO, messages)); builder.putMetadata("connector-id", newConnector.getId().get()); builder.putMetadata("connector-version-latest", Integer.toString(newConnector.getVersion())); builder.putMetadata("connector-version-connection", Integer.toString(oldConnector.getVersion())); builder.messages(messages); ConnectionBulletinBoard updated = builder.build(); if (!updated.equals(board)) { return builder.updatedAt(System.currentTimeMillis()).build(); } return null; } ConnectionUpdateHandler(DataManager dataManager, EncryptionComponent encryptionComponent, Validator validator); }
ConnectionUpdateHandler extends AbstractResourceUpdateHandler<ConnectionBulletinBoard> { ConnectionBulletinBoard computeBoard(Connection connection, Connector oldConnector, Connector newConnector) { final DataManager dataManager = getDataManager(); final String id = connection.getId().get(); final ConnectionBulletinBoard board = dataManager.fetchByPropertyValue(ConnectionBulletinBoard.class, "targetResourceId", id).orElse(null); final ConnectionBulletinBoard.Builder builder; if (board != null) { builder = new ConnectionBulletinBoard.Builder() .createFrom(board); } else { builder = new ConnectionBulletinBoard.Builder() .id(KeyGenerator.createKey()) .targetResourceId(id) .createdAt(System.currentTimeMillis()); } List<LeveledMessage> messages = new ArrayList<>(); messages.addAll(computeValidatorMessages(LeveledMessage.Builder::new, connection)); messages.addAll(computePropertiesDiffMessages(LeveledMessage.Builder::new, oldConnector.getProperties(), newConnector.getProperties())); if (!connection.isDerived()) { messages.addAll(computeMissingMandatoryPropertiesMessages( LeveledMessage.Builder::new, newConnector.getProperties(), merge(newConnector.getConfiguredProperties(), connection.getConfiguredProperties())) ); } messages.addAll(computeSecretsUpdateMessages(LeveledMessage.Builder::new, newConnector.getProperties(), connection.getConfiguredProperties())); builder.errors(countMessagesWithLevel(LeveledMessage.Level.ERROR, messages)); builder.warnings(countMessagesWithLevel(LeveledMessage.Level.WARN, messages)); builder.notices(countMessagesWithLevel(LeveledMessage.Level.INFO, messages)); builder.putMetadata("connector-id", newConnector.getId().get()); builder.putMetadata("connector-version-latest", Integer.toString(newConnector.getVersion())); builder.putMetadata("connector-version-connection", Integer.toString(oldConnector.getVersion())); builder.messages(messages); ConnectionBulletinBoard updated = builder.build(); if (!updated.equals(board)) { return builder.updatedAt(System.currentTimeMillis()).build(); } return null; } ConnectionUpdateHandler(DataManager dataManager, EncryptionComponent encryptionComponent, Validator validator); @Override boolean canHandle(ChangeEvent event); }
ConnectionUpdateHandler extends AbstractResourceUpdateHandler<ConnectionBulletinBoard> { ConnectionBulletinBoard computeBoard(Connection connection, Connector oldConnector, Connector newConnector) { final DataManager dataManager = getDataManager(); final String id = connection.getId().get(); final ConnectionBulletinBoard board = dataManager.fetchByPropertyValue(ConnectionBulletinBoard.class, "targetResourceId", id).orElse(null); final ConnectionBulletinBoard.Builder builder; if (board != null) { builder = new ConnectionBulletinBoard.Builder() .createFrom(board); } else { builder = new ConnectionBulletinBoard.Builder() .id(KeyGenerator.createKey()) .targetResourceId(id) .createdAt(System.currentTimeMillis()); } List<LeveledMessage> messages = new ArrayList<>(); messages.addAll(computeValidatorMessages(LeveledMessage.Builder::new, connection)); messages.addAll(computePropertiesDiffMessages(LeveledMessage.Builder::new, oldConnector.getProperties(), newConnector.getProperties())); if (!connection.isDerived()) { messages.addAll(computeMissingMandatoryPropertiesMessages( LeveledMessage.Builder::new, newConnector.getProperties(), merge(newConnector.getConfiguredProperties(), connection.getConfiguredProperties())) ); } messages.addAll(computeSecretsUpdateMessages(LeveledMessage.Builder::new, newConnector.getProperties(), connection.getConfiguredProperties())); builder.errors(countMessagesWithLevel(LeveledMessage.Level.ERROR, messages)); builder.warnings(countMessagesWithLevel(LeveledMessage.Level.WARN, messages)); builder.notices(countMessagesWithLevel(LeveledMessage.Level.INFO, messages)); builder.putMetadata("connector-id", newConnector.getId().get()); builder.putMetadata("connector-version-latest", Integer.toString(newConnector.getVersion())); builder.putMetadata("connector-version-connection", Integer.toString(oldConnector.getVersion())); builder.messages(messages); ConnectionBulletinBoard updated = builder.build(); if (!updated.equals(board)) { return builder.updatedAt(System.currentTimeMillis()).build(); } return null; } ConnectionUpdateHandler(DataManager dataManager, EncryptionComponent encryptionComponent, Validator validator); @Override boolean canHandle(ChangeEvent event);  }