use of org.wso2.carbon.apimgt.throttle.policy.deployer.internal.ServiceReferenceHolder in project carbon-apimgt by wso2.
the class APIUtilTierTest method testGetTiersFromApiPolicies.
@Test
public void testGetTiersFromApiPolicies() throws Exception {
System.setProperty("carbon.home", APIUtilRolesTest.class.getResource("/").getFile());
try {
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain("abc.com");
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(1);
String policyLevel = PolicyConstants.POLICY_LEVEL_API;
int tenantId = 1;
ApiMgtDAOMockCreator daoMockHolder = new ApiMgtDAOMockCreator(tenantId);
ApiMgtDAO apiMgtDAO = daoMockHolder.getMock();
PowerMockito.mockStatic(ServiceReferenceHolder.class);
ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
RealmService realmService = Mockito.mock(RealmService.class);
TenantManager tenantManager = Mockito.mock(TenantManager.class);
Mockito.when(realmService.getTenantManager()).thenReturn(tenantManager);
Mockito.when(tenantManager.getDomain(1)).thenReturn("abc.com");
Mockito.when(serviceReferenceHolder.getRealmService()).thenReturn(realmService);
Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
APIMConfigService apimConfigService = Mockito.mock(APIMConfigService.class);
Mockito.when(serviceReferenceHolder.getApimConfigService()).thenReturn(apimConfigService);
Mockito.when(apimConfigService.getTenantConfig("abc.com")).thenReturn(IOUtils.toString(tenantConf));
APIManagerConfigurationService apiManagerConfigurationService = Mockito.mock(APIManagerConfigurationService.class);
APIManagerConfiguration apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class);
Mockito.when(apiManagerConfigurationService.getAPIManagerConfiguration()).thenReturn(apiManagerConfiguration);
Mockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()).thenReturn(apiManagerConfigurationService);
ThrottleProperties throttleProperties = new ThrottleProperties();
throttleProperties.setEnableUnlimitedTier(true);
Mockito.when(apiManagerConfiguration.getThrottleProperties()).thenReturn(throttleProperties);
APIPolicy[] policies = generateApiPolicies(tiersReturned);
Mockito.when(apiMgtDAO.getAPIPolicies(tenantId)).thenReturn(policies);
Map<String, Tier> tiersFromPolicies = APIUtil.getTiersFromPolicies(policyLevel, tenantId);
Mockito.verify(apiMgtDAO, Mockito.only()).getAPIPolicies(tenantId);
for (APIPolicy policy : policies) {
Tier tier = tiersFromPolicies.get(policy.getPolicyName());
Assert.assertNotNull(tier);
Assert.assertEquals(policy.getPolicyName(), tier.getName());
Assert.assertEquals(policy.getDescription(), tier.getDescription());
}
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
}
use of org.wso2.carbon.apimgt.throttle.policy.deployer.internal.ServiceReferenceHolder in project carbon-apimgt by wso2.
the class APIUtilTierTest method testGetTiersFromAppPolicies.
@Test
public void testGetTiersFromAppPolicies() throws Exception {
System.setProperty("carbon.home", APIUtilTierTest.class.getResource("/").getFile());
try {
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain("abc.com");
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(1);
String policyLevel = PolicyConstants.POLICY_LEVEL_APP;
int tenantId = 1;
ApiMgtDAOMockCreator daoMockHolder = new ApiMgtDAOMockCreator(tenantId);
ApiMgtDAO apiMgtDAO = daoMockHolder.getMock();
PowerMockito.mockStatic(ServiceReferenceHolder.class);
ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
APIMConfigService apimConfigService = Mockito.mock(APIMConfigService.class);
Mockito.when(serviceReferenceHolder.getApimConfigService()).thenReturn(apimConfigService);
Mockito.when(apimConfigService.getTenantConfig("abc.com")).thenReturn(IOUtils.toString(tenantConf));
APIManagerConfigurationService apiManagerConfigurationService = Mockito.mock(APIManagerConfigurationService.class);
APIManagerConfiguration apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class);
Mockito.when(apiManagerConfigurationService.getAPIManagerConfiguration()).thenReturn(apiManagerConfiguration);
Mockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()).thenReturn(apiManagerConfigurationService);
RealmService realmService = Mockito.mock(RealmService.class);
TenantManager tenantManager = Mockito.mock(TenantManager.class);
Mockito.when(realmService.getTenantManager()).thenReturn(tenantManager);
Mockito.when(tenantManager.getDomain(1)).thenReturn("abc.com");
Mockito.when(serviceReferenceHolder.getRealmService()).thenReturn(realmService);
ThrottleProperties throttleProperties = new ThrottleProperties();
throttleProperties.setEnableUnlimitedTier(true);
Mockito.when(apiManagerConfiguration.getThrottleProperties()).thenReturn(throttleProperties);
ApplicationPolicy[] policies = generateAppPolicies(tiersReturned);
Mockito.when(apiMgtDAO.getApplicationPolicies(tenantId)).thenReturn(policies);
Map<String, Tier> tiersFromPolicies = APIUtil.getTiersFromPolicies(policyLevel, tenantId);
Mockito.verify(apiMgtDAO, Mockito.only()).getApplicationPolicies(tenantId);
for (ApplicationPolicy policy : policies) {
Tier tier = tiersFromPolicies.get(policy.getPolicyName());
Assert.assertNotNull(tier);
Assert.assertEquals(policy.getPolicyName(), tier.getName());
Assert.assertEquals(policy.getDescription(), tier.getDescription());
}
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
}
use of org.wso2.carbon.apimgt.throttle.policy.deployer.internal.ServiceReferenceHolder in project carbon-apimgt by wso2.
the class UserSignUpSimpleWorkflowExecutorTest method init.
@Before
public void init() throws Exception {
userSignUpSimpleWorkflowExecutor = new UserSignUpSimpleWorkflowExecutor();
workflowDTO = new WorkflowDTO();
workflowDTO.setExternalWorkflowReference("12345");
workflowDTO.setTenantDomain(tenantDomain);
workflowDTO.setStatus(WorkflowStatus.APPROVED);
workflowDTO.setWorkflowReference(username);
ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class);
RealmService realmService = Mockito.mock(RealmService.class);
TenantManager tenantManager = Mockito.mock(TenantManager.class);
UserRealm userRealm = Mockito.mock(UserRealm.class);
userStoreManager = Mockito.mock(UserStoreManager.class);
ServiceClient serviceClient = Mockito.mock(ServiceClient.class);
PowerMockito.mockStatic(ServiceReferenceHolder.class);
PowerMockito.mockStatic(SelfSignUpUtil.class);
PowerMockito.mockStatic(CarbonUtils.class);
Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
APIManagerConfigurationService apiManagerConfigurationService = new APIManagerConfigurationServiceImpl(apiManagerConfiguration);
Mockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()).thenReturn(apiManagerConfigurationService);
Mockito.when(serviceReferenceHolder.getRealmService()).thenReturn(realmService);
Mockito.when(realmService.getTenantManager()).thenReturn(tenantManager);
Mockito.when(tenantManager.getTenantId(tenantDomain)).thenReturn(tenantID);
Mockito.when(tenantManager.getTenantId(tenantDomain)).thenReturn(tenantID);
Mockito.when(realmService.getTenantUserRealm(tenantID)).thenReturn(userRealm);
Mockito.when(userRealm.getUserStoreManager()).thenReturn(userStoreManager);
}
use of org.wso2.carbon.apimgt.throttle.policy.deployer.internal.ServiceReferenceHolder in project carbon-apimgt by wso2.
the class SelfSignupUtilTestCase method testGetSelfSignupConfigFromRegistryTenant.
@Test
public void testGetSelfSignupConfigFromRegistryTenant() throws Exception {
PowerMockito.mockStatic(ServiceReferenceHolder.class);
ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
APIMConfigService apimConfigService = Mockito.mock(APIMConfigService.class);
Mockito.when(serviceReferenceHolder.getApimConfigService()).thenReturn(apimConfigService);
PowerMockito.mockStatic(APIUtil.class);
Mockito.when(apimConfigService.getSelfSighupConfig("bar.com")).thenReturn("wsdl");
OMElement omElement = Mockito.mock(OMElement.class);
Mockito.when(omElement.getFirstChildWithName(Matchers.any(QName.class))).thenReturn(omElement);
PowerMockito.mockStatic(AXIOMUtil.class);
Mockito.when(omElement.getChildrenWithLocalName(APIConstants.SELF_SIGN_UP_REG_ROLE_ELEM)).thenReturn(Mockito.mock(Iterator.class));
PowerMockito.when(AXIOMUtil.stringToOM("wsdl")).thenReturn(omElement);
PowerMockito.mockStatic(PasswordResolverFactory.class);
PasswordResolver passwordResolver = Mockito.mock(PasswordResolver.class);
PowerMockito.when(PasswordResolverFactory.getInstance()).thenReturn(passwordResolver);
UserRegistrationConfigDTO userRegistrationConfigDTO = SelfSignUpUtil.getSignupConfiguration("bar.com");
Assert.assertNotNull(userRegistrationConfigDTO);
}
use of org.wso2.carbon.apimgt.throttle.policy.deployer.internal.ServiceReferenceHolder in project carbon-apimgt by wso2.
the class SelfSignupUtilTestCase method testGetSelfSignupConfigFromRegistry.
@Test
public void testGetSelfSignupConfigFromRegistry() throws Exception {
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("foo.com");
Mockito.when(privilegedCarbonContext.getRegistry(RegistryType.SYSTEM_GOVERNANCE)).thenReturn(registry);
PowerMockito.mockStatic(ServiceReferenceHolder.class);
ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
APIMConfigService apimConfigService = Mockito.mock(APIMConfigService.class);
Mockito.when(serviceReferenceHolder.getApimConfigService()).thenReturn(apimConfigService);
PowerMockito.mockStatic(APIUtil.class);
Mockito.when(apimConfigService.getSelfSighupConfig("foo.com")).thenReturn("wsdl");
OMElement omElement = Mockito.mock(OMElement.class);
Mockito.when(omElement.getFirstChildWithName(Matchers.any(QName.class))).thenReturn(omElement);
PowerMockito.mockStatic(AXIOMUtil.class);
Mockito.when(omElement.getChildrenWithLocalName(APIConstants.SELF_SIGN_UP_REG_ROLE_ELEM)).thenReturn(Mockito.mock(Iterator.class));
PowerMockito.when(AXIOMUtil.stringToOM("wsdl")).thenReturn(omElement);
PowerMockito.mockStatic(PasswordResolverFactory.class);
PasswordResolver passwordResolver = Mockito.mock(PasswordResolver.class);
PowerMockito.when(PasswordResolverFactory.getInstance()).thenReturn(passwordResolver);
UserRegistrationConfigDTO userRegistrationConfigDTO = SelfSignUpUtil.getSignupConfiguration("foo.com");
Assert.assertNotNull(userRegistrationConfigDTO);
}
Aggregations