private void assertXsdFailureDuringLoad(String configXML, String... expectedMessages) { assertFailureDuringLoad(configXML, XsdValidationException.class, expectedMessages); }
@Test public void shouldNotAllowInvalidLabelTemplate() throws Exception { assertPipelineLabelTemplate("1.3.0"); assertPipelineLabelTemplate("1.3.0-{COUNT}"); assertPipelineLabelTemplate("1.3.0-$COUNT}"); assertPipelineLabelTemplate("1.3.0-${COUNT"); assertPipelineLabelTemplate("1.3.0-${}"); assertPipelineLabelTemplate("1.3.0-${COUNT}-${git:7]}"); assertPipelineLabelTemplate("1.3.0-${COUNT}-${git[:7}"); assertPipelineLabelTemplate("1.3.0-${COUNT}-${git[7]}"); assertPipelineLabelTemplate("1.3.0-${COUNT}-${git[:]}"); assertPipelineLabelTemplate("1.3.0-${COUNT}-${git[:-1]}"); }
@Test public void shouldThrowXsdValidationWhenPackageRepositoryIdsAreDuplicate() throws Exception { String xml = "<cruise schemaVersion='" + CONFIG_SCHEMA_VERSION + "'><repositories>\n" + withPackages(REPO, "") + withPackages(REPO, "") + " </repositories></cruise>"; assertXsdFailureDuringLoad(xml, "Duplicate unique value [repo-id] declared for identity constraint of element \"repositories\".", "Duplicate unique value [repo-id] declared for identity constraint \"uniqueRepositoryId\" of element \"repositories\"." ); }
@Test public void shouldNotAllowEmptyAuthInApproval() throws Exception { assertXsdFailureDuringLoad(STAGE_WITH_EMPTY_AUTH, "The content of element 'authorization' is not complete. One of '{user, role}' is expected."); }
@Test public void shouldDisallowModificationOfTokenGenerationKeyWhileTheServerIsOnline() throws Exception { xmlLoader.loadConfigHolder(configWithTokenGenerationKey("something")); systemEnvironment.setProperty("go.enforce.server.immutability", "Y"); assertFailureDuringLoad(configWithTokenGenerationKey("something-else"), RuntimeException.class, "The value of 'tokenGenerationKey' cannot be modified while the server is online. If you really want to make this change, you may do so while the server is offline. Please note: updating 'tokenGenerationKey' will invalidate all registration tokens issued to the agents so far."); }
@Test public void shouldNotThrowErrorIfMultipleMaterialsHaveSimilarNamesBug2337() throws Exception { String materials = " <materials>\n" + " <svn url=\"/hgrepo1\" dest=\"folder1/folder2\"/>\n" + " <svn url=\"/hgrepo2\" dest=\"folder1/folder2different\" />\n" + " </materials>\n"; assertValidMaterials(materials); }
/** * This is a test for a specific bug at a customer installation caused by a StackOverflowException in Xerces. * It seems to be caused by a regex bug in nonEmptyString. */ @Test public void shouldLoadConfigurationFileWithComplexNonEmptyString() throws Exception { String customerXML = this.getClass().getResource("/data/p4_heavy_cruise_config.xml").getFile(); assertThat(loadWithMigration(customerXML), not(nullValue())); }
@Test public void shouldNotAllowIllegalValueForRunOnAllAgents() throws Exception { try { loadJobWithRunOnAllAgents("bad_value"); fail("should have failed as runOnAllAgents' value is not valid(boolean)"); } catch (Exception e) { assertThat(e.getMessage(), containsString("'bad_value' is not a valid value for 'boolean'")); } }
@Test public void shouldNotAllowIllegalValueForRunMultipleInstanceJob() throws Exception { try { loadJobWithRunMultipleInstance("-1"); fail("should have failed as runOnAllAgents' value is not valid(boolean)"); } catch (Exception e) { assertThat(e.getMessage(), containsString("'-1' is not facet-valid with respect to minInclusive '1' for type 'positiveInteger'")); } try { loadJobWithRunMultipleInstance("abcd"); fail("should have failed as runOnAllAgents' value is not valid(boolean)"); } catch (Exception e) { assertThat(e.getMessage(), containsString("'abcd' is not a valid value for 'integer'")); } }
private void assertValidMaterials(String materials) throws Exception { createConfig(materials); }
ArtifactStore dockerhubStore = config.getArtifactStores().first(); assertConfigProperty(ancestorPublishArtifactConfig, "Image", "SECRET", true); assertConfigProperty(ancestorPublishArtifactConfig, "Tag", "ancestor_tag_${GO_PIPELINE_COUNTER}", false); assertConfigProperty(parentPublishArtifactConfig, "Image", "SECRET", true); assertConfigProperty(parentPublishArtifactConfig, "Tag", "parent_tag_${GO_PIPELINE_COUNTER}", false); assertConfigProperty(childFetchArtifactFromAncestorConfig, "FetchProperty", "SECRET", true); assertConfigProperty(childFetchArtifactFromAncestorConfig, "Tag", "ancestor_tag", false); assertConfigProperty(childFetchArtifactFromParentConfig, "FetchProperty", "SECRET", true); assertConfigProperty(childFetchArtifactFromParentConfig, "Tag", "parent_tag", false); assertConfigProperty(dockerhubStore, "RegistryURL", "https://index.docker.io/v1/", false); assertConfigProperty(dockerhubStore, "Username", "docker-user", false); assertConfigProperty(dockerhubStore, "Password", "SECRET", true);
@Test public void shouldThrowXsdValidationWhenPackageRepositoryNamesAreDuplicate() throws Exception { String xml = "<cruise schemaVersion='" + CONFIG_SCHEMA_VERSION + "'><repositories>\n" + format(REPO_WITH_NAME, "1", "repo", "") + format(REPO_WITH_NAME, "2", "repo", "") + " </repositories></cruise>"; assertXsdFailureDuringLoad(xml, "Duplicate unique value [repo] declared for identity constraint of element \"repositories\".", "Duplicate unique value [repo] declared for identity constraint \"uniqueRepositoryName\" of element \"repositories\"." ); }
@Test public void shouldNotThrowErrorIfMultipleMaterialsHaveSimilarNamesInDifferentOrder() throws Exception { String materials = " <materials>\n" + " <svn url=\"/hgrepo2\" dest=\"folder1/folder2different\" />\n" + " <svn url=\"/hgrepo1\" dest=\"folder1/folder2\"/>\n" + " </materials>\n"; assertValidMaterials(materials); }
@Test public void shouldNotAllowEmptyViewForPerforce() throws Exception { try { String p4XML = this.getClass().getResource("/data/p4-cruise-config-empty-view.xml").getFile(); loadWithMigration(p4XML); fail("Should not accept p4 section with empty view."); } catch (Exception expected) { assertThat(expected.getMessage(), containsString("P4 view cannot be empty.")); } }
@Test public void shouldSupportRunOnAllAgents() throws Exception { CruiseConfig cruiseConfig = loadJobWithRunOnAllAgents("true"); JobConfig job = cruiseConfig.findJob("pipeline1", "mingle", "do-something"); JobConfig jobConfig = new JobConfig("do-something"); jobConfig.setRunOnAllAgents(true); assertThat(job, is(jobConfig)); }
@Test public void shouldSupportRunMultipleInstance() throws Exception { CruiseConfig cruiseConfig = loadJobWithRunMultipleInstance("10"); JobConfig job = cruiseConfig.findJob("pipeline1", "mingle", "do-something"); JobConfig jobConfig = new JobConfig("do-something"); jobConfig.setRunInstanceCount(10); assertThat(job, is(jobConfig)); }
@Test public void shouldThrowXsdValidationWhenPackageNameIsMissing() throws Exception { String xml = "<cruise schemaVersion='" + CONFIG_SCHEMA_VERSION + "'><repositories>\n" + withPackages(REPO_WITH_MISSING_NAME, PACKAGE_WITH_MISSING_NAME) + " </repositories></cruise>"; assertXsdFailureDuringLoad(xml, "\"Name\" is required for Repository"); }
@Test public void shouldThrowExceptionIfBuildPlansExistWithTheSameNameWithinAPipeline() throws Exception { assertXsdFailureDuringLoad(JOBS_WITH_SAME_NAME, "Duplicate unique value [unit] declared for identity constraint of element \"jobs\".", "Duplicate unique value [unit] declared for identity constraint \"uniqueJob\" of element \"jobs\"." ); }
@Test public void shouldFailValidationForPipelineWithDuplicateStageNames() throws Exception { assertFailureDuringLoad(PIPELINES_WITH_DUPLICATE_STAGE_NAME, RuntimeException.class, "You have defined multiple stages called 'mingle'. Stage names are case-insensitive and must be unique." ); }
@Test public void shouldThrowXsdValidationWhenPackageRepositoryNameIsMissing() throws Exception { String xml = "<cruise schemaVersion='" + CONFIG_SCHEMA_VERSION + "'><repositories>\n" + withPackages(REPO_WITH_MISSING_NAME, "") + " </repositories></cruise>"; assertXsdFailureDuringLoad(xml, "\"Name\" is required for Repository"); }