Search in sources :

Example 1 with ETag

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;
    }
}
Also used : Message(org.mule.runtime.api.message.Message) ETag(nl.teslanet.mule.connectors.coap.api.options.ETag) Iterator(java.util.Iterator) Event(org.mule.runtime.api.event.Event) CoAPResponseAttributes(nl.teslanet.mule.connectors.coap.api.CoAPResponseAttributes) Collection(java.util.Collection) Test(org.junit.Test)

Example 2 with ETag

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);
}
Also used : ETag(nl.teslanet.mule.connectors.coap.api.options.ETag) DefaultRequestOptionsAttributes(nl.teslanet.mule.connectors.coap.internal.options.DefaultRequestOptionsAttributes) OptionSet(org.eclipse.californium.core.coap.OptionSet) Test(org.junit.Test)

Example 3 with ETag

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)));
}
Also used : ETag(nl.teslanet.mule.connectors.coap.api.options.ETag) DefaultRequestOptionsAttributes(nl.teslanet.mule.connectors.coap.internal.options.DefaultRequestOptionsAttributes) OptionSet(org.eclipse.californium.core.coap.OptionSet) Test(org.junit.Test)

Example 4 with ETag

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)));
}
Also used : ETag(nl.teslanet.mule.connectors.coap.api.options.ETag) DefaultRequestOptionsAttributes(nl.teslanet.mule.connectors.coap.internal.options.DefaultRequestOptionsAttributes) OptionSet(org.eclipse.californium.core.coap.OptionSet) Test(org.junit.Test)

Example 5 with ETag

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);
}
Also used : ETag(nl.teslanet.mule.connectors.coap.api.options.ETag) LinkedList(java.util.LinkedList)

Aggregations

ETag (nl.teslanet.mule.connectors.coap.api.options.ETag)41 Test (org.junit.Test)30 LinkedList (java.util.LinkedList)12 OptionSet (org.eclipse.californium.core.coap.OptionSet)6 DefaultRequestOptionsAttributes (nl.teslanet.mule.connectors.coap.internal.options.DefaultRequestOptionsAttributes)5 InvalidETagException (nl.teslanet.mule.connectors.coap.api.error.InvalidETagException)4 CoAPResponseAttributes (nl.teslanet.mule.connectors.coap.api.CoAPResponseAttributes)2 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 OtherOption (nl.teslanet.mule.connectors.coap.api.options.OtherOption)1 AbstractQueryParam (nl.teslanet.mule.connectors.coap.api.query.AbstractQueryParam)1 InternalInvalidByteArrayValueException (nl.teslanet.mule.connectors.coap.internal.exceptions.InternalInvalidByteArrayValueException)1 InternalInvalidOptionValueException (nl.teslanet.mule.connectors.coap.internal.exceptions.InternalInvalidOptionValueException)1 DefaultResponseOptionsAttributes (nl.teslanet.mule.connectors.coap.internal.options.DefaultResponseOptionsAttributes)1 BlockOption (org.eclipse.californium.core.coap.BlockOption)1 Option (org.eclipse.californium.core.coap.Option)1 Event (org.mule.runtime.api.event.Event)1 Message (org.mule.runtime.api.message.Message)1 CursorStreamProvider (org.mule.runtime.api.streaming.bytes.CursorStreamProvider)1 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)1