List of usage examples for javax.jms TextMessage getText
String getText() throws JMSException;
From source file:de.slub.fedora.jms.MessageMapperTest.java
@Test public void returnsNoIndexJobForGetObjectXmlMessage() throws Exception { TextMessage message = mock(TextMessage.class); when(message.getStringProperty(eq("pid"))).thenReturn("test:4711"); when(message.getStringProperty(eq("methodName"))).thenReturn("getObjectXML"); when(message.getText()).thenReturn(getContent("/jms/getObjectXML.xml")); assertEquals(0, MessageMapper.map(message).size()); }
From source file:com.amalto.core.storage.task.staging.ClusteredStagingTaskManagerTestCase.java
@Test public void testReceiveMessageForEmptyInfo() throws Exception { TextMessage message = Mockito.mock(TextMessage.class); Mockito.when(message.getText()).thenReturn( "<?xml version=\"1.0\"?><stagingJobCancellationMessage><dataContainer>container</dataContainer<taskId/></stagingJobCancellationMessage>"); taskManager.onMessage(message);//from ww w . j a v a2s .c o m Mockito.verifyNoMoreInteractions(this.repository); this.internalListener.assertNoMessageSent(); Mockito.when(message.getText()).thenReturn( "<?xml version=\"1.0\"?><stagingJobCancellationMessage><dataContainer/><taskId>ABCD</taskId></stagingJobCancellationMessage>"); taskManager.onMessage(message); Mockito.verifyNoMoreInteractions(this.repository); this.internalListener.assertNoMessageSent(); Mockito.when(message.getText()).thenReturn("<?xml version=\"1.0\"?><toto></toto>"); taskManager.onMessage(message); Mockito.verifyNoMoreInteractions(this.repository); this.internalListener.assertNoMessageSent(); }
From source file:de.slub.fedora.jms.MessageMapperTest.java
@Test public void returnsIndexJobForPurgeObjectMessage() throws Exception { TextMessage message = mock(TextMessage.class); when(message.getStringProperty(eq("pid"))).thenReturn("test-rest:1"); when(message.getStringProperty(eq("methodName"))).thenReturn("purgeObject"); when(message.getText()).thenReturn(getContent("/jms/purgeObject.xml")); IndexJob ij = findFirstByClass(MessageMapper.map(message), ObjectIndexJob.class); assertEquals(new ObjectIndexJob(IndexJob.Type.DELETE, "test-rest:1"), ij); }
From source file:de.slub.fedora.jms.MessageMapperTest.java
@Test public void returnsIndexJobForModifyObjectMessage() throws Exception { TextMessage message = mock(TextMessage.class); when(message.getStringProperty(eq("pid"))).thenReturn("test-rest:1"); when(message.getStringProperty(eq("methodName"))).thenReturn("modifyObject"); when(message.getText()).thenReturn(getContent("/jms/modifyObject.xml")); IndexJob ij = findFirstByClass(MessageMapper.map(message), ObjectIndexJob.class); assertEquals(new ObjectIndexJob(IndexJob.Type.UPDATE, "test-rest:1"), ij); }
From source file:de.slub.fedora.jms.MessageMapperTest.java
@Test public void returnsIndexJobForAddDatastreamMessage() throws Exception { TextMessage message = mock(TextMessage.class); when(message.getStringProperty(eq("pid"))).thenReturn("test-rest:1"); when(message.getStringProperty(eq("methodName"))).thenReturn("addDatastream"); when(message.getText()).thenReturn(getContent("/jms/addDatastream.xml")); IndexJob ij = findFirstByClass(MessageMapper.map(message), DatastreamIndexJob.class); assertEquals(new DatastreamIndexJob(IndexJob.Type.CREATE, "test-rest:1", "testAddDatastream"), ij); }
From source file:de.slub.fedora.jms.MessageMapperTest.java
@Test public void returnsIndexJobForPurgeDatastreamMessage() throws Exception { TextMessage message = mock(TextMessage.class); when(message.getStringProperty(eq("pid"))).thenReturn("test-rest:1"); when(message.getStringProperty(eq("methodName"))).thenReturn("purgeDatastream"); when(message.getText()).thenReturn(getContent("/jms/purgeDatastream.xml")); IndexJob ij = MessageMapper.map(message).get(0); assertEquals(new DatastreamIndexJob(IndexJob.Type.DELETE, "test-rest:1", "testPurgeDatastream"), ij); }
From source file:com.silverpeas.mailinglist.service.notification.TestNotificationHelper.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));/*from w w w . j a va2s .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")); assertThat(data.getMessage(), is(message.getSummary())); 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:org.hoteia.qalingo.core.jms.indexing.listener.IndexingObjectQueueListener.java
/** * Implementation of <code>MessageListener</code>. *///from ww w . j av a2 s . co m public void onMessage(Message message) { try { if (message instanceof TextMessage) { TextMessage tm = (TextMessage) message; String valueJMSMessage = tm.getText(); if (StringUtils.isNotEmpty(valueJMSMessage)) { final IndexingObjectMessageJms documentMessageJms = xmlMapper.getXmlMapper() .readValue(valueJMSMessage, IndexingObjectMessageJms.class); Long objectId = documentMessageJms.getObjectId(); if ("ProductMarketing".equals(documentMessageJms.getObjectType())) { final ProductMarketing productMarketing = productService.getProductMarketingById(objectId, FetchPlanGraphProduct.fullIndexedProductMarketingFetchPlan()); if (productMarketing != null) { ProductSku defaultProductSku = productMarketing.getDefaultProductSku(); if (defaultProductSku != null) { List<CatalogCategoryVirtual> catalogCategories = catalogCategoryService .findVirtualCategoriesByProductSkuId(defaultProductSku.getId(), new FetchPlan(categoryFetchPlans)); List<ProductSku> productSkus = new ArrayList<ProductSku>(); for (Iterator<ProductSku> iteratorProductSku = productMarketing.getProductSkus() .iterator(); iteratorProductSku.hasNext();) { ProductSku productSkuIterator = (ProductSku) iteratorProductSku.next(); final ProductSku reloadedProductSku = productService.getProductSkuByCode( productSkuIterator.getCode(), FetchPlanGraphProduct.fullIndexedProductSkuFetchPlan()); productSkus.add(reloadedProductSku); } try { productMarketingSolrService.addOrUpdateProductMarketing(productMarketing, productSkus, catalogCategories, null, null); } catch (SolrServerException e) { logger.error("Processed message to indexing failed, value: " + valueJMSMessage); } } } } else if ("ProductSku".equals(documentMessageJms.getObjectType())) { final ProductSku productSku = productService.getProductSkuById(objectId, FetchPlanGraphProduct.fullIndexedProductSkuFetchPlan()); if (productSku != null) { final ProductMarketing productMarketing = productService.getProductMarketingById( productSku.getProductMarketing().getId(), FetchPlanGraphProduct.fullIndexedProductMarketingFetchPlan()); List<CatalogCategoryVirtual> catalogCategories = catalogCategoryService .findVirtualCategoriesByProductSkuId(productSku.getId(), new FetchPlan(categoryFetchPlans)); try { productSkuSolrService.addOrUpdateProductSku(productMarketing, productSku, catalogCategories, null, null); } catch (SolrServerException e) { logger.error("Processed message to indexing failed, value: " + valueJMSMessage); } // AND UPDATE THE PRODUCT MARKETING - AGREGATE SKU OPTIONS ! if (productMarketing != null) { List<ProductSku> productSkus = new ArrayList<ProductSku>(); for (Iterator<ProductSku> iteratorProductSku = productMarketing.getProductSkus() .iterator(); iteratorProductSku.hasNext();) { ProductSku productSkuIterator = (ProductSku) iteratorProductSku.next(); final ProductSku reloadedProductSku = productService.getProductSkuByCode( productSkuIterator.getCode(), FetchPlanGraphProduct.fullIndexedProductSkuFetchPlan()); productSkus.add(reloadedProductSku); } try { productMarketingSolrService.addOrUpdateProductMarketing(productMarketing, productSkus, catalogCategories, null, null); } catch (SolrServerException e) { logger.error("Processed message to indexing failed, value: " + valueJMSMessage); } } } } else if ("Store".equals(documentMessageJms.getObjectType())) { final Store store = retailerService.getStoreById(objectId, new FetchPlan(storeFetchPlans)); if (store != null) { try { storeSolrService.addOrUpdateStore(store); } catch (SolrServerException e) { logger.error("Processed message to indexing failed, value: " + valueJMSMessage); } } } if (logger.isDebugEnabled()) { logger.debug("Processed message, value: " + valueJMSMessage); } } else { logger.warn("Document generation: Jms Message is empty"); } } } catch (JMSException e) { logger.error(e.getMessage(), e); } catch (IOException e) { logger.error(e.getMessage(), e); } }
From source file:fr.xebia.springframework.jms.support.converter.JaxbMessageConverterSpringTest.java
@Test public void testToMessage() throws Exception { 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 mandatory_parts_of_resource_event_are_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 w ww . 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()); }