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