Search in sources :

Example 1 with QueryParam

use of nl.teslanet.mule.connectors.coap.api.query.QueryParam in project mule-coap-connector by teslanet-nl.

the class OptLocationQueryOutbound1Test method getPropertyValue.

@Override
protected Object getPropertyValue() {
    LinkedList<QueryParam> list = new LinkedList<>();
    list.add(new QueryParam("first", "1"));
    list.add(new QueryParam("second", "2"));
    return list;
}
Also used : QueryParam(nl.teslanet.mule.connectors.coap.api.query.QueryParam) LinkedList(java.util.LinkedList)

Example 2 with QueryParam

use of nl.teslanet.mule.connectors.coap.api.query.QueryParam in project mule-coap-connector by teslanet-nl.

the class OptLocationQueryOutbound2Test method getPropertyValue.

@Override
protected Object getPropertyValue() {
    LinkedList<QueryParam> list = new LinkedList<>();
    list.add(new QueryParam("first", "1"));
    list.add(new QueryParam("second", "2"));
    list.add(new QueryParam("third", null));
    return list;
}
Also used : QueryParam(nl.teslanet.mule.connectors.coap.api.query.QueryParam) LinkedList(java.util.LinkedList)

Example 3 with QueryParam

use of nl.teslanet.mule.connectors.coap.api.query.QueryParam in project mule-coap-connector by teslanet-nl.

the class QueryTest method testSyncRequest.

/**
 * Test Sync request with query parameters.
 * @throws Exception should not happen in this test
 */
@Test
public void testSyncRequest() throws Exception {
    MuleEventSpy spy = new MuleEventSpy("query-handler");
    spy.clear();
    LinkedList<QueryParam> params = new LinkedList<>();
    params.add(new QueryParam("query1", "one"));
    params.add(new QueryParam("query2", "two"));
    params.add(new QueryParam("query3", null));
    Event result = flowRunner("request-sync").keepStreamsOpen().withPayload("nothing_important").withVariable("code", requestCode.toString()).withVariable("query", params).run();
    Message response = result.getMessage();
    // assertions...
    // assertTrue( "wrong response payload type", response.getPayload().getDataType().isCompatibleWith( DataType.BYTE_ARRAY ) );
    assertNotNull("no mule event", response);
    assertTrue("wrong attributes class", response.getAttributes().getValue() instanceof CoAPResponseAttributes);
    CoAPResponseAttributes attributes = (CoAPResponseAttributes) response.getAttributes().getValue();
    assertTrue("request failed", attributes.isSuccess());
    assertEquals("wrong request uri", expectedRequestUri(params), attributes.getRequestUri());
    CursorStreamProvider responsePayload = (CursorStreamProvider) TypedValue.unwrap(response.getPayload());
    assertArrayEquals("wrong response payload", expectedPayload(requestCode, params).getBytes(Defs.COAP_CHARSET), IOUtils.toByteArray(responsePayload.openCursor()));
}
Also used : CursorStreamProvider(org.mule.runtime.api.streaming.bytes.CursorStreamProvider) Message(org.mule.runtime.api.message.Message) AbstractQueryParam(nl.teslanet.mule.connectors.coap.api.query.AbstractQueryParam) QueryParam(nl.teslanet.mule.connectors.coap.api.query.QueryParam) Event(org.mule.runtime.api.event.Event) CoAPResponseAttributes(nl.teslanet.mule.connectors.coap.api.CoAPResponseAttributes) MuleEventSpy(nl.teslanet.mule.connectors.coap.test.utils.MuleEventSpy) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 4 with QueryParam

use of nl.teslanet.mule.connectors.coap.api.query.QueryParam in project mule-coap-connector by teslanet-nl.

the class QueryTest method testRequestSyncWithDefaults1.

/**
 * Test Sync request with default query parameters.
 * @throws Exception should not happen in this test
 */
