Search in sources :

Example 1 with AvailableUserStoreClassesRes

use of org.wso2.identity.integration.test.rest.api.server.user.store.v1.model.AvailableUserStoreClassesRes in project product-is by wso2.

the class UserStoreSuccessTest method testGetAvailableUserStoreClasses.

@Test(dependsOnMethods = { "testAddSecondaryUserStore" })
public void testGetAvailableUserStoreClasses() throws IOException {
    Map<String, AvailableUserStoreClassesRes> userStoreClassesResMap;
    String expectedResponse = readResource("get-available-user-store-classes.json");
    ObjectMapper jsonWriter = new ObjectMapper(new JsonFactory());
    List<AvailableUserStoreClassesRes> availableUserStoreClassesResList = Arrays.asList(jsonWriter.readValue(expectedResponse, AvailableUserStoreClassesRes[].class));
    userStoreClassesResMap = availableUserStoreClassesResList.stream().collect(Collectors.toMap(AvailableUserStoreClassesRes::getTypeId, c -> c));
    Response response = getResponseOfGet(USER_STORE_PATH_COMPONENT + USER_STORE_META_COMPONENT);
    ValidatableResponse validatableResponse = response.then().log().ifValidationFails().assertThat().statusCode(HttpStatus.SC_OK);
    for (Map.Entry<String, AvailableUserStoreClassesRes> resEntry : userStoreClassesResMap.entrySet()) {
        validatableResponse.body("find{ it.typeId == '" + resEntry.getKey() + "' }.typeName", equalTo(resEntry.getValue().getTypeName()));
        validatableResponse.body("find{ it.typeId == '" + resEntry.getKey() + "' }.className", equalTo(resEntry.getValue().getClassName()));
        validatableResponse.body("find{ it.typeId == '" + resEntry.getKey() + "' }.self", equalTo("/t/" + tenant + "/api/server/v1" + USER_STORE_PATH_COMPONENT + PATH_SEPARATOR + "meta/types/" + resEntry.getValue().getTypeId()));
    }
}
Also used : ValidatableResponse(io.restassured.response.ValidatableResponse) Response(io.restassured.response.Response) UserStoreListResponse(org.wso2.identity.integration.test.rest.api.server.user.store.v1.model.UserStoreListResponse) ValidatableResponse(io.restassured.response.ValidatableResponse) AvailableUserStoreClassesRes(org.wso2.identity.integration.test.rest.api.server.user.store.v1.model.AvailableUserStoreClassesRes) JsonFactory(com.fasterxml.jackson.core.JsonFactory) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.testng.annotations.Test)

Example 2 with AvailableUserStoreClassesRes

use of org.wso2.identity.integration.test.rest.api.server.user.store.v1.model.AvailableUserStoreClassesRes in project identity-api-server by wso2.

the class ServerUserStoreService method getAvailableUserStoreTypes.

/**
 * To retrieve the available user store classes.
 *
 * @return List<AvailableUserStoreClassesRes>.
 */
public List<AvailableUserStoreClassesRes> getAvailableUserStoreTypes() {
    UserStoreConfigService userStoreConfigService = UserStoreConfigServiceHolder.getInstance().getUserStoreConfigService();
    Set<String> classNames;
    try {
        classNames = userStoreConfigService.getAvailableUserStoreClasses();
        List<AvailableUserStoreClassesRes> propertiesToAdd = new ArrayList<>();
        Map<String, Boolean> userStoreManagersType = UserStoreManagerRegistry.getUserStoreManagersType();
        for (String className : classNames) {
            AvailableUserStoreClassesRes availableUserStoreClassesResDTO = new AvailableUserStoreClassesRes();
            String typeId = base64URLEncodeId(Objects.requireNonNull(getUserStoreTypeName(className)));
            availableUserStoreClassesResDTO.setClassName(className);
            availableUserStoreClassesResDTO.setTypeName(getUserStoreTypeName(className));
            availableUserStoreClassesResDTO.setTypeId(typeId);
            availableUserStoreClassesResDTO.setSelf(ContextLoader.buildURIForBody(String.format(V1_API_PATH_COMPONENT + UserStoreConstants.USER_STORE_PATH_COMPONENT + "/meta/types/%s", typeId)).toString());
            if (userStoreManagersType.containsKey(className)) {
                availableUserStoreClassesResDTO.setIsLocal(userStoreManagersType.get(className));
            }
            propertiesToAdd.add(availableUserStoreClassesResDTO);
        }
        return propertiesToAdd;
    } catch (IdentityUserStoreMgtException e) {
        UserStoreConstants.ErrorMessage errorEnum = UserStoreConstants.ErrorMessage.ERROR_CODE_RETRIEVING_USER_STORE_TYPE;
        throw handleIdentityUserStoreMgtException(e, errorEnum);
    }
}
Also used : IdentityUserStoreMgtException(org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreMgtException) AvailableUserStoreClassesRes(org.wso2.carbon.identity.api.server.userstore.v1.model.AvailableUserStoreClassesRes) ArrayList(java.util.ArrayList) UserStoreConfigService(org.wso2.carbon.identity.user.store.configuration.UserStoreConfigService)

Aggregations

JsonFactory (com.fasterxml.jackson.core.JsonFactory)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Response (io.restassured.response.Response)1 ValidatableResponse (io.restassured.response.ValidatableResponse)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Test (org.testng.annotations.Test)1 AvailableUserStoreClassesRes (org.wso2.carbon.identity.api.server.userstore.v1.model.AvailableUserStoreClassesRes)1 UserStoreConfigService (org.wso2.carbon.identity.user.store.configuration.UserStoreConfigService)1 IdentityUserStoreMgtException (org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreMgtException)1 AvailableUserStoreClassesRes (org.wso2.identity.integration.test.rest.api.server.user.store.v1.model.AvailableUserStoreClassesRes)1 UserStoreListResponse (org.wso2.identity.integration.test.rest.api.server.user.store.v1.model.UserStoreListResponse)1