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