use of com.thoughtworks.go.domain.feed.FeedEntry 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);
}
use of com.thoughtworks.go.domain.feed.FeedEntry 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);
}
use of com.thoughtworks.go.domain.feed.FeedEntry 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());
}
use of com.thoughtworks.go.domain.feed.FeedEntry 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);
}
use of com.thoughtworks.go.domain.feed.FeedEntry 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)));
}
Aggregations