Search in sources :

Example 1 with ThreatProtectionPolicyDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.dto.ThreatProtectionPolicyDTO in project carbon-apimgt by wso2.

the class ThreatProtectionPoliciesApiServiceImplTestCase method createThreatProtectionPolicyDTO.

private ThreatProtectionPolicyDTO createThreatProtectionPolicyDTO() {
    ThreatProtectionPolicyDTO policyDTO = new ThreatProtectionPolicyDTO();
    policyDTO.setName("TEST-POLICY");
    policyDTO.setType("XML");
    policyDTO.setUuid(UUID.randomUUID().toString());
    return policyDTO;
}
Also used : ThreatProtectionPolicyDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.ThreatProtectionPolicyDTO)

Example 2 with ThreatProtectionPolicyDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.dto.ThreatProtectionPolicyDTO in project carbon-apimgt by wso2.

the class ThreatProtectionPoliciesApiServiceImplTestCase method testThreatProtectionPoliciesPost.

@Test
public void testThreatProtectionPoliciesPost() throws Exception {
    PowerMockito.mockStatic(APIManagerFactory.class);
    APIManagerFactory apiManagerFactory = Mockito.mock(APIManagerFactory.class);
    APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
    PowerMockito.when(APIManagerFactory.getInstance()).thenReturn(apiManagerFactory);
    Mockito.when(apiManagerFactory.getAPIMgtAdminService()).thenReturn(adminService);
    ThreatProtectionPolicyDTO dto = createThreatProtectionPolicyDTO();
    ThreatProtectionPoliciesApiServiceImpl apiService = new ThreatProtectionPoliciesApiServiceImpl();
    Response response = apiService.threatProtectionPoliciesPost(dto, getRequest());
    Assert.assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    // Error path
    Mockito.doThrow(APIManagementException.class).when(adminService).addThreatProtectionPolicy(Mockito.any());
    response = apiService.threatProtectionPoliciesPost(createThreatProtectionPolicyDTO(), getRequest());
    Assert.assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) ThreatProtectionPolicyDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.ThreatProtectionPolicyDTO) APIManagerFactory(org.wso2.carbon.apimgt.core.impl.APIManagerFactory) APIMgtAdminServiceImpl(org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with ThreatProtectionPolicyDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.dto.ThreatProtectionPolicyDTO in project carbon-apimgt by wso2.

the class ThreatProtectionMappingUtil method toThreatProtectionPolicyDTO.

/**
 * Converts ThreatProtectionPolicy core model ThreatProtectionPolicyDTO rest api core model
 * @param policy apimgt core model of ThreatProtectionPolicy
 * @return ThreatProtectionPolicyDTO rest api core model
 */
public static ThreatProtectionPolicyDTO toThreatProtectionPolicyDTO(ThreatProtectionPolicy policy) {
    if (policy == null)
        return null;
    ThreatProtectionPolicyDTO dto = new ThreatProtectionPolicyDTO();
    dto.setUuid(policy.getUuid());
    dto.setName(policy.getName());
    dto.setType(policy.getType());
    dto.setPolicy(policy.getPolicy());
    return dto;
}
Also used : ThreatProtectionPolicyDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.ThreatProtectionPolicyDTO)

Example 4 with ThreatProtectionPolicyDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.dto.ThreatProtectionPolicyDTO in project carbon-apimgt by wso2.

the class MappingUtil method toThreatProtectionPolicyDTO.

/**
 * Converts ThreatProtectionPolicy core model ThreatProtectionPolicyDTO rest api core model
 * @param policy apimgt core model of ThreatProtectionPolicy
 * @return ThreatProtectionPolicyDTO rest api core model
 */
public static ThreatProtectionPolicyDTO toThreatProtectionPolicyDTO(ThreatProtectionPolicy policy) {
    if (policy == null)
        return null;
    ThreatProtectionPolicyDTO dto = new ThreatProtectionPolicyDTO();
    dto.setUuid(policy.getUuid());
    dto.setName(policy.getName());
    dto.setType(policy.getType());
    dto.setPolicy(policy.getPolicy());
    return dto;
}
Also used : ThreatProtectionPolicyDTO(org.wso2.carbon.apimgt.rest.api.core.dto.ThreatProtectionPolicyDTO)

Example 5 with ThreatProtectionPolicyDTO

use of org.wso2.carbon.apimgt.rest.api.publisher.dto.ThreatProtectionPolicyDTO in project carbon-apimgt by wso2.

the class ThreatProtectionPoliciesApiServiceImpl method threatProtectionPoliciesThreatProtectionPolicyIdGet.

/**
 * Get a specific threat protection policy
 *
 * @param threatProtectionPolicyId ID of the policy to be retrieved
 * @param request
 * @return Threat protection policy
 * @throws NotFoundException
 */
@Override
public Response threatProtectionPoliciesThreatProtectionPolicyIdGet(String threatProtectionPolicyId, Request request) throws NotFoundException {
    try {
        APIMgtAdminService apiMgtAdminService = APIManagerFactory.getInstance().getAPIMgtAdminService();
        ThreatProtectionPolicyDTO dto = ThreatProtectionMappingUtil.toThreatProtectionPolicyDTO(apiMgtAdminService.getThreatProtectionPolicy(threatProtectionPolicyId));
        return Response.ok().entity(dto).build();
    } catch (APIManagementException e) {
        log.error(e.getMessage(), e);
    }
    return Response.status(500).entity("Internal Server Error.").build();
}
Also used : APIMgtAdminService(org.wso2.carbon.apimgt.core.api.APIMgtAdminService) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException)

Aggregations

ThreatProtectionPolicy (org.wso2.carbon.apimgt.core.models.policy.ThreatProtectionPolicy)4 ThreatProtectionPolicyDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.ThreatProtectionPolicyDTO)4 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)3 ThreatProtectionPolicyDTO (org.wso2.carbon.apimgt.rest.api.core.dto.ThreatProtectionPolicyDTO)3 Response (javax.ws.rs.core.Response)2 Test (org.junit.Test)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 APIMgtAdminService (org.wso2.carbon.apimgt.core.api.APIMgtAdminService)2 APIManagerFactory (org.wso2.carbon.apimgt.core.impl.APIManagerFactory)2 APIMgtAdminServiceImpl (org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl)2 ThreatProtectionPolicyDTO (org.wso2.carbon.apimgt.rest.api.publisher.dto.ThreatProtectionPolicyDTO)2 ArrayList (java.util.ArrayList)1 Test (org.testng.annotations.Test)1 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)1