Search in sources :

Example 6 with ConfigurationException

use of org.wso2.carbon.config.ConfigurationException 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 7 with ConfigurationException

use of org.wso2.carbon.config.ConfigurationException 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 8 with ConfigurationException

use of org.wso2.carbon.config.ConfigurationException 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)

Example 9 with ConfigurationException

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

the class APIGatewayPublisherImplTestCase method testCreateContainerGateway.

@Test
public void testCreateContainerGateway() throws ContainerBasedGatewayException, ConfigurationException {
    APIGatewayPublisherImpl apiGatewayPublisher = new APIGatewayPublisherImpl();
    ContainerBasedGatewayGenerator containerBasedGatewayGenerator = Mockito.mock(ContainerBasedGatewayGenerator.class);
    apiGatewayPublisher.setContainerBasedGatewayGenerator(containerBasedGatewayGenerator);
    API api = SampleTestObjectCreator.createDefaultAPI().build();
    apiGatewayPublisher.createContainerBasedGateway("label", api);
    Mockito.verify(containerBasedGatewayGenerator, Mockito.times(1)).createContainerGateway("label", api);
}
Also used : API(org.wso2.carbon.apimgt.core.models.API) Test(org.junit.Test)

Example 10 with ConfigurationException

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

the class ServiceReferenceHolder method getFeature.

/**
 * Get feature details
 *
 * @param namespace   Namespace
 * @param featureName Name of the feature
 * @return feature returns the feature details
 */
private Feature getFeature(String namespace, String featureName) {
    Feature feature;
    try {
        if (configProvider != null) {
            Map configs = (Map) configProvider.getConfigurationObject(namespace);
            boolean enabled = false;
            if (configs != null) {
                enabled = (Boolean) configs.get(ConfigurationAPIConstants.ENABLED);
            }
            feature = new Feature(featureName, enabled);
            return feature;
        } else {
            log.error("Configuration provider is null");
        }
    } catch (ConfigurationException e) {
        log.error("Error getting configuration for namespace " + namespace, e);
    }
    feature = new Feature(featureName, false);
    log.info("Setting default configurations for [feature] " + featureName + " and [namespace] " + namespace);
    return feature;
}
Also used : ConfigurationException(org.wso2.carbon.config.ConfigurationException) Feature(org.wso2.carbon.apimgt.rest.api.configurations.models.Feature) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

ConfigProvider (org.wso2.carbon.config.provider.ConfigProvider)12 ConfigurationException (org.wso2.carbon.config.ConfigurationException)9 Test (org.junit.Test)5 HashMap (java.util.HashMap)3 Test (org.testng.annotations.Test)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 ContainerBasedGatewayConfiguration (org.wso2.carbon.apimgt.core.configuration.models.ContainerBasedGatewayConfiguration)2 APIMAppConfigurations (org.wso2.carbon.apimgt.rest.api.authenticator.configuration.models.APIMAppConfigurations)2 APIMUIConfigurations (org.wso2.carbon.apimgt.rest.api.configurations.models.APIMUIConfigurations)2 File (java.io.File)1 Iterator (java.util.Iterator)1 List (java.util.List)1 QName (javax.xml.namespace.QName)1 OXPath20ExpressionBPEL20 (org.apache.ode.bpel.elang.xpath20.o.OXPath20ExpressionBPEL20)1 ConfigurationException (org.apache.ode.bpel.explang.ConfigurationException)1