Search in sources :

Example 1 with CommonConfigDeployer

use of org.wso2.carbon.apimgt.impl.observers.CommonConfigDeployer in project carbon-apimgt by wso2.

the class APIManagerComponent method activate.

@Activate
protected void activate(ComponentContext componentContext) throws Exception {
    if (log.isDebugEnabled()) {
        log.debug("API manager component activated");
    }
    try {
        BundleContext bundleContext = componentContext.getBundleContext();
        addRxtConfigs();
        addApplicationsPermissionsToRegistry();
        int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
        String filePath = CarbonUtils.getCarbonConfigDirPath() + File.separator + "api-manager.xml";
        configuration.load(filePath);
        String gatewayType = configuration.getFirstProperty(APIConstants.API_GATEWAY_TYPE);
        if (APIConstants.API_GATEWAY_TYPE_SYNAPSE.equalsIgnoreCase(gatewayType)) {
            addDefinedSequencesToRegistry();
        }
        CommonConfigDeployer configDeployer = new CommonConfigDeployer();
        bundleContext.registerService(Axis2ConfigurationContextObserver.class.getName(), configDeployer, null);
        TenantLoadMessageSender tenantLoadMessageSender = new TenantLoadMessageSender();
        bundleContext.registerService(Axis2ConfigurationContextObserver.class.getName(), tenantLoadMessageSender, null);
        KeyMgtConfigDeployer keyMgtConfigDeployer = new KeyMgtConfigDeployer();
        bundleContext.registerService(Axis2ConfigurationContextObserver.class.getName(), keyMgtConfigDeployer, null);
        // Registering Notifiers
        bundleContext.registerService(Notifier.class.getName(), new SubscriptionsNotifier(), null);
        bundleContext.registerService(Notifier.class.getName(), new ApisNotifier(), null);
        bundleContext.registerService(Notifier.class.getName(), new ApplicationNotifier(), null);
        bundleContext.registerService(Notifier.class.getName(), new ApplicationRegistrationNotifier(), null);
        bundleContext.registerService(Notifier.class.getName(), new PolicyNotifier(), null);
        bundleContext.registerService(Notifier.class.getName(), new DeployAPIInGatewayNotifier(), null);
        bundleContext.registerService(Notifier.class.getName(), new ScopesNotifier(), null);
        bundleContext.registerService(Notifier.class.getName(), new CertificateNotifier(), null);
        bundleContext.registerService(Notifier.class.getName(), new GoogleAnalyticsNotifier(), null);
        bundleContext.registerService(Notifier.class.getName(), new ExternalGatewayNotifier(), null);
        bundleContext.registerService(Notifier.class.getName(), new ExternallyDeployedApiNotifier(), null);
        APIManagerConfigurationServiceImpl configurationService = new APIManagerConfigurationServiceImpl(configuration);
        ServiceReferenceHolder.getInstance().setAPIManagerConfigurationService(configurationService);
        APIMgtDBUtil.initialize();
        APIMConfigService apimConfigService = new APIMConfigServiceImpl();
        bundleContext.registerService(APIMConfigService.class.getName(), apimConfigService, null);
        APIUtil.loadAndSyncTenantConf(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
        APIUtil.loadTenantExternalStoreConfig(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
        APIUtil.loadTenantGAConfig(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
        APIUtil.loadTenantWorkFlowExtensions(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
        // load self sigup configuration to the registry
        APIUtil.loadTenantSelfSignUpConfigurations(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
        APIUtil.loadCommonOperationPolicies(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
        APIManagerAnalyticsConfiguration analyticsConfiguration = APIManagerAnalyticsConfiguration.getInstance();
        analyticsConfiguration.setAPIManagerConfiguration(configuration);
        registration = componentContext.getBundleContext().registerService(APIManagerConfigurationService.class.getName(), configurationService, null);
        KeyManagerConfigurationServiceImpl keyManagerConfigurationService = new KeyManagerConfigurationServiceImpl();
        registration = componentContext.getBundleContext().registerService(KeyManagerConfigurationService.class, keyManagerConfigurationService, null);
        JWTValidationService jwtValidationService = new JWTValidationServiceImpl();
        registration = componentContext.getBundleContext().registerService(JWTValidationService.class, jwtValidationService, null);
        ServiceReferenceHolder.getInstance().setKeyManagerConfigurationService(keyManagerConfigurationService);
        APIStatusObserverList.getInstance().init(configuration);
        log.debug("Reading Analytics Configuration from file...");
        // This method is called in two places. Mostly by the time activate hits,
        // ServiceDataPublisherAdmin is not activated. Therefore, this same method is run,
        // when ServiceDataPublisherAdmin is set.
        AuthorizationUtils.addAuthorizeRoleListener(APIConstants.AM_CREATOR_APIMGT_EXECUTION_ID, RegistryUtils.getAbsolutePath(RegistryContext.getBaseInstance(), APIUtil.getMountedPath(RegistryContext.getBaseInstance(), RegistryConstants.GOVERNANCE_REGISTRY_BASE_PATH) + APIConstants.API_APPLICATION_DATA_LOCATION), APIConstants.Permissions.API_CREATE, UserMgtConstants.EXECUTE_ACTION, null);
        AuthorizationUtils.addAuthorizeRoleListener(APIConstants.AM_CREATOR_GOVERNANCE_EXECUTION_ID, RegistryUtils.getAbsolutePath(RegistryContext.getBaseInstance(), APIUtil.getMountedPath(RegistryContext.getBaseInstance(), RegistryConstants.GOVERNANCE_REGISTRY_BASE_PATH) + "/trunk"), APIConstants.Permissions.API_CREATE, UserMgtConstants.EXECUTE_ACTION, null);
        AuthorizationUtils.addAuthorizeRoleListener(APIConstants.AM_PUBLISHER_APIMGT_EXECUTION_ID, RegistryUtils.getAbsolutePath(RegistryContext.getBaseInstance(), APIUtil.getMountedPath(RegistryContext.getBaseInstance(), RegistryConstants.GOVERNANCE_REGISTRY_BASE_PATH) + APIConstants.API_APPLICATION_DATA_LOCATION), APIConstants.Permissions.API_PUBLISH, UserMgtConstants.EXECUTE_ACTION, null);
        // Enabling API Publishers/Creators to make changes on life-cycle history.
        AuthorizationUtils.addAuthorizeRoleListener(APIConstants.AM_CREATOR_LIFECYCLE_EXECUTION_ID, RegistryUtils.getAbsolutePath(RegistryContext.getBaseInstance(), APIUtil.getMountedPath(RegistryContext.getBaseInstance(), RegistryConstants.GOVERNANCE_REGISTRY_BASE_PATH) + APIConstants.API_LIFE_CYCLE_HISTORY), APIConstants.Permissions.API_CREATE, UserMgtConstants.EXECUTE_ACTION, null);
        AuthorizationUtils.addAuthorizeRoleListener(APIConstants.AM_PUBLISHER_LIFECYCLE_EXECUTION_ID, RegistryUtils.getAbsolutePath(RegistryContext.getBaseInstance(), APIUtil.getMountedPath(RegistryContext.getBaseInstance(), RegistryConstants.GOVERNANCE_REGISTRY_BASE_PATH) + APIConstants.API_LIFE_CYCLE_HISTORY), APIConstants.Permissions.API_PUBLISH, UserMgtConstants.EXECUTE_ACTION, null);
        setupImagePermissions();
        GatewayArtifactsMgtDBUtil.initialize();
        configureEventPublisherProperties();
        configureNotificationEventPublisher();
        // Load initially available api contexts at the server startup. This Cache is only use by the products other than the api-manager
        /* TODO: Load Config values from apimgt.core*/
        boolean apiManagementEnabled = APIUtil.isAPIManagementEnabled();
        boolean loadAPIContextsAtStartup = APIUtil.isLoadAPIContextsAtStartup();
        if (apiManagementEnabled && loadAPIContextsAtStartup) {
            List<String> contextList = ApiMgtDAO.getInstance().getAllAvailableContexts();
            Cache contextCache = APIUtil.getAPIContextCache();
            for (String context : contextList) {
                contextCache.put(context, Boolean.TRUE);
            }
        }
        try {
            APIUtil.createDefaultRoles(MultitenantConstants.SUPER_TENANT_ID);
        } catch (APIManagementException e) {
            log.error("Failed create default roles for tenant " + MultitenantConstants.SUPER_TENANT_ID, e);
        } catch (Exception e) {
            // The generic Exception is handled explicitly so execution does not stop during config deployment
            log.error("Exception when creating default roles for tenant " + MultitenantConstants.SUPER_TENANT_ID, e);
        }
        // Adding default throttle policies
        addDefaultAdvancedThrottlePolicies();
        // Update all NULL THROTTLING_TIER values to Unlimited
        boolean isNullThrottlingTierConversionEnabled = APIUtil.updateNullThrottlingTierAtStartup();
        try {
            if (isNullThrottlingTierConversionEnabled) {
                ApiMgtDAO.getInstance().convertNullThrottlingTiers();
            }
        } catch (APIManagementException e) {
            log.error("Failed to convert NULL THROTTLING_TIERS to Unlimited");
        }
        // // Initialise KeyManager.
        // KeyManagerHolder.initializeKeyManager(configuration);
        // Initialise sql constants
        SQLConstantManagerFactory.initializeSQLConstantManager();
        // Initialize PasswordResolver
        PasswordResolverFactory.initializePasswordResolver();
        APIUtil.init();
        // Activating UserPostSelfRegistration handler componeAPITemplateBuilderImplnt
        try {
            registration = componentContext.getBundleContext().registerService(AbstractEventHandler.class.getName(), new UserPostSelfRegistrationHandler(), null);
        } catch (Exception e) {
            log.error("Error while activating UserPostSelfRegistration handler component.", e);
        }
        // Read the trust store
        ServerConfiguration config = CarbonUtils.getServerConfiguration();
        // Initialize product REST API token caches
        CacheProvider.createRESTAPITokenCache();
        CacheProvider.createRESTAPIInvalidTokenCache();
        CacheProvider.createGatewayJWTTokenCache();
        CacheProvider.createTenantConfigCache();
        CacheProvider.createRecommendationsCache();
        CacheProvider.createParsedSignJWTCache();
        CacheProvider.createGatewayBasicAuthResourceCache();
        CacheProvider.createGatewayUsernameCache();
        CacheProvider.createIntrospectionCache();
        // Initialize Recommendation wso2event output publisher
        configureRecommendationEventPublisherProperties();
        setupAccessTokenGenerator();
        retrieveAndSetParentTrustStore();
        if (configuration.getGatewayArtifactSynchronizerProperties().isRetrieveFromStorageEnabled()) {
            if (APIConstants.GatewayArtifactSynchronizer.DB_RETRIEVER_NAME.equals(configuration.getGatewayArtifactSynchronizerProperties().getRetrieverName())) {
                bundleContext.registerService(ArtifactRetriever.class.getName(), new DBRetriever(), null);
            }
        }
        bundleContext.registerService(ScopeValidator.class, new SystemScopesIssuer(), null);
    } catch (APIManagementException e) {
        log.error("Error while initializing the API manager component", e);
    } catch (APIManagerDatabaseException e) {
        log.fatal("Error while Creating the database", e);
    }
}
Also used : CertificateNotifier(org.wso2.carbon.apimgt.impl.notifier.CertificateNotifier) ExternalGatewayNotifier(org.wso2.carbon.apimgt.impl.notifier.ExternalGatewayNotifier) JWTValidationService(org.wso2.carbon.apimgt.impl.jwt.JWTValidationService) OAuthServerConfiguration(org.wso2.carbon.identity.oauth.config.OAuthServerConfiguration) ServerConfiguration(org.wso2.carbon.base.ServerConfiguration) ApplicationNotifier(org.wso2.carbon.apimgt.impl.notifier.ApplicationNotifier) APIManagerDatabaseException(org.wso2.carbon.apimgt.api.APIManagerDatabaseException) KeyManagerConfigurationServiceImpl(org.wso2.carbon.apimgt.impl.keymgt.KeyManagerConfigurationServiceImpl) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) KeyManagerConfigurationService(org.wso2.carbon.apimgt.impl.keymgt.KeyManagerConfigurationService) SubscriptionsNotifier(org.wso2.carbon.apimgt.impl.notifier.SubscriptionsNotifier) DBRetriever(org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.DBRetriever) KeyMgtConfigDeployer(org.wso2.carbon.apimgt.impl.observers.KeyMgtConfigDeployer) ApplicationRegistrationNotifier(org.wso2.carbon.apimgt.impl.notifier.ApplicationRegistrationNotifier) ExternallyDeployedApiNotifier(org.wso2.carbon.apimgt.impl.notifier.ExternallyDeployedApiNotifier) GoogleAnalyticsNotifier(org.wso2.carbon.apimgt.impl.notifier.GoogleAnalyticsNotifier) SubscriptionsNotifier(org.wso2.carbon.apimgt.impl.notifier.SubscriptionsNotifier) PolicyNotifier(org.wso2.carbon.apimgt.impl.notifier.PolicyNotifier) ApplicationNotifier(org.wso2.carbon.apimgt.impl.notifier.ApplicationNotifier) Notifier(org.wso2.carbon.apimgt.impl.notifier.Notifier) ScopesNotifier(org.wso2.carbon.apimgt.impl.notifier.ScopesNotifier) DeployAPIInGatewayNotifier(org.wso2.carbon.apimgt.impl.notifier.DeployAPIInGatewayNotifier) CertificateNotifier(org.wso2.carbon.apimgt.impl.notifier.CertificateNotifier) ExternalGatewayNotifier(org.wso2.carbon.apimgt.impl.notifier.ExternalGatewayNotifier) ApisNotifier(org.wso2.carbon.apimgt.impl.notifier.ApisNotifier) ExternallyDeployedApiNotifier(org.wso2.carbon.apimgt.impl.notifier.ExternallyDeployedApiNotifier) ApplicationRegistrationNotifier(org.wso2.carbon.apimgt.impl.notifier.ApplicationRegistrationNotifier) ApisNotifier(org.wso2.carbon.apimgt.impl.notifier.ApisNotifier) JWTValidationServiceImpl(org.wso2.carbon.apimgt.impl.jwt.JWTValidationServiceImpl) SystemScopesIssuer(org.wso2.carbon.apimgt.impl.issuers.SystemScopesIssuer) GoogleAnalyticsNotifier(org.wso2.carbon.apimgt.impl.notifier.GoogleAnalyticsNotifier) APIMConfigServiceImpl(org.wso2.carbon.apimgt.impl.config.APIMConfigServiceImpl) PolicyNotifier(org.wso2.carbon.apimgt.impl.notifier.PolicyNotifier) KeyStoreException(java.security.KeyStoreException) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) OutputEventAdapterException(org.wso2.carbon.event.output.adapter.core.exception.OutputEventAdapterException) APIMgtInternalException(org.wso2.carbon.apimgt.api.APIMgtInternalException) IOException(java.io.IOException) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) EventPublisherException(org.wso2.carbon.apimgt.eventing.EventPublisherException) UserStoreException(org.wso2.carbon.user.api.UserStoreException) APIManagerDatabaseException(org.wso2.carbon.apimgt.api.APIManagerDatabaseException) CertificateException(java.security.cert.CertificateException) ArtifactRetriever(org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.ArtifactRetriever) CommonConfigDeployer(org.wso2.carbon.apimgt.impl.observers.CommonConfigDeployer) DeployAPIInGatewayNotifier(org.wso2.carbon.apimgt.impl.notifier.DeployAPIInGatewayNotifier) APIManagerAnalyticsConfiguration(org.wso2.carbon.apimgt.impl.APIManagerAnalyticsConfiguration) APIManagerConfigurationServiceImpl(org.wso2.carbon.apimgt.impl.APIManagerConfigurationServiceImpl) Axis2ConfigurationContextObserver(org.wso2.carbon.utils.Axis2ConfigurationContextObserver) UserPostSelfRegistrationHandler(org.wso2.carbon.apimgt.impl.handlers.UserPostSelfRegistrationHandler) ScopesNotifier(org.wso2.carbon.apimgt.impl.notifier.ScopesNotifier) APIMConfigService(org.wso2.carbon.apimgt.impl.config.APIMConfigService) BundleContext(org.osgi.framework.BundleContext) TenantLoadMessageSender(org.wso2.carbon.apimgt.impl.observers.TenantLoadMessageSender) Cache(javax.cache.Cache) Activate(org.osgi.service.component.annotations.Activate)

Example 2 with CommonConfigDeployer

use of org.wso2.carbon.apimgt.impl.observers.CommonConfigDeployer 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);
}
Also used : ServiceReferenceHolder(org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) APIManagerConfiguration(org.wso2.carbon.apimgt.impl.APIManagerConfiguration) APIManagerConfigurationService(org.wso2.carbon.apimgt.impl.APIManagerConfigurationService) PrivilegedCarbonContext(org.wso2.carbon.context.PrivilegedCarbonContext) RegistryService(org.wso2.carbon.registry.core.service.RegistryService) ThrottleProperties(org.wso2.carbon.apimgt.impl.dto.ThrottleProperties) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with CommonConfigDeployer

use of org.wso2.carbon.apimgt.impl.observers.CommonConfigDeployer 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);
}
Also used : ServiceReferenceHolder(org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) APIManagerConfiguration(org.wso2.carbon.apimgt.impl.APIManagerConfiguration) APIManagerConfigurationService(org.wso2.carbon.apimgt.impl.APIManagerConfigurationService) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) PrivilegedCarbonContext(org.wso2.carbon.context.PrivilegedCarbonContext) RegistryService(org.wso2.carbon.registry.core.service.RegistryService) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 4 with CommonConfigDeployer

