use of org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl in project carbon-apimgt by wso2.
the class GatewaysApiServiceImplTestCase method gatewaysRegisterPostTest.
@Test
public void gatewaysRegisterPostTest() throws Exception {
APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
PowerMockito.mockStatic(RestApiUtil.class);
PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(adminService);
RegistrationDTO registrationDTO = Mockito.mock(RegistrationDTO.class);
LabelInfoDTO labelInfoDTO = Mockito.mock(LabelInfoDTO.class);
Mockito.when(registrationDTO.getLabelInfo()).thenReturn(labelInfoDTO);
RegistrationSummary registrationSummary = Mockito.mock(RegistrationSummary.class);
Mockito.when(adminService.getRegistrationSummary()).thenReturn(registrationSummary);
RegistrationSummary.AnalyticsInfo analyticsInfo = Mockito.mock(RegistrationSummary.AnalyticsInfo.class);
Mockito.when(registrationSummary.getAnalyticsInfo()).thenReturn(analyticsInfo);
RegistrationSummary.Credentials dssCredentials = Mockito.mock(RegistrationSummary.Credentials.class);
Mockito.when(registrationSummary.getAnalyticsInfo().getDasServerCredentials()).thenReturn(dssCredentials);
Mockito.when(dssCredentials.getUsername()).thenReturn(DSS_USERNAME);
Mockito.when(dssCredentials.getPassword()).thenReturn(DSS_PASSWORD);
RegistrationSummary.JWTInfo jwtInfo = Mockito.mock(RegistrationSummary.JWTInfo.class);
Mockito.when(registrationSummary.getJwtInfo()).thenReturn(jwtInfo);
RegistrationSummary.KeyManagerInfo keyManagerInfo = Mockito.mock(RegistrationSummary.KeyManagerInfo.class);
Mockito.when(registrationSummary.getKeyManagerInfo()).thenReturn(keyManagerInfo);
RegistrationSummary.Credentials keyManagerCredentials = Mockito.mock(RegistrationSummary.Credentials.class);
Mockito.when(registrationSummary.getKeyManagerInfo().getCredentials()).thenReturn(keyManagerCredentials);
Mockito.when(keyManagerCredentials.getUsername()).thenReturn(KEY_MANAGER_USERNAME);
Mockito.when(keyManagerCredentials.getPassword()).thenReturn(KEY_MANAGER_PASSWORD);
RegistrationSummary.ThrottlingInfo throttlingInfo = Mockito.mock(RegistrationSummary.ThrottlingInfo.class);
Mockito.when(registrationSummary.getThrottlingInfo()).thenReturn(throttlingInfo);
RegistrationSummary.ThrottlingInfo.DataPublisher dataPublisher = Mockito.mock(RegistrationSummary.ThrottlingInfo.DataPublisher.class);
Mockito.when(registrationSummary.getThrottlingInfo().getDataPublisher()).thenReturn(dataPublisher);
RegistrationSummary.Credentials throttlingServerCredentials = Mockito.mock(RegistrationSummary.Credentials.class);
Mockito.when(registrationSummary.getThrottlingInfo().getDataPublisher().getCredentials()).thenReturn(throttlingServerCredentials);
Mockito.when(throttlingServerCredentials.getUsername()).thenReturn(THROTTLE_SERVER_USERNAME);
Mockito.when(throttlingServerCredentials.getPassword()).thenReturn(THROTTLE_SERVER_PASSWORD);
RegistrationSummary.GoogleAnalyticsTrackingInfo googleAnalyticsTrackingInfo = Mockito.mock(RegistrationSummary.GoogleAnalyticsTrackingInfo.class);
Mockito.when(registrationSummary.getGoogleAnalyticsTrackingInfo()).thenReturn(googleAnalyticsTrackingInfo);
GatewaysApiServiceImpl gatewaysApiService = new GatewaysApiServiceImpl();
Response response = gatewaysApiService.gatewaysRegisterPost(registrationDTO, "application/json", getRequest());
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
CredentialsDTO analyticsInfoResponseCredentials = ((RegistrationSummaryDTO) response.getEntity()).getAnalyticsInfo().getCredentials();
CredentialsDTO keyManagerInfoResponseCredentials = ((RegistrationSummaryDTO) response.getEntity()).getKeyManagerInfo().getCredentials();
CredentialsDTO throttleServerInfoResponseCredentials = ((RegistrationSummaryDTO) response.getEntity()).getThrottlingInfo().getCredentials();
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
Assert.assertEquals(analyticsInfoResponseCredentials.getUsername(), DSS_USERNAME);
Assert.assertEquals(analyticsInfoResponseCredentials.getPassword(), DSS_PASSWORD);
Assert.assertEquals(keyManagerInfoResponseCredentials.getUsername(), KEY_MANAGER_USERNAME);
Assert.assertEquals(keyManagerInfoResponseCredentials.getPassword(), KEY_MANAGER_PASSWORD);
Assert.assertEquals(throttleServerInfoResponseCredentials.getUsername(), THROTTLE_SERVER_USERNAME);
Assert.assertEquals(throttleServerInfoResponseCredentials.getPassword(), THROTTLE_SERVER_PASSWORD);
}
use of org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl 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.impl.APIMgtAdminServiceImpl 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.impl.APIMgtAdminServiceImpl in project carbon-apimgt by wso2.
the class BlacklistApiServiceImplTest method blacklistConditionIdPutTest.
@Test
public void blacklistConditionIdPutTest() throws APIManagementException, NotFoundException {
printTestMethodName();
BlacklistApiServiceImpl blacklistApiService = new BlacklistApiServiceImpl();
String uuid = UUID.randomUUID().toString();
BlockingConditionDTO dto = new BlockingConditionDTO();
dto.setConditionId(UUID.randomUUID().toString());
dto.setStatus(true);
dto.setConditionType(BLOCKING_CONDITIONS_IP);
dto.setConditionValue("12.32.45.3");
APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
PowerMockito.mockStatic(RestApiUtil.class);
PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(adminService);
BlockConditions conditions = BlockingConditionMappingUtil.fromBlockingConditionDTOToBlockCondition(dto);
Mockito.doReturn(true).doThrow(new IllegalArgumentException()).when(adminService).updateBlockConditionStateByUUID(uuid, true);
Mockito.doReturn(conditions).doThrow(new IllegalArgumentException()).when(adminService).getBlockConditionByUUID(uuid);
Response response = blacklistApiService.blacklistConditionIdPut(uuid, dto, null, null, getRequest());
Assert.assertEquals(response.getStatus(), 200);
}
use of org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl in project carbon-apimgt by wso2.
the class BlacklistApiServiceImplTest method blacklistConditionIdGetTest.
@Test
public void blacklistConditionIdGetTest() throws APIManagementException, NotFoundException {
printTestMethodName();
BlacklistApiServiceImpl blacklistApiService = new BlacklistApiServiceImpl();
String uuid = UUID.randomUUID().toString();
APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
PowerMockito.mockStatic(RestApiUtil.class);
PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(adminService);
BlockConditions conditions = new BlockConditions();
conditions.setUuid(uuid);
Mockito.doReturn(conditions).doThrow(new IllegalArgumentException()).when(adminService).getBlockConditionByUUID(uuid);
Response response = blacklistApiService.blacklistConditionIdGet(uuid, null, null, getRequest());
Assert.assertEquals(response.getStatus(), 200);
}
Aggregations