use of org.wso2.carbon.apimgt.persistence.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.persistence.internal.ServiceReferenceHolder in project carbon-apimgt by wso2.
the class RegistryCacheInvalidationServiceTestCase method setup.
@Before
public void setup() throws Exception {
PowerMockito.mockStatic(ServiceReferenceHolder.class);
PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
Mockito.when(serviceReferenceHolder.getRealmService()).thenReturn(realmService);
Mockito.when(realmService.getTenantManager()).thenReturn(tenantManager);
Mockito.when(tenantManager.getTenantId(tenantDomain)).thenReturn(6543);
Mockito.when(serviceReferenceHolder.getRegistryService()).thenReturn(registryService);
Mockito.when(registryService.getGovernanceSystemRegistry(6543)).thenReturn(userRegistry);
PowerMockito.mockStatic(RegistryUtils.class);
Mockito.when(userRegistry.getRegistryContext()).thenReturn(registryContext);
System.setProperty(CARBON_HOME, "");
PrivilegedCarbonContext privilegedCarbonContext = Mockito.mock(PrivilegedCarbonContext.class);
PowerMockito.mockStatic(PrivilegedCarbonContext.class);
PowerMockito.when(PrivilegedCarbonContext.getThreadLocalCarbonContext()).thenReturn(privilegedCarbonContext);
}
use of org.wso2.carbon.apimgt.persistence.internal.ServiceReferenceHolder in project carbon-apimgt by wso2.
the class APIUtilRolesTest method testCreateDefaultRoles.
@Test
public void testCreateDefaultRoles() throws Exception {
System.setProperty("carbon.home", APIUtilRolesTest.class.getResource("/").getFile());
try {
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID);
final int tenantId = MultitenantConstants.SUPER_TENANT_ID;
final String tenantDomain = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME;
File siteConfFile = new File(Thread.currentThread().getContextClassLoader().getResource("tenant-conf.json").getFile());
String tenantConfValue = FileUtils.readFileToString(siteConfFile);
InputStream signUpConfStream = new FileInputStream(Thread.currentThread().getContextClassLoader().getResource("default-sign-up-config.xml").getFile());
ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
RealmService realmService = Mockito.mock(RealmService.class);
RegistryService registryService = Mockito.mock(RegistryService.class);
TenantManager tenantManager = Mockito.mock(TenantManager.class);
TenantIndexingLoader indexingLoader = Mockito.mock(TenantIndexingLoader.class);
UserRealm userRealm = Mockito.mock(UserRealm.class);
UserStoreManager userStoreManager = Mockito.mock(UserStoreManager.class);
RealmConfiguration realmConfiguration = Mockito.mock(RealmConfiguration.class);
APIMConfigService apimConfigService = Mockito.mock(APIMConfigService.class);
PowerMockito.mockStatic(PrivilegedCarbonContext.class);
PowerMockito.mockStatic(ServiceReferenceHolder.class);
PowerMockito.mockStatic(APIManagerComponent.class);
Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
Mockito.when(serviceReferenceHolder.getRealmService()).thenReturn(realmService);
Mockito.when(serviceReferenceHolder.getRegistryService()).thenReturn(registryService);
Mockito.when(serviceReferenceHolder.getIndexLoaderService()).thenReturn(indexingLoader);
Mockito.when(realmService.getTenantManager()).thenReturn(tenantManager);
Mockito.when(realmService.getBootstrapRealm()).thenReturn(userRealm);
Mockito.when(realmService.getTenantUserRealm(tenantId)).thenReturn(userRealm);
Mockito.when(userRealm.getUserStoreManager()).thenReturn(userStoreManager);
Mockito.when(userRealm.getRealmConfiguration()).thenReturn(realmConfiguration);
Mockito.when(realmConfiguration.getAdminUserName()).thenReturn("admin");
Mockito.when(tenantManager.getTenantId(tenantDomain)).thenReturn(tenantId);
Mockito.when(tenantManager.getDomain(tenantId)).thenReturn(tenantDomain);
Mockito.when(serviceReferenceHolder.getApimConfigService()).thenReturn(apimConfigService);
Mockito.when(apimConfigService.getTenantConfig(tenantDomain)).thenReturn(tenantConfValue);
Mockito.when(apimConfigService.getSelfSighupConfig(tenantDomain)).thenReturn(IOUtils.toString(signUpConfStream));
APIUtil.createDefaultRoles(tenantId);
String[] adminName = { "admin" };
Mockito.verify(userStoreManager, Mockito.atLeastOnce()).addRole(eq("Internal/publisher"), eq(adminName), new Permission[] { Mockito.any(Permission.class) });
Mockito.verify(userStoreManager, Mockito.atLeastOnce()).addRole(eq("Internal/subscriber"), eq(adminName), new Permission[] { Mockito.any(Permission.class) });
Mockito.verify(userStoreManager, Mockito.atLeastOnce()).addRole(eq("Internal/creator"), eq(adminName), new Permission[] { Mockito.any(Permission.class) });
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
}
use of org.wso2.carbon.apimgt.persistence.internal.ServiceReferenceHolder in project carbon-apimgt by wso2.
the class ThrottleHandlerTest method init.
@Before
public void init() {
timer = Mockito.mock(Timer.class);
timer = Mockito.mock(Timer.class);
context = Mockito.mock(Timer.Context.class);
throttleEvaluator = Mockito.mock(ThrottleConditionEvaluator.class);
accessInformation = Mockito.mock(AccessInformation.class);
Mockito.when(timer.start()).thenReturn(context);
verbInfoDTO = new ArrayList<>();
verbInfo = new VerbInfoDTO();
verbInfo.setHttpVerb(httpVerb);
verbInfo.setRequestKey(apiContext + "/" + apiVersion + resourceUri + ":" + httpVerb);
verbInfo.setThrottling(throttlingTier);
verbInfoDTO.add(verbInfo);
conditionGroupDTO = new ConditionGroupDTO();
conditionGroupDTO.setConditionGroupId("_default");
conditionGroupDTOs = new ConditionGroupDTO[1];
conditionGroupDTOs[0] = conditionGroupDTO;
apiLevelThrottleKey = apiContext + ":" + apiVersion;
resourceLevelThrottleKey = apiContext + "/" + apiVersion + resourceUri + ":" + httpVerb;
org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder.class);
PowerMockito.mockStatic(org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder.class);
Mockito.when(org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
APIManagerConfigurationService apiManagerConfigurationService = Mockito.mock(APIManagerConfigurationService.class);
APIManagerConfiguration apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class);
Mockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()).thenReturn(apiManagerConfigurationService);
Mockito.when(apiManagerConfigurationService.getAPIManagerConfiguration()).thenReturn(apiManagerConfiguration);
Mockito.when(apiManagerConfiguration.getExtensionListenerMap()).thenReturn(extensionListenerMap);
}
use of org.wso2.carbon.apimgt.persistence.internal.ServiceReferenceHolder in project carbon-apimgt by wso2.
the class OAuthTokenGeneratorTest method setup.
@Before
public void setup() throws ParseException, IOException, APIManagementException {
PowerMockito.spy(TokenCache.class);
tokenCache = TokenCache.getInstance();
PowerMockito.when(TokenCache.getInstance()).thenReturn(tokenCache);
PowerMockito.mockStatic(OAuthClient.class);
PowerMockito.mockStatic(ServiceReferenceHolder.class);
ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
Mockito.when(serviceReferenceHolder.isRedisEnabled()).thenReturn(false);
latch = new CountDownLatch(1);
// Initialize mock token response.
mockTokenResponse = new TokenResponse();
mockTokenResponse.setAccessToken("testAccessToken");
mockTokenResponse.setTokenType("Bearer");
PowerMockito.when(OAuthClient.generateToken(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.any(), Mockito.anyString(), Mockito.any(), Mockito.anyString())).thenReturn(mockTokenResponse);
// Initialize properties of oAuthEndpoint object having common values.
oAuthEndpoint = new OAuthEndpoint();
oAuthEndpoint.setTokenApiUrl("testTokenURL");
oAuthEndpoint.setClientId("testClientID");
oAuthEndpoint.setClientSecret("decryptedClientSecret");
JSONParser parser = new JSONParser();
oAuthEndpoint.setCustomParameters((JSONObject) parser.parse("{}"));
}
Aggregations