use of org.wso2.carbon.apimgt.core.api.APIMgtAdminService in project carbon-apimgt by wso2.
the class PolicyExportManagerTest method testCreateArchiveFromExecutionPlans.
@Test(description = "testing creating archive from execution plans")
public void testCreateArchiveFromExecutionPlans() throws APIManagementException {
APIMgtAdminService apiMgtAdminService = Mockito.mock(APIMgtAdminService.class);
List<APIPolicy> apiPolicies = new ArrayList<>();
List<ApplicationPolicy> applicationPolicies = new ArrayList<>();
List<SubscriptionPolicy> subscriptionPolicies = new ArrayList<>();
List<CustomPolicy> customPolicies = new ArrayList<>();
apiPolicies.add(SampleTestObjectCreator.createDefaultAPIPolicy());
applicationPolicies.add(SampleTestObjectCreator.createDefaultApplicationPolicy());
subscriptionPolicies.add(SampleTestObjectCreator.createDefaultSubscriptionPolicy());
customPolicies.add(SampleTestObjectCreator.createDefaultCustomPolicy());
Mockito.when(apiMgtAdminService.getApiPolicies()).thenReturn(apiPolicies);
Mockito.when(apiMgtAdminService.getApplicationPolicies()).thenReturn(applicationPolicies);
Mockito.when(apiMgtAdminService.getCustomRules()).thenReturn(customPolicies);
Mockito.when(apiMgtAdminService.getSubscriptionPolicies()).thenReturn(subscriptionPolicies);
PolicyExportManager policyExportManager = new PolicyExportManager(apiMgtAdminService);
String path = policyExportManager.createArchiveFromExecutionPlans("exportDir", exportRootDirectory, "policies");
String unzippedPath = exportRootDirectory + File.separator + "export-policies";
APIFileUtils.extractArchive(path, unzippedPath);
Assert.assertEquals(new File(APIFileUtils.getDirectoryList(unzippedPath).iterator().next()).listFiles().length == 6, true, "Exported policy count is not equal to ");
}
use of org.wso2.carbon.apimgt.core.api.APIMgtAdminService in project carbon-apimgt by wso2.
the class EndpointsApiServiceImplTestCase method endpointsGetTest.
@Test
public void endpointsGetTest() throws Exception {
APIMgtAdminServiceImpl apiMgtAdminService = Mockito.mock(APIMgtAdminServiceImpl.class);
PowerMockito.mockStatic(RestApiUtil.class);
PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(apiMgtAdminService);
Endpoint endpointOne = SampleTestObjectCreator.createUniqueEndpoint();
Endpoint endpointTwo = SampleTestObjectCreator.createUniqueEndpoint();
Endpoint endpointThree = SampleTestObjectCreator.createUniqueEndpoint();
List<Endpoint> endpointList = new ArrayList<>();
endpointList.add(endpointOne);
endpointList.add(endpointTwo);
endpointList.add(endpointThree);
Mockito.when(apiMgtAdminService.getAllEndpoints()).thenReturn(endpointList);
EndpointsApiServiceImpl endpointsApiService = new EndpointsApiServiceImpl();
Response response = endpointsApiService.endpointsGet(null, null, getRequest());
Assert.assertEquals(response.getStatus(), 200);
Assert.assertEquals(((EndpointListDTO) response.getEntity()).getList().size(), 3);
}
use of org.wso2.carbon.apimgt.core.api.APIMgtAdminService in project carbon-apimgt by wso2.
the class SubscriptionsApiServiceImplTestCase method getResponse.
private Response getResponse(String apiContext, String apiVersion) throws Exception {
APIMgtAdminServiceImpl apiMgtAdminService = Mockito.mock(APIMgtAdminServiceImpl.class);
APIManagerFactory instance = Mockito.mock(APIManagerFactory.class);
PowerMockito.mockStatic(APIManagerFactory.class);
PowerMockito.when(APIManagerFactory.getInstance()).thenReturn(instance);
Mockito.when(instance.getAPIMgtAdminService()).thenReturn(apiMgtAdminService);
SubscriptionsApiServiceImpl subscriptionsApiService = new SubscriptionsApiServiceImpl();
Mockito.when(apiMgtAdminService.getAPISubscriptions(LIMIT)).thenReturn(createSubscriptionValidationDataList());
return subscriptionsApiService.subscriptionsGet(apiContext, apiVersion, LIMIT, null, getRequest());
}
use of org.wso2.carbon.apimgt.core.api.APIMgtAdminService 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.core.api.APIMgtAdminService in project carbon-apimgt by wso2.
the class SubscriptionsApiServiceImpl method subscriptionsGet.
/**
* Retrieve subscriptions
*
* @param apiContext Context of the API
* @param apiVersion API version
* @param limit Limit value
* @return Subscriptions of the API
* @throws NotFoundException If failed to retrieve subscriptions
*/
@Override
public Response subscriptionsGet(String apiContext, String apiVersion, Integer limit, String accept, Request request) throws NotFoundException {
try {
APIMgtAdminService apiMgtAdminService = APIManagerFactory.getInstance().getAPIMgtAdminService();
List<SubscriptionValidationData> subscriptionsOfApi;
if (StringUtils.isEmpty(apiContext) || StringUtils.isEmpty(apiVersion)) {
APIUtils.logDebug("API Context or version is null or empty. Retrieving subscriptions of all APIs", log);
subscriptionsOfApi = apiMgtAdminService.getAPISubscriptions(limit);
} else {
subscriptionsOfApi = apiMgtAdminService.getAPISubscriptionsOfApi(apiContext, apiVersion);
}
SubscriptionListDTO subscriptionsList = new SubscriptionListDTO();
subscriptionsList.setList(MappingUtil.convertToSubscriptionListDto(subscriptionsOfApi));
return Response.ok(subscriptionsList).build();
} catch (APIManagementException e) {
String errorMessage = "Error while retrieving subscriptions.";
HashMap<String, String> paramList = new HashMap<String, String>();
if (!StringUtils.isEmpty(apiContext)) {
paramList.put(APIMgtConstants.ExceptionsConstants.API_CONTEXT, apiContext);
}
if (!StringUtils.isEmpty(apiVersion)) {
paramList.put(APIMgtConstants.ExceptionsConstants.API_VERSION, apiVersion);
}
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
Aggregations