Search in sources :

Example 21 with Code

use of org.eclipse.californium.core.coap.CoAP.Code in project californium by eclipse.

the class MappingProperties method initCoapMethod.

/**
 * Initialize {@link #coapCodes} from raw property.
 *
 * @param key key for entry to load
 */
protected void initCoapMethod(String key) {
    String httpMethod = getString(key);
    String tag = getTag(KEY_COAP_METHOD, key);
    Code code = Code.valueOfText(tag);
    if (code != null && httpMethod != null) {
        coapCodes.put(code, httpMethod);
    }
}
Also used : ResponseCode(org.eclipse.californium.core.coap.CoAP.ResponseCode) Code(org.eclipse.californium.core.coap.CoAP.Code)

Example 22 with Code

use of org.eclipse.californium.core.coap.CoAP.Code 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 23 with Code

use of org.eclipse.californium.core.coap.CoAP.Code in project mule-coap-connector by teslanet-nl.

the class AbstractSecureClientTestCase method setUpClass.

@BeforeClass
public static void setUpClass() throws Exception {
    inboundCalls = new ArrayList<Code>();
    inboundCalls.add(Code.GET);
    inboundCalls.add(Code.PUT);
    inboundCalls.add(Code.POST);
    inboundCalls.add(Code.DELETE);
    outboundCalls = new ArrayList<Code>();
    outboundCalls.add(Code.GET);
    outboundCalls.add(Code.PUT);
    outboundCalls.add(Code.POST);
    outboundCalls.add(Code.DELETE);
    paths = new HashMap<Code, String>();
    paths.put(Code.GET, "/service/get_me");
    paths.put(Code.PUT, "/service/put_me");
    paths.put(Code.POST, "/service/post_me");
    paths.put(Code.DELETE, "/service/delete_me");
    uri = new URI("coaps", "127.0.0.1", null, null, null);
}
Also used : Code(org.eclipse.californium.core.coap.CoAP.Code) URI(java.net.URI) BeforeClass(org.junit.BeforeClass)

Example 24 with Code

use of org.eclipse.californium.core.coap.CoAP.Code 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 25 with Code

use of org.eclipse.californium.core.coap.CoAP.Code 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)

Aggregations

Code (org.eclipse.californium.core.coap.CoAP.Code)26 Request (org.eclipse.californium.core.coap.Request)18 ResponseCode (org.eclipse.californium.core.coap.CoAP.ResponseCode)14 CoapResponse (org.eclipse.californium.core.CoapResponse)12 CoapClient (org.eclipse.californium.core.CoapClient)11 Test (org.junit.Test)11 Future (io.vertx.core.Future)8 OptionSet (org.eclipse.californium.core.coap.OptionSet)8 Test (org.junit.jupiter.api.Test)8 URI (java.net.URI)7 Truth.assertThat (com.google.common.truth.Truth.assertThat)6 Handler (io.vertx.core.Handler)6 Promise (io.vertx.core.Promise)6 Timeout (io.vertx.junit5.Timeout)6 VertxTestContext (io.vertx.junit5.VertxTestContext)6 URISyntaxException (java.net.URISyntaxException)6 StandardCharsets (java.nio.charset.StandardCharsets)6 X509Certificate (java.security.cert.X509Certificate)6 List (java.util.List)6 TimeUnit (java.util.concurrent.TimeUnit)6