use of org.wso2.carbon.apimgt.impl.observers.CommonConfigDeployer in project carbon-apimgt by wso2.

the class CommonConfigDeployerTestCase method testCreatedConfigurationContextRuntimeException.

@Test
public void testCreatedConfigurationContextRuntimeException() throws APIManagementException {
    System.setProperty(CARBON_HOME, "");
    PowerMockito.mockStatic(CommonUtil.class);
    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);
    RegistryService registryService = Mockito.mock(RegistryService.class);
    Mockito.when(ServiceReferenceHolder.getInstance().getRegistryService()).thenReturn(registryService);
    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);
    ConfigurationContext configurationContext = Mockito.mock(ConfigurationContext.class);
    PowerMockito.mockStatic(APIUtil.class);
    // Mockito.doThrow(new RuntimeException("error")).when(APIUtil.loadTenantConf(TENANT_ID));
    PowerMockito.doThrow(new RuntimeException("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);
}
Also used : ServiceReferenceHolder(org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) APIManagerConfiguration(org.wso2.carbon.apimgt.impl.APIManagerConfiguration) APIManagerConfigurationService(org.wso2.carbon.apimgt.impl.APIManagerConfigurationService) PrivilegedCarbonContext(org.wso2.carbon.context.PrivilegedCarbonContext) RegistryService(org.wso2.carbon.registry.core.service.RegistryService) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

ConfigurationContext (org.apache.axis2.context.ConfigurationContext)3 Test (org.junit.Test)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 APIManagerConfiguration (org.wso2.carbon.apimgt.impl.APIManagerConfiguration)3 APIManagerConfigurationService (org.wso2.carbon.apimgt.impl.APIManagerConfigurationService)3 ServiceReferenceHolder (org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder)3 PrivilegedCarbonContext (org.wso2.carbon.context.PrivilegedCarbonContext)3 RegistryService (org.wso2.carbon.registry.core.service.RegistryService)3 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)2 IOException (java.io.IOException)1 KeyStoreException (java.security.KeyStoreException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 CertificateException (java.security.cert.CertificateException)1 Cache (javax.cache.Cache)1 BundleContext (org.osgi.framework.BundleContext)1 Activate (org.osgi.service.component.annotations.Activate)1 APIManagerDatabaseException (org.wso2.carbon.apimgt.api.APIManagerDatabaseException)1 APIMgtInternalException (org.wso2.carbon.apimgt.api.APIMgtInternalException)1 EventPublisherException (org.wso2.carbon.apimgt.eventing.EventPublisherException)1 APIManagerAnalyticsConfiguration (org.wso2.carbon.apimgt.impl.APIManagerAnalyticsConfiguration)1