BaseAmqpService { @SuppressWarnings("unchecked") public <T> T convertMessage(@NotNull final Message message, final Class<T> clazz) { checkMessageBody(message); message.getMessageProperties().getHeaders().put(AbstractJavaTypeMapper.DEFAULT_CLASSID_FIELD_NAME, clazz.getName()); return (T) rabbitTemplate.getMessageConverter().fromMessage(message); } BaseAmqpService(final RabbitTemplate rabbitTemplate); @SuppressWarnings("unchecked") T convertMessage(@NotNull final Message message, final Class<T> clazz);  }
@Test @Description("Verify that the message conversion works") public void convertMessageTest() { final DmfActionUpdateStatus actionUpdateStatus = createActionStatus(); final Message message = rabbitTemplate.getMessageConverter().toMessage(actionUpdateStatus, createJsonProperties()); final DmfActionUpdateStatus convertedActionUpdateStatus = baseAmqpService.convertMessage(message, DmfActionUpdateStatus.class); assertThat(convertedActionUpdateStatus).isEqualToComparingFieldByField(actionUpdateStatus); }
@Test @Description("Tests invalid null message content") @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) }) public void convertMessageWithNullContent() { try { baseAmqpService.convertMessage(new Message(null, createJsonProperties()), DmfActionUpdateStatus.class); fail("Expected MessageConversionException for inavlid JSON"); } catch (final MessageConversionException e) { } }
@Test @Description("Tests invalid empty message content") @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) }) public void updateActionStatusWithEmptyContent() { try { baseAmqpService.convertMessage(new Message("".getBytes(), createJsonProperties()), DmfActionUpdateStatus.class); fail("Expected MessageConversionException for inavlid JSON"); } catch (final MessageConversionException e) { } }
@Test @Description("Tests invalid json message content") @ExpectEvents({ @Expect(type = TargetCreatedEvent.class, count = 0) }) public void updateActionStatusWithInvalidJsonContent() { try { baseAmqpService.convertMessage(new Message("Invalid Json".getBytes(), createJsonProperties()), DmfActionUpdateStatus.class); fail("Expected MessageConversionException for inavlid JSON"); } catch (final MessageConversionException e) { } }