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", "<script>this && that</script>,", "matcher2");
}
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));
}
}
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();
}
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();
}
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);
}
Aggregations