Search in sources :

Example 1 with StageFeedEntry

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

the class StageServiceTest method findCompletedStagesFor_shouldNotCacheTheResultPerPipelineForFeedsBeforeAGivenID.

@Test
public void findCompletedStagesFor_shouldNotCacheTheResultPerPipelineForFeedsBeforeAGivenID() {
    Date updateDate = new Date();
    when(stageDao.findCompletedStagesFor("cruise", FeedModifier.Before, 1L, 25)).thenReturn(asList(stageFeedEntry("cruise", updateDate))).thenReturn(asList(stageFeedEntry("cruise", updateDate)));
    // Setup Mingle Config
    MingleConfig mingleConfig = new MingleConfig("http://foo.bar:7019/baz/", "go-project");
    when(goConfigService.currentCruiseConfig()).thenReturn(cruiseConfigWithMingle("cruise", mingleConfig));
    // Setup card numbers
    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);
    FeedEntries feedEntries = service.feedBefore(1L, "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"))));
    feedEntries = service.feedBefore(1L, "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, times(2)).findCompletedStagesFor("cruise", FeedModifier.Before, 1L, 25);
    verifyNoMoreInteractions(stageDao);
}
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 2 with StageFeedEntry

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

the class StageServiceTest method findCompletedStagesFor_shouldInvalidateCacheOnCompletionOfAStage.

@Test
public void findCompletedStagesFor_shouldInvalidateCacheOnCompletionOfAStage() {
    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 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"))));
    Stage stage = StageMother.createPassedStage("cruise", 1, "stage", 1, "job", updateDate);
    stage.setIdentifier(new StageIdentifier("cruise", 1, "stage", String.valueOf(1)));
    // Should remove from the cache
    service.updateResult(stage);
    // Should retrieve from db again.
    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, times(2)).findCompletedStagesFor("cruise", FeedModifier.Latest, -1, 25);
    verify(changesetService, times(2)).modificationsOfPipelines(asList(1L), "cruise", Username.ANONYMOUS);
    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 3 with StageFeedEntry

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

the class StageAtomFeedsReaderTest method checkWeFollowPagingUntilWeHitADuplicate.

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

Example 4 with StageFeedEntry

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

the class StageSqlMapDaoIntegrationTest method shouldReturnAllCompletedStagesForTheGivenPipeline.

@Test
public void shouldReturnAllCompletedStagesForTheGivenPipeline() throws SQLException {
    PipelineAndStage[] cruiseStages = run4Pipelines("cruise");
    run4Pipelines("mingle");
    List<FeedEntry> completedStages = new ArrayList<>(stageDao.findCompletedStagesFor("cruise", FeedModifier.Latest, -1, 5));
    StageFeedEntry latestFeedEntry = (StageFeedEntry) completedStages.get(0);
    assertThat(completedStages.size()).isEqualTo(4);
    assertFeed(completedStages.get(0), cruiseStages[3].stage);
    assertFeed(completedStages.get(1), cruiseStages[2].stage);
    assertFeed(completedStages.get(2), cruiseStages[1].stage);
    assertFeed(completedStages.get(3), cruiseStages[0].stage);
    assertThat(latestFeedEntry.getResult()).isEqualTo(StageResult.Failed.name());
    assertThat(latestFeedEntry.getPipelineId()).isEqualTo(cruiseStages[3].stage.getPipelineId());
}
Also used : StageFeedEntry(com.thoughtworks.go.domain.feed.stage.StageFeedEntry) FeedEntry(com.thoughtworks.go.domain.feed.FeedEntry) StageFeedEntry(com.thoughtworks.go.domain.feed.stage.StageFeedEntry) Test(org.junit.jupiter.api.Test)

Example 5 with StageFeedEntry

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

the class StageSqlMapDaoIntegrationTest method findStageFeedBy_shouldGetStageFeeds.

@Test
public void findStageFeedBy_shouldGetStageFeeds() {
    PipelineAndStage[] cruiseStages = run4Pipelines("cruise");
    run4Pipelines("mingle");
    List<StageFeedEntry> completedStages = stageDao.findStageFeedBy("cruise", 1, FeedModifier.Latest, 2);
    StageFeedEntry latestFeedEntry = completedStages.get(0);
    assertThat(completedStages.size()).isEqualTo(2);
    assertFeed(completedStages.get(0), cruiseStages[3].stage);
    assertFeed(completedStages.get(1), cruiseStages[2].stage);
    assertThat(latestFeedEntry.getResult()).isEqualTo(StageResult.Failed.name());
    assertThat(latestFeedEntry.getPipelineId()).isEqualTo(cruiseStages[3].stage.getPipelineId());
}
Also used : 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