Search in sources :

Example 6 with FunctionDAO

use of org.wso2.carbon.apimgt.core.dao.FunctionDAO 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 7 with FunctionDAO

use of org.wso2.carbon.apimgt.core.dao.FunctionDAO 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

FunctionDAO (org.wso2.carbon.apimgt.core.dao.FunctionDAO)5 Test (org.testng.annotations.Test)4 Function (org.wso2.carbon.apimgt.core.models.Function)4 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)3 Connection (java.sql.Connection)2 SQLException (java.sql.SQLException)2 RestCallUtil (org.wso2.carbon.apimgt.core.api.RestCallUtil)2 Event (org.wso2.carbon.apimgt.core.models.Event)2 HttpResponse (org.wso2.carbon.apimgt.core.models.HttpResponse)2 Gson (com.google.gson.Gson)1 URI (java.net.URI)1 ZonedDateTime (java.time.ZonedDateTime)1 ArrayList (java.util.ArrayList)1 AnalyticsDAO (org.wso2.carbon.apimgt.core.dao.AnalyticsDAO)1 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)1