@Test public void shouldModifyExistingPipelineTemplateWhenPostedAsPartial() throws Exception { configHelper.addPipelineWithGroup( "some-group", "some-pipeline", "some-dev", "some-linux", "some-windows"); configHelper.addAgent("some-home", "UUID"); String newXml = NEW_TEMPLATES; String md5 = goConfigDao.md5OfConfigFile(); ModelAndView mav = controller.postGroupAsXmlPartial("Pipeline Templates", newXml, md5, response); assertResponseMessage(mav, "Template changed successfully."); assertThat(response.getStatus(), is(SC_OK)); assertThat(response.getContentType(), is(RESPONSE_CHARSET_JSON)); assertThat(configHelper.currentConfig().getTemplates().size(), is(1)); }
@Test public void shouldGetGroupWithTemplatesAsXml() throws Exception { configHelper.addTemplate("template-1", "dev"); configHelper.addPipelineWithGroup("group", "pipeline", "dev", "linux"); PipelineConfig pipelineWithTemplate = configHelper.addPipelineWithTemplate("group", "pipeline-with-template", "template-1"); assertThat( pipelineWithTemplate.size(), is(0)); // should not expect mutation of pipeline config passed in assertThat( configHelper .currentConfig() .pipelineConfigByName(new CaseInsensitiveString("pipeline-with-template")) .size(), is(1)); CruiseConfig config = goConfigService.currentCruiseConfig(); PipelineConfig pipelineConfig = config.pipelineConfigByName(new CaseInsensitiveString("pipeline-with-template")); assertThat("Should not modify the original template", pipelineConfig.size(), is(1)); controller.getGroupAsXmlPartial("group", null, response); String content = "<pipelines group=\"group\">\n" + " <pipeline name=\"pipeline\">\n" + " <materials>\n" + " <svn url=\"svn:///user:pass@tmp/foo\" />\n" + " </materials>\n" + " <stage name=\"dev\">\n" + " <jobs>\n" + " <job name=\"linux\" />\n" + " </jobs>\n" + " </stage>\n" + " </pipeline>\n" + " <pipeline name=\"pipeline-with-template\" template=\"template-1\">\n" + " <materials>\n" + " <svn url=\"svn:///user:pass@tmp/foo\" />\n" + " </materials>\n" + " </pipeline>\n" + "</pipelines>"; assertValidContentAndStatus(SC_OK, "text/xml", content); MockHttpServletResponse postResponse = new MockHttpServletResponse(); controller.postGroupAsXmlPartial("group", content, null, postResponse); config = goConfigService.currentCruiseConfig(); pipelineConfig = config.pipelineConfigByName(new CaseInsensitiveString("pipeline-with-template")); assertThat("Should not modify the original template", pipelineConfig.size(), is(1)); }