Search in sources :

Example 6 with StageFeedEntry

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

the class StageService method populateAuthorsAndMingleCards.

private void populateAuthorsAndMingleCards(List<StageFeedEntry> stageEntries, String pipelineName, Username username) {
    List<Long> pipelineIds = new ArrayList<>();
    for (StageFeedEntry stageEntry : stageEntries) {
        pipelineIds.add(stageEntry.getPipelineId());
    }
    CruiseConfig config = goConfigService.currentCruiseConfig();
    Map<Long, List<ModificationForPipeline>> revisionsPerPipeline = changesetService.modificationsOfPipelines(pipelineIds, pipelineName, username);
    for (StageFeedEntry stageEntry : stageEntries) {
        List<ModificationForPipeline> revs = revisionsPerPipeline.get(stageEntry.getPipelineId());
        for (ModificationForPipeline rev : revs) {
            Author author = rev.getAuthor();
            if (author != null) {
                stageEntry.addAuthor(author);
            }
            String pipelineForRev = rev.getPipelineId().getPipelineName();
            if (config.hasPipelineNamed(new CaseInsensitiveString(pipelineForRev))) {
                PipelineConfig pipelineConfig = config.pipelineConfigByName(new CaseInsensitiveString(pipelineForRev));
                MingleConfig mingleConfig = pipelineConfig.getMingleConfig();
                Set<String> cardNos = rev.getCardNumbersFromComments();
                if (mingleConfig.isDefined()) {
                    for (String cardNo : cardNos) {
                        stageEntry.addCard(new MingleCard(mingleConfig, cardNo));
                    }
                }
            } else {
                LOGGER.debug("pipeline not found: {}", pipelineForRev);
            }
        }
    }
}
Also used : ModificationForPipeline(com.thoughtworks.go.server.ui.ModificationForPipeline) StageFeedEntry(com.thoughtworks.go.domain.feed.stage.StageFeedEntry) MingleCard(com.thoughtworks.go.server.ui.MingleCard) Author(com.thoughtworks.go.domain.feed.Author)

Example 7 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(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));
    assertEquals(entries, actual);
    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(org.springframework.orm.ibatis.SqlMapClientTemplate) StageFeedEntry(com.thoughtworks.go.domain.feed.stage.StageFeedEntry) Test(org.junit.Test)

Example 8 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");
    MingleConfig mingleConfig = new MingleConfig("http://foo.bar:7019/baz/", "go-project");
    pipelineConfig.setMingleConfig(mingleConfig);
    Map<Long, List<ModificationForPipeline>> expectedModMapDown = new HashMap<>();
    Modification mod1 = ModificationsMother.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, is(new FeedEntries(asList(expected, expected))));
    assertThat(feedEntries.get(0).getAuthors(), is(asList(new Author(ModificationsMother.MOD_USER_COMMITTER, ModificationsMother.EMAIL_ADDRESS))));
    assertEquals(feedEntries.get(0).getMingleCards().size(), 0);
    assertThat(feedEntries.get(1).getAuthors(), is(asList(new Author(ModificationsMother.MOD_USER_COMMITTER, ModificationsMother.EMAIL_ADDRESS))));
    assertThat(feedEntries.get(1).getMingleCards(), is(asList(new MingleCard(mingleConfig, "123"))));
}
Also used : FeedEntries(com.thoughtworks.go.domain.feed.FeedEntries) Modification(com.thoughtworks.go.domain.materials.Modification) StageFeedEntry(com.thoughtworks.go.domain.feed.stage.StageFeedEntry) FeedEntry(com.thoughtworks.go.domain.feed.FeedEntry) Author(com.thoughtworks.go.domain.feed.Author) Arrays.asList(java.util.Arrays.asList) Test(org.junit.Test)

Example 9 with StageFeedEntry

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

the class StageServiceTest method findCompletedStagesFor_shouldCacheTheResultPerPipeline.

