use of org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder in project carbon-apimgt by wso2.
the class CommonConfigDeployerTestCase method testCreatedConfigurationContext.
@Test
public void testCreatedConfigurationContext() throws APIManagementException {
PowerMockito.mockStatic(CommonUtil.class);
System.setProperty(CARBON_HOME, "");
PrivilegedCarbonContext privilegedCarbonContext = Mockito.mock(PrivilegedCarbonContext.class);
PowerMockito.mockStatic(PrivilegedCarbonContext.class);
PowerMockito.when(PrivilegedCarbonContext.getThreadLocalCarbonContext()).thenReturn(privilegedCarbonContext);
Mockito.when(privilegedCarbonContext.getTenantDomain()).thenReturn(TENANT_DOMAIN);
Mockito.when(privilegedCarbonContext.getTenantId()).thenReturn(TENANT_ID);
ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
PowerMockito.mockStatic(ServiceReferenceHolder.class);
PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
APIManagerConfigurationService apiManagerConfigurationService = Mockito.mock(APIManagerConfigurationService.class);
Mockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()).thenReturn(apiManagerConfigurationService);
APIManagerConfiguration apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class);
Mockito.when(apiManagerConfigurationService.getAPIManagerConfiguration()).thenReturn(apiManagerConfiguration);
ThrottleProperties throttleProperties = new ThrottleProperties();
RegistryService registryService = Mockito.mock(RegistryService.class);
Mockito.when(ServiceReferenceHolder.getInstance().getRegistryService()).thenReturn(registryService);
Mockito.when(apiManagerConfiguration.getThrottleProperties()).thenReturn(throttleProperties);
ThrottleProperties.PolicyDeployer policyDeployer = Mockito.mock(ThrottleProperties.PolicyDeployer.class);
throttleProperties.setPolicyDeployer(policyDeployer);
Mockito.when(apiManagerConfiguration.getFirstProperty(APIConstants.API_GATEWAY_TYPE)).thenReturn(APIConstants.API_GATEWAY_TYPE_SYNAPSE);
ConfigurationContext configurationContext = Mockito.mock(ConfigurationContext.class);
PowerMockito.mockStatic(APIUtil.class);
CommonConfigDeployer commonConfigDeployer = new CommonConfigDeployer();
commonConfigDeployer.createdConfigurationContext(configurationContext);
PowerMockito.verifyStatic(APIUtil.class);
APIUtil.createDefaultRoles(TENANT_ID);
PowerMockito.verifyStatic(APIUtil.class);
APIUtil.loadAndSyncTenantConf(TENANT_DOMAIN);
// PowerMockito.verifyStatic(APIUtil.class);
// APIUtil.addDefaultTenantAdvancedThrottlePolicies(TENANT_DOMAIN, TENANT_ID);
}
use of org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder in project carbon-apimgt by wso2.
the class CommonConfigDeployerTestCase method testExceptions.
@Test
public void testExceptions() throws Exception {
PowerMockito.mockStatic(APIUtil.class);
PowerMockito.mockStatic(CommonUtil.class);
System.setProperty(CARBON_HOME, "");
PrivilegedCarbonContext privilegedCarbonContext = Mockito.mock(PrivilegedCarbonContext.class);
PowerMockito.mockStatic(PrivilegedCarbonContext.class);
PowerMockito.when(PrivilegedCarbonContext.getThreadLocalCarbonContext()).thenReturn(privilegedCarbonContext);
Mockito.when(privilegedCarbonContext.getTenantDomain()).thenReturn(TENANT_DOMAIN);
Mockito.when(privilegedCarbonContext.getTenantId()).thenReturn(TENANT_ID);
ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
PowerMockito.mockStatic(ServiceReferenceHolder.class);
PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
APIManagerConfigurationService apiManagerConfigurationService = Mockito.mock(APIManagerConfigurationService.class);
Mockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()).thenReturn(apiManagerConfigurationService);
APIManagerConfiguration apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class);
Mockito.when(apiManagerConfigurationService.getAPIManagerConfiguration()).thenReturn(apiManagerConfiguration);
Mockito.when(apiManagerConfiguration.getFirstProperty(APIConstants.API_GATEWAY_TYPE)).thenReturn(APIConstants.API_GATEWAY_TYPE_SYNAPSE);
RegistryService registryService = Mockito.mock(RegistryService.class);
Mockito.when(ServiceReferenceHolder.getInstance().getRegistryService()).thenReturn(registryService);
ConfigurationContext configurationContext = Mockito.mock(ConfigurationContext.class);
PowerMockito.mockStatic(APIUtil.class);
PowerMockito.doThrow(new APIManagementException("error")).when(APIUtil.class);
APIUtil.addDefaultTenantAdvancedThrottlePolicies(TENANT_DOMAIN, TENANT_ID);
PowerMockito.doThrow(new APIManagementException("error")).when(APIUtil.class);
APIUtil.writeDefinedSequencesToTenantRegistry(TENANT_ID);
PowerMockito.doThrow(new APIManagementException("error")).when(APIUtil.class);
APIUtil.loadTenantExternalStoreConfig(TENANT_DOMAIN);
PowerMockito.doThrow(new APIManagementException("error")).when(APIUtil.class);
APIUtil.loadTenantGAConfig(TENANT_DOMAIN);
PowerMockito.doThrow(new APIManagementException("error")).when(APIUtil.class);
APIUtil.loadTenantWorkFlowExtensions(TENANT_DOMAIN);
PowerMockito.doThrow(new APIManagementException("error")).when(APIUtil.class);
APIUtil.loadTenantSelfSignUpConfigurations(TENANT_DOMAIN);
PowerMockito.doThrow(new APIManagementException("error")).when(APIUtil.class);
APIUtil.loadAndSyncTenantConf(TENANT_DOMAIN);
PowerMockito.doThrow(new APIManagementException("error")).when(APIUtil.class);
APIUtil.createDefaultRoles(TENANT_ID);
CommonConfigDeployer commonConfigDeployer = new CommonConfigDeployer();
commonConfigDeployer.createdConfigurationContext(configurationContext);
PowerMockito.verifyStatic(APIUtil.class, Mockito.times(1));
APIUtil.createDefaultRoles(TENANT_ID);
}
use of org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder in project carbon-apimgt by wso2.
the class WSO2APIPublisherTestCase method init.
@Before
public void init() throws Exception {
store = new APIStore();
store.setDisplayName(storeName);
store.setUsername(storeUserName);
store.setPassword(storePassword);
store.setEndpoint(storeEndpoint);
identifier = new APIIdentifier(apiIdentifier);
api = new API(identifier);
defaultHttpClient = Mockito.mock(CloseableHttpClient.class);
wso2APIPublisher = new WSO2APIPublisherWrapper(defaultHttpClient, username, Mockito.mock(APIProvider.class));
CloseableHttpResponse httpResponse = Mockito.mock(CloseableHttpResponse.class);
ServiceReferenceHolder serviceReferenceHolder = TestUtils.getServiceReferenceHolder();
RealmService realmService = Mockito.mock(RealmService.class);
tenantManager = Mockito.mock(TenantManager.class);
Mockito.when(serviceReferenceHolder.getRealmService()).thenReturn(realmService);
Mockito.when(realmService.getTenantManager()).thenReturn(tenantManager);
HttpEntity entity = Mockito.mock(HttpEntity.class);
statusLine = Mockito.mock(StatusLine.class);
Mockito.doReturn(statusLine).when(httpResponse).getStatusLine();
Mockito.doReturn(entity).when(httpResponse).getEntity();
PowerMockito.mockStatic(EntityUtils.class);
APIManagerConfigurationService apiManagerConfigurationService = Mockito.mock(APIManagerConfigurationService.class);
Mockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()).thenReturn(apiManagerConfigurationService);
APIManagerConfiguration apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class);
Mockito.when(apiManagerConfigurationService.getAPIManagerConfiguration()).thenReturn(apiManagerConfiguration);
Mockito.when(apiManagerConfiguration.getFirstProperty(APIConstants.EXTERNAL_API_STORES + "." + APIConstants.EXTERNAL_API_STORES_STORE_URL)).thenReturn(storeRedirectURL);
HttpGet httpGet = Mockito.mock(HttpGet.class);
HttpPost httpPost = Mockito.mock(HttpPost.class);
HttpDelete httpDelete = Mockito.mock(HttpDelete.class);
PowerMockito.whenNew(HttpGet.class).withAnyArguments().thenReturn(httpGet);
PowerMockito.whenNew(HttpPost.class).withAnyArguments().thenReturn(httpPost);
PowerMockito.whenNew(HttpDelete.class).withAnyArguments().thenReturn(httpDelete);
Mockito.doReturn(httpResponse).when(defaultHttpClient).execute(httpPost);
Mockito.doReturn(httpResponse).when(defaultHttpClient).execute(httpGet);
Mockito.doReturn(httpResponse).when(defaultHttpClient).execute(httpDelete);
MultipartEntityBuilder multipartEntityBuilder = Mockito.mock(MultipartEntityBuilder.class);
PowerMockito.mockStatic(MultipartEntityBuilder.class);
Mockito.when(MultipartEntityBuilder.create()).thenReturn(multipartEntityBuilder);
Mockito.when(multipartEntityBuilder.build()).thenReturn(Mockito.mock(HttpEntity.class));
Mockito.doNothing().when(httpPost).setEntity(Matchers.any());
importExportAPI = Mockito.mock(ImportExportAPI.class);
}
use of org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder in project carbon-apimgt by wso2.
the class RestAPIStoreUtilsTest method mockStaticInitializer.
@BeforeClass
public static void mockStaticInitializer() {
PowerMockito.mockStatic(ServiceReferenceHolder.class);
ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
APIManagerConfigurationService apiManagerConfigurationService = Mockito.mock(APIManagerConfigurationService.class);
Mockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()).thenReturn(apiManagerConfigurationService);
APIManagerConfiguration apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class);
Mockito.when(apiManagerConfigurationService.getAPIManagerConfiguration()).thenReturn(apiManagerConfiguration);
Mockito.when(apiManagerConfiguration.getFirstProperty(Mockito.anyString())).thenReturn("true");
mocklog = Mockito.mock(Log.class);
PowerMockito.mockStatic(LogFactory.class);
Mockito.when(LogFactory.getLog(Mockito.any(Class.class))).thenReturn(mocklog);
}
use of org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder in project carbon-apimgt by wso2.
the class RestAPIStoreUtilsTest method testIsUserOwnerOfApplicationlowerCase.
@Test
public void testIsUserOwnerOfApplicationlowerCase() {
String username = "William Black";
String lowerCaseUsername = "william black";
PowerMockito.mockStatic(RestApiCommonUtil.class);
Mockito.when(RestApiCommonUtil.getLoggedInUsername()).thenReturn(username);
PowerMockito.mockStatic(Application.class);
Application mockApplication = Mockito.mock(Application.class);
Subscriber subscriber = Mockito.mock(Subscriber.class);
Mockito.when(mockApplication.getSubscriber()).thenReturn(subscriber);
Mockito.when(subscriber.getName()).thenReturn(lowerCaseUsername);
PowerMockito.mockStatic(ServiceReferenceHolder.class);
ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
APIManagerConfigurationService apiManagerConfigurationService = Mockito.mock(APIManagerConfigurationService.class);
Mockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()).thenReturn(apiManagerConfigurationService);
APIManagerConfiguration configuration = Mockito.mock(APIManagerConfiguration.class);
Mockito.when(apiManagerConfigurationService.getAPIManagerConfiguration()).thenReturn(configuration);
Mockito.when(configuration.getFirstProperty(APIConstants.API_STORE_FORCE_CI_COMPARISIONS)).thenReturn("true");
Assert.assertEquals(true, RestAPIStoreUtils.isUserOwnerOfApplication(mockApplication));
}
Aggregations