Search in sources :

Example 1 with ResourceIdentifier

use of org.eclipse.hono.util.ResourceIdentifier in project hono by eclipse.

the class HonoMessagingMessageFilterTest method testVerifyDetectsMissingBody.

@Test
public void testVerifyDetectsMissingBody() {
    // GIVEN a valid telemetry message without body
    final Message msg = givenAMessageHavingProperties(MY_DEVICE, MY_TENANT, CONTENT_TYPE_OCTET_STREAM, null);
    // WHEN receiving the message via a link with matching tenant
    final ResourceIdentifier linkTarget = getResourceIdentifier(MY_TENANT);
    // THEN message validation fails
    assertFalse(HonoMessagingMessageFilter.verify(linkTarget, msg));
}
Also used : ResourceIdentifier(org.eclipse.hono.util.ResourceIdentifier) Message(org.apache.qpid.proton.message.Message) Test(org.junit.Test)

Example 2 with ResourceIdentifier

use of org.eclipse.hono.util.ResourceIdentifier in project hono by eclipse.

the class HonoMessagingMessageFilterTest method testVerifySucceedsForMatchingDevice.

@Test
public void testVerifySucceedsForMatchingDevice() {
    // GIVEN a telemetry message for myDevice
    final Message msg = givenAMessageHavingProperties(MY_DEVICE, MY_TENANT);
    // WHEN receiving the message via a link with matching target address
    final ResourceIdentifier linkTarget = getResourceIdentifier(MY_TENANT, MY_DEVICE);
    // THEN message validation succeeds
    assertTrue(HonoMessagingMessageFilter.verify(linkTarget, msg));
    assertMessageAnnotationsContainProperties(msg, MY_TENANT, MY_DEVICE);
}
Also used : ResourceIdentifier(org.eclipse.hono.util.ResourceIdentifier) Message(org.apache.qpid.proton.message.Message) Test(org.junit.Test)

Example 3 with ResourceIdentifier

use of org.eclipse.hono.util.ResourceIdentifier in project hono by eclipse.

the class HonoMessagingMessageFilterTest method testVerifySucceedsForTenantOnlyLinkTarget.

@Test
public void testVerifySucceedsForTenantOnlyLinkTarget() {
    // GIVEN a telemetry message for myDevice
    final Message msg = givenAMessageHavingProperties(MY_DEVICE);
    // WHEN receiving the message via a link with matching target address
    final ResourceIdentifier linkTarget = getResourceIdentifier(MY_TENANT);
    // THEN message validation succeeds
    assertTrue(HonoMessagingMessageFilter.verify(linkTarget, msg));
    assertMessageAnnotationsContainProperties(msg, MY_TENANT, MY_DEVICE);
}
Also used : ResourceIdentifier(org.eclipse.hono.util.ResourceIdentifier) Message(org.apache.qpid.proton.message.Message) Test(org.junit.Test)

Example 4 with ResourceIdentifier

use of org.eclipse.hono.util.ResourceIdentifier in project hono by eclipse.

the class MessageForwardingEndpointTest method testOnLinkAttachClosesLinkIfDownstreamIsNotAvailable.

/**
 * Verifies that the endpoint does not open a link with a client if the
 * downstream messaging network is not available.
 */
