use of org.apache.camel.Producer in project camel by apache.
the class DefaultProducerCacheTest method testCacheStopExpired.
public void testCacheStopExpired() throws Exception {
ProducerCache cache = new ProducerCache(this, context, 5);
cache.start();
assertEquals("Size should be 0", 0, cache.size());
for (int i = 0; i < 8; i++) {
Endpoint e = new MyEndpoint(true, i);
Producer p = cache.acquireProducer(e);
cache.releaseProducer(e, p);
}
// the eviction is async so force cleanup
cache.cleanUp();
assertEquals("Size should be 5", 5, cache.size());
// the eviction listener is async so sleep a bit
Thread.sleep(1000);
// should have stopped the 3 evicted
assertEquals(3, stopCounter.get());
cache.stop();
// should have stopped all 8
assertEquals(8, stopCounter.get());
}
use of org.apache.camel.Producer in project camel by apache.
the class CMISQueryProducerTest method getResultCountFromHeader.
@Test
public void getResultCountFromHeader() throws Exception {
Endpoint endpoint = context.getEndpoint("cmis://" + getUrl() + "?queryMode=true");
Producer producer = endpoint.createProducer();
Exchange exchange = createExchangeWithInBody("SELECT * FROM cmis:document WHERE CONTAINS('Camel test content.')");
producer.process(exchange);
@SuppressWarnings("unchecked") List<Map<String, Object>> documents = exchange.getOut().getBody(List.class);
assertEquals(2, documents.size());
assertEquals(2, exchange.getOut().getHeader("CamelCMISResultCount"));
}
use of org.apache.camel.Producer in project camel by apache.
the class CMISQueryProducerTest method limitNumberOfResultsWithReadSizeHeader.
@Test
public void limitNumberOfResultsWithReadSizeHeader() throws Exception {
Endpoint endpoint = context.getEndpoint("cmis://" + getUrl() + "?queryMode=true");
Producer producer = endpoint.createProducer();
Exchange exchange = createExchangeWithInBody("SELECT * FROM cmis:document WHERE CONTAINS('Camel test content.')");
exchange.getIn().getHeaders().put("CamelCMISReadSize", 1);
producer.process(exchange);
@SuppressWarnings("unchecked") List<Map<String, Object>> documents = exchange.getOut().getBody(List.class);
assertEquals(1, documents.size());
}
use of org.apache.camel.Producer in project camel by apache.
the class CMISQueryProducerTest method retrieveAlsoDocumentContent.
@Test
public void retrieveAlsoDocumentContent() throws Exception {
Endpoint endpoint = context.getEndpoint("cmis://" + getUrl() + "?queryMode=true");
Producer producer = endpoint.createProducer();
Exchange exchange = createExchangeWithInBody("SELECT * FROM cmis:document WHERE cmis:name='test1.txt'");
exchange.getIn().getHeaders().put("CamelCMISRetrieveContent", true);
producer.process(exchange);
@SuppressWarnings("unchecked") List<Map<String, Object>> documents = exchange.getOut().getBody(List.class);
InputStream content = (InputStream) documents.get(0).get("CamelCMISContent");
assertEquals("This is the first Camel test content.", readFromStream(content));
}
use of org.apache.camel.Producer in project camel by apache.
the class MailAttachmentDuplicateNamesTest method testSendAndRecieveMailWithAttachmentsWithDuplicateNames.
@Test
public void testSendAndRecieveMailWithAttachmentsWithDuplicateNames() throws Exception {
// clear mailbox
Mailbox.clearAll();
// START SNIPPET: e1
// create an exchange with a normal body and attachment to be produced as email
Endpoint endpoint = context.getEndpoint("smtp://james@mymailserver.com?password=secret");
// create the exchange with the mail message that is multipart with a file and a Hello World text/plain message.
Exchange exchange = endpoint.createExchange();
Message in = exchange.getIn();
in.setBody("Hello World");
in.addAttachment("logo.jpeg", new DataHandler(new FileDataSource("src/test/data/logo.jpeg")));
in.addAttachment("logo.jpeg", new DataHandler(new FileDataSource("src/test/data/logo.jpeg")));
// create a producer that can produce the exchange (= send the mail)
Producer producer = endpoint.createProducer();
// start the producer
producer.start();
// and let it go (processes the exchange by sending the email)
producer.process(exchange);
// END SNIPPET: e1
// need some time for the mail to arrive on the inbox (consumed and sent to the mock)
Thread.sleep(2000);
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(1);
Exchange out = mock.assertExchangeReceived(0);
mock.assertIsSatisfied();
// plain text
assertEquals("Hello World", out.getIn().getBody(String.class));
// attachment
Map<String, DataHandler> attachments = out.getIn().getAttachments();
assertNotNull("Should have attachments", attachments);
assertEquals(1, attachments.size());
DataHandler handler = out.getIn().getAttachment("logo.jpeg");
assertNotNull("The logo should be there", handler);
// content type should match
boolean match1 = "image/jpeg; name=logo.jpeg".equals(handler.getContentType());
boolean match2 = "application/octet-stream; name=logo.jpeg".equals(handler.getContentType());
assertTrue("Should match 1 or 2", match1 || match2);
producer.stop();
}
Aggregations