Search in sources :

Example 1 with RestCallUtil

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");
    }
}
Also used : Function(org.wso2.carbon.apimgt.core.models.Function) ZonedDateTime(java.time.ZonedDateTime) RestCallUtil(org.wso2.carbon.apimgt.core.api.RestCallUtil) ArrayList(java.util.ArrayList) HttpResponse(org.wso2.carbon.apimgt.core.models.HttpResponse) Event(org.wso2.carbon.apimgt.core.models.Event) URI(java.net.URI) FunctionDAO(org.wso2.carbon.apimgt.core.dao.FunctionDAO) Test(org.testng.annotations.Test)

Example 2 with RestCallUtil

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");
    }
}
Also used : RestCallUtil(org.wso2.carbon.apimgt.core.api.RestCallUtil) FunctionDAO(org.wso2.carbon.apimgt.core.dao.FunctionDAO) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)2 RestCallUtil (org.wso2.carbon.apimgt.core.api.RestCallUtil)2 FunctionDAO (org.wso2.carbon.apimgt.core.dao.FunctionDAO)2 URI (java.net.URI)1 ZonedDateTime (java.time.ZonedDateTime)1 ArrayList (java.util.ArrayList)1 Event (org.wso2.carbon.apimgt.core.models.Event)1 Function (org.wso2.carbon.apimgt.core.models.Function)1 HttpResponse (org.wso2.carbon.apimgt.core.models.HttpResponse)1