ConnectorDefinitionService { protected void validate(List<ConnectorDefinition> connectorDefinitions) { if (!connectorDefinitions.isEmpty()) { Set<String> processedNames = new HashSet<>(); for (ConnectorDefinition connectorDefinition : connectorDefinitions) { String name = connectorDefinition.getName(); if (name == null || name.isEmpty()) { throw new IllegalStateException("connectorDefinition name cannot be null or empty"); } if (name.contains(".")) { throw new IllegalStateException("connectorDefinition name cannot have '.' character"); } if (!processedNames.add(name)) { throw new IllegalStateException("More than one connectorDefinition with name '" + name + "' was found. Names must be unique."); } } } } ConnectorDefinitionService(String connectorRoot, ObjectMapper objectMapper, ResourcePatternResolver resourceLoader); List<ConnectorDefinition> get();  }
@Test public void validateShouldThrowExceptionWhenConnectorNameIsNull() { ConnectorDefinition connectorDefinition = new ConnectorDefinition(); connectorDefinition.setName(null); Throwable throwable = catchThrowable( () -> connectorDefinitionService.validate(Collections.singletonList(connectorDefinition)) ); assertThat(throwable) .isInstanceOf(IllegalStateException.class) .hasMessage("connectorDefinition name cannot be null or empty"); }
@Test public void validateShouldThrowExceptionWhenConnectorNameIsEmpty() { ConnectorDefinition connectorDefinition = new ConnectorDefinition(); connectorDefinition.setName(""); Throwable throwable = catchThrowable( () -> connectorDefinitionService.validate(Collections.singletonList(connectorDefinition)) ); assertThat(throwable) .isInstanceOf(IllegalStateException.class) .hasMessage("connectorDefinition name cannot be null or empty"); }
@Test public void validateShouldThrowExceptionWhenConnectorNameContainsDotCharacter() { ConnectorDefinition connectorDefinition = new ConnectorDefinition(); connectorDefinition.setName("connector.name"); Throwable throwable = catchThrowable( () -> connectorDefinitionService.validate(Collections.singletonList(connectorDefinition)) ); assertThat(throwable) .isInstanceOf(IllegalStateException.class) .hasMessage("connectorDefinition name cannot have '.' character"); }
@Test public void validateShouldThrowExceptionWhenTwoConnectorsHaveTheSameName() { ConnectorDefinition connectorDefinition = new ConnectorDefinition(); connectorDefinition.setName("Conflicting name connector"); ConnectorDefinition connectorDefinitionWithSameName = new ConnectorDefinition(); connectorDefinitionWithSameName.setName("Conflicting name connector"); Throwable throwable = catchThrowable( () -> connectorDefinitionService.validate(Arrays.asList(connectorDefinition, connectorDefinitionWithSameName)) ); assertThat(throwable) .isInstanceOf(IllegalStateException.class) .hasMessage("More than one connectorDefinition with name '" + connectorDefinition.getName() + "' was found. Names must be unique."); }