diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2019-04-10 11:17:00 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2019-04-23 10:37:56 +0200 |
commit | 0a302ac9af19485e0eb713776c1435bc64dbf8fd (patch) | |
tree | af85dbeae6aeb1f0790ab84fbceba93d120dbe1e /server | |
parent | 7fc90932dcb356e1f4078f1e2c07bf7a4f27bc23 (diff) | |
download | sonarqube-0a302ac9af19485e0eb713776c1435bc64dbf8fd.tar.gz sonarqube-0a302ac9af19485e0eb713776c1435bc64dbf8fd.zip |
SONAR-11753 fix DB incompatibility in EmailSubscriberDto
Diffstat (limited to 'server')
5 files changed, 59 insertions, 45 deletions
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/EmailSubscriberDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/EmailSubscriberDto.java index 7d12c847093..1f790579382 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/EmailSubscriberDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/EmailSubscriberDto.java @@ -20,19 +20,11 @@ package org.sonar.db; import java.util.Objects; -import javax.annotation.concurrent.Immutable; -@Immutable public final class EmailSubscriberDto { - private final String login; - private final boolean global; - private final String email; - - public EmailSubscriberDto(String login, boolean global, String email) { - this.login = login; - this.global = global; - this.email = email; - } + private String login; + private boolean global; + private String email; public String getLogin() { return login; @@ -46,6 +38,21 @@ public final class EmailSubscriberDto { return email; } + public EmailSubscriberDto setLogin(String login) { + this.login = login; + return this; + } + + public EmailSubscriberDto setGlobal(boolean global) { + this.global = global; + return this; + } + + public EmailSubscriberDto setEmail(String email) { + this.email = email; + return this; + } + @Override public boolean equals(Object o) { if (this == o) { @@ -73,4 +80,11 @@ public final class EmailSubscriberDto { ", email='" + email + '\'' + '}'; } + + public static EmailSubscriberDto create(String login, boolean global, String email) { + return new EmailSubscriberDto() + .setLogin(login) + .setGlobal(global) + .setEmail(email); + } } diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/permission/AuthorizationDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/permission/AuthorizationDaoTest.java index bd47b6e35d1..a9edaf58a21 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/permission/AuthorizationDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/permission/AuthorizationDaoTest.java @@ -1261,7 +1261,7 @@ public class AuthorizationDaoTest { } private static EmailSubscriberDto globalEmailSubscriberOf(UserDto userDto) { - return new EmailSubscriberDto(userDto.getLogin(), true, emailOf(userDto)); + return EmailSubscriberDto.create(userDto.getLogin(), true, emailOf(userDto)); } private static Consumer<UserDto> withEmail(String login) { diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesDaoTest.java index b93f129625d..26106ca6821 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/property/PropertiesDaoTest.java @@ -207,7 +207,7 @@ public class PropertiesDaoTest { insertProperty(propertyKeyOf(dispatcherKey, channelKey), "false", projectId, userId4); assertThat(underTest.findEmailSubscribersForNotification(db.getSession(), dispatcherKey, channelKey, null)) - .containsOnly(new EmailSubscriberDto("user1", true, emailOf("user1")), new EmailSubscriberDto("user2", true, emailOf("user2"))); + .containsOnly(EmailSubscriberDto.create("user1", true, emailOf("user1")), EmailSubscriberDto.create("user2", true, emailOf("user2"))); assertThat(underTest.findEmailSubscribersForNotification(db.getSession(), dispatcherKey, otherChannelKey, null)) .isEmpty(); @@ -240,13 +240,13 @@ public class PropertiesDaoTest { Set<String> allLogins = of("user1", "user2", "user3", "user4"); assertThat(underTest.findEmailSubscribersForNotification(db.getSession(), dispatcherKey, channelKey, null, allLogins)) - .containsOnly(new EmailSubscriberDto("user1", true, emailOf("user1")), new EmailSubscriberDto("user2", true, emailOf("user2"))); + .containsOnly(EmailSubscriberDto.create("user1", true, emailOf("user1")), EmailSubscriberDto.create("user2", true, emailOf("user2"))); assertThat(underTest.findEmailSubscribersForNotification(db.getSession(), dispatcherKey, channelKey, null, of("user1", "user2"))) - .containsOnly(new EmailSubscriberDto("user1", true, emailOf("user1")), new EmailSubscriberDto("user2", true, emailOf("user2"))); + .containsOnly(EmailSubscriberDto.create("user1", true, emailOf("user1")), EmailSubscriberDto.create("user2", true, emailOf("user2"))); assertThat(underTest.findEmailSubscribersForNotification(db.getSession(), dispatcherKey, channelKey, null, of("user2"))) - .containsOnly(new EmailSubscriberDto("user2", true, emailOf("user2"))); + .containsOnly(EmailSubscriberDto.create("user2", true, emailOf("user2"))); assertThat(underTest.findEmailSubscribersForNotification(db.getSession(), dispatcherKey, channelKey, null, of("user1"))) - .containsOnly(new EmailSubscriberDto("user1", true, emailOf("user1"))); + .containsOnly(EmailSubscriberDto.create("user1", true, emailOf("user1"))); assertThat(underTest.findEmailSubscribersForNotification(db.getSession(), dispatcherKey, channelKey, null, of())) .isEmpty(); @@ -283,14 +283,14 @@ public class PropertiesDaoTest { assertThat(underTest.findEmailSubscribersForNotification(db.getSession(), dispatcherKey, channelKey, projectKey)) .containsOnly( - new EmailSubscriberDto("user1", true, emailOf("user1")), - new EmailSubscriberDto("user2", true, emailOf("user2")), new EmailSubscriberDto("user2", false, "user2@foo"), - new EmailSubscriberDto("user3", false, emailOf("user3"))); + EmailSubscriberDto.create("user1", true, emailOf("user1")), + EmailSubscriberDto.create("user2", true, emailOf("user2")), EmailSubscriberDto.create("user2", false, "user2@foo"), + EmailSubscriberDto.create("user3", false, emailOf("user3"))); assertThat(underTest.findEmailSubscribersForNotification(db.getSession(), dispatcherKey, channelKey, otherProjectKey)) .containsOnly( - new EmailSubscriberDto("user1", true, emailOf("user1")), - new EmailSubscriberDto("user2", true, emailOf("user2"))); + EmailSubscriberDto.create("user1", true, emailOf("user1")), + EmailSubscriberDto.create("user2", true, emailOf("user2"))); assertThat(underTest.findEmailSubscribersForNotification(db.getSession(), dispatcherKey, otherChannelKey, otherProjectKey)) .isEmpty(); assertThat(underTest.findEmailSubscribersForNotification(db.getSession(), otherDispatcherKey, channelKey, otherProjectKey)) @@ -323,24 +323,24 @@ public class PropertiesDaoTest { assertThat(underTest.findEmailSubscribersForNotification(db.getSession(), dispatcherKey, channelKey, projectKey, allLogins)) .containsOnly( - new EmailSubscriberDto("user1", true, emailOf("user1")), - new EmailSubscriberDto("user2", true, emailOf("user2")), new EmailSubscriberDto("user2", false, "user2@foo"), - new EmailSubscriberDto("user3", false, emailOf("user3"))); + EmailSubscriberDto.create("user1", true, emailOf("user1")), + EmailSubscriberDto.create("user2", true, emailOf("user2")), EmailSubscriberDto.create("user2", false, "user2@foo"), + EmailSubscriberDto.create("user3", false, emailOf("user3"))); assertThat(underTest.findEmailSubscribersForNotification(db.getSession(), dispatcherKey, channelKey, projectKey, of("user1"))) .containsOnly( - new EmailSubscriberDto("user1", true, emailOf("user1"))); + EmailSubscriberDto.create("user1", true, emailOf("user1"))); assertThat(underTest.findEmailSubscribersForNotification(db.getSession(), dispatcherKey, channelKey, projectKey, of("user2"))) .containsOnly( - new EmailSubscriberDto("user2", true, emailOf("user2")), new EmailSubscriberDto("user2", false, "user2@foo")); + EmailSubscriberDto.create("user2", true, emailOf("user2")), EmailSubscriberDto.create("user2", false, "user2@foo")); assertThat(underTest.findEmailSubscribersForNotification(db.getSession(), dispatcherKey, channelKey, projectKey, of("user3"))) - .containsOnly(new EmailSubscriberDto("user3", false, emailOf("user3"))); + .containsOnly(EmailSubscriberDto.create("user3", false, emailOf("user3"))); assertThat(underTest.findEmailSubscribersForNotification(db.getSession(), dispatcherKey, channelKey, projectKey, of())) .isEmpty(); assertThat(underTest.findEmailSubscribersForNotification(db.getSession(), dispatcherKey, channelKey, otherProjectKey, allLogins)) .containsOnly( - new EmailSubscriberDto("user1", true, emailOf("user1")), - new EmailSubscriberDto("user2", true, emailOf("user2"))); + EmailSubscriberDto.create("user1", true, emailOf("user1")), + EmailSubscriberDto.create("user2", true, emailOf("user2"))); assertThat(underTest.findEmailSubscribersForNotification(db.getSession(), dispatcherKey, otherChannelKey, otherProjectKey, allLogins)) .isEmpty(); assertThat(underTest.findEmailSubscribersForNotification(db.getSession(), otherDispatcherKey, channelKey, otherProjectKey, allLogins)) @@ -368,12 +368,12 @@ public class PropertiesDaoTest { assertThat(underTest.findEmailSubscribersForNotification(db.getSession(), dispatcherKey, channelKey, projectKey)) .containsOnly( - new EmailSubscriberDto("user1", true, emailOf("user1")), new EmailSubscriberDto("user1", false, emailOf("user1")), - new EmailSubscriberDto("user3", true, emailOf("user3"))); + EmailSubscriberDto.create("user1", true, emailOf("user1")), EmailSubscriberDto.create("user1", false, emailOf("user1")), + EmailSubscriberDto.create("user3", true, emailOf("user3"))); assertThat(underTest.findEmailSubscribersForNotification(db.getSession(), dispatcherKey, channelKey, null)) .containsOnly( - new EmailSubscriberDto("user1", true, emailOf("user1")), - new EmailSubscriberDto("user3", true, emailOf("user3"))); + EmailSubscriberDto.create("user1", true, emailOf("user1")), + EmailSubscriberDto.create("user3", true, emailOf("user3"))); } @Test @@ -398,12 +398,12 @@ public class PropertiesDaoTest { assertThat(underTest.findEmailSubscribersForNotification(db.getSession(), dispatcherKey, channelKey, projectKey, allLogins)) .containsOnly( - new EmailSubscriberDto("user1", true, emailOf("user1")), new EmailSubscriberDto("user1", false, emailOf("user1")), - new EmailSubscriberDto("user3", true, emailOf("user3"))); + EmailSubscriberDto.create("user1", true, emailOf("user1")), EmailSubscriberDto.create("user1", false, emailOf("user1")), + EmailSubscriberDto.create("user3", true, emailOf("user3"))); assertThat(underTest.findEmailSubscribersForNotification(db.getSession(), dispatcherKey, channelKey, null, allLogins)) .containsOnly( - new EmailSubscriberDto("user1", true, emailOf("user1")), - new EmailSubscriberDto("user3", true, emailOf("user3"))); + EmailSubscriberDto.create("user1", true, emailOf("user1")), + EmailSubscriberDto.create("user3", true, emailOf("user3"))); } @Test diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/notification/DefaultNotificationManagerTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/notification/DefaultNotificationManagerTest.java index d1520314553..8f29056655f 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/notification/DefaultNotificationManagerTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/notification/DefaultNotificationManagerTest.java @@ -345,7 +345,7 @@ public class DefaultNotificationManagerTest { String projectKey = randomAlphabetic(6); when(propertiesDao.findEmailSubscribersForNotification(dbSession, dispatcherKey, "EmailNotificationChannel", projectKey)) .thenReturn( - newHashSet(new EmailSubscriberDto("user1", false, "user1@foo"), new EmailSubscriberDto("user3", false, "user3@foo"), new EmailSubscriberDto("user3", true, "user3@foo"))); + newHashSet(EmailSubscriberDto.create("user1", false, "user1@foo"), EmailSubscriberDto.create("user3", false, "user3@foo"), EmailSubscriberDto.create("user3", true, "user3@foo"))); when(authorizationDao.keepAuthorizedLoginsOnProject(dbSession, newHashSet("user3", "user4"), projectKey, globalPermission)) .thenReturn(newHashSet("user3")); when(authorizationDao.keepAuthorizedLoginsOnProject(dbSession, newHashSet("user1", "user3"), projectKey, projectPermission)) @@ -370,7 +370,7 @@ public class DefaultNotificationManagerTest { Set<String> logins = ImmutableSet.of("user1", "user2", "user3"); when(propertiesDao.findEmailSubscribersForNotification(dbSession, dispatcherKey, "EmailNotificationChannel", projectKey, logins)) .thenReturn( - newHashSet(new EmailSubscriberDto("user1", false, "user1@foo"), new EmailSubscriberDto("user3", false, "user3@foo"), new EmailSubscriberDto("user3", true, "user3@foo"))); + newHashSet(EmailSubscriberDto.create("user1", false, "user1@foo"), EmailSubscriberDto.create("user3", false, "user3@foo"), EmailSubscriberDto.create("user3", true, "user3@foo"))); when(authorizationDao.keepAuthorizedLoginsOnProject(dbSession, newHashSet("user3", "user4"), projectKey, globalPermission)) .thenReturn(newHashSet("user3")); when(authorizationDao.keepAuthorizedLoginsOnProject(dbSession, newHashSet("user1", "user3"), projectKey, projectPermission)) @@ -393,7 +393,7 @@ public class DefaultNotificationManagerTest { String projectPermission = randomAlphanumeric(5); String projectKey = randomAlphabetic(6); Set<EmailSubscriberDto> subscribers = IntStream.range(0, 1 + new Random().nextInt(10)) - .mapToObj(i -> new EmailSubscriberDto("user" + i, true, "user" + i + "@sonarsource.com")) + .mapToObj(i -> EmailSubscriberDto.create("user" + i, true, "user" + i + "@sonarsource.com")) .collect(Collectors.toSet()); Set<String> logins = subscribers.stream().map(EmailSubscriberDto::getLogin).collect(Collectors.toSet()); when(propertiesDao.findEmailSubscribersForNotification(dbSession, dispatcherKey, "EmailNotificationChannel", projectKey)) @@ -418,7 +418,7 @@ public class DefaultNotificationManagerTest { String projectPermission = randomAlphanumeric(5); String projectKey = randomAlphabetic(6); Set<EmailSubscriberDto> subscribers = IntStream.range(0, 1 + new Random().nextInt(10)) - .mapToObj(i -> new EmailSubscriberDto("user" + i, true, "user" + i + "@sonarsource.com")) + .mapToObj(i -> EmailSubscriberDto.create("user" + i, true, "user" + i + "@sonarsource.com")) .collect(Collectors.toSet()); Set<String> logins = subscribers.stream().map(EmailSubscriberDto::getLogin).collect(Collectors.toSet()); when(propertiesDao.findEmailSubscribersForNotification(dbSession, dispatcherKey, "EmailNotificationChannel", projectKey, logins)) @@ -443,7 +443,7 @@ public class DefaultNotificationManagerTest { String projectPermission = randomAlphanumeric(5); String projectKey = randomAlphabetic(6); Set<EmailSubscriberDto> subscribers = IntStream.range(0, 1 + new Random().nextInt(10)) - .mapToObj(i -> new EmailSubscriberDto("user" + i, false, "user" + i + "@sonarsource.com")) + .mapToObj(i -> EmailSubscriberDto.create("user" + i, false, "user" + i + "@sonarsource.com")) .collect(Collectors.toSet()); Set<String> logins = subscribers.stream().map(EmailSubscriberDto::getLogin).collect(Collectors.toSet()); when(propertiesDao.findEmailSubscribersForNotification(dbSession, dispatcherKey, "EmailNotificationChannel", projectKey)) @@ -468,7 +468,7 @@ public class DefaultNotificationManagerTest { String projectPermission = randomAlphanumeric(5); String projectKey = randomAlphabetic(6); Set<EmailSubscriberDto> subscribers = IntStream.range(0, 1 + new Random().nextInt(10)) - .mapToObj(i -> new EmailSubscriberDto("user" + i, false, "user" + i + "@sonarsource.com")) + .mapToObj(i -> EmailSubscriberDto.create("user" + i, false, "user" + i + "@sonarsource.com")) .collect(Collectors.toSet()); Set<String> logins = subscribers.stream().map(EmailSubscriberDto::getLogin).collect(Collectors.toSet()); when(propertiesDao.findEmailSubscribersForNotification(dbSession, dispatcherKey, "EmailNotificationChannel", projectKey, logins)) diff --git a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/BuiltInQPChangeNotificationHandlerTest.java b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/BuiltInQPChangeNotificationHandlerTest.java index 7691d0e86d1..6145f79a9a9 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/BuiltInQPChangeNotificationHandlerTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/qualityprofile/BuiltInQPChangeNotificationHandlerTest.java @@ -109,7 +109,7 @@ public class BuiltInQPChangeNotificationHandlerTest { .mapToObj(i -> mock(BuiltInQPChangeNotification.class)) .collect(toSet()); Set<EmailSubscriberDto> emailSubscribers = IntStream.range(0, 1 + new Random().nextInt(10)) - .mapToObj(i -> new EmailSubscriberDto("login_" + i, true, "login_" + i + "@foo")) + .mapToObj(i -> EmailSubscriberDto.create("login_" + i, true, "login_" + i + "@foo")) .collect(toSet()); when(authorizationDao.selectQualityProfileAdministratorLogins(dbSession)) .thenReturn(emailSubscribers); |