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;
}
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());
}
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;
}
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;
}
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();
}
Aggregations