Search in sources :

Example 1 with NotificationFilter

use of com.thoughtworks.go.domain.NotificationFilter in project gocd by gocd.

the class StageNotificationServiceTest method prepareOneMatchedUser.

private String prepareOneMatchedUser() {
    String jezMail = "jez@cruise.com";
    User jez = new User("jez", new String[] { "lgao" }, jezMail, true);
    jez.setNotificationFilters(Arrays.asList(new NotificationFilter("go", "dev", StageEvent.All, true)));
    when(userService.findValidSubscribers(new StageConfigIdentifier("go", "dev"))).thenReturn(new Users(Arrays.asList(jez)));
    return jezMail;
}
Also used : User(com.thoughtworks.go.domain.User) StageConfigIdentifier(com.thoughtworks.go.domain.StageConfigIdentifier) Matchers.anyString(org.mockito.Matchers.anyString) StringContains.containsString(org.hamcrest.core.StringContains.containsString) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Users(com.thoughtworks.go.domain.Users) NotificationFilter(com.thoughtworks.go.domain.NotificationFilter)

Example 2 with NotificationFilter

use of com.thoughtworks.go.domain.NotificationFilter in project gocd by gocd.

the class MyGoControllerTest method shouldRenderPipelineStageCombinationJSONSortedByPipelineNameIgnoringCase.

@Test
public void shouldRenderPipelineStageCombinationJSONSortedByPipelineNameIgnoringCase() {
    HttpServletRequest request = mock(HttpServletRequest.class);
    User user = new User(USERNAME, "Srikanth Maga", new String[] { "rope", "srikanth" }, "sriki@tw.com", true);
    user.addNotificationFilter(new NotificationFilter("p1", "s1", StageEvent.All, true));
    user.addNotificationFilter(new NotificationFilter("p2", "s2", StageEvent.Fails, true));
    when(userService.load(USERID)).thenReturn(user);
    List<PipelineConfigs> groups = new ArrayList<>();
    groups.add(PipelineConfigMother.createGroup("g3", PipelineConfigMother.createPipelineConfigWithStages("pipeline3-1", "stage3-1")));
    groups.add(PipelineConfigMother.createGroup("g1", PipelineConfigMother.createPipelineConfigWithStages("PIPELINE2-1", "stage2-1")));
    groups.add(PipelineConfigMother.createGroup("g1", PipelineConfigMother.createPipelineConfigWithStages("pipeline1-1", "stage1-1", "stage1-2")));
    when(pipelineConfigService.viewableGroupsFor(new Username(new CaseInsensitiveString(user.getName())))).thenReturn(groups);
    ModelAndView modelAndView = controller.handleRequest(null, request);
    assertThat(modelAndView.getModel().get("matchers"), is(new Matcher("rope,srikanth")));
    assertThat(modelAndView.getModel().get("email"), is("sriki@tw.com"));
    assertThat(modelAndView.getModel().get("emailMe"), is(true));
    assertThat(modelAndView.getModel().get("notificationFilters"), is(user.getNotificationFilters()));
    assertThat(modelAndView.getModel().get("l"), is(localizer));
    assertThat(modelAndView.getModel().get("pipelines"), is("[{\"name\":\"" + GoConstants.ANY_PIPELINE + "\",\"stages\":[{\"stageName\":\"" + GoConstants.ANY_STAGE + "\"}]}," + "{\"name\":\"pipeline1-1\",\"stages\":[{\"stageName\":\"" + GoConstants.ANY_STAGE + "\"},{\"stageName\":\"stage1-1\"},{\"stageName\":\"stage1-2\"}]}," + "{\"name\":\"PIPELINE2-1\",\"stages\":[{\"stageName\":\"" + GoConstants.ANY_STAGE + "\"},{\"stageName\":\"stage2-1\"}]}," + "{\"name\":\"pipeline3-1\",\"stages\":[{\"stageName\":\"" + GoConstants.ANY_STAGE + "\"},{\"stageName\":\"stage3-1\"}]}]"));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) User(com.thoughtworks.go.domain.User) Username(com.thoughtworks.go.server.domain.Username) Matcher(com.thoughtworks.go.domain.Matcher) ArrayList(java.util.ArrayList) ModelAndView(org.springframework.web.servlet.ModelAndView) PipelineConfigs(com.thoughtworks.go.config.PipelineConfigs) NotificationFilter(com.thoughtworks.go.domain.NotificationFilter) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 3 with NotificationFilter

