/** * Checks if an arbitrary option is present. * @param number the option number * @return true if present */ public boolean hasOption(int number) { return Collections.binarySearch(asSortedList(), new Option(number)) >= 0; }
/** * Checks if an arbitrary option is present. * @param number the option number * @return true if present */ public boolean hasOption(int number) { return Collections.binarySearch(asSortedList(), new Option(number)) >= 0; }
public OdlOnem2mCoapRequestPrimitiveBuilder setOperationExecutionTime(String value) { onem2mRequest.optionsSet.addOption(new Option(Onem2m.CoapOption.ONEM2M_OET, value)); return this; } public OdlOnem2mCoapRequestPrimitiveBuilder setResponseType(String value) {
public OdlOnem2mCoapRequestPrimitiveBuilder setOriginatingTimestamp(String value) { onem2mRequest.optionsSet.addOption(new Option(Onem2m.CoapOption.ONEM2M_OT, value)); return this; } public OdlOnem2mCoapRequestPrimitiveBuilder setRequestExpirationTimestamp(String value) {
public OdlOnem2mCoapRequestPrimitiveBuilder setRequestExpirationTimestamp(String value) { onem2mRequest.optionsSet.addOption(new Option(Onem2m.CoapOption.ONEM2M_RQET, value)); return this; } public OdlOnem2mCoapRequestPrimitiveBuilder setResultExpirationTimestamp(String value) {
public OdlOnem2mCoapRequestPrimitiveBuilder setResultExpirationTimestamp(String value) { onem2mRequest.optionsSet.addOption(new Option(Onem2m.CoapOption.ONEM2M_RSET, value)); return this; } public OdlOnem2mCoapRequestPrimitiveBuilder setOperationExecutionTime(String value) {
public OdlOnem2mCoapRequestPrimitiveBuilder setGroupRequestIdentifier(String value) { onem2mRequest.optionsSet.addOption(new Option(Onem2m.CoapOption.ONEM2M_GID, value)); return this; } public OdlOnem2mCoapRequestPrimitiveBuilder setFilterCriteriaCreatedBefore(String value) {
public OdlOnem2mCoapRequestPrimitiveBuilder setName(String value) { onem2mRequest.optionsSet.addOption(new Option(Onem2m.CoapOption.ONEM2M_NM, value)); return this; }
public OdlOnem2mCoapRequestPrimitiveBuilder setRequestIdentifier(String value) { onem2mRequest.optionsSet.addOption(new Option(Onem2m.CoapOption.ONEM2M_RQI, value)); return this; }
public OdlOnem2mCoapRequestPrimitiveBuilder setFrom(String value) { onem2mRequest.optionsSet.addOption(new Option(Onem2m.CoapOption.ONEM2M_FR, value)); return this; }
@Override protected boolean preDeliverResponse(Exchange exchange, Response response) { response.getOptions().addOption(new Option(200)); return false; } };
/** * Verifies that the message deliverer delivers incoming * requests to resources if a subclass has not yet processed the response. */ @Test public void testDeliverRequestProcessesRequestAfterPreDeliverRequest() { // GIVEN a message deliverer subclass that adds a custom option to incoming // requests final Option customOption = new Option(200); ServerMessageDeliverer deliverer = new ServerMessageDeliverer(rootResource) { @Override protected boolean preDeliverRequest(Exchange exchange) { exchange.getRequest().getOptions().addOption(customOption); return false; } }; // WHEN a request is received deliverer.deliverRequest(incomingRequest); // THEN the request is delivered to the match-all root resource ArgumentCaptor<Exchange> exchangeCaptor = ArgumentCaptor.forClass(Exchange.class); verify(rootResource).handleRequest(exchangeCaptor.capture()); // and the request contains the custom option assertTrue(exchangeCaptor.getValue().getRequest().getOptions().hasOption(200)); }
@Test public void testSetStringValue() { Option option = new Option(); option.setStringValue(""); assertArrayEquals(option.getValue(), new byte[0]); option.setStringValue("Californium"); assertArrayEquals(option.getValue(), "Californium".getBytes()); }
@Test public void testResponseParsing() { Response response = new Response(ResponseCode.CONTENT); response.setType(Type.NON); response.setMID(expectedMid); response.setToken(new byte[] { 22, -1, 0, 78, 100, 22 }); response.getOptions().addETag(new byte[] { 1, 0, 0, 0, 0, 1 }) .addLocationPath("/one/two/three/four/five/six/seven/eight/nine/ten") .addOption(new Option(57453, "Arbitrary".hashCode())).addOption(new Option(19205, "Arbitrary1")) .addOption(new Option(19205, "Arbitrary2")).addOption(new Option(19205, "Arbitrary3")); RawData rawData = serializer.serializeResponse(response); Response result = (Response) parser.parseMessage(rawData); assertEquals(response.getMID(), result.getMID()); assertArrayEquals(response.getToken(), result.getToken()); assertEquals(response.getOptions().asSortedList(), result.getOptions().asSortedList()); }
@Test public void testSetValue() { Option option = new Option(); option.setValue(new byte[4]); assertArrayEquals(option.getValue(), new byte[4]); option.setValue(new byte[] {69, -104, 35, 55, -104, 116, 35, -104}); assertArrayEquals(option.getValue(), new byte[] {69, -104, 35, 55, -104, 116, 35, -104}); }
@Test public void testArbitraryOptions() { OptionSet options = new OptionSet(); options.addETag(new byte[] {1, 2, 3}); options.addLocationPath("abc"); options.addOption(new Option(7)); options.addOption(new Option(43)); options.addOption(new Option(33)); options.addOption(new Option(17)); // Check that options are in the set Assert.assertTrue(options.hasOption(OptionNumberRegistry.ETAG)); Assert.assertTrue(options.hasOption(OptionNumberRegistry.LOCATION_PATH)); Assert.assertTrue(options.hasOption(7)); Assert.assertTrue(options.hasOption(17)); Assert.assertTrue(options.hasOption(33)); Assert.assertTrue(options.hasOption(43)); // Check that others are not Assert.assertFalse(options.hasOption(19)); Assert.assertFalse(options.hasOption(53)); // Check that we can remove options options.clearETags(); Assert.assertFalse(options.hasOption(OptionNumberRegistry.ETAG)); }
Option option = new Option(currentOption); option.setValue(reader.readBytes(optionLength));
/** * Verifies that incoming responses are delivered to their originating requests * if a subclass has not already processed the response. */ @Test public void testDeliverResponseProcessesResponseAfterPreDeliverResponse() { // GIVEN a message deliverer subclass that adds a custom option to incoming // responses ServerMessageDeliverer deliverer = new ServerMessageDeliverer(rootResource) { @Override protected boolean preDeliverResponse(Exchange exchange, Response response) { response.getOptions().addOption(new Option(200)); return false; } }; // WHEN a response is received deliverer.deliverResponse(outboundRequest, incomingResponse); // THEN the response is delivered to the request assertNotNull(outboundRequest.getRequest().getResponse()); // and the response contains the custom option assertTrue(outboundRequest.getRequest().getResponse().getOptions().hasOption(200)); } }
@Test public void testSetIntegerValue() { Option option = new Option(); option.setIntegerValue(0); assertArrayEquals(option.getValue(), new byte[0]); assertEquals(0, option.getIntegerValue()); option.setIntegerValue(11); assertArrayEquals(option.getValue(), new byte[] {11}); assertEquals(11, option.getIntegerValue()); option.setIntegerValue(255); assertArrayEquals(option.getValue(), new byte[] { (byte) 255 }); assertEquals(255, option.getIntegerValue()); option.setIntegerValue(256); assertArrayEquals(option.getValue(), new byte[] {1, 0}); assertEquals(256, option.getIntegerValue()); option.setIntegerValue(18273); assertArrayEquals(option.getValue(), new byte[] {71, 97}); assertEquals(18273, option.getIntegerValue()); option.setIntegerValue(1<<16); assertArrayEquals(option.getValue(), new byte[] {1, 0, 0}); assertEquals(1<<16, option.getIntegerValue()); option.setIntegerValue(23984773); assertArrayEquals(option.getValue(), new byte[] {1, 109, (byte) 250, (byte) 133}); assertEquals(23984773, option.getIntegerValue()); option.setIntegerValue(0xFFFFFFFF); assertArrayEquals(option.getValue(), new byte[] {(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF}); assertEquals(0xFFFFFFFF, option.getIntegerValue()); }
@Test public void testSetLongValue() { Option option = new Option();