@Test
public void testRequestSyncWithDefaults1() throws Exception {
    MuleEventSpy spy = new MuleEventSpy("query-handler");
    spy.clear();
    LinkedList<QueryParam> params = new LinkedList<>();
    params.add(new QueryParam("query1", "one"));
    params.add(new QueryParam("query2", "two"));
    params.add(new QueryParam("query3", null));
    LinkedList<QueryParam> expectedParams = new LinkedList<>();
    expectedParams.add(new QueryParam("test1", "one"));
    expectedParams.add(new QueryParam("test2", "two"));
    expectedParams.add(new QueryParam("novalue1", null));
    expectedParams.add(new QueryParam("query1", "one"));
    expectedParams.add(new QueryParam("query2", "two"));
    expectedParams.add(new QueryParam("query3", null));
    Event result = flowRunner("request-sync-with-defaults").keepStreamsOpen().withPayload("nothing_important").withVariable("code", requestCode.toString()).withVariable("query", params).run();
    Message response = result.getMessage();
    // assertions...
    // assertTrue( "wrong response payload type", response.getPayload().getDataType().isCompatibleWith( DataType.BYTE_ARRAY ) );
    assertNotNull("no mule event", response);
    assertTrue("wrong attributes class", response.getAttributes().getValue() instanceof CoAPResponseAttributes);
    CoAPResponseAttributes attributes = (CoAPResponseAttributes) response.getAttributes().getValue();
    assertTrue("request failed", attributes.isSuccess());
    assertEquals("wrong request uri", expectedRequestUri(expectedParams), attributes.getRequestUri());
    CursorStreamProvider responsePayload = (CursorStreamProvider) TypedValue.unwrap(response.getPayload());
    assertArrayEquals("wrong response payload", expectedPayload(requestCode, expectedParams).getBytes(Defs.COAP_CHARSET), IOUtils.toByteArray(responsePayload.openCursor()));
}
Also used : CursorStreamProvider(org.mule.runtime.api.streaming.bytes.CursorStreamProvider) Message(org.mule.runtime.api.message.Message) AbstractQueryParam(nl.teslanet.mule.connectors.coap.api.query.AbstractQueryParam) QueryParam(nl.teslanet.mule.connectors.coap.api.query.QueryParam) Event(org.mule.runtime.api.event.Event) CoAPResponseAttributes(nl.teslanet.mule.connectors.coap.api.CoAPResponseAttributes) MuleEventSpy(nl.teslanet.mule.connectors.coap.test.utils.MuleEventSpy) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 5 with QueryParam

use of nl.teslanet.mule.connectors.coap.api.query.QueryParam in project mule-coap-connector by teslanet-nl.

the class QueryTest method testFixedAsyncRequest.

/**
 * Test Async request with fixed query parameters.
 * @throws Exception should not happen in this test
 */
@Test
public void testFixedAsyncRequest() throws Exception {
    MuleEventSpy spy = new MuleEventSpy("query-handler");
    spy.clear();
    LinkedList<QueryParam> params = new LinkedList<>();
    params.add(new QueryParam("query1", "one"));
    params.add(new QueryParam("query2", "two"));
    params.add(new QueryParam("query3", null));
    LinkedList<QueryParam> expectedParams = new LinkedList<>();
    expectedParams.add(new QueryParam("test3", "three"));
    expectedParams.add(new QueryParam("test4", "four"));
    expectedParams.add(new QueryParam("novalue2", null));
    Event result = flowRunner("request-async-fixed").withPayload("nothing_important").withVariable("code", requestCode.toString()).withVariable("query", params).run();
    Message response = result.getMessage();
    assertTrue("wrong response payload", response.getPayload().getDataType().isCompatibleWith(DataType.STRING));
    assertEquals("wrong response payload", "nothing_important", (String) response.getPayload().getValue());
    // let handler do its asynchronous work
    await().atMost(10, TimeUnit.SECONDS).until(() -> {
        return spy.getEvents().size() == 1;
    });
    // assertions...
    response = (Message) spy.getEvents().get(0).getContent();
    assertTrue("wrong attributes class", response.getAttributes().getValue() instanceof CoAPResponseAttributes);
    CoAPResponseAttributes attributes = (CoAPResponseAttributes) response.getAttributes().getValue();
    assertTrue("error response", attributes.isSuccess());
    assertEquals("wrong request uri", expectedRequestUri(expectedParams), attributes.getRequestUri());
    assertArrayEquals("wrong response payload", expectedPayload(requestCode, expectedParams).getBytes(Defs.COAP_CHARSET), (byte[]) response.getPayload().getValue());
}
Also used : Message(org.mule.runtime.api.message.Message) AbstractQueryParam(nl.teslanet.mule.connectors.coap.api.query.AbstractQueryParam) QueryParam(nl.teslanet.mule.connectors.coap.api.query.QueryParam) Event(org.mule.runtime.api.event.Event) CoAPResponseAttributes(nl.teslanet.mule.connectors.coap.api.CoAPResponseAttributes) MuleEventSpy(nl.teslanet.mule.connectors.coap.test.utils.MuleEventSpy) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Aggregations

LinkedList (java.util.LinkedList)12 QueryParam (nl.teslanet.mule.connectors.coap.api.query.QueryParam)12 CoAPResponseAttributes (nl.teslanet.mule.connectors.coap.api.CoAPResponseAttributes)10 AbstractQueryParam (nl.teslanet.mule.connectors.coap.api.query.AbstractQueryParam)10 MuleEventSpy (nl.teslanet.mule.connectors.coap.test.utils.MuleEventSpy)10 Test (org.junit.Test)10 Event (org.mule.runtime.api.event.Event)10 Message (org.mule.runtime.api.message.Message)10 CursorStreamProvider (org.mule.runtime.api.streaming.bytes.CursorStreamProvider)5