Search in sources :

Example 6 with ConfigProvider

use of org.wso2.carbon.config.provider.ConfigProvider in project carbon-apimgt by wso2.

the class ScopeRegistrationServiceStubFactoryTest method testGetScopeRegistrationForWso2Is.

@Test
public void testGetScopeRegistrationForWso2Is() throws Exception {
    KeyMgtConfigurations keyManagerConfiguration = new KeyMgtConfigurations();
    keyManagerConfiguration.setKeyManagerImplClass(WSO2ISKeyManagerImpl.class.getCanonicalName());
    ConfigProvider configProvider = Mockito.mock(ConfigProvider.class);
    APIMConfigurations apimConfigurations = new APIMConfigurations();
    apimConfigurations.setKeyManagerConfigs(keyManagerConfiguration);
    Mockito.when(configProvider.getConfigurationObject(APIMConfigurations.class)).thenReturn(apimConfigurations);
    ServiceReferenceHolder.getInstance().setConfigProvider(configProvider);
    ScopeRegistration scopeRegistration = ScopeRegistrationServiceStubFactory.getScopeRegistration();
    Assert.assertTrue(scopeRegistration instanceof WSO2ISScopeRegistrationImpl);
}
Also used : KeyMgtConfigurations(org.wso2.carbon.apimgt.core.configuration.models.KeyMgtConfigurations) ConfigProvider(org.wso2.carbon.config.provider.ConfigProvider) APIMConfigurations(org.wso2.carbon.apimgt.core.configuration.models.APIMConfigurations) WSO2ISKeyManagerImpl(org.wso2.carbon.apimgt.core.impl.WSO2ISKeyManagerImpl) Test(org.testng.annotations.Test)

Example 7 with ConfigProvider

use of org.wso2.carbon.config.provider.ConfigProvider in project carbon-apimgt by wso2.

the class ServiceReferenceHolder method getAPIMAppConfiguration.

public APIMAppConfigurations getAPIMAppConfiguration() {
    try {
        if (configProvider != null) {
            config = configProvider.getConfigurationObject(APIMAppConfigurations.class);
        } else {
            log.error("Configuration provider is null");
        }
    } catch (ConfigurationException e) {
        log.error("Error getting config : org.wso2.carbon.apimgt.rest.api.authenticator.internal.APIMAppConfiguration", e);
    }
    if (config == null) {
        config = new APIMAppConfigurations();
        log.info("Setting default configurations...");
    }
    return config;
}
Also used : ConfigurationException(org.wso2.carbon.config.ConfigurationException) APIMAppConfigurations(org.wso2.carbon.apimgt.rest.api.authenticator.configuration.models.APIMAppConfigurations)

Example 8 with ConfigProvider

use of org.wso2.carbon.config.provider.ConfigProvider in project carbon-apimgt by wso2.

the class ServiceReferenceHolderTestCase method testGetRestAPIConfigurationMap.

@Test
public void testGetRestAPIConfigurationMap() throws ConfigurationException {
    // // Happy Path
    ServiceReferenceHolder instance = ServiceReferenceHolder.getInstance();
    ConfigProvider configProvider = Mockito.mock(ConfigProvider.class);
    instance.setConfigProvider(configProvider);
    Map<String, String> expectedConfigMap = new HashMap<>();
    expectedConfigMap.put("apimBaseUrl", "https://localhost:9443/");
    Mockito.when(configProvider.getConfigurationObject("xxx-namespace-xxx")).thenReturn(expectedConfigMap);
    Map<String, String> actualConfigMap = instance.getRestAPIConfigurationMap("xxx-namespace-xxx");
    Assert.assertEquals(expectedConfigMap, actualConfigMap);
    // // Error path
    // // ConfigurationException
    Mockito.when(configProvider.getConfigurationObject("xxx-namespace-xxx")).thenThrow(ConfigurationException.class);
    actualConfigMap = instance.getRestAPIConfigurationMap("xxx-namespace-xxx");
    Assert.assertNull(actualConfigMap);
    // // config provider is null
    instance.setConfigProvider(null);
    actualConfigMap = instance.getRestAPIConfigurationMap("xxx-namespace-xxx");
    Assert.assertNull(actualConfigMap);
}
Also used : ConfigProvider(org.wso2.carbon.config.provider.ConfigProvider) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 9 with ConfigProvider

