use of org.wso2.carbon.apimgt.impl.config.APIMConfigService 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.impl.config.APIMConfigService 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.impl.config.APIMConfigService 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);
}
use of org.wso2.carbon.apimgt.impl.config.APIMConfigService in project carbon-apimgt by wso2.
the class APIUtilTest method testGetAppAttributeKeysFromRegistry.
@Test
public void testGetAppAttributeKeysFromRegistry() throws Exception {
System.setProperty("carbon.home", APIUtilTest.class.getResource("/").getFile());
try {
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID);
final int tenantId = -1234;
final String property = APIConstants.ApplicationAttributes.APPLICATION_CONFIGURATIONS;
ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
PowerMockito.mockStatic(ServiceReferenceHolder.class);
RegistryService registryService = Mockito.mock(RegistryService.class);
Resource resource = Mockito.mock(Resource.class);
Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
File siteConfFile = new File(Thread.currentThread().getContextClassLoader().getResource("tenant-conf.json").getFile());
String tenantConfValue = FileUtils.readFileToString(siteConfFile);
APIMConfigService apimConfigService = Mockito.mock(APIMConfigService.class);
Mockito.when(serviceReferenceHolder.getApimConfigService()).thenReturn(apimConfigService);
Mockito.when(apimConfigService.getTenantConfig(tenantDomain)).thenReturn(tenantConfValue);
JSONParser parser = new JSONParser();
JSONObject json = (JSONObject) parser.parse(tenantConfValue);
JSONObject applicationAttributes = (JSONObject) json.get(property);
JSONObject appAttributes = APIUtil.getAppAttributeKeysFromRegistry(tenantDomain);
Assert.assertEquals(applicationAttributes, appAttributes);
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
}
use of org.wso2.carbon.apimgt.impl.config.APIMConfigService in project carbon-apimgt by wso2.
the class APIMWSDLReaderTest method doMockStatics.
public static void doMockStatics() throws APIManagementException {
System.setProperty("carbon.home", APIUtilTest.class.getResource("/").getFile());
try {
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
Map<String, Environment> gatewayEnvironments = new HashMap<String, Environment>();
Environment env1 = new Environment();
env1.setType("hybrid");
env1.setApiGatewayEndpoint("http://localhost:8280,https://localhost:8243");
gatewayEnvironments.put("e1", env1);
PowerMockito.mockStatic(ServiceReferenceHolder.class);
PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
PowerMockito.when(ServiceReferenceHolder.getInstance().getAPIManagerConfigurationService()).thenReturn(apimConfigService);
PowerMockito.when(ServiceReferenceHolder.getInstance().getAPIManagerConfigurationService().getAPIManagerConfiguration()).thenReturn(apimConfig);
PowerMockito.when(ServiceReferenceHolder.getInstance().getAPIManagerConfigurationService().getAPIManagerConfiguration().getApiGatewayEnvironments()).thenReturn(gatewayEnvironments);
ApiMgtDAO apiMgtDAO = Mockito.mock(ApiMgtDAO.class);
PowerMockito.mockStatic(ApiMgtDAO.class);
Mockito.when(ApiMgtDAO.getInstance()).thenReturn(apiMgtDAO);
Mockito.when(apiMgtDAO.getAllEnvironments(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)).thenReturn(new ArrayList<org.wso2.carbon.apimgt.api.model.Environment>());
PowerMockito.when(APIUtil.getEnvironments("61416403c40f086ad2dc5eed")).thenReturn(gatewayEnvironments);
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
}
Aggregations