use of com.thoughtworks.go.domain.feed.Author in project gocd by gocd.
the class StageFeedEntryTest method shouldNotAddDuplicateAuthorsCardsToAuthorsList.
@Test
public void shouldNotAddDuplicateAuthorsCardsToAuthorsList() {
StageFeedEntry entry = new StageFeedEntry(1, 1, new StageIdentifier(), 1, new Date(), StageResult.Passed);
entry.addAuthor(new Author("name", "email"));
entry.addAuthor(new Author("name", "email"));
entry.addAuthor(new Author("name1", "email1"));
assertThat(entry.getAuthors().size(), is(2));
}
use of com.thoughtworks.go.domain.feed.Author 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.Author 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.Author 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);
}
}
}
}
use of com.thoughtworks.go.domain.feed.Author in project gocd by gocd.
the class StageServiceIntegrationTest method shouldNotLoadStageAuthorsAndMingleCards_fromUpstreamInvisibleToUser.
@Test
public void shouldNotLoadStageAuthorsAndMingleCards_fromUpstreamInvisibleToUser() throws Exception {
MingleConfig upstreamMingle = new MingleConfig("https://mingle.gingle/when/single", "jingle");
MingleConfig downstreamMingle = new MingleConfig("https://downstream-mingle", "go");
PipelineConfig downstream = setup2DependentInstances(upstreamMingle, downstreamMingle);
configFileHelper.enableSecurity();
configFileHelper.addAdmins("super-hero");
configFileHelper.addAuthorizedUserForPipelineGroup("loser", "upstream-without-mingle");
configFileHelper.addAuthorizedUserForPipelineGroup("loser", "downstream");
configFileHelper.addAuthorizedUserForPipelineGroup("boozer", "upstream-with-mingle");
FeedEntries feed = stageService.feed(downstream.name().toString(), new Username(new CaseInsensitiveString("loser")));
assertAuthorsAndCardsOnEntry((StageFeedEntry) feed.get(0), Arrays.asList(new Author("svn 3 guy", "svn.3@gmail.com"), new Author("p4 2 guy", "p4.2@gmail.com")), Arrays.asList(new MingleCard(downstreamMingle, "103")));
assertAuthorsAndCardsOnEntry((StageFeedEntry) feed.get(1), Arrays.asList(new Author("svn 1 guy", "svn.1@gmail.com"), new Author("svn 2 guy", "svn.2@gmail.com"), new Author("p4 1 guy", "p4.1@gmail.com")), Arrays.asList(new MingleCard(downstreamMingle, "101"), new MingleCard(downstreamMingle, "102")));
}
Aggregations