use of org.wso2.carbon.utils.ServerConstants.CARBON_HOME 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.utils.ServerConstants.CARBON_HOME 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.utils.ServerConstants.CARBON_HOME 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.utils.ServerConstants.CARBON_HOME 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.utils.ServerConstants.CARBON_HOME in project carbon-apimgt by wso2.
the class APIConsumerImplTest method testGetAllPaginatedPublishedLightWeightAPIs.
@Test
public void testGetAllPaginatedPublishedLightWeightAPIs() throws Exception {
APIConsumerImpl apiConsumer = new APIConsumerImplWrapper();
PowerMockito.doNothing().when(APIUtil.class, "loadTenantRegistry", Mockito.anyInt());
PowerMockito.when(APIUtil.isAllowDisplayMultipleVersions()).thenReturn(false, true);
System.setProperty(CARBON_HOME, "");
GenericArtifactManager artifactManager = Mockito.mock(GenericArtifactManager.class);
PowerMockito.when(APIUtil.getArtifactManager(apiConsumer.registry, APIConstants.API_KEY)).thenReturn(artifactManager);
GenericArtifact artifact = Mockito.mock(GenericArtifact.class);
GenericArtifact[] genericArtifacts = new GenericArtifact[] { artifact };
Mockito.when(artifactManager.findGenericArtifacts(Mockito.anyMap())).thenReturn(genericArtifacts);
APIIdentifier apiId1 = new APIIdentifier("admin", "API1", "1.0.0");
API api = new API(apiId1);
Mockito.when(APIUtil.getLightWeightAPI(artifact)).thenReturn(api);
assertNotNull(apiConsumer.getAllPaginatedPublishedLightWeightAPIs(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, 0, 10));
assertNotNull(apiConsumer.getAllPaginatedPublishedLightWeightAPIs(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, 0, 10));
// artifact manager null path
PowerMockito.when(APIUtil.getArtifactManager((UserRegistry) (Mockito.anyObject()), Mockito.anyString())).thenReturn(null);
assertNotNull(apiConsumer.getAllPaginatedPublishedLightWeightAPIs(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, 0, 10));
// generic artifact null path
PowerMockito.when(APIUtil.getArtifactManager((UserRegistry) (Mockito.anyObject()), Mockito.anyString())).thenReturn(artifactManager);
Mockito.when(artifactManager.findGenericArtifacts(Mockito.anyMap())).thenReturn(null);
assertNotNull(apiConsumer.getAllPaginatedPublishedLightWeightAPIs(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, 0, 10));
}
Aggregations