Search in sources :

Example 26 with Provider

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;
}
Also used : ConfigurationException(org.wso2.carbon.config.ConfigurationException) APIMAppConfigurations(org.wso2.carbon.apimgt.rest.api.authenticator.configuration.models.APIMAppConfigurations)

Example 27 with Provider

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);
}
Also used : ConfigProvider(org.wso2.carbon.config.provider.ConfigProvider) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 28 with Provider

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("-", "_"));
}
Also used : API(org.wso2.carbon.apimgt.core.models.API) Test(org.testng.annotations.Test)

Example 29 with Provider

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());
}
Also used : ConfigProvider(org.wso2.carbon.config.provider.ConfigProvider) Test(org.testng.annotations.Test)

Example 30 with Provider

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

APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)82 ArrayList (java.util.ArrayList)70 API (org.wso2.carbon.apimgt.api.model.API)64 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)50 Test (org.junit.Test)49 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)45 HashMap (java.util.HashMap)40 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)36 IOException (java.io.IOException)35 Resource (org.wso2.carbon.registry.core.Resource)34 UserRegistry (org.wso2.carbon.registry.core.session.UserRegistry)32 HashSet (java.util.HashSet)30 GenericArtifact (org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact)29 UserStoreException (org.wso2.carbon.user.api.UserStoreException)29 PreparedStatement (java.sql.PreparedStatement)28 Connection (java.sql.Connection)27 SQLException (java.sql.SQLException)27 ResultSet (java.sql.ResultSet)25 QName (javax.xml.namespace.QName)25 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)25