use of org.wso2.carbon.apimgt.impl.APIManagerFactory 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.impl.APIManagerFactory 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.impl.APIManagerFactory 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.impl.APIManagerFactory in project carbon-apimgt by wso2.
the class ThreatProtectionApiServiceImplTestCase method threatProtectionPoliciesGetExceptionTestCase.
@Test
public void threatProtectionPoliciesGetExceptionTestCase() throws Exception {
PowerMockito.mockStatic(APIManagerFactory.class);
APIManagerFactory apiManagerFactory = Mockito.mock(APIManagerFactory.class);
PowerMockito.when(APIManagerFactory.getInstance()).thenReturn(apiManagerFactory);
APIManagementException apiManagementException = new APIManagementException("Error");
PowerMockito.when(apiManagerFactory.getAPIMgtAdminService()).thenThrow(apiManagementException);
ThreatProtectionPoliciesApiServiceImpl threatProtectionApiService = new ThreatProtectionPoliciesApiServiceImpl();
Response response = threatProtectionApiService.threatProtectionPoliciesGet(getRequest());
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
}
use of org.wso2.carbon.apimgt.impl.APIManagerFactory in project carbon-apimgt by wso2.
the class ApiStoreSdkGenerationManagerTestCase method testGenerateSdkForApi.
@Test
public void testGenerateSdkForApi() throws APIManagementException, ApiStoreSdkGenerationException {
String apiId = UUID.randomUUID().toString();
APIManagerFactory instance = Mockito.mock(APIManagerFactory.class);
PowerMockito.mockStatic(APIManagerFactory.class);
PowerMockito.when(APIManagerFactory.getInstance()).thenReturn(instance);
APIStore apiStore = Mockito.mock(APIStoreImpl.class);
Mockito.when(instance.getAPIConsumer(USER)).thenReturn(apiStore);
API api = SampleTestObjectCreator.createDefaultAPI().build();
Mockito.when(apiStore.getAPIbyUUID(apiId)).thenReturn(api);
Mockito.when(apiStore.getApiSwaggerDefinition(apiId)).thenReturn(swaggerPetStore);
ApiStoreSdkGenerationManager sdkGenerationManager = new ApiStoreSdkGenerationManager();
String pathToZip = sdkGenerationManager.generateSdkForApi(apiId, LANGUAGE, USER);
File sdkZipFile = new File(pathToZip);
Assert.assertTrue(sdkZipFile.exists() && sdkZipFile.length() > MIN_SDK_SIZE);
}
Aggregations