Search in sources :

Example 11 with APIAdmin

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();
}
Also used : EnvironmentListDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.EnvironmentListDTO) APIAdmin(org.wso2.carbon.apimgt.api.APIAdmin) Environment(org.wso2.carbon.apimgt.api.model.Environment) APIAdminImpl(org.wso2.carbon.apimgt.impl.APIAdminImpl)

Example 12 with APIAdmin

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();
}
Also used : APIAdmin(org.wso2.carbon.apimgt.api.APIAdmin) Environment(org.wso2.carbon.apimgt.api.model.Environment) APIAdminImpl(org.wso2.carbon.apimgt.impl.APIAdminImpl) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 13 with APIAdmin

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;
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) MonetizationUsagePublishInfo(org.wso2.carbon.apimgt.api.model.MonetizationUsagePublishInfo) APIAdmin(org.wso2.carbon.apimgt.api.APIAdmin) APIAdminImpl(org.wso2.carbon.apimgt.impl.APIAdminImpl)

Example 14 with APIAdmin

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");
}
Also used : APIAdmin(org.wso2.carbon.apimgt.api.APIAdmin) Test(org.junit.Test) BeforeTest(org.testng.annotations.BeforeTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 15 with APIAdmin

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);
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) APIAdmin(org.wso2.carbon.apimgt.api.APIAdmin) Schema(org.everit.json.schema.Schema) APIUtil(org.wso2.carbon.apimgt.impl.utils.APIUtil) File(java.io.File) Test(org.junit.Test) BeforeTest(org.testng.annotations.BeforeTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

APIAdmin (org.wso2.carbon.apimgt.api.APIAdmin)46 APIAdminImpl (org.wso2.carbon.apimgt.impl.APIAdminImpl)39 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)31 Test (org.junit.Test)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)8 BeforeTest (org.testng.annotations.BeforeTest)8 KeyManagerConfigurationDTO (org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO)8 APIUtil (org.wso2.carbon.apimgt.impl.utils.APIUtil)6 ArrayList (java.util.ArrayList)5 Schema (org.everit.json.schema.Schema)5 File (java.io.File)4 URI (java.net.URI)4 URISyntaxException (java.net.URISyntaxException)4 BotDetectionData (org.wso2.carbon.apimgt.api.model.botDataAPI.BotDetectionData)4 APIPolicy (org.wso2.carbon.apimgt.api.model.policy.APIPolicy)4 ApplicationPolicy (org.wso2.carbon.apimgt.api.model.policy.ApplicationPolicy)4 GlobalPolicy (org.wso2.carbon.apimgt.api.model.policy.GlobalPolicy)4 Policy (org.wso2.carbon.apimgt.api.model.policy.Policy)4 SubscriptionPolicy (org.wso2.carbon.apimgt.api.model.policy.SubscriptionPolicy)4 Gson (com.google.gson.Gson)3