use of org.wso2.carbon.apimgt.core.api.APIMgtAdminService in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method apisGetApisEmptyStatusTestCase.
@Test
public void apisGetApisEmptyStatusTestCase() throws Exception {
String labels = "ZONE_ONE,ZONE_TWO";
APIMgtAdminServiceImpl apiMgtAdminService = Mockito.mock(APIMgtAdminServiceImpl.class);
PowerMockito.mockStatic(RestApiUtil.class);
PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(apiMgtAdminService);
ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
Response response = apisApiService.apisGet(labels, "", getRequest());
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
}
use of org.wso2.carbon.apimgt.core.api.APIMgtAdminService in project carbon-apimgt by wso2.
the class ApisApiServiceImplTestCase method apisGetApisEmptyLabelsTestCase.
@Test
public void apisGetApisEmptyLabelsTestCase() throws Exception {
String labels = "";
APIMgtAdminServiceImpl apiMgtAdminService = Mockito.mock(APIMgtAdminServiceImpl.class);
PowerMockito.mockStatic(RestApiUtil.class);
PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(apiMgtAdminService);
ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
Response response = apisApiService.apisGet(labels, "Published", getRequest());
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
}
use of org.wso2.carbon.apimgt.core.api.APIMgtAdminService in project carbon-apimgt by wso2.
the class PoliciesApiServiceImpl method policiesThrottlingAdvancedGet.
/**
* Get policies
*
* @param ifNoneMatch If-None-Match header value
* @param ifModifiedSince If-Modified-Since header value
* @param request msf4j request object
* @return Response object
* @throws NotFoundException if an error occurred when particular resource does not exits in the system.
*/
@Override
public Response policiesThrottlingAdvancedGet(String ifNoneMatch, String ifModifiedSince, Request request) throws NotFoundException {
if (log.isDebugEnabled()) {
log.debug("Received Advance Throttle Policy GET request");
}
try {
APIMgtAdminService apiMgtAdminService = RestApiUtil.getAPIMgtAdminService();
List<APIPolicy> policies = apiMgtAdminService.getApiPolicies();
AdvancedThrottlePolicyListDTO advancedThrottlePolicyListDTO = AdvancedThrottlePolicyMappingUtil.fromAPIPolicyArrayToListDTO(policies);
return Response.ok().entity(advancedThrottlePolicyListDTO).build();
} catch (APIManagementException e) {
String errorMessage = "Error occurred while retrieving Advance Policies";
org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
use of org.wso2.carbon.apimgt.core.api.APIMgtAdminService in project carbon-apimgt by wso2.
the class PoliciesApiServiceImpl method policiesThrottlingSubscriptionGet.
/**
* Get subscription level policies
*
* @param ifNoneMatch If-None-Match header value
* @param ifModifiedSince If-Modified-Since header value
* @param request msf4j request object
* @return Response object
* @throws NotFoundException if an error occurred when particular resource does not exits in the system.
*/
@Override
public Response policiesThrottlingSubscriptionGet(String ifNoneMatch, String ifModifiedSince, Request request) throws NotFoundException {
if (log.isDebugEnabled()) {
log.debug("Received Application Throttle Policy GET request");
}
try {
APIMgtAdminService apiMgtAdminService = RestApiUtil.getAPIMgtAdminService();
List<SubscriptionPolicy> policies = apiMgtAdminService.getSubscriptionPolicies();
SubscriptionThrottlePolicyListDTO subscriptionThrottlePolicyListDTO = SubscriptionThrottlePolicyMappingUtil.fromSubscriptionPolicyArrayToListDTO(policies);
return Response.ok().entity(subscriptionThrottlePolicyListDTO).build();
} catch (APIManagementException e) {
String errorMessage = "Error occurred while retrieving Application Policies";
org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
use of org.wso2.carbon.apimgt.core.api.APIMgtAdminService 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