use of org.wso2.carbon.apimgt.api.model.Provider 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;
}
use of org.wso2.carbon.apimgt.api.model.Provider 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.apimgt.api.model.Provider in project carbon-apimgt by wso2.
the class APIConfigContextTestCase method testAPINameWithNumber.
@Test
public void testAPINameWithNumber() throws APITemplateException {
String apiId = UUID.randomUUID().toString();
API nameWithNumberAPI = new API.APIBuilder("provider", "1111testapi", "1.0.0").id(apiId).context("testcontext").build();
APIConfigContext apiConfigContext = new APIConfigContext(nameWithNumberAPI, "org.test");
apiConfigContext.validate();
String actualServiceName = (String) apiConfigContext.getContext().get("serviceName");
Assert.assertEquals(actualServiceName, "prefix_1111testapi_" + apiId.replaceAll("-", "_"));
}
use of org.wso2.carbon.apimgt.api.model.Provider in project carbon-apimgt by wso2.
the class ServiceDiscoveryConfigBuilderTestCase method testWhenExceptionThrownByConfigProvider.
@Test(description = "Test the flow where Config Provider throws an exception")
public void testWhenExceptionThrownByConfigProvider() throws Exception {
ConfigProvider configProvider = Mockito.mock(ConfigProvider.class);
Mockito.doThrow(ConfigurationException.class).when(configProvider).getConfigurationObject(ServiceDiscoveryConfigurations.class);
ServiceDiscoveryConfigBuilder.build(configProvider);
Assert.assertNotNull(ServiceDiscoveryConfigBuilder.getServiceDiscoveryConfiguration());
}
use of org.wso2.carbon.apimgt.api.model.Provider 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