GuestDataUpdateReceiver implements MessageListener { @Override public void onMessage(Message message) { LOGGER.info(() -> "Received message " + message); try { GuestModel guest = JAXB.unmarshal(new StringReader(message.getBody(String.class)), GuestModel.class); LOGGER.info(() -> "Received " + guest); guestModelRepository.storeGuestModel(guest); } catch (DataBindingException | JMSException e) { LOGGER.log(SEVERE, "Cannot handle message " + message, e); } } GuestDataUpdateReceiver(); @Inject  GuestDataUpdateReceiver(GuestModelRepository guestModelRepository); @Override void onMessage(Message message); static final String GUEST_EVENT_TOPIC; }
@Test public void invalid_messages_are_not_stored() throws JMSException { GuestDataUpdateReceiver receiver = new GuestDataUpdateReceiver(guestModelRepository); final String messagePayload = "CRAP"; new Expectations() {{ textMessage.getBody(String.class); result = messagePayload; }}; receiver.onMessage(textMessage); new Verifications() {{ guestModelRepository.storeGuestModel(withInstanceOf(GuestModel.class)); times = 0; }}; }
@Test public void a_valid_text_message_gets_processed() throws JMSException, IOException { GuestDataUpdateReceiver receiver = new GuestDataUpdateReceiver(guestModelRepository); final String messagePayload = readValidGuestXml(); new Expectations() {{ textMessage.getBody(String.class); result = messagePayload; }}; receiver.onMessage(textMessage); }
@Test public void valid_guest_models_are_stored() throws JMSException, IOException { GuestDataUpdateReceiver receiver = new GuestDataUpdateReceiver(guestModelRepository); final String messagePayload = readValidGuestXml(); new Expectations() {{ textMessage.getBody(String.class); result = messagePayload; }}; receiver.onMessage(textMessage); new Verifications() {{ guestModelRepository.storeGuestModel(withInstanceOf(GuestModel.class)); times = 1; }}; }