use of org.wso2.carbon.apimgt.core.exception.APIManagementException in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testObserverEventListener.
@Test(description = "Event Observers for event listening")
public void testObserverEventListener() throws APIManagementException {
EventLogger observer = Mockito.mock(EventLogger.class);
APIPublisherImpl apiPub = getApiPublisherImpl();
apiPub.registerObserver(observer);
Event event = Event.APP_CREATION;
String username = USER;
Map<String, String> metaData = new HashMap<>();
ZonedDateTime eventTime = ZonedDateTime.now(ZoneOffset.UTC);
apiPub.notifyObservers(event, username, eventTime, metaData);
Mockito.verify(observer, Mockito.times(1)).captureEvent(event, username, eventTime, metaData);
}
use of org.wso2.carbon.apimgt.core.exception.APIManagementException in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testGetAPILifeCycleDataExceptionWhenRetrievingAPILifeCycle.
@Test(description = "Could not retrieve api lifecycle when Getting api lifecycle data", expectedExceptions = APIManagementException.class)
public void testGetAPILifeCycleDataExceptionWhenRetrievingAPILifeCycle() throws APIManagementException, LifecycleException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
APILifecycleManager apiLifecycleManager = Mockito.mock(APILifecycleManager.class);
APIGateway gateway = Mockito.mock(APIGateway.class);
APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO, apiLifecycleManager, gateway);
API api = SampleTestObjectCreator.createDefaultAPI().build();
String uuid = api.getId();
String lcState = api.getLifeCycleStatus();
String lifecycleId = api.getLifecycleInstanceId();
Mockito.when(apiDAO.getAPISummary(uuid)).thenReturn(api);
Mockito.doThrow(new LifecycleException("Couldn't retrieve API Lifecycle for " + uuid)).when(apiLifecycleManager).getLifecycleDataForState(lifecycleId, lcState);
apiPublisher.getAPILifeCycleData(uuid);
}
use of org.wso2.carbon.apimgt.core.exception.APIManagementException in project carbon-apimgt by wso2.
the class WorkflowsApiServiceImplTestCase method testWorkflowsWorkflowReferenceIdGetException.
@Test
public void testWorkflowsWorkflowReferenceIdGetException() throws Exception {
printTestMethodName();
WorkflowsApiServiceImpl workflowsApiService = new WorkflowsApiServiceImpl();
APIMgtAdminServiceImpl adminService = Mockito.mock(APIMgtAdminServiceImpl.class);
PowerMockito.mockStatic(RestApiUtil.class);
PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(adminService);
String workflowRefId = UUID.randomUUID().toString();
String message = "Error while retrieving workflow entry for :" + workflowRefId;
Mockito.doThrow(new APIManagementException(message, ExceptionCodes.APIMGT_DAO_EXCEPTION)).when(adminService).retrieveWorkflow(workflowRefId);
Response response = workflowsApiService.workflowsWorkflowReferenceIdGet(workflowRefId, getRequest());
assertEquals(500, response.getStatus());
}
use of org.wso2.carbon.apimgt.core.exception.APIManagementException in project carbon-apimgt by wso2.
the class PoliciesApiServiceImpl method policiesThrottlingApplicationIdPut.
/**
* Updates/adds a new Application throttle policy to the system
*
* @param id Uuid of the policy.
* @param body DTO object including the Policy meta information
* @param ifMatch If-Match header value
* @param ifUnmodifiedSince If-Unmodified-Since header value
* @param request msf4j request object
* @return Response object response object with the updated application throttle policy resource
* @throws NotFoundException if an error occurred when particular resource does not exits in the system.
*/
@Override
public Response policiesThrottlingApplicationIdPut(String id, ApplicationThrottlePolicyDTO body, String ifMatch, String ifUnmodifiedSince, Request request) throws NotFoundException {
APIMgtAdminService.PolicyLevel tierLevel = APIMgtAdminService.PolicyLevel.application;
if (log.isDebugEnabled()) {
log.info("Received Application Policy PUT request " + body + " with tierLevel = " + tierLevel);
}
try {
APIMgtAdminService apiMgtAdminService = RestApiUtil.getAPIMgtAdminService();
ApplicationPolicy applicationPolicy = ApplicationThrottlePolicyMappingUtil.fromApplicationThrottlePolicyDTOToModel(body);
applicationPolicy.setUuid(id);
apiMgtAdminService.updateApplicationPolicy(applicationPolicy);
return Response.status(Response.Status.OK).entity(ApplicationThrottlePolicyMappingUtil.fromApplicationThrottlePolicyToDTO(apiMgtAdminService.getApplicationPolicyByUuid(id))).build();
} catch (APIManagementException e) {
String errorMessage = "Error occurred while updating Application Policy. policy uuid: " + id;
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
use of org.wso2.carbon.apimgt.core.exception.APIManagementException in project carbon-apimgt by wso2.
the class PoliciesApiServiceImpl method policiesThrottlingCustomGet.
/**
* Retrieves all custom policies.
*
* @param ifNoneMatch If-None-Match header value
* @param ifModifiedSince If-Modified-Since header value
* @param request msf4j request object
* @return All matched Global Throttle policies to the given request
* @throws NotFoundException if an error occurred when particular resource does not exits in the system.
*/
@Override
public Response policiesThrottlingCustomGet(String ifNoneMatch, String ifModifiedSince, Request request) throws NotFoundException {
if (log.isDebugEnabled()) {
log.debug("Received Custom Policy GET request.");
}
try {
APIMgtAdminService apiMgtAdminService = RestApiUtil.getAPIMgtAdminService();
List<CustomPolicy> policies = apiMgtAdminService.getCustomRules();
CustomRuleListDTO customRuleListDTO = CustomPolicyMappingUtil.fromCustomPolicyArrayToListDTO(policies);
return Response.ok().entity(customRuleListDTO).build();
} catch (APIManagementException e) {
String errorMessage = "Error occurred while retrieving custom policies";
org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
Aggregations