Search in sources :

Example 1 with PreferenceResp

use of org.wso2.carbon.identity.api.server.identity.governance.v1.model.PreferenceResp in project product-is by wso2.

the class IdentityGovernanceSuccessTest method testSearchGovernanceConnectorProperties.

@Test(dataProvider = "connectorPropertiesProvider")
public void testSearchGovernanceConnectorProperties(List<PreferenceResp> connectorList, String requestJson) throws IOException {
    String body = readResource(requestJson);
    Response response = getResponseOfPost(IDENTITY_GOVERNANCE_ENDPOINT_URI + "/preferences", body);
    for (PreferenceResp preferenceResp : connectorList) {
        String baseIdentifier = "find{ it.('connector-name') == '" + preferenceResp.getConnectorName() + "' }.";
        List<PropertyReq> properties = preferenceResp.getProperties();
        int i = 0;
        for (PropertyReq propertyReq : properties) {
            ValidatableResponse validatableResponse = response.then().log().ifValidationFails().assertThat().statusCode(HttpStatus.SC_OK);
            validatableResponse.body(baseIdentifier + "properties", notNullValue()).body(baseIdentifier + "properties[" + i + "].name", equalTo(propertyReq.getName())).body(baseIdentifier + "properties[" + i + "].value", equalTo(propertyReq.getValue()));
            i++;
        }
    }
}
Also used : ValidatableResponse(io.restassured.response.ValidatableResponse) Response(io.restassured.response.Response) PreferenceResp(org.wso2.identity.integration.test.rest.api.server.identity.governance.v1.dto.PreferenceResp) ValidatableResponse(io.restassured.response.ValidatableResponse) PropertyReq(org.wso2.identity.integration.test.rest.api.server.identity.governance.v1.dto.PropertyReq) Test(org.testng.annotations.Test)

Example 2 with PreferenceResp

use of org.wso2.carbon.identity.api.server.identity.governance.v1.model.PreferenceResp in project identity-api-server by wso2.

the class ServerIdentityGovernanceService method getConfigPreference.

/**
 * Get governance connector properties according to the search attribute.
 *
 * @param preferenceSearchAttribute Governance connector details.
 * @return Governance connector properties for the given connector or properties.
 */
public List<PreferenceResp> getConfigPreference(List<PreferenceSearchAttribute> preferenceSearchAttribute) {
    IdentityGovernanceService identityGovernanceService = GovernanceDataHolder.getIdentityGovernanceService();
    String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
    List<PreferenceResp> preferenceRespList = new ArrayList<>();
    for (PreferenceSearchAttribute prefSearchAttr : preferenceSearchAttribute) {
        String connectorName = prefSearchAttr.getConnectorName();
        List<String> expectedProperties = prefSearchAttr.getProperties();
        Property[] properties;
        try {
            ConnectorConfig connectorConfig = identityGovernanceService.getConnectorWithConfigs(tenantDomain, connectorName);
            if (connectorConfig == null) {
                throw handleBadRequestError(GovernanceConstants.ErrorMessage.ERROR_CODE_INCORRECT_CONNECTOR_NAME, connectorName);
            }
            properties = connectorConfig.getProperties();
            PreferenceResp preferenceResp = buildPreferenceRespDTO(connectorName, properties, expectedProperties);
            preferenceRespList.add(preferenceResp);
        } catch (IdentityGovernanceException e) {
            GovernanceConstants.ErrorMessage errorEnum = GovernanceConstants.ErrorMessage.ERROR_CODE_ERROR_RETRIEVING_CONNECTOR_PREFERENCES;
            Response.Status status = Response.Status.INTERNAL_SERVER_ERROR;
            throw handleException(e, errorEnum, status);
        }
    }
    return preferenceRespList;
}
Also used : PreferenceSearchAttribute(org.wso2.carbon.identity.api.server.identity.governance.v1.model.PreferenceSearchAttribute) ConnectorConfig(org.wso2.carbon.identity.governance.bean.ConnectorConfig) ArrayList(java.util.ArrayList) IdentityGovernanceException(org.wso2.carbon.identity.governance.IdentityGovernanceException) PreferenceResp(org.wso2.carbon.identity.api.server.identity.governance.v1.model.PreferenceResp) IdentityGovernanceService(org.wso2.carbon.identity.governance.IdentityGovernanceService) Property(org.wso2.carbon.identity.application.common.model.Property)

