use of nl.teslanet.mule.connectors.coap.api.options.ETag in project mule-coap-connector by teslanet-nl.
the class AbstractInboundPropertyTestCase method testInboundProperty.
/**
* Test inbound property
* @throws Exception should not happen in this test
*/
@Test
public void testInboundProperty() throws Exception {
Event result = flowRunner("do_request").withPayload("nothing_important").withVariable("code", requestCode.name()).withVariable("host", "127.0.0.1").withVariable("port", null).withVariable("path", path + getPathExtension()).run();
Message response = result.getMessage();
assertTrue("wrong attributes class", response.getAttributes().getValue() instanceof CoAPResponseAttributes);
CoAPResponseAttributes attributes = (CoAPResponseAttributes) response.getAttributes().getValue();
assertEquals("wrong response code", expectedResponseCode.name(), attributes.getResponseCode());
switch(getPropertyType()) {
case CollectionOfByteArray:
{
@SuppressWarnings("unchecked") Collection<byte[]> property = (Collection<byte[]>) fetchInboundProperty(attributes);
assertNotNull("property is not found in inbound scope", property);
@SuppressWarnings("unchecked") Collection<byte[]> expected = (Collection<byte[]>) getExpectedInboundPropertyValue();
assertEquals("option value list length differ", expected.size(), property.size());
Iterator<byte[]> propertyIt = property.iterator();
Iterator<byte[]> expectedIt = expected.iterator();
while (propertyIt.hasNext() && expectedIt.hasNext()) {
byte[] optionValue = propertyIt.next();
byte[] expectedValue = expectedIt.next();
assertArrayEquals("value in collection not equal", expectedValue, optionValue);
}
;
}
break;
case CollectionOfObject:
{
@SuppressWarnings("unchecked") Collection<Object> property = (Collection<Object>) fetchInboundProperty(attributes);
assertNotNull("property is not found in inbound scope", property);
@SuppressWarnings("unchecked") Collection<Object> expected = (Collection<Object>) getExpectedInboundPropertyValue();
assertEquals("option value list length differ", expected.size(), property.size());
Iterator<Object> propertyIt = property.iterator();
Iterator<Object> expectedIt = expected.iterator();
while (propertyIt.hasNext() && expectedIt.hasNext()) {
Object optionValue = propertyIt.next();
Object expectedValue = expectedIt.next();
assertEquals("value in collection not equal", expectedValue, optionValue);
}
;
}
break;
case CollectionOfETag:
{
@SuppressWarnings("unchecked") Collection<ETag> property = (Collection<ETag>) fetchInboundProperty(attributes);
assertNotNull("property is not found in inbound scope", property);
@SuppressWarnings("unchecked") Collection<ETag> expected = (Collection<ETag>) getExpectedInboundPropertyValue();
assertEquals("option value list length differ", expected.size(), property.size());
Iterator<ETag> propertyIt = property.iterator();
Iterator<ETag> expectedIt = expected.iterator();
while (propertyIt.hasNext() && expectedIt.hasNext()) {
ETag optionValue = propertyIt.next();
ETag expectedValue = expectedIt.next();
assertTrue("value in collection not equal", expectedValue.equals(optionValue));
}
;
}
break;
case ByteArray:
assertArrayEquals("wrong inbound property value", (byte[]) getExpectedInboundPropertyValue(), (byte[]) fetchInboundProperty(attributes));
break;
case ETag:
assertTrue("wrong inbound property value", ((ETag) getExpectedInboundPropertyValue()).equals((ETag) fetchInboundProperty(attributes)));
break;
default:
assertEquals("wrong inbound property value", getExpectedInboundPropertyValue(), fetchInboundProperty(attributes));
break;
}
}
use of nl.teslanet.mule.connectors.coap.api.options.ETag in project mule-coap-connector by teslanet-nl.
the class DefaultRequestOptionsAttributesTest method testOptionSetifExists.
@Test
public void testOptionSetifExists() throws InvalidETagException, InternalInvalidOptionValueException {
OptionSet set = new OptionSet();
byte[] etagValue1 = {};
set.addIfMatch(etagValue1.clone());
DefaultRequestOptionsAttributes attributes = new DefaultRequestOptionsAttributes(set);
List<ETag> list = attributes.getIfMatch();
boolean ifExists = attributes.isIfExists();
assertNull(list);
assertTrue("coap.opt.if_match.any: wrong value", ifExists);
}
use of nl.teslanet.mule.connectors.coap.api.options.ETag in project mule-coap-connector by teslanet-nl.
the class DefaultRequestOptionsAttributesTest method testOptionETagMultiple.
@Test
public void testOptionETagMultiple() throws InvalidETagException, InternalInvalidOptionValueException {
OptionSet set = new OptionSet();
byte[] etagValue1 = { (byte) 0x00, (byte) 0xFF };
byte[] etagValue2 = { (byte) 0x11, (byte) 0xFF };
byte[] etagValue3 = { (byte) 0x22, (byte) 0xFF };
set.addETag(etagValue1.clone());
set.addETag(etagValue2.clone());
DefaultRequestOptionsAttributes attributes = new DefaultRequestOptionsAttributes(set);
List<ETag> list = attributes.getEtags();
assertNotNull(list);
assertEquals("coap.opt.etag.list: wrong number of etags", 2, list.size());
assertTrue("coap.opt.etag.list: missing etag", list.contains(new ETag(etagValue1)));
assertTrue("coap.opt.etag.list: missing etag", list.contains(new ETag(etagValue2)));
assertFalse("coap.opt.etag.list: etag not expected", list.contains(new ETag(etagValue3)));
}
use of nl.teslanet.mule.connectors.coap.api.options.ETag in project mule-coap-connector by teslanet-nl.
the class DefaultRequestOptionsAttributesTest method testOptionSetIfMatch.
@Test
public void testOptionSetIfMatch() throws InvalidETagException, InternalInvalidOptionValueException {
OptionSet set = new OptionSet();
byte[] etagValue1 = { (byte) 0x00, (byte) 0xFF };
byte[] etagValue2 = { (byte) 0x11, (byte) 0xFF };
set.addIfMatch(etagValue1.clone());
DefaultRequestOptionsAttributes attributes = new DefaultRequestOptionsAttributes(set);
List<ETag> list = attributes.getIfMatch();
assertNotNull(list);
assertEquals("coap.opt.if_match.etags: wrong number of etags", 1, list.size());
assertTrue("coap.opt.if_match.etags: missing etag", list.contains(new ETag(etagValue1)));
assertFalse("coap.opt.if_match.etags: etag not expected", list.contains(new ETag(etagValue2)));
}
use of nl.teslanet.mule.connectors.coap.api.options.ETag in project mule-coap-connector by teslanet-nl.
the class OptEtagListInbound1Test method getExpectedPropertyValue.
@Override
protected Object getExpectedPropertyValue() throws InvalidETagException {
LinkedList<ETag> list = new LinkedList<ETag>();
list.add(new ETag("0011FF"));
return Collections.unmodifiableList(list);
}
Aggregations