Search in sources :

Example 6 with CoapResponse

use of org.eclipse.californium.core.CoapResponse in project camel by apache.

the class CoAPRestVerbTest method testGetAll.

@Test
public void testGetAll() throws Exception {
    NetworkConfig.createStandardWithoutFile();
    CoapClient client = new CoapClient("coap://localhost:" + coapport + "/users");
    client.setTimeout(1000000);
    CoapResponse rsp = client.get();
    assertEquals("[{ \"id\":\"1\", \"name\":\"Scott\" },{ \"id\":\"2\", \"name\":\"Claus\" }]", rsp.getResponseText());
}
Also used : CoapResponse(org.eclipse.californium.core.CoapResponse) CoapClient(org.eclipse.californium.core.CoapClient) Test(org.junit.Test)

Example 7 with CoapResponse

use of org.eclipse.californium.core.CoapResponse in project camel by apache.

the class CoAPRestVerbTest method testGetOne.

@Test
public void testGetOne() throws Exception {
    NetworkConfig.createStandardWithoutFile();
    CoapClient client = new CoapClient("coap://localhost:" + coapport + "/users/1");
    client.setTimeout(1000000);
    CoapResponse rsp = client.get();
    assertEquals("{ \"id\":\"1\", \"name\":\"Scott\" }", rsp.getResponseText());
}
Also used : CoapResponse(org.eclipse.californium.core.CoapResponse) CoapClient(org.eclipse.californium.core.CoapClient) Test(org.junit.Test)

Example 8 with CoapResponse

use of org.eclipse.californium.core.CoapResponse in project camel by apache.

the class CoAPRestVerbTest method testPost.

@Test
public void testPost() throws Exception {
    NetworkConfig.createStandardWithoutFile();
    final String body = "{ \"id\":\"1\", \"name\":\"Scott\" }";
    MockEndpoint mock = getMockEndpoint("mock:create");
    mock.expectedBodiesReceived(body);
    CoapClient client = new CoapClient("coap://localhost:" + coapport + "/users");
    client.setTimeout(1000000);
    CoapResponse rsp = client.post(body, MediaTypeRegistry.APPLICATION_JSON);
    assertMockEndpointsSatisfied();
}
Also used : CoapResponse(org.eclipse.californium.core.CoapResponse) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) CoapClient(org.eclipse.californium.core.CoapClient) Test(org.junit.Test)

Aggregations

CoapClient (org.eclipse.californium.core.CoapClient)8 CoapResponse (org.eclipse.californium.core.CoapResponse)8 Test (org.junit.Test)7 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)4 Message (org.apache.camel.Message)1