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));
}
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);
}
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);
}
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();
}
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();
}
Aggregations