public CoapResponse sendRequest(OdlOnem2mCoapRequestPrimitive onem2mRequest) { return coapClient.advanced(onem2mRequest.coapRequest); } }
@Test public void testAdvancedUsesUriFromRequest() throws Exception { String unexistingUri = String.format("coap://%s:%d/%s", serverAddress.getHostString(), serverAddress.getPort(), "unexisting"); client.setURI(unexistingUri); final CountDownLatch latch = new CountDownLatch(1); Request request = new Request(Code.GET, Type.CON); request.setURI(uri); // Try a put and receive a METHOD_NOT_ALLOWED client.advanced(new TestHandler("Test 10") { @Override public void onLoad(CoapResponse response) { latch.countDown(); } }, request); assertTrue(latch.await(1, TimeUnit.SECONDS)); }
@Test public void testAdvancedUsesTypeFromRequest() throws Exception { final CountDownLatch latch = new CountDownLatch(1); // But expecting CONs as specified in request client.useNONs(); Request request = new Request(Code.GET, Type.CON); // Try a put and receive a METHOD_NOT_ALLOWED client.advanced(new TestHandler("Test 9") { @Override public void onLoad(CoapResponse response) { // It is CON latch.countDown(); } }, request); assertTrue(latch.await(1, TimeUnit.SECONDS)); }
response = client.advanced(req12); System.out.println(response.advanced().getType() + "-" + response.getCode()); System.out.println(response.getResponseText());
Request request = createRequest(GET, path, server); coapClient.advanced(new CoapHandler() {
@Test public void testAdvancedUsesTypeFromRequest() throws Exception { String uri = TestTools.getUri(serverEndpoint, TARGET); CoapClient client = new CoapClient(uri).useExecutor(); // Set NONs but expecting CONs as specified in request client.useNONs(); Request request = new Request(Code.GET, Type.CON); CoapResponse resp = client.advanced(request); Assert.assertEquals(Type.ACK, resp.advanced().getType()); Assert.assertEquals(CONTENT_1, resp.getResponseText()); }
@Test public void testAdvancedUsesUriFromRequest() throws Exception { String nonExistingUri = TestTools.getUri(serverEndpoint, "non-existing"); CoapClient client = new CoapClient(nonExistingUri).useExecutor(); Request request = new Request(Code.GET, Type.CON); String uri = TestTools.getUri(serverEndpoint, TARGET); request.setURI(uri); CoapResponse resp = client.advanced(request); Assert.assertEquals(Type.ACK, resp.advanced().getType()); Assert.assertEquals(CONTENT_1, resp.getResponseText()); }