use of org.wso2.carbon.config.provider.ConfigProvider in project carbon-apimgt by wso2.

the class APIGatewayPublisherImplTestCase method testGetContainerBasedGatewayGenerator.

@Test
public void testGetContainerBasedGatewayGenerator() throws ContainerBasedGatewayException, ConfigurationException {
    APIGatewayPublisherImpl apiGatewayPublisher = new APIGatewayPublisherImpl();
    ConfigProvider configProvider = Mockito.mock(ConfigProvider.class);
    ContainerBasedGatewayConfiguration containerBasedGatewayConfig = new ContainerBasedGatewayConfiguration();
    Mockito.when(configProvider.getConfigurationObject(ContainerBasedGatewayConfiguration.class)).thenReturn(containerBasedGatewayConfig);
    ContainerBasedGatewayConfigBuilder.build(configProvider);
    ContainerBasedGatewayGenerator containerBasedGatewayGenerator = apiGatewayPublisher.getContainerBasedGatewayGenerator();
    Assert.assertNotNull(containerBasedGatewayGenerator);
}
Also used : ContainerBasedGatewayConfiguration(org.wso2.carbon.apimgt.core.configuration.models.ContainerBasedGatewayConfiguration) ConfigProvider(org.wso2.carbon.config.provider.ConfigProvider) Test(org.junit.Test)

Example 10 with ConfigProvider

use of org.wso2.carbon.config.provider.ConfigProvider in project carbon-apimgt by wso2.

the class APIGatewayPublisherImplTestCase method testGetContainerBasedGatewayGeneratorForException.

@Test(expected = ContainerBasedGatewayException.class)
public void testGetContainerBasedGatewayGeneratorForException() throws ContainerBasedGatewayException, ConfigurationException {
    APIGatewayPublisherImpl apiGatewayPublisher = new APIGatewayPublisherImpl();
    ConfigProvider configProvider = Mockito.mock(ConfigProvider.class);
    ContainerBasedGatewayConfiguration containerBasedGatewayConfig = new ContainerBasedGatewayConfiguration();
    containerBasedGatewayConfig.setImplClass("org.wso2.invalid.class.name");
    Mockito.when(configProvider.getConfigurationObject(ContainerBasedGatewayConfiguration.class)).thenReturn(containerBasedGatewayConfig);
    ContainerBasedGatewayConfigBuilder.build(configProvider);
    ContainerBasedGatewayGenerator containerBasedGatewayGenerator = apiGatewayPublisher.getContainerBasedGatewayGenerator();
    Assert.assertNotNull(containerBasedGatewayGenerator);
}
Also used : ContainerBasedGatewayConfiguration(org.wso2.carbon.apimgt.core.configuration.models.ContainerBasedGatewayConfiguration) ConfigProvider(org.wso2.carbon.config.provider.ConfigProvider) Test(org.junit.Test)

Aggregations

ConfigProvider (org.wso2.carbon.config.provider.ConfigProvider)17 ConfigurationException (org.wso2.carbon.config.ConfigurationException)9 Test (org.testng.annotations.Test)8 Test (org.junit.Test)4 HashMap (java.util.HashMap)3 ContainerBasedGatewayConfiguration (org.wso2.carbon.apimgt.core.configuration.models.ContainerBasedGatewayConfiguration)3 WorkflowConfig (org.wso2.carbon.apimgt.core.models.WorkflowConfig)3 Feature (org.wso2.carbon.apimgt.rest.api.configurations.models.Feature)3 Path (java.nio.file.Path)2 Map (java.util.Map)2 BeforeTest (org.testng.annotations.BeforeTest)2 BrokerConfigProvider (org.wso2.broker.common.BrokerConfigProvider)2 APIMConfigurations (org.wso2.carbon.apimgt.core.configuration.models.APIMConfigurations)2 APIMAppConfigurations (org.wso2.carbon.apimgt.rest.api.authenticator.configuration.models.APIMAppConfigurations)2 APIMUIConfigurations (org.wso2.carbon.apimgt.rest.api.configurations.models.APIMUIConfigurations)2 HikariDataSource (com.zaxxer.hikari.HikariDataSource)1 File (java.io.File)1 Context (javax.naming.Context)1 NamingException (javax.naming.NamingException)1 BundleContext (org.osgi.framework.BundleContext)1