@Override public boolean validateTree(ValidationContext validationContext) { validate(validationContext); return !hasErrors(); }
@Test public void validate_shouldValidatePluggableArtifactStoreId() { final ValidationContext validationContext = mock(ValidationContext.class); final PluggableArtifactConfig artifactConfig = new PluggableArtifactConfig("Artifact-ID", "Store-ID"); final ArtifactStores artifactStores = mock(ArtifactStores.class); assertFalse(artifactConfig.hasErrors()); when(validationContext.artifactStores()).thenReturn(artifactStores); when(validationContext.isWithinPipelines()).thenReturn(true); when(validationContext.getPipeline()).thenReturn(PipelineConfigMother.pipelineConfig("pipe")); when(artifactStores.find("Store-ID")).thenReturn(null); artifactConfig.validate(validationContext); assertTrue(artifactConfig.hasErrors()); assertThat(artifactConfig.errors().getAll(), hasSize(1)); assertThat(artifactConfig.errors().getAllOn("storeId"), hasSize(1)); assertThat(artifactConfig.errors().on("storeId"), is("Artifact store with id `Store-ID` does not exist. Please correct the `storeId` attribute on pipeline `pipe`.")); }
@Test public void validate_shouldValidateUniquenessOnId() { final PluggableArtifactConfig existingConfig = new PluggableArtifactConfig("Artifact-ID", "Store-ID"); final List<ArtifactConfig> artifactConfigConfigs = Arrays.asList(existingConfig); final PluggableArtifactConfig newConfig = new PluggableArtifactConfig("Artifact-ID", "Store-ID"); newConfig.validateUniqueness(artifactConfigConfigs); assertTrue(newConfig.hasErrors()); assertTrue(existingConfig.hasErrors()); assertThat(newConfig.errors().on("id"), is("Duplicate pluggable artifacts with id `Artifact-ID` defined.")); assertThat(existingConfig.errors().on("id"), is("Duplicate pluggable artifacts with id `Artifact-ID` defined.")); }
@Test public void validate_shouldValidateArtifactPropertiesConfigurationKeyUniqueness() { final ValidationContext validationContext = mock(ValidationContext.class); final PluggableArtifactConfig artifactConfig = new PluggableArtifactConfig("Artifact-ID", "Store-ID", create("Foo", false, "Bar"), create("Foo", true, "Bar")); final ArtifactStores artifactStores = mock(ArtifactStores.class); assertFalse(artifactConfig.hasErrors()); when(validationContext.artifactStores()).thenReturn(artifactStores); when(artifactStores.find("Store-ID")).thenReturn(new ArtifactStore("Store-ID", "pluginId")); artifactConfig.validate(validationContext); Configuration configuration = artifactConfig.getConfiguration(); assertThat(configuration.get(0).errors().getAllOn("configurationKey"), is(Arrays.asList("Duplicate key 'Foo' found for Pluggable Artifact"))); assertThat(configuration.get(1).errors().getAllOn("configurationKey"), is(Arrays.asList("Duplicate key 'Foo' found for Pluggable Artifact"))); }
@Test public void validate_shouldValidateArtifactPropertiesConfig() { final PluggableArtifactConfig existingConfig = new PluggableArtifactConfig("id1", "Store-ID", create("Foo", false, "Bar")); final List<ArtifactConfig> artifactConfigConfigs = Arrays.asList(existingConfig); final PluggableArtifactConfig newConfig = new PluggableArtifactConfig("id2", "Store-ID", create("Foo", false, "Bar")); newConfig.validateUniqueness(artifactConfigConfigs); assertTrue(newConfig.hasErrors()); assertTrue(existingConfig.hasErrors()); assertThat(newConfig.errors().on("id"), is("Duplicate pluggable artifacts configuration defined.")); assertThat(existingConfig.errors().on("id"), is("Duplicate pluggable artifacts configuration defined.")); }
@Test public void validate_shouldNotErrorWhenArtifactPropertiesConfigurationIsSameForDifferentStores() { final PluggableArtifactConfig existingConfig = new PluggableArtifactConfig("id1", "storeId1", create("Foo", false, "Bar")); final List<ArtifactConfig> artifactConfigConfigs = Arrays.asList(existingConfig); final PluggableArtifactConfig newConfig = new PluggableArtifactConfig("id2", "storeId2", create("Foo", false, "Bar")); newConfig.validateUniqueness(artifactConfigConfigs); assertFalse(newConfig.hasErrors()); assertFalse(existingConfig.hasErrors()); assertNull(newConfig.errors().on("id")); assertNull(existingConfig.errors().on("id")); }