use of org.wso2.msf4j.Response in project carbon-apimgt by wso2.
the class PoliciesApiServiceImplTestCase method testPoliciesTierLevelTierNameGetException.
@Test
public void testPoliciesTierLevelTierNameGetException() throws Exception {
printTestMethodName();
PoliciesApiServiceImpl policiesApiService = new PoliciesApiServiceImpl();
APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
PowerMockito.mockStatic(RestAPIPublisherUtil.class);
PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
Mockito.doThrow(new LabelException("Error occurred", ExceptionCodes.POLICY_LEVEL_NOT_SUPPORTED)).when(apiPublisher).getPolicyByName(RestApiUtil.mapRestApiPolicyLevelToPolicyLevelEnum("subscription"), "Gold");
Response response = policiesApiService.policiesTierLevelTierNameGet("Gold", "subscription", null, null, getRequest());
assertEquals(response.getStatus(), 400);
assertTrue(response.getEntity().toString().contains("Throttle Policy level invalid"));
}
use of org.wso2.msf4j.Response in project carbon-apimgt by wso2.
the class SubscriptionsApiServiceImplTestCase method testSubscriptionsSubscriptionIdGetExist.
@Test
public void testSubscriptionsSubscriptionIdGetExist() throws Exception {
printTestMethodName();
SubscriptionsApiServiceImpl subscriptionsApiService = new SubscriptionsApiServiceImpl();
APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
String sub1 = UUID.randomUUID().toString();
PowerMockito.mockStatic(RestAPIPublisherUtil.class);
PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
Mockito.doReturn(null).doThrow(new IllegalArgumentException()).when(apiPublisher).getSubscriptionByUUID(sub1);
Response response = subscriptionsApiService.subscriptionsSubscriptionIdGet(sub1, null, null, getRequest());
assertEquals(response.getStatus(), 404);
assertTrue(response.getEntity().toString().contains("Subscription not found"));
}
use of org.wso2.msf4j.Response in project carbon-apimgt by wso2.
the class SubscriptionsApiServiceImplTestCase method testSubscriptionsGetException.
@Test
public void testSubscriptionsGetException() throws Exception {
printTestMethodName();
SubscriptionsApiServiceImpl subscriptionsApiService = new SubscriptionsApiServiceImpl();
APIPublisher apiPublisher = Mockito.mock(APIPublisherImpl.class);
PowerMockito.mockStatic(RestAPIPublisherUtil.class);
PowerMockito.when(RestAPIPublisherUtil.getApiPublisher(USER)).thenReturn(apiPublisher);
String subscriptionId = UUID.randomUUID().toString();
Subscription subscription = SampleTestObjectCreator.createSubscription(subscriptionId);
subscription.setStatus(APIMgtConstants.SubscriptionStatus.REJECTED);
Mockito.doThrow(new APIManagementException("Error occurred", ExceptionCodes.SUBSCRIPTION_STATE_INVALID)).when(apiPublisher).getSubscriptionByUUID(subscriptionId);
Response response = subscriptionsApiService.subscriptionsUnblockSubscriptionPost(subscriptionId, null, null, getRequest());
assertEquals(response.getStatus(), 400);
assertTrue(response.getEntity().toString().contains("Invalid state change for subscription"));
}
use of org.wso2.msf4j.Response in project carbon-apimgt by wso2.
the class MappingUtil 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 SubscriptionsApiServiceImpl method subscriptionsGet.
/**
* Retrieve all subscriptions for a particular API
*
* @param apiId ID of the API
* @param limit Maximum subscriptions to return
* @param offset Starting position of the pagination
* @param ifNoneMatch If-Match header value
* @param request ms4j request object
* @return List of qualifying subscriptions DTOs as the response
* @throws NotFoundException When the particular resource does not exist in the system
*/
@Override
public Response subscriptionsGet(String apiId, Integer limit, Integer offset, String ifNoneMatch, Request request) throws NotFoundException {
String username = RestApiUtil.getLoggedInUsername(request);
List<Subscription> subscriptionList;
try {
APIPublisher apiPublisher = RestAPIPublisherUtil.getApiPublisher(username);
if (StringUtils.isNotEmpty(apiId)) {
subscriptionList = apiPublisher.getSubscriptionsByAPI(apiId);
SubscriptionListDTO subscriptionListDTO = MappingUtil.fromSubscriptionListToDTO(subscriptionList, limit, offset);
return Response.ok().entity(subscriptionListDTO).build();
} else {
RestApiUtil.handleBadRequest("API ID can not be null", log);
}
} catch (APIManagementException e) {
String errorMessage = "Error while retrieving subscriptions of API " + apiId;
HashMap<String, String> paramList = new HashMap<String, String>();
paramList.put(APIMgtConstants.ExceptionsConstants.API_ID, apiId);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
return null;
}
Aggregations