RegistrationMessageFilter extends BaseMessageFilter { public static boolean verify(final ResourceIdentifier linkTarget, final Message msg) { final Object correlationId = MessageHelper.getCorrelationId(msg); if (!hasValidDeviceId(linkTarget, msg)) { return false; } else if (correlationId == null) { LOG.trace("message has neither a message-id nor correlation-id"); return false; } else if (msg.getSubject() == null) { LOG.trace("message [correlation ID: {}] does not contain a subject", correlationId); return false; } else if (msg.getReplyTo() == null) { LOG.trace("message [correlation ID: {}] contains no reply-to address", correlationId); return false; } else { return true; } } private  RegistrationMessageFilter(); static boolean verify(final ResourceIdentifier linkTarget, final Message msg);  }
@Test public void testVerifyDetectsDeviceIdMismatch() { final Message msg = givenAMessageHavingProperties(MY_DEVICE + "_1", RegistrationConstants.ACTION_GET); final ResourceIdentifier linkTarget = getResourceIdentifier(MY_TENANT, MY_DEVICE); assertFalse(RegistrationMessageFilter.verify(linkTarget, msg)); }
@Test public void testVerifyDetectsMissingDeviceId() { final Message msg = givenAMessageHavingProperties(null, RegistrationConstants.ACTION_GET); final ResourceIdentifier linkTarget = getResourceIdentifier(MY_TENANT); assertFalse(RegistrationMessageFilter.verify(linkTarget, msg)); }
@Test public void testVerifyDetectsMissingAction() { final Message msg = givenAMessageHavingProperties(MY_DEVICE, null); final ResourceIdentifier linkTarget = getResourceIdentifier(MY_TENANT); assertFalse(RegistrationMessageFilter.verify(linkTarget, msg)); }
@Test public void testVerifySucceedsForTenantOnlyLinkTarget() { final Message msg = givenAMessageHavingProperties(MY_DEVICE, RegistrationConstants.ACTION_GET); final ResourceIdentifier linkTarget = getResourceIdentifier(MY_TENANT); assertTrue(RegistrationMessageFilter.verify(linkTarget, msg)); }
@Test public void testVerifySucceedsForMatchingDevice() { final Message msg = givenAMessageHavingProperties(MY_DEVICE, RegistrationConstants.ACTION_GET); final ResourceIdentifier linkTarget = getResourceIdentifier(MY_TENANT, MY_DEVICE); assertTrue(RegistrationMessageFilter.verify(linkTarget, msg)); }