ConnectServiceImpl implements ConnectService { public boolean configurationMatches(ConnectorInstance connectorInstance, ConnectorInstance existingConnectorInstance) { Assert.notNull(existingConnectorInstance, "Existing connector instance is undefined for " + connectorInstance.getName() + "."); Assert.notNull(existingConnectorInstance.getConfig(), "Configuration is undefined for existing connector instance " + connectorInstance.getName() + "."); boolean mismatch = existingConnectorInstance.getConfig().entrySet().stream() .filter(entry -> existingConnectorInstance.getConfig().containsKey(entry.getKey())) .filter(entry -> !existingConnectorInstance.getConfig().get(entry.getKey()).equals(entry.getValue())) .count() != 0 || connectorInstance.getConfig().entrySet().stream() .filter(entry -> !existingConnectorInstance.getConfig().containsKey(entry.getKey())) .count() != 0 || existingConnectorInstance.getConfig().entrySet().stream() .filter(existingEntry -> !connectorInstance.getConfig().containsKey(existingEntry.getKey())) .count() != 0; if (!mismatch) { LOGGER.info("New configuration matches for connector instance {}.", connectorInstance.getName()); } else { LOGGER.info("New configuration mismatch for connector instance {}.", connectorInstance.getName()); } return !mismatch; } ConnectServiceImpl(WebClient connectWebClient); @Override Mono<Void> deleteConnector(String name); @Override Mono<Void> refreshConnector(ConnectorInstance connectorInstance); boolean configurationMatches(ConnectorInstance connectorInstance,
			ConnectorInstance existingConnectorInstance);  }
@Test public void assertIdenticalConfiguration() { Map<String, String> newConfig = new HashMap<>(); newConfig.put("config1", "value1"); newConfig.put("config2", "value2"); newConfig.put("config3", "value3"); ConnectorInstance connectorInstance = new ConnectorInstance("test-connector", newConfig); Map<String, String> oldConfig = new HashMap<>(); oldConfig.put("config1", "value1"); oldConfig.put("config2", "value2"); oldConfig.put("config3", "value3"); ConnectorInstance existingConnectorInstance = new ConnectorInstance("test-connector", oldConfig); Assertions.assertTrue(connectService.configurationMatches(connectorInstance, existingConnectorInstance)); }
@Test public void assertMismatchingConfiguration() { Map<String, String> newConfig = new HashMap<>(); newConfig.put("config1", "value1"); newConfig.put("config2", "value2"); ConnectorInstance connectorInstance = new ConnectorInstance("test-connector", newConfig); Map<String, String> oldConfig = new HashMap<>(); oldConfig.put("config1", "value1"); oldConfig.put("config2", "value2"); oldConfig.put("config3", "value3"); ConnectorInstance existingConnectorInstance = new ConnectorInstance("test-connector", oldConfig); Assertions.assertFalse(connectService.configurationMatches(connectorInstance, existingConnectorInstance)); newConfig = new HashMap<>(); newConfig.put("config1", "value1"); newConfig.put("config2", "value2"); newConfig.put("config3", "value3"); connectorInstance = new ConnectorInstance("test-connector", newConfig); oldConfig = new HashMap<>(); oldConfig.put("config1", "value1"); oldConfig.put("config2", "value2"); existingConnectorInstance = new ConnectorInstance("test-connector", oldConfig); Assertions.assertFalse(connectService.configurationMatches(connectorInstance, existingConnectorInstance)); newConfig = new HashMap<>(); newConfig.put("config1", "bad-value"); newConfig.put("config2", "value2"); newConfig.put("config3", "value3"); connectorInstance = new ConnectorInstance("test-connector", newConfig); oldConfig = new HashMap<>(); oldConfig.put("config1", "value1"); oldConfig.put("config2", "value2"); newConfig.put("config3", "value3"); existingConnectorInstance = new ConnectorInstance("test-connector", oldConfig); Assertions.assertFalse(connectService.configurationMatches(connectorInstance, existingConnectorInstance)); }