@Test public void headerTest() throws JMSException, UnknownHostException { TextMessage msg = Mockito.mock(TextMessage.class); Mockito.when(session.createTextMessage(Matchers.anyString())).thenReturn(msg); EventServiceBindingDescriptor eventServiceBindingDescriptor = Mockito.mock(EventServiceBindingDescriptor.class); Mockito.when(eventServiceBindingDescriptor.getServiceVersion()).thenReturn(new ServiceVersion(1, 0)); cut.marshallEvent(eventServiceBindingDescriptor, new ExpectedEvent("bob", "100 chancellors"), session); String thisHost = InetAddress.getLocalHost().getCanonicalHostName(); Mockito.verify(msg).setStringProperty(Matchers.eq(JMSPropertyConstants.MESSAGE_ID_FIELD_NAME), Matchers.anyString()); Mockito.verify(msg).setStringProperty(Matchers.eq(JMSPropertyConstants.MESSAGE_ROUTING_FIELD_NAME), Matchers.argThat(new StartsWith(thisHost))); }
@Override public TextMessage marshallEvent(EventServiceBindingDescriptor bindingDescriptor, Event event, Object session) throws CougarException { try { TextMessage message = ((Session)session).createTextMessage(marshallEventBody(event)); message.setStringProperty(JMSPropertyConstants.MESSAGE_ROUTING_FIELD_NAME, getHostString(event)); String messageId = event.getMessageId(); if (messageId == null) { messageId = new RequestUUIDImpl().toString(); } message.setStringProperty(JMSPropertyConstants.MESSAGE_ID_FIELD_NAME, messageId); message.setStringProperty(JMSPropertyConstants.EVENT_VERSION_FIELD_NAME, bindingDescriptor.getServiceVersion().toString()); message.setStringProperty(JMSPropertyConstants.EVENT_NAME_FIELD_NAME, event.getClass().getSimpleName()); message.setBooleanProperty("JMS_SonicMQ_preserveUndelivered", true); message.setBooleanProperty("JMS_SonicMQ_notifyUndelivered", true); message.setJMSDeliveryMode(deliveryMode); message.setJMSExpiration(expirationTime); message.setJMSPriority(priority); return message; } catch (JMSException jmsex) { throw new CougarFrameworkException("Error marshalling Event", jmsex); } catch (UnknownHostException e) { throw new CougarFrameworkException("Error looking up local host name", e); } }
JMSEventMarshaller implements EventMarshaller<TextMessage> { @Override public TextMessage marshallEvent(EventServiceBindingDescriptor bindingDescriptor, Event event, Object session) throws CougarException { try { TextMessage message = ((Session)session).createTextMessage(marshallEventBody(event)); message.setStringProperty(JMSPropertyConstants.MESSAGE_ROUTING_FIELD_NAME, getHostString(event)); String messageId = event.getMessageId(); if (messageId == null) { messageId = new RequestUUIDImpl().toString(); } message.setStringProperty(JMSPropertyConstants.MESSAGE_ID_FIELD_NAME, messageId); message.setStringProperty(JMSPropertyConstants.EVENT_VERSION_FIELD_NAME, bindingDescriptor.getServiceVersion().toString()); message.setStringProperty(JMSPropertyConstants.EVENT_NAME_FIELD_NAME, event.getClass().getSimpleName()); message.setBooleanProperty("JMS_SonicMQ_preserveUndelivered", true); message.setBooleanProperty("JMS_SonicMQ_notifyUndelivered", true); message.setJMSDeliveryMode(deliveryMode); message.setJMSExpiration(expirationTime); message.setJMSPriority(priority); return message; } catch (JMSException jmsex) { throw new CougarFrameworkException("Error marshalling Event", jmsex); } catch (UnknownHostException e) { throw new CougarFrameworkException("Error looking up local host name", e); } } }
JMSEventMarshaller implements EventMarshaller<TextMessage> { @Override public TextMessage marshallEvent(EventServiceBindingDescriptor bindingDescriptor, Event event, Object session) throws CougarException { try { TextMessage message = ((Session)session).createTextMessage(marshallEventBody(event)); message.setStringProperty(JMSPropertyConstants.MESSAGE_ROUTING_FIELD_NAME, getHostString(event)); String messageId = event.getMessageId(); if (messageId == null) { messageId = new RequestUUIDImpl().toString(); } message.setStringProperty(JMSPropertyConstants.MESSAGE_ID_FIELD_NAME, messageId); message.setStringProperty(JMSPropertyConstants.EVENT_VERSION_FIELD_NAME, bindingDescriptor.getServiceVersion().toString()); message.setStringProperty(JMSPropertyConstants.EVENT_NAME_FIELD_NAME, event.getClass().getSimpleName()); message.setBooleanProperty("JMS_SonicMQ_preserveUndelivered", true); message.setBooleanProperty("JMS_SonicMQ_notifyUndelivered", true); message.setJMSDeliveryMode(deliveryMode); message.setJMSExpiration(expirationTime); message.setJMSPriority(priority); return message; } catch (JMSException jmsex) { throw new CougarFrameworkException("Error marshalling Event", jmsex); } catch (UnknownHostException e) { throw new CougarFrameworkException("Error looking up local host name", e); } }  }
JMSEventMarshaller implements EventMarshaller<TextMessage> { @Override public TextMessage marshallEvent(EventServiceBindingDescriptor bindingDescriptor, Event event, Object session) throws CougarException { try { TextMessage message = ((Session)session).createTextMessage(marshallEventBody(event)); message.setStringProperty(JMSPropertyConstants.MESSAGE_ROUTING_FIELD_NAME, getHostString(event)); String messageId = event.getMessageId(); if (messageId == null) { messageId = new RequestUUIDImpl().toString(); } message.setStringProperty(JMSPropertyConstants.MESSAGE_ID_FIELD_NAME, messageId); message.setStringProperty(JMSPropertyConstants.EVENT_VERSION_FIELD_NAME, bindingDescriptor.getServiceVersion().toString()); message.setStringProperty(JMSPropertyConstants.EVENT_NAME_FIELD_NAME, event.getClass().getSimpleName()); message.setBooleanProperty("JMS_SonicMQ_preserveUndelivered", true); message.setBooleanProperty("JMS_SonicMQ_notifyUndelivered", true); message.setJMSDeliveryMode(deliveryMode); message.setJMSExpiration(expirationTime); message.setJMSPriority(priority); return message; } catch (JMSException jmsex) { throw new CougarFrameworkException("Error marshalling Event", jmsex); } catch (UnknownHostException e) { throw new CougarFrameworkException("Error looking up local host name", e); } }  String marshallEventBody(Event event); String getHostString(Event event); @Override TextMessage marshallEvent(EventServiceBindingDescriptor bindingDescriptor, Event event, Object session); String getCharacterEncoding(); void setCharacterEncoding(String characterEncoding); int getDeliveryMode(); void setDeliveryMode(int deliveryMode); long getExpirationTime(); void setExpirationTime(long expirationTime); int getPriority(); void setPriority(int priority); DataBindingFactory getDataBindingFactory(); void setDataBindingFactory(DataBindingFactory dataBindingFactory); void setDateFormatPattern(String dateFormatPattern); }
JMSEventMarshaller implements EventMarshaller<TextMessage> { @Override public TextMessage marshallEvent(EventServiceBindingDescriptor bindingDescriptor, Event event, Object session) throws CougarException { try { TextMessage message = ((Session)session).createTextMessage(marshallEventBody(event)); message.setStringProperty(JMSPropertyConstants.MESSAGE_ROUTING_FIELD_NAME, getHostString(event)); String messageId = event.getMessageId(); if (messageId == null) { messageId = new RequestUUIDImpl().toString(); } message.setStringProperty(JMSPropertyConstants.MESSAGE_ID_FIELD_NAME, messageId); message.setStringProperty(JMSPropertyConstants.EVENT_VERSION_FIELD_NAME, bindingDescriptor.getServiceVersion().toString()); message.setStringProperty(JMSPropertyConstants.EVENT_NAME_FIELD_NAME, event.getClass().getSimpleName()); message.setBooleanProperty("JMS_SonicMQ_preserveUndelivered", true); message.setBooleanProperty("JMS_SonicMQ_notifyUndelivered", true); message.setJMSDeliveryMode(deliveryMode); message.setJMSExpiration(expirationTime); message.setJMSPriority(priority); return message; } catch (JMSException jmsex) { throw new CougarFrameworkException("Error marshalling Event", jmsex); } catch (UnknownHostException e) { throw new CougarFrameworkException("Error looking up local host name", e); } }  String marshallEventBody(Event event); String getHostString(Event event); @Override TextMessage marshallEvent(EventServiceBindingDescriptor bindingDescriptor, Event event, Object session); String getCharacterEncoding(); void setCharacterEncoding(String characterEncoding); int getDeliveryMode(); void setDeliveryMode(int deliveryMode); long getExpirationTime(); void setExpirationTime(long expirationTime); int getPriority(); void setPriority(int priority); DataBindingFactory getDataBindingFactory(); void setDataBindingFactory(DataBindingFactory dataBindingFactory); void setDateFormatPattern(String dateFormatPattern); static final String DEFAULT_CHARACTER_ENCODING; static final int DEFAULT_DELIVERY_MODE; static final long DEFAULT_EXPIRATION_TIME; static final int DEFAULT_PRIORITY; static final String DEFAULT_ROUTE_TIMESTAMP_DATE_FORMAT; }