List of usage examples for javax.jms TextMessage getText
String getText() throws JMSException;
From source file:com.silverpeas.mailinglist.service.notification.AdvancedNotificationHelperTest.java
@Test public void testNotifyInternals() throws Exception { ServicesFactory servicesFactory = ServicesFactory.getFactory(); Message message = servicesFactory.getMessageService().getMessage("700"); assertThat(message, is(notNullValue())); MailingList list = servicesFactory.getMailingListService().findMailingList("100"); assertThat(list, is(notNullValue())); assertThat(list.getModerators(), is(notNullValue())); assertThat(list.getModerators().size(), is(3)); assertThat(list.getReaders(), is(notNullValue())); assertThat(list.getReaders().size(), is(2)); List<String> userIds = Arrays.asList(new String[] { "200", "201", "202", "203", "204" }); notificationHelper.notifyInternals(message, list, userIds, null, false); List<TextMessage> messages = MockObjectFactory.getMessages(JNDINames.JMS_QUEUE); assertThat(messages, is(notNullValue())); assertThat(messages.size(), is(5));/*w w w . j a v a2s . co m*/ for (TextMessage alert : messages) { assertThat(alert.getText(), is(notNullValue())); NotificationData data = NotificationServerUtil.convertXMLToNotificationData(alert.getText()); assertThat(data, is(notNullValue())); String channel = data.getTargetChannel(); assertThat(channel, is("SMTP")); String recipient = data.getTargetReceipt(); assertThat(recipient, is(notNullValue())); assertThat("Erreur destinataire " + recipient, recipient, isOneOf("homer.simpson@silverpeas.com", "marge.simpson@silverpeas.com", "lisa.simpson@silverpeas.com", "maggie.simpson@silverpeas.com", "bart.simpson@silverpeas.com")); String notificationMessage = "<html><head/><body>p><b>Message [" + message.getTitle() + "] :</b></p><p>" + message.getSummary() + " ...<br/><a href=\"/Rmailinglist/100/" + "message/700\">Cliquer ici</a></p></body></html>"; assertThat(data.getMessage(), is(notificationMessage)); String url = (String) data.getTargetParam().get("URL"); assertThat(url, is(notNullValue())); assertThat(url, is("http://localhost:8000/silverpeas//autoRedirect.jsp?domainId=0&" + "goto=%2FRmailinglist%2F100%2Fmessage%2F700")); String source = (String) data.getTargetParam().get("SOURCE"); assertThat(source, is(notNullValue())); assertThat(source, is("thesimpsons@silverpeas.com")); } }
From source file:fr.xebia.springframework.jms.support.converter.JaxbMessageConverterTest.java
@Test public void testToMessage() throws Exception { JaxbMessageConverter jaxbMessageConverter = createJaxbMessageConverter(Employee.class, Gender.class); Employee employee = new Employee(1, "Cyrille", "Le Clerc", Gender.MALE, DatatypeFactory.newInstance() .newXMLGregorianCalendarDate(1976, 01, 05, DatatypeConstants.FIELD_UNDEFINED)); TextMessage actualMessage = (TextMessage) jaxbMessageConverter.toMessage(employee, session); String actual = actualMessage.getText(); String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "<Employee>" + "<id>1</id>" + "<lastName>Le Clerc</lastName>" + "<firstName>Cyrille</firstName>" + "<gender>MALE</gender>" + "<birthdate>1976-01-05</birthdate>" + "</Employee>"; Assert.assertEquals(expected, actual); }
From source file:org.apigw.monitoring.jms.messagelistener.MonitoringMessageListenerTest.java
@Test public void a_complete_log_end_resource_event_is_saved_to_storage() throws Exception { MonitoringMessageListener mml = new MonitoringMessageListener(); TextMessage message = mock(TextMessage.class); when(message.getText()).thenReturn(createMessagePayLoadForResourceEvent(ResourceEventType.LOGEND)); mml.setResourceEventRepository(resourceEventRepository); mml.onMessage(message);//w w w . ja v a 2 s .co m List<ResourceEvent> events = resourceEventRepository.findAll(); assertEquals(1, events.size()); ResourceEvent event = events.get(0); assertNotNull("Event timestamp can not be null", event.getTimestamp()); assertNotNull("Must have a CorrelationId", event.getCorrelationId()); assertEquals(ResourceEventType.LOGEND, event.getEventType()); assertNotNull("Message needs to be there", event.getMessage()); assertNotNull("HTTP Status needs to be there", event.getHttpStatus()); assertEquals(200, event.getHttpStatus()); }
From source file:de.slub.fedora.jms.MessageMapperTest.java
@Test public void returnsIndexJobForModifyDatastreamByValueMessage() throws Exception { TextMessage message = mock(TextMessage.class); when(message.getStringProperty(eq("pid"))).thenReturn("test-rest:1"); when(message.getStringProperty(eq("methodName"))).thenReturn("modifyDatastreamByValue"); when(message.getText()).thenReturn(getContent("/jms/modifyDatastreamByValue.xml")); IndexJob ij = findFirstByClass(MessageMapper.map(message), DatastreamIndexJob.class); assertEquals(new DatastreamIndexJob(IndexJob.Type.UPDATE, "test-rest:1", "testModifyDatastream"), ij); }
From source file:de.slub.fedora.jms.MessageMapperTest.java
@Test public void returnsObjectIndexJobForUpdateDatastreamMessage() throws Exception { TextMessage message = mock(TextMessage.class); when(message.getStringProperty(eq("pid"))).thenReturn("test-rest:1"); when(message.getStringProperty(eq("methodName"))).thenReturn("modifyDatastreamByValue"); when(message.getText()).thenReturn(getContent("/jms/modifyDatastreamByValue.xml")); IndexJob ij = findFirstByClass(MessageMapper.map(message), ObjectIndexJob.class); assertEquals(new ObjectIndexJob(IndexJob.Type.UPDATE, "test-rest:1", "testModifyDatastream"), ij); }
From source file:org.apigw.monitoring.jms.messagelistener.MonitoringMessageListenerTest.java
@Test public void a_complete_log_start_resource_event_is_saved_to_storage() throws Exception { MonitoringMessageListener mml = new MonitoringMessageListener(); TextMessage message = mock(TextMessage.class); when(message.getText()).thenReturn(createMessagePayLoadForResourceEvent(ResourceEventType.LOGSTART)); mml.setResourceEventRepository(resourceEventRepository); mml.onMessage(message);/*from ww w. j a v a 2s .c o m*/ List<ResourceEvent> events = resourceEventRepository.findAll(); assertEquals(1, events.size()); ResourceEvent event = events.get(0); assertNotNull("Event timestamp can not be null", event.getTimestamp()); assertNotNull("Must have a CorrelationId", event.getCorrelationId()); assertEquals(ResourceEventType.LOGSTART, event.getEventType()); assertNotNull("Endpoint needs to be there", event.getEndpoint()); assertNotNull("Resource needs to be there", event.getResource()); assertNotNull("IP needs to be there", event.getIp()); assertNotNull("Message needs to be there", event.getMessage()); }
From source file:org.apigw.monitoring.jms.messagelistener.MonitoringMessageListenerTest.java
@Test public void a_redelivered_auth_event_message_is_not_persisted_again() throws Exception { MonitoringMessageListener mml = new MonitoringMessageListener(); mml.setAuthEventRepository(authEventRepository); TextMessage message = mock(TextMessage.class); when(message.getText()).thenReturn(createMessagePayLoadForAuthEvent(AuthEventType.AUTHORIZATIONGRANT)); when(message.getJMSRedelivered()).thenReturn(false); mml.onMessage(message);/*from w ww .j a v a 2s. c o m*/ List<AuthEvent> events = authEventRepository.findAll(); assertEquals(1, events.size()); when(message.getJMSRedelivered()).thenReturn(true); mml.onMessage(message); events = authEventRepository.findAll(); assertEquals(1, events.size()); }
From source file:org.apigw.monitoring.jms.messagelistener.MonitoringMessageListenerTest.java
@Test public void a_redelivered_resource_event_message_is_not_persisted_again() throws Exception { MonitoringMessageListener mml = new MonitoringMessageListener(); mml.setResourceEventRepository(resourceEventRepository); TextMessage message = mock(TextMessage.class); when(message.getText()).thenReturn(createMessagePayLoadForResourceEvent(ResourceEventType.LOGSTART)); when(message.getJMSRedelivered()).thenReturn(false); mml.onMessage(message);//from www .j av a2 s. co m List<ResourceEvent> events = resourceEventRepository.findAll(); assertEquals(1, events.size()); when(message.getJMSRedelivered()).thenReturn(true); mml.onMessage(message); events = resourceEventRepository.findAll(); assertEquals(1, events.size()); }
From source file:de.adorsys.jmspojo.JMSMessageListenerServiceAdapterTest.java
@Test public void testCreateAdapterVoid() throws JMSException { TextMessage textMessage = queueSession.createTextMessage(OBJECT_MAPPER.serialize(new PingMessage("ping"))); textMessage.setJMSReplyTo(reqlayQ);//from w w w .j ava2 s .c o m SampleMessageServiceVoid service = new SampleMessageServiceVoid(); JMSMessageListenerServiceAdapter<SampleMessageServiceVoid> adapter = JMSMessageListenerServiceAdapter .createAdapter(service, cf, OBJECT_MAPPER); adapter.onMessage(textMessage); TextMessage message = (TextMessage) queueSession.createReceiver(reqlayQ).receive(1000); assertNotNull(message); assertNull(message.getStringProperty("ERROR")); assertNull(message.getText()); }
From source file:NewPojo.MessageBean.java
@Override public void onMessage(Message message) { SessionBean bean = null;//from w ww . ja v a2s . c o m TextMessage textMessage = null; System.out.println("**** I am in Message Bean ******"); try { if (message instanceof TextMessage) { textMessage = (TextMessage) message; bean = new SessionBean(); JSONObject object = new JSONObject(textMessage.getText()); String name = object.getString("customerName"); String phone = object.getString("phoneNumber"); String wallMaterial = object.getString("material"); int wallArea = Integer.parseInt(object.getString("wallArea")); int numberOfCoatings = Integer.parseInt(object.getString("numberOfCoatings")); int ceilingArea = Integer.parseInt(object.getString("ceilingArea")); bean.calculatePrice(name, phone, wallMaterial, wallArea, numberOfCoatings, ceilingArea); } } catch (JSONException ex) { ex.printStackTrace(); } catch (JMSException ex) { Logger.getLogger(MessageBean.class.getName()).log(Level.SEVERE, null, ex); } }