Search in sources :

Example 6 with CoapClient

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

the class CoAPRestComponentTest method testCoAP.

@Test
public void testCoAP() throws Exception {
    NetworkConfig.createStandardWithoutFile();
    CoapClient client;
    CoapResponse rsp;
    client = new CoapClient("coap://localhost:" + coapport + "/TestResource/Ducky");
    client.setTimeout(1000000);
    rsp = client.get();
    assertEquals("Hello Ducky", rsp.getResponseText());
    rsp = client.post("data", MediaTypeRegistry.TEXT_PLAIN);
    assertEquals("Hello Ducky: data", rsp.getResponseText());
    client = new CoapClient("coap://localhost:" + coapport + "/TestParms?id=Ducky");
    client.setTimeout(1000000);
    rsp = client.get();
    assertEquals("Hello Ducky", rsp.getResponseText());
    rsp = client.post("data", MediaTypeRegistry.TEXT_PLAIN);
    assertEquals("Hello Ducky: data", rsp.getResponseText());
    assertEquals(MediaTypeRegistry.TEXT_PLAIN, rsp.getOptions().getContentFormat());
}
Also used : CoapResponse(org.eclipse.californium.core.CoapResponse) CoapClient(org.eclipse.californium.core.CoapClient) Test(org.junit.Test)

Example 7 with CoapClient

use of org.eclipse.californium.core.CoapClient 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 8 with CoapClient

use of org.eclipse.californium.core.CoapClient 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 9 with CoapClient

use of org.eclipse.californium.core.CoapClient 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)9 CoapResponse (org.eclipse.californium.core.CoapResponse)8 Test (org.junit.Test)7 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)4 URI (java.net.URI)1 Message (org.apache.camel.Message)1