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);
}
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);
}
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);
}
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);
}
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;
}
Aggregations