Search in sources :

Example 1 with FeedEntries

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

the class StageServiceIntegrationTest method shouldLoadStageAuthorsAndMingleCards_forFirstPageOfFeed.

@Test
public void shouldLoadStageAuthorsAndMingleCards_forFirstPageOfFeed() 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);
    FeedEntries feed = stageService.feed(downstream.name().toString(), new Username(new CaseInsensitiveString("loser")));
    assertStageEntryAuthorAndMingleCards(upstreamMingle, downstreamMingle, feed);
}
Also used : FeedEntries(com.thoughtworks.go.domain.feed.FeedEntries) Username(com.thoughtworks.go.server.domain.Username) Test(org.junit.Test)

Example 2 with FeedEntries

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

the class StageServiceIntegrationTest method shouldLoadStageAuthorsAndMingleCards_forSubsequentPages.

@Test
public void shouldLoadStageAuthorsAndMingleCards_forSubsequentPages() 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);
    FeedEntries feed = stageService.feedBefore(Integer.MAX_VALUE, downstream.name().toString(), new Username(new CaseInsensitiveString("loser")));
    assertStageEntryAuthorAndMingleCards(upstreamMingle, downstreamMingle, feed);
}
Also used : FeedEntries(com.thoughtworks.go.domain.feed.FeedEntries) Username(com.thoughtworks.go.server.domain.Username) Test(org.junit.Test)

Example 3 with FeedEntries

use of com.thoughtworks.go.domain.feed.FeedEntries 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 4 with FeedEntries

use of com.thoughtworks.go.domain.feed.FeedEntries 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 5 with FeedEntries

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

the class FeedService method stagesXml.

public Document stagesXml(Username username, String pipelineName, Integer pipelineCounter, String baseUrl) {
    if (!goConfigService.hasPipelineNamed(new CaseInsensitiveString(pipelineName))) {
        throw new RecordNotFoundException(EntityType.Pipeline, pipelineName);
    }
    if (!securityService.hasViewPermissionForPipeline(username, pipelineName)) {
        throw new NotAuthorizedException(NOT_AUTHORIZED_TO_VIEW_PIPELINE);
    }
    FeedEntries feedEntries = stageService.findStageFeedBy(pipelineName, pipelineCounter, FeedModifier.Before, username);
    FeedEntriesRepresenter representable = new FeedEntriesRepresenter(pipelineName, feedEntries);
    return xmlApiService.write(representable, baseUrl);
}
Also used : FeedEntries(com.thoughtworks.go.domain.feed.FeedEntries) RecordNotFoundException(com.thoughtworks.go.config.exceptions.RecordNotFoundException) NotAuthorizedException(com.thoughtworks.go.config.exceptions.NotAuthorizedException) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString)

Aggregations

FeedEntries (com.thoughtworks.go.domain.feed.FeedEntries)18 Author (com.thoughtworks.go.domain.feed.Author)7 StageFeedEntry (com.thoughtworks.go.domain.feed.stage.StageFeedEntry)7 Username (com.thoughtworks.go.server.domain.Username)7 Test (org.junit.Test)6 Test (org.junit.jupiter.api.Test)6 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)5 FeedEntry (com.thoughtworks.go.domain.feed.FeedEntry)4 Arrays.asList (java.util.Arrays.asList)4 List (java.util.List)3 XmlWriterContext (com.thoughtworks.go.domain.XmlWriterContext)2 FileSource (com.thoughtworks.go.junit5.FileSource)2 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)2 ArrayList (java.util.ArrayList)2 Document (org.dom4j.Document)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 BasicCruiseConfig (com.thoughtworks.go.config.BasicCruiseConfig)1 CruiseConfig (com.thoughtworks.go.config.CruiseConfig)1 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)1 NotAuthorizedException (com.thoughtworks.go.config.exceptions.NotAuthorizedException)1