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());
}
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());
}
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());
}
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();
}
Aggregations