@Test
public void findCompletedStagesFor_shouldCacheTheResultPerPipeline() {
    Date updateDate = new Date();
    when(stageDao.findCompletedStagesFor("cruise", FeedModifier.Latest, -1, 25)).thenReturn(asList(stageFeedEntry("cruise", updateDate))).thenReturn(asList(stageFeedEntry("cruise", updateDate)));
    MingleConfig mingleConfig = new MingleConfig("http://foo.bar:7019/baz/", "go-project");
    when(goConfigService.currentCruiseConfig()).thenReturn(cruiseConfigWithMingle("cruise", mingleConfig));
    Map<Long, List<ModificationForPipeline>> expectedMap = new HashMap<>();
    expectedMap.put(1L, asList(new ModificationForPipeline(new PipelineId("cruise", 1L), ModificationsMother.checkinWithComment("revision", "#123 hello wolrd", updateDate), "Svn", "fooBarBaaz")));
    when(changesetService.modificationsOfPipelines(asList(1L), "cruise", Username.ANONYMOUS)).thenReturn(expectedMap);
    StageService service = new StageService(stageDao, null, null, null, null, null, changesetService, goConfigService, transactionTemplate, transactionSynchronizationManager, new StubGoCache(transactionSynchronizationManager));
    FeedEntry expected = stageFeedEntry("cruise", updateDate);
    // Should prime the cache
    FeedEntries feedEntries = service.feed("cruise", Username.ANONYMOUS);
    assertThat(feedEntries, is(new FeedEntries(asList(expected))));
    assertThat(feedEntries.get(0).getAuthors(), is(asList(new Author(ModificationsMother.MOD_USER_COMMITTER, ModificationsMother.EMAIL_ADDRESS))));
    assertThat(feedEntries.get(0).getMingleCards(), is(asList(new MingleCard(mingleConfig, "123"))));
    // Should use the cache
    feedEntries = service.feed("cruise", Username.ANONYMOUS);
    assertThat(feedEntries, is(new FeedEntries(asList(expected))));
    assertThat(feedEntries.get(0).getAuthors(), is(asList(new Author(ModificationsMother.MOD_USER_COMMITTER, ModificationsMother.EMAIL_ADDRESS))));
    assertThat(feedEntries.get(0).getMingleCards(), is(asList(new MingleCard(mingleConfig, "123"))));
    verify(stageDao).findCompletedStagesFor("cruise", FeedModifier.Latest, -1, 25);
    verify(changesetService).modificationsOfPipelines(asList(1L), "cruise", Username.ANONYMOUS);
    verifyNoMoreInteractions(stageDao);
    verifyNoMoreInteractions(changesetService);
}
Also used : FeedEntries(com.thoughtworks.go.domain.feed.FeedEntries) StageFeedEntry(com.thoughtworks.go.domain.feed.stage.StageFeedEntry) FeedEntry(com.thoughtworks.go.domain.feed.FeedEntry) Author(com.thoughtworks.go.domain.feed.Author) Arrays.asList(java.util.Arrays.asList) Test(org.junit.Test)

Example 10 with StageFeedEntry

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

the class StageAtomFeedsReaderTest method canPaginateToGetStages.

@Test
public void canPaginateToGetStages() throws Exception {
    when(stageDao.findAllCompletedStages(FeedModifier.Latest, -1, StageAtomFeedsReader.PAGE_SIZE)).thenReturn(Arrays.asList(feedEntry(4), feedEntry(3)));
    when(stageDao.findAllCompletedStages(FeedModifier.Before, 3, StageAtomFeedsReader.PAGE_SIZE)).thenReturn(Arrays.asList(feedEntry(2), feedEntry(1)));
    new StageAtomFeedsReader(stageDao).readFromLatest(stageFeedHandler, pipelineInstanceLoader);
    List<StageFeedEntry> list = stageFeedHandler.handledFeeds();
    assertEquals(4, list.size());
    assertEquals(4, list.get(0).getId());
    assertEquals(3, list.get(1).getId());
    assertEquals(2, list.get(2).getId());
    assertEquals(1, list.get(3).getId());
}
Also used : StageAtomFeedsReader(com.thoughtworks.studios.shine.cruise.stage.feeds.StageAtomFeedsReader) StageFeedEntry(com.thoughtworks.go.domain.feed.stage.StageFeedEntry) Test(org.junit.Test)

Aggregations

StageFeedEntry (com.thoughtworks.go.domain.feed.stage.StageFeedEntry)11 Test (org.junit.Test)9 FeedEntry (com.thoughtworks.go.domain.feed.FeedEntry)6 Author (com.thoughtworks.go.domain.feed.Author)5 FeedEntries (com.thoughtworks.go.domain.feed.FeedEntries)5 Arrays.asList (java.util.Arrays.asList)4 StageAtomFeedsReader (com.thoughtworks.studios.shine.cruise.stage.feeds.StageAtomFeedsReader)3 Modification (com.thoughtworks.go.domain.materials.Modification)1 MingleCard (com.thoughtworks.go.server.ui.MingleCard)1 ModificationForPipeline (com.thoughtworks.go.server.ui.ModificationForPipeline)1 SqlMapClientTemplate (org.springframework.orm.ibatis.SqlMapClientTemplate)1