Search in sources :

Example 21 with Response

use of org.wso2.msf4j.Response in project carbon-apimgt by wso2.

the class PoliciesApiServiceImpl method policiesThrottlingAdvancedPost.

/**
 * Create Policy
 *
 * @param body              DTO object including the Policy meta information
 * @param request           msf4j request object
 * @return Response object
 * @throws NotFoundException if an error occurred when particular resource does not exits in the system.
 */
@Override
public Response policiesThrottlingAdvancedPost(AdvancedThrottlePolicyDTO body, Request request) throws NotFoundException {
    APIMgtAdminService.PolicyLevel tierLevel = APIMgtAdminService.PolicyLevel.api;
    if (log.isDebugEnabled()) {
        log.info("Received Advance Policy POST request " + body + " with tierLevel = " + tierLevel);
    }
    if (log.isDebugEnabled()) {
        log.info("Received Advance Policy PUT request " + body + " with tierLevel = " + tierLevel);
    }
    try {
        APIMgtAdminService apiMgtAdminService = RestApiUtil.getAPIMgtAdminService();
        APIPolicy apiPolicy = AdvancedThrottlePolicyMappingUtil.fromAdvancedPolicyDTOToPolicy(body);
        String policyId = apiMgtAdminService.addApiPolicy(apiPolicy);
        return Response.status(Response.Status.CREATED).entity(AdvancedThrottlePolicyMappingUtil.fromAdvancedPolicyToDTO(apiMgtAdminService.getApiPolicyByUuid(policyId))).build();
    } catch (APIManagementException e) {
        String errorMessage = "Error occurred while adding Advanced Throttle Policy, policy name: " + body.getPolicyName();
        ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
        log.error(errorMessage, e);
        return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
    }
}
Also used : APIMgtAdminService(org.wso2.carbon.apimgt.core.api.APIMgtAdminService) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO) APIPolicy(org.wso2.carbon.apimgt.core.models.policy.APIPolicy)

Example 22 with Response

use of org.wso2.msf4j.Response in project carbon-apimgt by wso2.

the class WorkflowMappingUtil method toWorkflowResponseDTO.

/**
 * Map WorkflowResponse to WorkflowResponseDTO
 * @param response WorkflowResponse object
 * @return WorkflowResponseDTO mapped WorkflowResponseDTO
 */
public static WorkflowResponseDTO toWorkflowResponseDTO(WorkflowResponse response) {
    WorkflowResponseDTO responseDTO = new WorkflowResponseDTO();
    responseDTO.setWorkflowStatus(WorkflowStatusEnum.valueOf(response.getWorkflowStatus().toString()));
    responseDTO.setJsonPayload(response.getJSONPayload());
    return responseDTO;
}
Also used : WorkflowResponseDTO(org.wso2.carbon.apimgt.rest.api.admin.dto.WorkflowResponseDTO)

Example 23 with Response

use of org.wso2.msf4j.Response in project carbon-apimgt by wso2.

the class LabelsApiServiceImplTest method testLabelsPost.

@Test
public void testLabelsPost() throws Exception {
    APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
    PowerMockito.mockStatic(RestApiUtil.class);
    PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(adminService);
    Label label1 = new Label.Builder().id("1").name("label1").type("GATEWAY").build();
    LabelsApiServiceImpl labelService = new LabelsApiServiceImpl();
    Mockito.when(labelService.labelsPost(LabelMappingUtil.fromLabelToDTO(label1), "application/json", getRequest())).thenReturn(Response.status(Response.Status.CREATED).entity(LabelMappingUtil.fromLabelToDTO(label1)).build());
    Response response = labelService.labelsPost(LabelMappingUtil.fromLabelToDTO(label1), "application/json", getRequest());
    Assert.assertEquals(response.getStatus(), Response.Status.CREATED);
}
Also used : Response(javax.ws.rs.core.Response) APIMgtAdminServiceImpl(org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl) Label(org.wso2.carbon.apimgt.core.models.Label) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 24 with Response

use of org.wso2.msf4j.Response in project carbon-apimgt by wso2.

the class LabelsApiServiceImplTest method testLabelsLabelIdPut.

@Test
public void testLabelsLabelIdPut() throws Exception {
    APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
    PowerMockito.mockStatic(RestApiUtil.class);
    PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(adminService);
    List<Label> labels = new ArrayList<>();
    Label label1 = new Label.Builder().id("1").name("label1").type("GATEWAY").build();
    Label label2 = new Label.Builder().id("2").name("label2").type("STORE").build();
    labels.add(label1);
    labels.add(label2);
    LabelsApiServiceImpl labelService = new LabelsApiServiceImpl();
    Mockito.when(labelService.labelsLabelIdPut("1", LabelMappingUtil.fromLabelToDTO(label1), "application/Json", getRequest())).thenReturn(Response.status(Response.Status.OK).entity(LabelMappingUtil.fromLabelArrayToListDTO(labels)).build());
    Response response = labelService.labelsLabelIdPut("1", LabelMappingUtil.fromLabelToDTO(label1), "application/Json", getRequest());
    Assert.assertEquals(response.getEntity(), LabelMappingUtil.fromLabelArrayToListDTO(labels));
}
Also used : Response(javax.ws.rs.core.Response) APIMgtAdminServiceImpl(org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl) Label(org.wso2.carbon.apimgt.core.models.Label) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 25 with Response

use of org.wso2.msf4j.Response in project carbon-apimgt by wso2.

the class LabelsApiServiceImplTest method testLabelsDelete.

@Test
public void testLabelsDelete() throws Exception {
    APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
    PowerMockito.mockStatic(RestApiUtil.class);
    PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(adminService);
    LabelsApiServiceImpl labelService = new LabelsApiServiceImpl();
    Mockito.doNothing().when(labelService.labelsLabelIdDelete("1", getRequest()));
    Response response = labelService.labelsLabelIdDelete("1", getRequest());
    Assert.assertEquals(response.getStatus(), Response.Status.OK);
}
Also used : Response(javax.ws.rs.core.Response) APIMgtAdminServiceImpl(org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

Response (javax.ws.rs.core.Response)323 Test (org.junit.Test)317 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)317 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)247 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)189 WorkflowResponse (org.wso2.carbon.apimgt.core.api.WorkflowResponse)153 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)146 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)141 GeneralWorkflowResponse (org.wso2.carbon.apimgt.core.workflow.GeneralWorkflowResponse)139 HashMap (java.util.HashMap)115 Request (org.wso2.msf4j.Request)92 ArrayList (java.util.ArrayList)69 APIMgtAdminServiceImpl (org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl)67 APIMgtAdminService (org.wso2.carbon.apimgt.core.api.APIMgtAdminService)45 API (org.wso2.carbon.apimgt.core.models.API)39 File (java.io.File)38 Test (org.testng.annotations.Test)36 Response (feign.Response)35 FileInputStream (java.io.FileInputStream)33 DocumentInfo (org.wso2.carbon.apimgt.core.models.DocumentInfo)30