Search in sources :

Example 16 with StageFeedEntry

use of com.thoughtworks.go.domain.feed.stage.StageFeedEntry in project gocd by gocd.

the class FeedEntriesRepresenterTest method shouldGenerateFeedXml.

@ParameterizedTest
@FileSource(files = "/feeds/stages-with-entries.xml")
void shouldGenerateFeedXml(String expectedXML) {
    String pipelineName = "up42";
    StageFeedEntry entryOne = cancelled();
    StageFeedEntry entryTwo = passed();
    entryOne.getAuthors().add(new Author("bob", "bob@gocd.org"));
    entryTwo.getAuthors().add(new Author("joe <joe@gocd.org>", null));
    XmlWriterContext context = new XmlWriterContext("https://go-server/go", null, null, null, new SystemEnvironment());
    FeedEntriesRepresenter representable = new FeedEntriesRepresenter(pipelineName, new FeedEntries(entryOne, entryTwo));
    Document document = representable.toXml(context);
    XmlAssert.assertThat(document.asXML()).and(expectedXML).ignoreWhitespace().areIdentical();
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) FeedEntries(com.thoughtworks.go.domain.feed.FeedEntries) Author(com.thoughtworks.go.domain.feed.Author) XmlWriterContext(com.thoughtworks.go.domain.XmlWriterContext) Document(org.dom4j.Document) StageFeedEntry(com.thoughtworks.go.domain.feed.stage.StageFeedEntry) FileSource(com.thoughtworks.go.junit5.FileSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 17 with StageFeedEntry

use of com.thoughtworks.go.domain.feed.stage.StageFeedEntry in project gocd by gocd.

the class StageServiceTest method shouldReturnFeedsEvenIfUpstreamPipelineIsDeleted.

@Test
public void shouldReturnFeedsEvenIfUpstreamPipelineIsDeleted() {
    Date updateDate = new Date();
    CruiseConfig config = mock(BasicCruiseConfig.class);
    PipelineConfig pipelineConfig = PipelineConfigMother.pipelineConfig("down");
    Map<Long, List<ModificationForPipeline>> expectedModMapDown = new HashMap<>();
    Modification mod1 = checkinWithComment("revision", "#123 hello wolrd", updateDate);
    expectedModMapDown.put(1L, asList(new ModificationForPipeline(new PipelineId("down", 1L), mod1, "Svn", "fooBarBaaz")));
    FeedEntry expected = stageFeedEntry("down", updateDate);
    when(stageDao.findCompletedStagesFor("down", FeedModifier.Latest, -1, 25)).thenReturn(asList(stageFeedEntry("down", updateDate), stageFeedEntry("down", updateDate)));
    when(goConfigService.currentCruiseConfig()).thenReturn(config);
    when(changesetService.modificationsOfPipelines(asList(1L, 1L), "down", Username.ANONYMOUS)).thenReturn(expectedModMapDown);
    when(config.hasPipelineNamed(any(CaseInsensitiveString.class))).thenReturn(false).thenReturn(true);
    when(config.pipelineConfigByName(any(CaseInsensitiveString.class))).thenReturn(pipelineConfig);
    StageService service = new StageService(stageDao, null, null, null, null, null, changesetService, goConfigService, transactionTemplate, transactionSynchronizationManager, new StubGoCache(transactionSynchronizationManager));
    FeedEntries feedEntries = service.feed("down", Username.ANONYMOUS);
    assertThat(feedEntries).isEqualTo(new FeedEntries(asList(expected, expected)));
    assertThat(feedEntries.get(0).getAuthors()).isEqualTo(asList(new Author(MOD_USER_COMMITTER, EMAIL_ADDRESS)));
    assertThat(feedEntries.get(1).getAuthors()).isEqualTo(asList(new Author(MOD_USER_COMMITTER, EMAIL_ADDRESS)));
}
Also used : FeedEntries(com.thoughtworks.go.domain.feed.FeedEntries) Modification(com.thoughtworks.go.domain.materials.Modification) PipelineConfig(com.thoughtworks.go.config.PipelineConfig) HashMap(java.util.HashMap) ModificationForPipeline(com.thoughtworks.go.server.ui.ModificationForPipeline) Date(java.util.Date) CruiseConfig(com.thoughtworks.go.config.CruiseConfig) BasicCruiseConfig(com.thoughtworks.go.config.BasicCruiseConfig) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) StageFeedEntry(com.thoughtworks.go.domain.feed.stage.StageFeedEntry) FeedEntry(com.thoughtworks.go.domain.feed.FeedEntry) PipelineId(com.thoughtworks.go.server.ui.PipelineId) Author(com.thoughtworks.go.domain.feed.Author) Arrays.asList(java.util.Arrays.asList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) Test(org.junit.jupiter.api.Test)

Example 18 with StageFeedEntry

use of com.thoughtworks.go.domain.feed.stage.StageFeedEntry in project gocd by gocd.