@SuppressWarnings({ "unchecked" })
@Test
public void testOnLinkAttachClosesLinkIfDownstreamIsNotAvailable() {
    // GIVEN an endpoint without a connection to the downstream messaging network
    final ResourceIdentifier targetAddress = ResourceIdentifier.fromString("telemetry/tenant");
    final ProtonConnection connection = mock(ProtonConnection.class);
    final ProtonReceiver receiver = mock(ProtonReceiver.class);
    when(receiver.getRemoteQoS()).thenReturn(ProtonQoS.AT_MOST_ONCE);
    final DownstreamAdapter adapter = mock(DownstreamAdapter.class);
    doAnswer(invocation -> {
        final Handler<AsyncResult<Void>> handler = invocation.getArgument(1);
        handler.handle(Future.failedFuture("downstream not available"));
        return null;
    }).when(adapter).onClientAttach(any(UpstreamReceiver.class), any(Handler.class));
    final MessageForwardingEndpoint<HonoMessagingConfigProperties> endpoint = getEndpoint();
    endpoint.setDownstreamAdapter(adapter);
    // WHEN a client tries to attach
    endpoint.onLinkAttach(connection, receiver, targetAddress);
    // THEN the endpoint closes the link
    final ArgumentCaptor<ErrorCondition> errorCondition = ArgumentCaptor.forClass(ErrorCondition.class);
    verify(receiver).setCondition(errorCondition.capture());
    assertThat(errorCondition.getValue().getCondition(), is(AmqpError.PRECONDITION_FAILED));
    verify(receiver).close();
}
Also used : ProtonReceiver(io.vertx.proton.ProtonReceiver) ResourceIdentifier(org.eclipse.hono.util.ResourceIdentifier) ProtonConnection(io.vertx.proton.ProtonConnection) ErrorCondition(org.apache.qpid.proton.amqp.transport.ErrorCondition) ProtonMessageHandler(io.vertx.proton.ProtonMessageHandler) Handler(io.vertx.core.Handler) AsyncResult(io.vertx.core.AsyncResult) Test(org.junit.Test)

Example 5 with ResourceIdentifier

use of org.eclipse.hono.util.ResourceIdentifier in project hono by eclipse.

the class MessageForwardingEndpointTest method testOnLinkAttachClosesLinkIfClientWantsToUseUnsupportedDeliveryMode.

/**
 * Verifies that the endpoint does not open a link with a client that uses an unsupported
 * delivery mode.
 */
@Test
public void testOnLinkAttachClosesLinkIfClientWantsToUseUnsupportedDeliveryMode() {
    // GIVEN an endpoint
    MessageForwardingEndpoint<HonoMessagingConfigProperties> endpoint = getEndpoint();
    // WHEN a client tries to attach using an unsupported delivery mode
    final ProtonConnection connection = mock(ProtonConnection.class);
    final ProtonReceiver receiver = mock(ProtonReceiver.class);
    final ResourceIdentifier targetAddress = ResourceIdentifier.fromString("telemetry/tenant");
    when(receiver.getRemoteQoS()).thenReturn(ProtonQoS.AT_LEAST_ONCE);
    endpoint.onLinkAttach(connection, receiver, targetAddress);
    // THEN the endpoint closes the link
    final ArgumentCaptor<ErrorCondition> errorCondition = ArgumentCaptor.forClass(ErrorCondition.class);
    verify(receiver).setCondition(errorCondition.capture());
    assertThat(errorCondition.getValue(), is(ErrorConditions.ERROR_UNSUPPORTED_DELIVERY_MODE));
    verify(receiver).close();
}
Also used : ProtonReceiver(io.vertx.proton.ProtonReceiver) ProtonConnection(io.vertx.proton.ProtonConnection) ResourceIdentifier(org.eclipse.hono.util.ResourceIdentifier) ErrorCondition(org.apache.qpid.proton.amqp.transport.ErrorCondition) Test(org.junit.Test)

Aggregations

ResourceIdentifier (org.eclipse.hono.util.ResourceIdentifier)82 Message (org.apache.qpid.proton.message.Message)30 Future (io.vertx.core.Future)24 HttpURLConnection (java.net.HttpURLConnection)22 MessageHelper (org.eclipse.hono.util.MessageHelper)22 ClientErrorException (org.eclipse.hono.client.ClientErrorException)20 Test (org.junit.Test)20 Test (org.junit.jupiter.api.Test)19 Handler (io.vertx.core.Handler)18 Map (java.util.Map)18 Span (io.opentracing.Span)17 Buffer (io.vertx.core.buffer.Buffer)17 SpanContext (io.opentracing.SpanContext)16 Constants (org.eclipse.hono.util.Constants)16 Promise (io.vertx.core.Promise)15 Objects (java.util.Objects)14 AsyncResult (io.vertx.core.AsyncResult)13 Vertx (io.vertx.core.Vertx)13 ProtonConnection (io.vertx.proton.ProtonConnection)13 ProtonReceiver (io.vertx.proton.ProtonReceiver)13