Search in sources :

Example 1 with User

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

the class NotificationTemplateTest method shouldHTMLEscapeMatchers.

@Test
public void shouldHTMLEscapeMatchers() throws Exception {
    HashMap<String, Object> data = new HashMap<>();
    User user = new User("name", "display-name", new String[] { "<script>this && that</script>", "matcher2" }, "email1@host.com", true);
    user.populateModel(data);
    data.put("pipelines", "[]");
    data.put("l", null);
    Document actualDoc = Jsoup.parse(new TestVelocityView(TEMPLATE_PATH, data).render());
    assertMatchers(actualDoc, "<script>this && that</script>,matcher2", "&lt;script&gt;this &amp;&amp; that&lt;/script&gt;,", "matcher2");
}
Also used : User(com.thoughtworks.go.domain.User) HashMap(java.util.HashMap) Document(org.jsoup.nodes.Document) Test(org.junit.Test)

Example 2 with User

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

the class StageNotificationService method sendNotifications.

public void sendNotifications(StageIdentifier stageIdentifier, StageEvent event, Username cancelledBy) {
    Users users = userService.findValidSubscribers(stageIdentifier.stageConfigIdentifier());
    if (users.isEmpty()) {
        return;
    }
    Stage stage = stageService.findStageWithIdentifier(stageIdentifier);
    Pipeline pipeline = pipelineService.fullPipelineById(stage.getPipelineId());
    MaterialRevisions materialRevisions = pipeline.getMaterialRevisions();
    List<TestSuite> failedTestSuites = null;
    if (systemEnvironment.isShineEnabled()) {
        failedTestSuites = shineDao.failedTestsFor(stageIdentifier);
    }
    String emailBody = new EmailBodyGenerator(materialRevisions, cancelledBy, systemEnvironment, stageIdentifier, failedTestSuites).getContent();
    String subject = "Stage [" + stageIdentifier.stageLocator() + "]" + event.describe();
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug(String.format("Processing notification titled [%s]", subject));
    }
    for (User user : users) {
        if (user.matchNotification(stageIdentifier.stageConfigIdentifier(), event, materialRevisions)) {
            StringBuilder emailWithSignature = new StringBuilder(emailBody).append("\n\n").append("Sent by Go on behalf of ").append(user.getName());
            SendEmailMessage sendEmailMessage = new SendEmailMessage(subject, emailWithSignature.toString(), user.getEmail());
            emailNotificationTopic.post(sendEmailMessage);
        }
    }
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug(String.format("Finished processing notification titled [%s]", subject));
    }
}
Also used : User(com.thoughtworks.go.domain.User) SendEmailMessage(com.thoughtworks.go.server.messaging.SendEmailMessage) TestSuite(com.thoughtworks.go.domain.testinfo.TestSuite) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) Stage(com.thoughtworks.go.domain.Stage) Users(com.thoughtworks.go.domain.Users) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Pipeline(com.thoughtworks.go.domain.Pipeline)

Example 3 with User

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

the class UserSqlMapDaoCachingTest method shouldRemoveEnabledUserCountFromCacheWhenAUserIsDisabled.

@Test
public void shouldRemoveEnabledUserCountFromCacheWhenAUserIsDisabled() throws Exception {
    userDao.saveOrUpdate(new User("some-random-user"));
    makeSureThatCacheIsInitialized();
    userDao.disableUsers(Arrays.asList("some-random-user"));
    assertThatEnabledUserCacheHasBeenCleared();
}
Also used : User(com.thoughtworks.go.domain.User) Test(org.junit.Test)

Example 4 with User

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

the class UserSqlMapDaoCachingTest method shouldRemoveEnabledUserCountFromCacheWhenAUserIsSaved.

@Test
public void shouldRemoveEnabledUserCountFromCacheWhenAUserIsSaved() throws Exception {
    makeSureThatCacheIsInitialized();
    userDao.saveOrUpdate(new User("some-random-user"));
    assertThatEnabledUserCacheHasBeenCleared();
}
Also used : User(com.thoughtworks.go.domain.User) Test(org.junit.Test)

Example 5 with User

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

the class UserSqlMapDaoCachingTest method enabledUserCacheShouldBeThreadSafe.

@Test(timeout = 60000)
public void enabledUserCacheShouldBeThreadSafe() throws Exception {
    ThreadSafetyChecker threadSafetyChecker = new ThreadSafetyChecker(10000);
    threadSafetyChecker.addOperation(new ThreadSafetyChecker.Operation() {

        @Override
        public void execute(int runIndex) {
            StopWatch stopWatch = new StopWatch("enabledUserCount");
            stopWatch.start("enabledUserCount");
            userDao.enabledUserCount();
            stopWatch.stop();
            System.out.println(stopWatch.shortSummary());
        }
    });
    threadSafetyChecker.addOperation(new ThreadSafetyChecker.Operation() {

        @Override
        public void execute(int runIndex) {
            StopWatch stopWatch = new StopWatch("deleteAll");
            stopWatch.start("deleteAll");
            userDao.deleteAll();
            stopWatch.stop();
            System.out.println(stopWatch.shortSummary());
        }
    });
    threadSafetyChecker.addOperation(new ThreadSafetyChecker.Operation() {

        @Override
        public void execute(int runIndex) {
            StopWatch stopWatch = new StopWatch("saveOrUpdate");
            stopWatch.start("saveOrUpdate");
            userDao.saveOrUpdate(new User("some-random-user " + runIndex));
            stopWatch.stop();
            System.out.println(stopWatch.shortSummary());
        }
    });
    threadSafetyChecker.addOperation(new ThreadSafetyChecker.Operation() {

        @Override
        public void execute(int runIndex) {
            StopWatch stopWatch = new StopWatch("enableUsers");
            stopWatch.start("enableUsers");
            userDao.enableUsers(Arrays.asList("some-random-user " + runIndex));
            stopWatch.stop();
            System.out.println(stopWatch.shortSummary());
        }
    });
    threadSafetyChecker.run(250);
}
Also used : User(com.thoughtworks.go.domain.User) StopWatch(org.springframework.util.StopWatch) Test(org.junit.Test)

Aggregations

User (com.thoughtworks.go.domain.User)49 Test (org.junit.Test)35 NullUser (com.thoughtworks.go.domain.NullUser)10 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)7 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)6 NotificationFilter (com.thoughtworks.go.domain.NotificationFilter)6 UserSearchModel (com.thoughtworks.go.presentation.UserSearchModel)6 HashMap (java.util.HashMap)5 Document (org.jsoup.nodes.Document)5 PipelineSelections (com.thoughtworks.go.server.domain.user.PipelineSelections)4 Date (java.util.Date)4 ArrayList (java.util.ArrayList)3 StringContains.containsString (org.hamcrest.core.StringContains.containsString)3 Authentication (org.springframework.security.Authentication)3 PipelineConfigs (com.thoughtworks.go.config.PipelineConfigs)2 Users (com.thoughtworks.go.domain.Users)2 HashSet (java.util.HashSet)2 DisabledException (org.springframework.security.DisabledException)2 TransactionStatus (org.springframework.transaction.TransactionStatus)2 ModelAndView (org.springframework.web.servlet.ModelAndView)2