@Test public void testSetOptionsSetsUriHostOption() { Request req = Request.newGet(); req.setDestination(InetAddress.getLoopbackAddress()); req.setOptions(URI.create("coap://iot.eclipse.org")); assertThat(req.getDestinationPort(), is(CoAP.DEFAULT_COAP_PORT)); assertThat(req.getOptions().getUriHost(), is("iot.eclipse.org")); }
options.add(new Option(OptionNumberRegistry.IF_MATCH, value)); if (hasUriHost()) options.add(new Option(OptionNumberRegistry.URI_HOST, getUriHost())); if (etag_list != null) for (byte[] value:etag_list) options.add(new Option(OptionNumberRegistry.ETAG, value));
options.add(new Option(OptionNumberRegistry.IF_MATCH, value)); if (hasUriHost()) options.add(new Option(OptionNumberRegistry.URI_HOST, getUriHost())); if (etag_list != null) for (byte[] value:etag_list) options.add(new Option(OptionNumberRegistry.ETAG, value));
@Test public void testSetURIDoesNotSetUriHostOptionForIp4Address() { Request req = Request.newGet().setURI("coap://192.168.0.1"); assertNull(req.getOptions().getUriHost()); }
String host = getOptions().getUriHost(); if (host == null) { if (getDestination() != null) {
@Test public void testSetURIDoesNotSetUriHostOptionForIp6Address() { // use www.google.com's IPv6 address Request req = Request.newGet().setURI("coap://[2a00:1450:4001:817::2003]"); assertNull(req.getOptions().getUriHost()); }
String host = getOptions().getUriHost(); if (host == null) { if (getDestination() != null) {
@Test public void testSetURISetsUriHostOptionToHostName() { assumeTrue(dnsIsWorking()); Request req = Request.newGet().setURI("coaps://localhost"); assertNotNull(req.getDestination()); assertThat(req.getDestinationPort(), is(CoAP.DEFAULT_COAP_SECURE_PORT)); assertThat(req.getOptions().getUriHost(), is("localhost")); }
/** * Verifies that the URI examples from <a href="https://tools.ietf.org/html/rfc7252#section-6.3"> * RFC 7252, Section 6.3</a> result in the same option values. * @throws URISyntaxException */ @Test public void testSetOptionsCompliesWithRfcExample() throws URISyntaxException { String[] exampleUris = new String[]{ "coap://example.com:5683/~sensors/temp.xml", "coap://EXAMPLE.com/%7Esensors/temp.xml", "coap://EXAMPLE.com:/%7esensors/temp.xml" }; for (String uriString : exampleUris) { URI uri = new URI(uriString); Request req = Request.newGet(); // explicitly set destination address so that we do not rely on working DNS req.setDestination(InetAddress.getLoopbackAddress()); req.setOptions(uri); assertThat(req.getOptions().getUriHost(), is("example.com")); assertThat(req.getDestinationPort(), is(5683)); assertThat(req.getOptions().getUriPort(), is(nullValue())); assertThat(req.getOptions().getUriPathString(), is("~sensors/temp.xml")); } }