@Test
public void test_addGroupToSafe_successfully() {

    String token = "5PDrOhsy4ig8L3EpsJZSLAMg";
    String path = "shared/mysafe01";
    SafeGroup safeGroup = new SafeGroup("shared/mysafe01","mygroup01","read");
    String jsonstr = "{  \"path\": \"shared/mysafe01\",  \"groupname\": \"mygroup01\",  \"access\": \"read\"}";
    UserDetails userDetails = new UserDetails();
    userDetails.setUsername("testuser1");
    Response userResponse = getMockResponse(HttpStatus.OK, true, "{\"data\":{\"bound_cidrs\":[],\"max_ttl\":0,\"policies\":[\"default\",\"w_shared_mysafe01\",\"w_shared_mysafe02\"],\"ttl\":0,\"groups\":\"admin\"}}");
    Response groupResponse = getMockResponse(HttpStatus.OK, true, "{\"data\":{\"bound_cidrs\":[],\"max_ttl\":0,\"policies\":[\"default\",\"w_shared_mysafe01\",\"w_shared_mysafe02\"],\"ttl\":0,\"groups\":\"admin\"}}");
    Response idapConfigureResponse = getMockResponse(HttpStatus.NO_CONTENT, true, "{\"policies\":null}");
    Response responseNoContent = getMockResponse(HttpStatus.NO_CONTENT, true, "");
    ResponseEntity<String> responseEntityExpected = ResponseEntity.status(HttpStatus.OK).body("{\"messages\":[\"Group is successfully associated with Safe\"]}");
    when(ControllerUtil.areSafeGroupInputsValid(safeGroup)).thenReturn(true);
    when(JSONUtil.getJSON(safeGroup)).thenReturn(jsonstr);
    when(ControllerUtil.canAddPermission(path, token)).thenReturn(true);
    when(reqProcessor.process("/auth/ldap/groups","{\"groupname\":\"mygroup01\"}",token)).thenReturn(groupResponse);
    try {
        //when(ControllerUtil.getPoliciesAsStringFromJson(any(), any())).thenReturn("default,w_shared_mysafe01,w_shared_mysafe02");
        List<String> resList = new ArrayList<>();
        resList.add("default");
        resList.add("w_shared_mysafe01");
        resList.add("w_shared_mysafe02");
        when(ControllerUtil.getPoliciesAsListFromJson(any(), any())).thenReturn(resList);
    } catch (IOException e) {
        e.printStackTrace();
    }
    when(ControllerUtil.configureLDAPGroup(any(),any(),eq(token))).thenReturn(idapConfigureResponse);
    when(ControllerUtil.updateMetadata(any(),eq(token))).thenReturn(responseNoContent);
    ReflectionTestUtils.setField(safesService, "vaultAuthMethod", "oidc");
    List<String> policies = new ArrayList<>();
    policies.add("default");
    policies.add("w_shared_mysafe02");
    policies.add("r_shared_mysafe01");
    List<String> currentpolicies = new ArrayList<>();
    currentpolicies.add("default");
    currentpolicies.add("w_shared_mysafe01");
    currentpolicies.add("w_shared_mysafe02");
    OIDCGroup oidcGroup = new OIDCGroup("123-123-123", currentpolicies);
    when(OIDCUtil.getIdentityGroupDetails("mygroup01", token)).thenReturn(oidcGroup);
    Response response = new Response();
    response.setHttpstatus(HttpStatus.NO_CONTENT);
    when(OIDCUtil.updateGroupPolicies(token, "mygroup01", policies, currentpolicies, oidcGroup.getId())).thenReturn(response);
    ResponseEntity<String> responseEntity = safesService.addGroupToSafe(token, safeGroup, userDetails);
    assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
    assertEquals(responseEntityExpected, responseEntity);
}