use of org.wso2.carbon.apimgt.core.api.RestCallUtil in project carbon-apimgt by wso2.
the class FunctionTriggerTestCase method testCaptureEvent.
@Test(description = "Test method for capturing event")
public void testCaptureEvent() throws APIManagementException, URISyntaxException {
FunctionDAO functionDAO = Mockito.mock(FunctionDAO.class);
RestCallUtil restCallUtil = Mockito.mock(RestCallUtil.class);
FunctionTrigger functionTrigger = new FunctionTrigger(functionDAO, restCallUtil);
URI testUri = new URI("http://testEndpointUri");
List<Function> functions = new ArrayList<>();
Function function = new Function(FUNCTION_NAME, testUri);
functions.add(function);
HttpResponse response = new HttpResponse();
response.setResponseCode(200);
Event event = Event.API_CREATION;
ZonedDateTime eventTime = ZonedDateTime.now();
Mockito.when(functionDAO.getUserFunctionsForEvent(USER_NAME, event)).thenReturn(functions);
Mockito.when(restCallUtil.postRequest(Mockito.eq(function.getEndpointURI()), Mockito.eq(null), Mockito.eq(null), Mockito.any(), Mockito.eq(MediaType.APPLICATION_JSON_TYPE), Mockito.eq(Collections.emptyMap()))).thenReturn(response);
functionTrigger.captureEvent(event, USER_NAME, eventTime, new HashMap<>());
// When the event parameter is null
try {
functionTrigger.captureEvent(null, USER_NAME, eventTime, new HashMap<>());
} catch (IllegalArgumentException e) {
Assert.assertEquals(e.getMessage(), "Event must not be null");
}
// When the username parameter is null
try {
functionTrigger.captureEvent(event, null, eventTime, new HashMap<>());
} catch (IllegalArgumentException e) {
Assert.assertEquals(e.getMessage(), "Username must not be null");
}
// When the eventTime parameter is null
try {
functionTrigger.captureEvent(event, USER_NAME, null, new HashMap<>());
} catch (IllegalArgumentException e) {
Assert.assertEquals(e.getMessage(), "Event_time must not be null");
}
// When the metadata parameter is null
try {
functionTrigger.captureEvent(event, USER_NAME, eventTime, null);
} catch (IllegalArgumentException e) {
Assert.assertEquals(e.getMessage(), "Payload must not be null");
}
}
use of org.wso2.carbon.apimgt.core.api.RestCallUtil in project carbon-apimgt by wso2.
the class FunctionTriggerTestCase method testConstructorException.
@Test(description = "Exception thrown from the FunctionTrigger constructor")
public void testConstructorException() {
FunctionDAO functionDAO = Mockito.mock(FunctionDAO.class);
RestCallUtil restCallUtil = Mockito.mock(RestCallUtil.class);
// When functionDAO is null
try {
FunctionTrigger functionTrigger = new FunctionTrigger(null, restCallUtil);
} catch (IllegalArgumentException e) {
Assert.assertEquals(e.getMessage(), "FunctionDAO param must not be null");
}
// When restCallUtil is null
try {
FunctionTrigger functionTrigger = new FunctionTrigger(functionDAO, null);
} catch (IllegalArgumentException e) {
Assert.assertEquals(e.getMessage(), "RestCallUtil param must not be null");
}
}
Aggregations