-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent ISE: Duplicate key when calling getGroups
Filter out non user groups as those may have duplicate names. Never fail for duplicates, but just use the first one then. This closes #789
- Loading branch information
Showing
3 changed files
with
148 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
...oltool-bundle/src/test/java/biz/netcentric/cq/tools/actool/ims/IMSUserManagementTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package biz.netcentric.cq.tools.actool.ims; | ||
|
||
/*- | ||
* #%L | ||
* Access Control Tool Bundle | ||
* %% | ||
* Copyright (C) 2015 - 2024 Cognizant Netcentric | ||
* %% | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* #L% | ||
*/ | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.Arrays; | ||
import java.util.HashSet; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import org.apache.http.impl.client.HttpClientBuilder; | ||
import org.apache.http.osgi.services.HttpClientBuilderFactory; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
import biz.netcentric.cq.tools.actool.ims.IMSUserManagement.Configuration; | ||
import biz.netcentric.cq.tools.actool.ims.response.GroupResponse; | ||
import biz.netcentric.cq.tools.actool.ims.response.IMSGroup; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class IMSUserManagementTest { | ||
|
||
private static String MOCK_TOKEN = "mockToken"; | ||
@Mock | ||
private Configuration configuration; | ||
@Mock | ||
private HttpClientBuilderFactory httpClientBuilderFactory; | ||
@Mock | ||
private HttpClientBuilder httpClientBuilder; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
Mockito.when(httpClientBuilderFactory.newBuilder()).thenReturn(httpClientBuilder); | ||
} | ||
|
||
@Test | ||
void testGetGroups() throws IOException { | ||
IMSUserManagement imsUserManagement = new IMSUserManagement(configuration, httpClientBuilderFactory) { | ||
@Override | ||
GroupResponse getGroups(String token, int page) throws java.io.IOException { | ||
try (InputStream inputStream = getClass().getResourceAsStream("groupResponse" + page +".json")) { | ||
ObjectMapper objectMapper = new ObjectMapper(); | ||
return objectMapper.readValue(inputStream, GroupResponse.class); | ||
} | ||
} | ||
}; | ||
Map<String, IMSGroup> groups = imsUserManagement.getGroups(MOCK_TOKEN); | ||
assertEquals(2, groups.size()); | ||
// check keys only | ||
Set<String> expectedKeys = new HashSet<>(Arrays.asList("document cloud 1", "document cloud 2")); | ||
assertEquals(expectedKeys, groups.keySet()); | ||
} | ||
|
||
} |
64 changes: 64 additions & 0 deletions
64
...troltool-bundle/src/test/resources/biz/netcentric/cq/tools/actool/ims/groupResponse0.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
{ | ||
"lastPage": true, | ||
"result": "success", | ||
"groups": [ | ||
{ | ||
"type": "SYSADMIN_GROUP", | ||
"groupName": "Administrators", | ||
"memberCount": 11 | ||
}, | ||
{ | ||
"type": "USER_GROUP", | ||
"groupName": "Document Cloud 1", | ||
"memberCount": 26, | ||
"adminGroupName": "_admin_Document Cloud 1", | ||
"licenseQuota": "2" | ||
}, | ||
{ | ||
"type": "USER_GROUP", | ||
"groupName": "Document Cloud 2", | ||
"memberCount": 26, | ||
"adminGroupName": "_admin_Document Cloud 1", | ||
"licenseQuota": "2" | ||
}, | ||
{ | ||
"type": "PRODUCT_PROFILE", | ||
"groupName": "Default Support Profile", | ||
"memberCount": 0, | ||
"productName": "All Apps plan - 100 GB", | ||
"licenseQuota": "8" | ||
}, | ||
{ | ||
"type": "PRODUCT_ADMIN_GROUP", | ||
"groupName": "_product_admin_Adobe Document Cloud for business", | ||
"memberCount": 2, | ||
"productProfileName": "Adobe Document Cloud for business" | ||
}, | ||
{ | ||
"type": "PRODUCT_ADMIN_GROUP", | ||
"groupName": "_product_admin_Adobe Document Cloud for business", | ||
"memberCount": 2, | ||
"productProfileName": "Adobe Document Cloud for business" | ||
}, | ||
{ | ||
"groupId": 561043099, | ||
"groupName": "_product_admin_Adobe Experience Manager as a Cloud Service (ENTERPRISE_PRODUCT,Cloud Manager,DX - E123)", | ||
"type": "PRODUCT_ADMIN_GROUP", | ||
"memberCount": 7, | ||
"productName": "Adobe Experience Manager as a Cloud Service (ENTERPRISE_PRODUCT,Cloud Manager,DX - E123)" | ||
}, | ||
{ | ||
"groupId": 743706203, | ||
"groupName": "_product_admin_Adobe Experience Manager as a Cloud Service (ENTERPRISE_PRODUCT,Cloud Manager,DX - E123)", | ||
"type": "PRODUCT_ADMIN_GROUP", | ||
"memberCount": 1, | ||
"productName": "Adobe Experience Manager as a Cloud Service (ENTERPRISE_PRODUCT,Cloud Manager,DX - E123)" | ||
}, | ||
{ | ||
"type": "DEVELOPER_GROUP", | ||
"groupName": "_developer_Adobe Document Cloud for business", | ||
"memberCount": 5, | ||
"productProfileName": "Adobe Document Cloud for business" | ||
} | ||
] | ||
} |