use of org.wso2.carbon.apimgt.api.APIAdmin in project carbon-apimgt by wso2.
the class EnvironmentsApiServiceImpl method environmentsGet.
/**
* Get list of gateway environments from config api-manager.xml and dynamic environments (from DB)
*
* @param messageContext message context
* @return created environment
* @throws APIManagementException if failed to get list
*/
public Response environmentsGet(MessageContext messageContext) throws APIManagementException {
APIAdmin apiAdmin = new APIAdminImpl();
String organization = RestApiUtil.getValidatedOrganization(messageContext);
List<Environment> envList = apiAdmin.getAllEnvironments(organization);
EnvironmentListDTO envListDTO = EnvironmentMappingUtil.fromEnvListToEnvListDTO(envList);
return Response.ok().entity(envListDTO).build();
}
use of org.wso2.carbon.apimgt.api.APIAdmin in project carbon-apimgt by wso2.
the class EnvironmentsApiServiceImpl method environmentsEnvironmentIdPut.
/**
* Update gateway environment
*
* @param environmentId environment ID
* @param body environment to be updated
* @param messageContext message context
* @return updated environment
* @throws APIManagementException if failed to update
*/
public Response environmentsEnvironmentIdPut(String environmentId, EnvironmentDTO body, MessageContext messageContext) throws APIManagementException {
APIAdmin apiAdmin = new APIAdminImpl();
body.setId(environmentId);
String organization = RestApiUtil.getValidatedOrganization(messageContext);
Environment env = EnvironmentMappingUtil.fromEnvDtoToEnv(body);
apiAdmin.updateEnvironment(organization, env);
URI location = null;
try {
location = new URI(RestApiConstants.RESOURCE_PATH_ENVIRONMENT + "/" + environmentId);
} catch (URISyntaxException e) {
String errorMessage = "Error while updating Environment : " + environmentId;
RestApiUtil.handleInternalServerError(errorMessage, e, log);
}
return Response.ok(location).entity(body).build();
}
use of org.wso2.carbon.apimgt.api.APIAdmin in project carbon-apimgt by wso2.
the class MonetizationApiServiceImpl method monetizationPublishUsageStatusGet.
/**
* Retrieves the status of the last monetization usage publishing job
*
* @return Retruns the status of the last monetization usage publishing jon
*/
@Override
public Response monetizationPublishUsageStatusGet(MessageContext messageContext) {
MonetizationUsagePublishInfo monetizationUsagePublishInfo;
try {
APIAdmin apiAdmin = new APIAdminImpl();
monetizationUsagePublishInfo = apiAdmin.getMonetizationUsagePublishInfo();
return Response.ok().entity(MonetizationAPIMappinUtil.fromUsageStateToDTO(monetizationUsagePublishInfo)).build();
} catch (APIManagementException ex) {
RestApiUtil.handleInternalServerError("Could not derive monetization usage publish info", ex, log);
}
return null;
}
use of org.wso2.carbon.apimgt.api.APIAdmin in project carbon-apimgt by wso2.
the class APIAdminImplTest method getTenantConfig.
@Test
public void getTenantConfig() throws APIManagementException {
APIAdmin apiAdmin = new APIAdminImpl();
Mockito.when(apimConfigService.getTenantConfig("abc.com")).thenReturn("abcde");
Assert.assertEquals(apiAdmin.getTenantConfig("abc.com"), "abcde");
Mockito.verify(apimConfigService, Mockito.times(1)).getTenantConfig("abc.com");
}
use of org.wso2.carbon.apimgt.api.APIAdmin in project carbon-apimgt by wso2.
the class APIAdminImplTest method updateTenantConfigNegative1.
// Schema not present
@Test
public void updateTenantConfigNegative1() throws Exception {
File siteConfFile = new File(Thread.currentThread().getContextClassLoader().getResource("tenant-conf.json").getFile());
String tenantConf = FileUtils.readFileToString(siteConfFile);
PowerMockito.doNothing().when(APIUtil.class, "validateRestAPIScopes", tenantConf);
Schema schema = Mockito.mock(Schema.class);
PowerMockito.when(APIUtil.class, "retrieveTenantConfigJsonSchema").thenReturn(null);
APIAdmin apiAdmin = new APIAdminImpl();
Mockito.doNothing().when(apimConfigService).updateTenantConfig("abc.com", tenantConf);
try {
apiAdmin.updateTenantConfig("abc.com", tenantConf);
Assert.fail("Method successfully invoked");
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "tenant-config validation failure");
Assert.assertEquals(e.getErrorHandler(), ExceptionCodes.INTERNAL_ERROR);
}
}
Aggregations