Search in sources :

Example 16 with FeedEntries

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

the class PipelineStagesFeedServiceTest method shouldReturnUnauthorizedIfUserDoesNotHaveViewPermissionsForFeedBefore.

@Test
public void shouldReturnUnauthorizedIfUserDoesNotHaveViewPermissionsForFeedBefore() {
    when(securityService.hasViewPermissionForPipeline(user, "cruise")).thenReturn(false);
    FeedEntries feedEntries = pipelineStagesFeedResolver.feedBefore(user, 100L, operationResult);
    assertThat(feedEntries, is(nullValue()));
    verifyThatUserIsUnauthorized();
    verifyNoMoreInteractions(stageService);
}
Also used : FeedEntries(com.thoughtworks.go.domain.feed.FeedEntries) Test(org.junit.jupiter.api.Test)

Example 17 with FeedEntries

use of com.thoughtworks.go.domain.feed.FeedEntries 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)));
}
Also used : FeedEntries(com.thoughtworks.go.domain.feed.FeedEntries) Modification(com.thoughtworks.go.domain.materials.Modification) PipelineConfig(com.thoughtworks.go.config.PipelineConfig) HashMap(java.util.HashMap) ModificationForPipeline(com.thoughtworks.go.server.ui.ModificationForPipeline) Date(java.util.Date) CruiseConfig(com.thoughtworks.go.config.CruiseConfig) BasicCruiseConfig(com.thoughtworks.go.config.BasicCruiseConfig) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) StageFeedEntry(com.thoughtworks.go.domain.feed.stage.StageFeedEntry) FeedEntry(com.thoughtworks.go.domain.feed.FeedEntry) PipelineId(com.thoughtworks.go.server.ui.PipelineId) Author(com.thoughtworks.go.domain.feed.Author) Arrays.asList(java.util.Arrays.asList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) Test(org.junit.jupiter.api.Test)

Example 18 with FeedEntries

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

the class StageServiceIntegrationTest method shouldNotLoadStageAuthors_fromUpstreamInvisibleToUser.

@Test
public void shouldNotLoadStageAuthors_fromUpstreamInvisibleToUser() throws Exception {
    PipelineConfig downstream = setup2DependentInstances();
    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")));
    assertAuthorsOnEntry((StageFeedEntry) feed.get(0), Arrays.asList(new Author("svn 3 guy", "svn.3@gmail.com"), new Author("p4 2 guy", "p4.2@gmail.com")));
    assertAuthorsOnEntry((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")));
}
Also used : FeedEntries(com.thoughtworks.go.domain.feed.FeedEntries) Username(com.thoughtworks.go.server.domain.Username) Author(com.thoughtworks.go.domain.feed.Author) Test(org.junit.jupiter.api.Test)

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