use of com.thoughtworks.go.domain.NotificationFilter in project gocd by gocd.

the class StageNotificationServiceIntegrationTest method prepareOneNotMatchedUser.

private String prepareOneNotMatchedUser() {
    String chrisMail = "chris@cruise.com";
    User chris = new User("chris", new String[] { "will not be matched" }, chrisMail, true);
    chris.addNotificationFilter(new NotificationFilter(pipelineFixture.pipelineName, pipelineFixture.ftStage, StageEvent.All, true));
    userDao.saveOrUpdate(chris);
    return chrisMail;
}
Also used : User(com.thoughtworks.go.domain.User) StringContains.containsString(org.hamcrest.core.StringContains.containsString) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) NotificationFilter(com.thoughtworks.go.domain.NotificationFilter)

Example 4 with NotificationFilter

use of com.thoughtworks.go.domain.NotificationFilter in project gocd by gocd.

the class StageNotificationServiceIntegrationTest method prepareOneMatchedUser.

private String prepareOneMatchedUser(StageEvent event) {
    String jezMail = "jez@cruise.com";
    User jez = new User("jez", new String[] { "lgao" }, jezMail, true);
    jez.addNotificationFilter(new NotificationFilter(pipelineFixture.pipelineName, pipelineFixture.ftStage, event, true));
    userDao.saveOrUpdate(jez);
    return jezMail;
}
Also used : User(com.thoughtworks.go.domain.User) StringContains.containsString(org.hamcrest.core.StringContains.containsString) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) NotificationFilter(com.thoughtworks.go.domain.NotificationFilter)

Example 5 with NotificationFilter

use of com.thoughtworks.go.domain.NotificationFilter in project gocd by gocd.

the class UserSqlMapDaoCachingTest method shouldCacheUserOnFind.

@Test
public void shouldCacheUserOnFind() {
    User first = new User("first");
    first.addNotificationFilter(new NotificationFilter("pipline", "stage1", StageEvent.Fails, true));
    first.addNotificationFilter(new NotificationFilter("pipline", "stage2", StageEvent.Fails, true));
    int originalUserCacheSize = sessionFactory.getStatistics().getSecondLevelCacheStatistics(User.class.getCanonicalName()).getEntries().size();
    int originalNotificationsCacheSize = sessionFactory.getStatistics().getSecondLevelCacheStatistics(User.class.getCanonicalName() + ".notificationFilters").getEntries().size();
    userDao.saveOrUpdate(first);
    long userId = userDao.findUser("first").getId();
    assertThat(sessionFactory.getStatistics().getSecondLevelCacheStatistics(User.class.getCanonicalName()).getEntries().size(), is(originalUserCacheSize + 1));
    SecondLevelCacheStatistics notificationFilterCollectionCache = sessionFactory.getStatistics().getSecondLevelCacheStatistics(User.class.getCanonicalName() + ".notificationFilters");
    assertThat(notificationFilterCollectionCache.getEntries().size(), is(originalNotificationsCacheSize + 1));
    assertThat(notificationFilterCollectionCache.getEntries().get(userId), is(Matchers.notNullValue()));
}
Also used : User(com.thoughtworks.go.domain.User) SecondLevelCacheStatistics(org.hibernate.stat.SecondLevelCacheStatistics) NotificationFilter(com.thoughtworks.go.domain.NotificationFilter) Test(org.junit.Test)

Aggregations

NotificationFilter (com.thoughtworks.go.domain.NotificationFilter)7 User (com.thoughtworks.go.domain.User)6 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)4 StringContains.containsString (org.hamcrest.core.StringContains.containsString)3 Test (org.junit.Test)3 PipelineConfigs (com.thoughtworks.go.config.PipelineConfigs)1 Matcher (com.thoughtworks.go.domain.Matcher)1 StageConfigIdentifier (com.thoughtworks.go.domain.StageConfigIdentifier)1 Users (com.thoughtworks.go.domain.Users)1 Username (com.thoughtworks.go.server.domain.Username)1 Redirection (com.thoughtworks.go.server.ui.controller.Redirection)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 SecondLevelCacheStatistics (org.hibernate.stat.SecondLevelCacheStatistics)1 Document (org.jsoup.nodes.Document)1 Matchers.anyString (org.mockito.Matchers.anyString)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1