Search in sources :

Example 1 with APIMUIConfigurations

use of org.wso2.carbon.apimgt.rest.api.configurations.models.APIMUIConfigurations in project carbon-apimgt by wso2.

the class ConfigurationsAPI method environments.

/**
 * Get environment configurations from deployment.yaml and returns the list of environments
 *
 * @return Response List of environments: {"environments":[
 * {"host":"localhost:9292","loginTokenPath":"/login/token","label":"Development"},
 * {"host":"localhost:9293","loginTokenPath":"/login/token","label":"Production"}
 * ]}
 */
@GET
@Path("/environments")
@Produces(MediaType.APPLICATION_JSON)
public Response environments() {
    APIMUIConfigurations apimUIConfigurations = ConfigurationService.getInstance().getApimUIConfigurations();
    EnvironmentConfigBean environmentConfigBean = new EnvironmentConfigBean();
    environmentConfigBean.setEnvironments(apimUIConfigurations.getEnvironments());
    return Response.ok(environmentConfigBean, MediaType.APPLICATION_JSON).build();
}
Also used : EnvironmentConfigBean(org.wso2.carbon.apimgt.rest.api.configurations.utils.bean.EnvironmentConfigBean) APIMUIConfigurations(org.wso2.carbon.apimgt.rest.api.configurations.models.APIMUIConfigurations) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with APIMUIConfigurations

use of org.wso2.carbon.apimgt.rest.api.configurations.models.APIMUIConfigurations in project carbon-apimgt by wso2.

the class ConfigurationServiceTestCase method testGetEnvironmentConfigurations.

@Test(description = "Test for EnvironmentConfigurations Configurations")
public void testGetEnvironmentConfigurations() {
    // //Happy Path
    APIMUIConfigurations apimUIConfigurations = ConfigurationService.getInstance().getApimUIConfigurations();
    Assert.assertNotNull(apimUIConfigurations);
}
Also used : APIMUIConfigurations(org.wso2.carbon.apimgt.rest.api.configurations.models.APIMUIConfigurations) Test(org.testng.annotations.Test)

Example 3 with APIMUIConfigurations

use of org.wso2.carbon.apimgt.rest.api.configurations.models.APIMUIConfigurations in project carbon-apimgt by wso2.

the class ServiceReferenceHolderTestCase method testGetEnvironmentConfigurations.

@Test
public void testGetEnvironmentConfigurations() {
    ServiceReferenceHolder instance = ServiceReferenceHolder.getInstance();
    // //Happy Path
    ConfigProvider configProvider = Mockito.mock(ConfigProvider.class);
    instance.setConfigProvider(configProvider);
    APIMUIConfigurations apimUIConfigurations = instance.getApimUIConfigurations();
    Assert.assertNotNull(apimUIConfigurations);
    // //ConfigProvider is null
    instance.setConfigProvider(null);
    apimUIConfigurations = instance.getApimUIConfigurations();
    Assert.assertNotNull(apimUIConfigurations);
    // //CarbonConfigurationException when reading configs
    configProvider = new ConfigProvider() {

        @Override
        public <T> T getConfigurationObject(Class<T> configClass) throws ConfigurationException {
            throw new ConfigurationException("Error while creating configuration instance");
        }

        @Override
        public Object getConfigurationObject(String namespace) throws ConfigurationException {
            throw new ConfigurationException("Error while creating configuration instance");
        }

        public <T> T getConfigurationObject(String s, Class<T> aClass) throws ConfigurationException {
            return null;
        }
    };
    instance.setConfigProvider(configProvider);
    apimUIConfigurations = instance.getApimUIConfigurations();
    Assert.assertNotNull(apimUIConfigurations);
}
Also used : ConfigProvider(org.wso2.carbon.config.provider.ConfigProvider) ConfigurationException(org.wso2.carbon.config.ConfigurationException) APIMUIConfigurations(org.wso2.carbon.apimgt.rest.api.configurations.models.APIMUIConfigurations) Test(org.testng.annotations.Test)

Example 4 with APIMUIConfigurations

use of org.wso2.carbon.apimgt.rest.api.configurations.models.APIMUIConfigurations in project carbon-apimgt by wso2.

the class ServiceReferenceHolder method getApimUIConfigurations.

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

Example 5 with APIMUIConfigurations

use of org.wso2.carbon.apimgt.rest.api.configurations.models.APIMUIConfigurations in project carbon-apimgt by wso2.

the class ConfigurationsAPITestCase method testEnvironments.

@Test
public void testEnvironments() {
    // Happy Path - 200
    // //Default configurations
    ConfigurationsAPI configurationsAPI = new ConfigurationsAPI();
    Response response = configurationsAPI.environments();
    Assert.assertEquals(response.getStatus(), 200);
    EnvironmentConfigBean environmentConfigBean = (EnvironmentConfigBean) response.getEntity();
    Assert.assertFalse(environmentConfigBean.getEnvironments().isEmpty());
    Assert.assertNotNull(environmentConfigBean.getEnvironments().get(0).getHost());
    Assert.assertFalse(environmentConfigBean.getEnvironments().get(0).getLabel().isEmpty());
    Assert.assertFalse(environmentConfigBean.getEnvironments().get(0).getLoginTokenPath().isEmpty());
    // //Custom configurations
    APIMUIConfigurations apimUIConfigurations = ConfigurationService.getInstance().getApimUIConfigurations();
    apimUIConfigurations.setEnvironments(getSampleEnvironments());
    response = configurationsAPI.environments();
    environmentConfigBean = (EnvironmentConfigBean) response.getEntity();
    Assert.assertEquals(environmentConfigBean.getEnvironments().size(), getSampleEnvironments().size());
    for (int i = 0; i < environmentConfigBean.getEnvironments().size(); i++) {
        Assert.assertEquals(environmentConfigBean.getEnvironments().get(i).getLabel(), getSampleEnvironments().get(i).getLabel());
        Assert.assertEquals(environmentConfigBean.getEnvironments().get(i).getHost(), getSampleEnvironments().get(i).getHost());
        Assert.assertEquals(environmentConfigBean.getEnvironments().get(i).getLoginTokenPath(), getSampleEnvironments().get(i).getLoginTokenPath());
    }
}
Also used : Response(javax.ws.rs.core.Response) EnvironmentConfigBean(org.wso2.carbon.apimgt.rest.api.configurations.utils.bean.EnvironmentConfigBean) APIMUIConfigurations(org.wso2.carbon.apimgt.rest.api.configurations.models.APIMUIConfigurations) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Aggregations

APIMUIConfigurations (org.wso2.carbon.apimgt.rest.api.configurations.models.APIMUIConfigurations)5 Test (org.testng.annotations.Test)3 EnvironmentConfigBean (org.wso2.carbon.apimgt.rest.api.configurations.utils.bean.EnvironmentConfigBean)2 ConfigurationException (org.wso2.carbon.config.ConfigurationException)2 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 Response (javax.ws.rs.core.Response)1 BeforeTest (org.testng.annotations.BeforeTest)1 ConfigProvider (org.wso2.carbon.config.provider.ConfigProvider)1