Search in sources :

Example 46 with MuleEventSpy

use of nl.teslanet.mule.connectors.coap.test.utils.MuleEventSpy in project mule-coap-connector by teslanet-nl.

the class AbstractSecureClientTestCase method testInbound.

@Test(timeout = 60000L)
public void testInbound() throws Exception {
    expectException();
    MuleEventSpy spy = spyMessage();
    String payload = "test-payload";
    for (Code call : inboundCalls) {
        spy.clear();
        client.useLateNegotiation();
        Request request = new Request(call);
        request.setURI(uri.resolve(getPath(call)));
        switch(call) {
            case DELETE:
            case GET:
                request.setUnintendedPayload();
                break;
            default:
                break;
        }
        request.setPayload(payload);
        CoapResponse response = client.advanced(request);
        assertNotNull("get gave no response", response);
        assertTrue("response indicates failure: " + response.getCode() + " msg: " + response.getResponseText(), response.isSuccess());
        assertEquals("Spy has collected wrong number of events", 1, spy.getEvents().size());
        assertEquals("payload has wrong class", payload.getBytes().getClass(), spy.getEvents().get(0).getContent().getClass());
        assertArrayEquals("property has wrong value", payload.getBytes(), (byte[]) spy.getEvents().get(0).getContent());
        client.shutdown();
    }
}
Also used : CoapResponse(org.eclipse.californium.core.CoapResponse) Request(org.eclipse.californium.core.coap.Request) Code(org.eclipse.californium.core.coap.CoAP.Code) MuleEventSpy(nl.teslanet.mule.connectors.coap.test.utils.MuleEventSpy) Test(org.junit.Test)

Example 47 with MuleEventSpy

use of nl.teslanet.mule.connectors.coap.test.utils.MuleEventSpy in project mule-coap-connector by teslanet-nl.

the class InsecureClientTest method testInsecureClientGet.

@Test(timeout = 15000)
public void testInsecureClientGet() throws Exception {
    MuleEventSpy spy = spyMessage();
    Code call = Code.GET;
    CoapClient client = getClient(getPath(call));
    Request request = new Request(call);
    CoapResponse response = client.advanced(request);
    assertNull("should not receive a response", response);
    assertSpy(spy);
    client.shutdown();
}
Also used : CoapResponse(org.eclipse.californium.core.CoapResponse) Request(org.eclipse.californium.core.coap.Request) Code(org.eclipse.californium.core.coap.CoAP.Code) MuleEventSpy(nl.teslanet.mule.connectors.coap.test.utils.MuleEventSpy) CoapClient(org.eclipse.californium.core.CoapClient) Test(org.junit.Test)

Example 48 with MuleEventSpy

use of nl.teslanet.mule.connectors.coap.test.utils.MuleEventSpy in project mule-coap-connector by teslanet-nl.

the class InsecureClientTest method testInsecureClientPut.

@Test()
public void testInsecureClientPut() throws Exception {
    MuleEventSpy spy = spyMessage();
    Code call = Code.PUT;
    CoapClient client = getClient(getPath(call));
    Request request = new Request(call);
    request.setPayload("nothing important");
    CoapResponse response = client.advanced(request);
    assertNull("should not receive a response", response);
    assertSpy(spy);
    client.shutdown();
}
Also used : CoapResponse(org.eclipse.californium.core.CoapResponse) Request(org.eclipse.californium.core.coap.Request) Code(org.eclipse.californium.core.coap.CoAP.Code) MuleEventSpy(nl.teslanet.mule.connectors.coap.test.utils.MuleEventSpy) CoapClient(org.eclipse.californium.core.CoapClient) Test(org.junit.Test)

Example 49 with MuleEventSpy

use of nl.teslanet.mule.connectors.coap.test.utils.MuleEventSpy in project mule-coap-connector by teslanet-nl.

the class InsecureClientTest method spyMessage.

/**
 * Create spy for requests with a message replacement
 * @return the spy
 */
private MuleEventSpy spyMessage(byte[] replacement) {
    MuleEventSpy spy = new MuleEventSpy("securityTest", null, replacement);
    spy.clear();
    return spy;
}
Also used : MuleEventSpy(nl.teslanet.mule.connectors.coap.test.utils.MuleEventSpy)

Example 50 with MuleEventSpy

use of nl.teslanet.mule.connectors.coap.test.utils.MuleEventSpy in project mule-coap-connector by teslanet-nl.

the class InsecureClientTest method testInsecureClientPost.

@Test(timeout = 15000)
public void testInsecureClientPost() throws Exception {
    MuleEventSpy spy = spyMessage();
    Code call = Code.POST;
    CoapClient client = getClient(getPath(call));
    Request request = new Request(call);
    request.setPayload("nothing important");
    CoapResponse response = client.advanced(request);
    assertNull("should not receive a response", response);
    assertSpy(spy);
    client.shutdown();
}
Also used : CoapResponse(org.eclipse.californium.core.CoapResponse) Request(org.eclipse.californium.core.coap.Request) Code(org.eclipse.californium.core.coap.CoAP.Code) MuleEventSpy(nl.teslanet.mule.connectors.coap.test.utils.MuleEventSpy) CoapClient(org.eclipse.californium.core.CoapClient) Test(org.junit.Test)

Aggregations

MuleEventSpy (nl.teslanet.mule.connectors.coap.test.utils.MuleEventSpy)50 Test (org.junit.Test)46 Message (org.mule.runtime.api.message.Message)30 CoAPResponseAttributes (nl.teslanet.mule.connectors.coap.api.CoAPResponseAttributes)29 Event (org.mule.runtime.api.event.Event)24 Request (org.eclipse.californium.core.coap.Request)13 CoapResponse (org.eclipse.californium.core.CoapResponse)12 LinkedList (java.util.LinkedList)10 AbstractQueryParam (nl.teslanet.mule.connectors.coap.api.query.AbstractQueryParam)10 QueryParam (nl.teslanet.mule.connectors.coap.api.query.QueryParam)10 Code (org.eclipse.californium.core.coap.CoAP.Code)6 CursorStreamProvider (org.mule.runtime.api.streaming.bytes.CursorStreamProvider)5 CoapClient (org.eclipse.californium.core.CoapClient)4 SocketException (java.net.SocketException)3 OptionSet (org.eclipse.californium.core.coap.OptionSet)3 ResponseException (nl.teslanet.mule.connectors.coap.api.error.ResponseException)2 ConditionTimeoutException (org.awaitility.core.ConditionTimeoutException)2 Instant (java.time.Instant)1 CoAPRequestAttributes (nl.teslanet.mule.connectors.coap.api.CoAPRequestAttributes)1 ClientErrorResponseException (nl.teslanet.mule.connectors.coap.api.error.ClientErrorResponseException)1