use of org.wso2.carbon.apimgt.rest.api.publisher.dto.ThreatProtectionPolicyListDTO in project carbon-apimgt by wso2.
the class ThreatProtectionPoliciesApiServiceImpl method threatProtectionPoliciesGet.
/**
* Get a list of all threat protection policies
*
* @param request
* @return List of threat protection policies
* @throws NotFoundException
*/
@Override
public Response threatProtectionPoliciesGet(Request request) throws NotFoundException {
String username = RestApiUtil.getLoggedInUsername(request);
try {
APIPublisher apiPublisher = RestAPIPublisherUtil.getApiPublisher(username);
List<ThreatProtectionPolicy> list = apiPublisher.getThreatProtectionPolicies();
ThreatProtectionPolicyListDTO listDTO = new ThreatProtectionPolicyListDTO();
for (ThreatProtectionPolicy policy : list) {
listDTO.addListItem(MappingUtil.toThreatProtectionPolicyDTO(policy));
}
return Response.ok().entity(listDTO).build();
} catch (APIManagementException e) {
log.error(e.getMessage(), e);
}
return Response.status(500).entity("Internal Server Error.").build();
}
use of org.wso2.carbon.apimgt.rest.api.publisher.dto.ThreatProtectionPolicyListDTO in project carbon-apimgt by wso2.
the class ThreatProtectionApiServiceImplTestCase method threatProtectionPoliciesGetTestCase.
@Test
public void threatProtectionPoliciesGetTestCase() throws Exception {
APIMgtAdminServiceImpl apiMgtAdminService = Mockito.mock(APIMgtAdminServiceImpl.class);
PowerMockito.mockStatic(APIManagerFactory.class);
APIManagerFactory apiManagerFactory = Mockito.mock(APIManagerFactory.class);
PowerMockito.when(APIManagerFactory.getInstance()).thenReturn(apiManagerFactory);
PowerMockito.when(apiManagerFactory.getAPIMgtAdminService()).thenReturn(apiMgtAdminService);
List<ThreatProtectionPolicy> list = new ArrayList<>();
list.add(SampleTestObjectCreator.createUniqueThreatProtectionPolicy());
list.add(SampleTestObjectCreator.createUniqueThreatProtectionPolicy());
list.add(SampleTestObjectCreator.createUniqueThreatProtectionPolicy());
PowerMockito.when(apiMgtAdminService.getThreatProtectionPolicyList()).thenReturn(list);
ThreatProtectionPoliciesApiServiceImpl threatProtectionApiService = new ThreatProtectionPoliciesApiServiceImpl();
Response response = threatProtectionApiService.threatProtectionPoliciesGet(getRequest());
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
int apiCount = ((ThreatProtectionPolicyListDTO) response.getEntity()).getList().size();
Assert.assertEquals(apiCount, 3);
}
use of org.wso2.carbon.apimgt.rest.api.publisher.dto.ThreatProtectionPolicyListDTO in project carbon-apimgt by wso2.
the class ThreatProtectionPoliciesApiServiceImpl method threatProtectionPoliciesGet.
/**
* Get a list of all threat protection policies
*
* @param request
* @return List of threat protection policies
* @throws NotFoundException
*/
@Override
public Response threatProtectionPoliciesGet(Request request) throws NotFoundException {
try {
APIMgtAdminService apiMgtAdminService = APIManagerFactory.getInstance().getAPIMgtAdminService();
List<ThreatProtectionPolicy> policyList = apiMgtAdminService.getThreatProtectionPolicyList();
ThreatProtectionPolicyListDTO listDTO = new ThreatProtectionPolicyListDTO();
for (ThreatProtectionPolicy policy : policyList) {
listDTO.addListItem(MappingUtil.toThreatProtectionPolicyDTO(policy));
}
return Response.ok().entity(listDTO).build();
} catch (APIManagementException e) {
log.error(e.getMessage(), e);
}
return Response.status(500).entity("Internal Server Error.").build();
}
use of org.wso2.carbon.apimgt.rest.api.publisher.dto.ThreatProtectionPolicyListDTO in project carbon-apimgt by wso2.
the class ThreatProtectionPoliciesApiServiceImpl method threatProtectionPoliciesGet.
/**
* Get a list of all threat protection policies
*
* @param request
* @return List of threat protection policies
* @throws NotFoundException
*/
@Override
public Response threatProtectionPoliciesGet(Request request) throws NotFoundException {
try {
APIMgtAdminService apiMgtAdminService = APIManagerFactory.getInstance().getAPIMgtAdminService();
List<ThreatProtectionPolicy> policyList = apiMgtAdminService.getThreatProtectionPolicyList();
ThreatProtectionPolicyListDTO listDTO = new ThreatProtectionPolicyListDTO();
for (ThreatProtectionPolicy policy : policyList) {
listDTO.addListItem(ThreatProtectionMappingUtil.toThreatProtectionPolicyDTO(policy));
}
return Response.ok().entity(listDTO).build();
} catch (APIManagementException e) {
log.error(e.getMessage(), e);
}
return Response.status(500).entity("Internal Server Error.").build();
}
use of org.wso2.carbon.apimgt.rest.api.publisher.dto.ThreatProtectionPolicyListDTO in project carbon-apimgt by wso2.
the class ThreatProtectionApiServiceImplTestCase method threatProtectionPoliciesGetTestCase.
@Test
public void threatProtectionPoliciesGetTestCase() throws Exception {
PowerMockito.mockStatic(RestApiUtil.class);
PowerMockito.when(RestApiUtil.getLoggedInUsername(Mockito.any())).thenReturn("username");
PowerMockito.mockStatic(RestAPIPublisherUtil.class);
APIPublisher publisher = Mockito.mock(APIPublisher.class);
Mockito.when(RestAPIPublisherUtil.getApiPublisher(Mockito.anyString())).thenReturn(publisher);
List<ThreatProtectionPolicy> list = new ArrayList<>();
list.add(Mockito.mock(ThreatProtectionPolicy.class));
list.add(Mockito.mock(ThreatProtectionPolicy.class));
Mockito.when(publisher.getThreatProtectionPolicies()).thenReturn(list);
ThreatProtectionPoliciesApiServiceImpl apiService = new ThreatProtectionPoliciesApiServiceImpl();
Response response = apiService.threatProtectionPoliciesGet(getRequest());
Assert.assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
ThreatProtectionPolicyListDTO resList = (ThreatProtectionPolicyListDTO) response.getEntity();
Assert.assertEquals(2, resList.getList().size());
}
Aggregations