Example 3 with PreferenceResp

use of org.wso2.carbon.identity.api.server.identity.governance.v1.model.PreferenceResp in project product-is by wso2.

the class IdentityGovernanceSuccessTest method init.

@BeforeClass(alwaysRun = true)
public void init() throws IOException {
    super.testInit(API_VERSION, swaggerDefinition, tenant);
    String expectedResponse = readResource("get-categories-response.json");
    ObjectMapper jsonWriter = new ObjectMapper(new JsonFactory());
    List<CategoriesRes> categoryList = Arrays.asList(jsonWriter.readValue(expectedResponse, CategoriesRes[].class));
    categories = categoryList.stream().collect(Collectors.toMap(CategoriesRes::getId, c -> c));
    String expectedResponseForConnectors = readResource("get-connector-properties-response.json");
    ObjectMapper objectMapper = new ObjectMapper(new JsonFactory());
    connectors = Arrays.asList(objectMapper.readValue(expectedResponseForConnectors, PreferenceResp[].class));
    String expectedResponseForConnectorsWithoutProperty = readResource("get-properties-without-property-name-response.json");
    ObjectMapper mapper = new ObjectMapper(new JsonFactory());
    connectorsWithAllProperties = Arrays.asList(mapper.readValue(expectedResponseForConnectorsWithoutProperty, PreferenceResp[].class));
}
Also used : PreferenceResp(org.wso2.identity.integration.test.rest.api.server.identity.governance.v1.dto.PreferenceResp) JsonFactory(com.fasterxml.jackson.core.JsonFactory) CategoriesRes(org.wso2.identity.integration.test.rest.api.server.identity.governance.v1.dto.CategoriesRes) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BeforeClass(org.testng.annotations.BeforeClass)

Example 4 with PreferenceResp

use of org.wso2.carbon.identity.api.server.identity.governance.v1.model.PreferenceResp in project identity-api-server by wso2.

the class ServerIdentityGovernanceService method buildPreferenceRespDTO.

private PreferenceResp buildPreferenceRespDTO(String connectorName, Property[] properties, List<String> expectedProperties) {
    PreferenceResp preferenceResp = new PreferenceResp();
    List<PropertyReq> propertyReqList = buildPropertyReqDTO(properties, expectedProperties);
    preferenceResp.setProperties(propertyReqList);
    preferenceResp.setConnectorName(connectorName);
    return preferenceResp;
}
Also used : PreferenceResp(org.wso2.carbon.identity.api.server.identity.governance.v1.model.PreferenceResp) PropertyReq(org.wso2.carbon.identity.api.server.identity.governance.v1.model.PropertyReq)

Aggregations

PreferenceResp (org.wso2.carbon.identity.api.server.identity.governance.v1.model.PreferenceResp)2 PreferenceResp (org.wso2.identity.integration.test.rest.api.server.identity.governance.v1.dto.PreferenceResp)2 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 BeforeClass (org.testng.annotations.BeforeClass)1 Test (org.testng.annotations.Test)1 PreferenceSearchAttribute (org.wso2.carbon.identity.api.server.identity.governance.v1.model.PreferenceSearchAttribute)1 PropertyReq (org.wso2.carbon.identity.api.server.identity.governance.v1.model.PropertyReq)1 Property (org.wso2.carbon.identity.application.common.model.Property)1 IdentityGovernanceException (org.wso2.carbon.identity.governance.IdentityGovernanceException)1 IdentityGovernanceService (org.wso2.carbon.identity.governance.IdentityGovernanceService)1 ConnectorConfig (org.wso2.carbon.identity.governance.bean.ConnectorConfig)1 CategoriesRes (org.wso2.identity.integration.test.rest.api.server.identity.governance.v1.dto.CategoriesRes)1 PropertyReq (org.wso2.identity.integration.test.rest.api.server.identity.governance.v1.dto.PropertyReq)1