the class StageSqlMapDaoIntegrationTest method findCompletedStagesFor_shouldInvalidateCacheOnCompletionOfAStageForTheGivenPipeline.

@Test
public void findCompletedStagesFor_shouldInvalidateCacheOnCompletionOfAStageForTheGivenPipeline() {
    SqlMapClientTemplate mockTemplate = mock(SqlMapClientTemplate.class);
    stageDao.setSqlMapClientTemplate(mockTemplate);
    List<StageFeedEntry> entries = asList(new StageFeedEntry(1L, 1L, null, 1L, null, null));
    when(mockTemplate.queryForList(eq("allCompletedStagesForPipeline"), any())).thenReturn((List) entries);
    stageDao.findCompletedStagesFor("cruise", FeedModifier.Latest, 10, 100);
    updateResultInTransaction(StageMother.completedFailedStageInstance("cruise", "stage", "job"), StageResult.Failed);
    List<FeedEntry> actual = new ArrayList<>(stageDao.findCompletedStagesFor("cruise", FeedModifier.Latest, 10, 100));
    assertThat(actual).isEqualTo(entries);
    verify(mockTemplate, times(2)).queryForList(eq("allCompletedStagesForPipeline"), any());
}
Also used : StageFeedEntry(com.thoughtworks.go.domain.feed.stage.StageFeedEntry) FeedEntry(com.thoughtworks.go.domain.feed.FeedEntry) SqlMapClientTemplate(com.thoughtworks.go.server.transaction.SqlMapClientTemplate) StageFeedEntry(com.thoughtworks.go.domain.feed.stage.StageFeedEntry) Test(org.junit.jupiter.api.Test)

Example 19 with StageFeedEntry

use of com.thoughtworks.go.domain.feed.stage.StageFeedEntry in project gocd by gocd.

the class StageSqlMapDaoIntegrationTest method shouldLoadApproverAndUnderstandIfBuildWasForced.

@Test
public void shouldLoadApproverAndUnderstandIfBuildWasForced() throws SQLException {
    mingleConfig.get(0).updateApproval(Approval.manualApproval());
    Pipeline cancelled = dbHelper.schedulePipeline(mingleConfig, ModificationsMother.modifySomeFiles(mingleConfig), "loser", new TimeProvider());
    dbHelper.cancelStage(pipelineAndFirstStageOf(cancelled).stage);
    mingleConfig.get(0).updateApproval(Approval.automaticApproval());
    Pipeline passed = dbHelper.schedulePipeline(mingleConfig, ModificationsMother.modifySomeFiles(mingleConfig), "boozer", new TimeProvider());
    dbHelper.passStage(pipelineAndFirstStageOf(passed).stage);
    Pipeline failed = dbHelper.schedulePipeline(mingleConfig, new TimeProvider());
    dbHelper.failStage(pipelineAndFirstStageOf(failed).stage);
    List<StageFeedEntry> completedStages = stageDao.findCompletedStagesFor(mingleConfig.name().toString(), FeedModifier.Before, transitionId(pipelineAndFirstStageOf(failed).stage), 2);
    assertThat(completedStages.get(0).isManuallyTriggered()).isFalse();
    assertThat(completedStages.get(0).getApprovedBy()).isEqualTo("boozer");
    assertThat(completedStages.get(1).isManuallyTriggered()).isTrue();
    assertThat(completedStages.get(1).getApprovedBy()).isEqualTo("loser");
}
Also used : TimeProvider(com.thoughtworks.go.util.TimeProvider) StageFeedEntry(com.thoughtworks.go.domain.feed.stage.StageFeedEntry) Test(org.junit.jupiter.api.Test)

Aggregations

StageFeedEntry (com.thoughtworks.go.domain.feed.stage.StageFeedEntry)19 FeedEntries (com.thoughtworks.go.domain.feed.FeedEntries)8 Author (com.thoughtworks.go.domain.feed.Author)7 FeedEntry (com.thoughtworks.go.domain.feed.FeedEntry)6 Test (org.junit.Test)6 Test (org.junit.jupiter.api.Test)5 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)4 Arrays.asList (java.util.Arrays.asList)4 List (java.util.List)4 StageIdentifier (com.thoughtworks.go.domain.StageIdentifier)3 ModificationForPipeline (com.thoughtworks.go.server.ui.ModificationForPipeline)3 StageAtomFeedsReader (com.thoughtworks.studios.shine.cruise.stage.feeds.StageAtomFeedsReader)3 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 CruiseConfig (com.thoughtworks.go.config.CruiseConfig)2 XmlWriterContext (com.thoughtworks.go.domain.XmlWriterContext)2 Document (org.dom4j.Document)2 BasicCruiseConfig (com.thoughtworks.go.config.BasicCruiseConfig)1 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)1 XmlRepresentable (com.thoughtworks.go.domain.XmlRepresentable)1