@Test public void shouldCreateGroupForCurrentConfigIfItHasChanged() throws Exception { PipelineHistoryGroups historyGroups = preparePipelineHistoryGroups(pipelineConfig); PipelineConfig newConfig = PipelineConfigMother.createPipelineConfigWithStages("mingle", "stage1", "stage2"); presenter = new PipelineHistoryJsonPresentationModel( pipelinePauseInfo, historyGroups, newConfig, pagination(), CAN_FORCE, hasForceBuildCause, hasModification, true); JsonTester jsonTester = new JsonTester(presenter.toJson()); jsonTester.shouldContain( "{ 'groups' : [ {" + " 'config' : {" + " 'stages' : [ " + " {'name' : 'stage1', isAutoApproved : 'true'}," + " {'name' : 'stage2', isAutoApproved : 'true'}" + " ]" + " }" + " }, {" + " 'config' : {" + " 'stages' : [ " + " {'name' : 'dev', isAutoApproved : 'true'}," + " {'name' : 'ft', isAutoApproved : 'false'}" + " ]" + " }" + " } ]" + "}"); }
@Test public void needsApprovalInJsonShouldBeFalseWhenPipelineIsPaused() throws Exception { pipelinePauseInfo.setPaused(true); JsonTester jsonTester = new JsonTester(presenter.toJson()); jsonTester.shouldContain("{ 'paused' : 'true' }"); jsonTester.shouldNotContain("{ 'needsApproval' : 'true' }"); }
@Test public void shouldContainPipelineHistory() throws Exception { JsonMap json = presenter.toJson(); JsonTester jsonTester = new JsonTester(json); jsonTester.shouldContain( "{ 'groups' : [ {" + " 'history' : [" + " { 'pipelineId' : '1'," + " 'scheduled_date' : 'less than a minute ago'," + " 'stages' : [" + " { 'stageStatus' : 'Passed', 'stageName':'dev', 'stageId':'0'," + " 'approvedBy' : '" + DEFAULT_APPROVED_BY + "', " + " 'getCanRun' : 'false' , 'scheduled' : 'true' }," + " { 'stageStatus' : 'Passed', 'stageName':'ft', 'stageId':'0'," + " 'approvedBy' : '" + APPROVED_BY + "', " + " 'getCanRun' : 'false', 'getCanCancel' : 'false', 'scheduled' : 'true' }]" + " }" + " ]" + " } ] " + "}"); }
@Test public void shouldContainPipelinePauseInfo() throws Exception { pipelinePauseInfo.setPaused(true); pipelinePauseInfo.setPauseCause("pauseCause"); pipelinePauseInfo.setPauseBy("pauseBy"); JsonTester jsonTester = new JsonTester(presenter.toJson()); jsonTester.shouldContain("{ 'paused' : 'true' }"); jsonTester.shouldContain("{ 'pauseCause' : 'pauseCause' }"); jsonTester.shouldContain("{ 'pauseBy' : 'pauseBy' }"); }
@Test public void shouldContainPipelineConfig() throws Exception { JsonTester jsonTester = new JsonTester(presenter.toJson()); jsonTester.shouldContain( "{ 'groups' : [ {" + " 'config' : {" + " 'stages' : [ " + " {'name' : 'dev', isAutoApproved : 'true'}," + " {'name' : 'ft', isAutoApproved : 'false'}" + " ]" + " }" + " } ] " + "}"); }
@Test public void shouldEscapeBuildCauseMessage() throws Exception { String userWithHtmlCharacters = "<user>"; pipeline.setBuildCause( BuildCause.createManualForced( materialRevisions(userWithHtmlCharacters), new Username(new CaseInsensitiveString(userWithHtmlCharacters)))); StageJsonPresentationModel presenter = new StageJsonPresentationModel(pipeline, stage, null, new Agents()); JsonTester jsonTester = new JsonTester(presenter.toJson()); String expected = StringEscapeUtils.escapeHtml(userWithHtmlCharacters); jsonTester.shouldContain("{'buildCause':'Forced by " + expected + "'}"); }
@Test public void shouldContainPipelinePageInfo() throws Exception { JsonTester jsonTester = new JsonTester(presenter.toJson()); jsonTester.shouldContain( "{ 'pipelineName' : 'mingle'," + " 'count' : '" + COUNT + "'," + " 'canForce' : '" + (CAN_FORCE ? "true" : "false") + "'," + " 'start' : '" + START + "'," + " 'perPage' : '" + PER_PAGE + "'," + "}"); }