aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-server-common/src/test
diff options
context:
space:
mode:
authorAurelien Poscia <aurelien.poscia@sonarsource.com>2023-03-10 16:23:31 +0100
committersonartech <sonartech@sonarsource.com>2023-03-22 20:04:07 +0000
commitc1b29099072474f28a30e153f80ab3d1c4f0dd41 (patch)
tree60cd78b0ff93f98f25761e6bf2c4f19005d33af9 /server/sonar-server-common/src/test
parentc711b44ab5873bd602605552b05b04a1a26b255c (diff)
downloadsonarqube-c1b29099072474f28a30e153f80ab3d1c4f0dd41.tar.gz
sonarqube-c1b29099072474f28a30e153f80ab3d1c4f0dd41.zip
SONAR-18689 add filtering by managed in /api/users/search
Diffstat (limited to 'server/sonar-server-common/src/test')
-rw-r--r--server/sonar-server-common/src/test/java/org/sonar/server/management/DelegatingManagedInstanceServiceTest.java28
1 files changed, 28 insertions, 0 deletions
diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/management/DelegatingManagedInstanceServiceTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/management/DelegatingManagedInstanceServiceTest.java
index 542074300b5..e201461ec52 100644
--- a/server/sonar-server-common/src/test/java/org/sonar/server/management/DelegatingManagedInstanceServiceTest.java
+++ b/server/sonar-server-common/src/test/java/org/sonar/server/management/DelegatingManagedInstanceServiceTest.java
@@ -125,6 +125,24 @@ public class DelegatingManagedInstanceServiceTest {
.withMessage("The instance can't be managed by more than one identity provider and 2 were found.");
}
+ @Test
+ public void getManagedUsersSqlFilter_whenNoDelegates_throws() {
+ Set<ManagedInstanceService> managedInstanceServices = emptySet();
+ DelegatingManagedInstanceService delegatingManagedInstanceService = new DelegatingManagedInstanceService(managedInstanceServices);
+ assertThatIllegalStateException()
+ .isThrownBy(() -> delegatingManagedInstanceService.getManagedUsersSqlFilter(true))
+ .withMessage("This instance is not managed.");
+ }
+
+ @Test
+ public void getManagedUsersSqlFilter_delegatesToRightService_andPropagateAnswer() {
+ AlwaysManagedInstanceService alwaysManagedInstanceService = new AlwaysManagedInstanceService();
+ DelegatingManagedInstanceService managedInstanceService = new DelegatingManagedInstanceService(Set.of(new NeverManagedInstanceService(), alwaysManagedInstanceService));
+
+ assertThat(managedInstanceService.getManagedUsersSqlFilter(true)).isNotNull().isEqualTo(alwaysManagedInstanceService.getManagedUsersSqlFilter(
+ true));
+ }
+
private ManagedInstanceService getManagedInstanceService(Set<String> userUuids, Map<String, Boolean> uuidToManaged) {
ManagedInstanceService anotherManagedInstanceService = mock(ManagedInstanceService.class);
when(anotherManagedInstanceService.isInstanceExternallyManaged()).thenReturn(true);
@@ -149,6 +167,11 @@ public class DelegatingManagedInstanceServiceTest {
public Map<String, Boolean> getGroupUuidToManaged(DbSession dbSession, Set<String> groupUuids) {
return null;
}
+
+ @Override
+ public String getManagedUsersSqlFilter(boolean filterByManaged) {
+ return null;
+ }
}
private static class AlwaysManagedInstanceService implements ManagedInstanceService {
@@ -167,6 +190,11 @@ public class DelegatingManagedInstanceServiceTest {
public Map<String, Boolean> getGroupUuidToManaged(DbSession dbSession, Set<String> groupUuids) {
return null;
}
+
+ @Override
+ public String getManagedUsersSqlFilter(boolean filterByManaged) {
+ return "any filter";
+ }
}
}