use of org.apache.camel.Exchange in project camel by apache.
the class LdapRouteTest method testLdapRouteWithPaging.
@Test
public void testLdapRouteWithPaging() throws Exception {
camel.addRoutes(createRouteBuilder("ldap:localhost:" + port + "?base=ou=system&pageSize=5"));
camel.start();
Endpoint endpoint = camel.getEndpoint("direct:start");
Exchange exchange = endpoint.createExchange();
// then we set the LDAP filter on the in body
exchange.getIn().setBody("(objectClass=*)");
// now we send the exchange to the endpoint, and receives the response from Camel
Exchange out = template.send(endpoint, exchange);
Collection<SearchResult> searchResults = defaultLdapModuleOutAssertions(out);
assertEquals(16, searchResults.size());
}
use of org.apache.camel.Exchange in project camel by apache.
the class LdapRouteTest method testLdapRouteStandard.
@Test
public void testLdapRouteStandard() throws Exception {
camel.addRoutes(createRouteBuilder("ldap:localhost:" + port + "?base=ou=system"));
camel.start();
// START SNIPPET: invoke
Endpoint endpoint = camel.getEndpoint("direct:start");
Exchange exchange = endpoint.createExchange();
// then we set the LDAP filter on the in body
exchange.getIn().setBody("(!(ou=test1))");
// now we send the exchange to the endpoint, and receives the response from Camel
Exchange out = template.send(endpoint, exchange);
Collection<SearchResult> searchResults = defaultLdapModuleOutAssertions(out);
assertFalse(contains("uid=test1,ou=test,ou=system", searchResults));
assertTrue(contains("uid=test2,ou=test,ou=system", searchResults));
assertTrue(contains("uid=testNoOU,ou=test,ou=system", searchResults));
assertTrue(contains("uid=tcruise,ou=actors,ou=system", searchResults));
// START SNIPPET: invoke
}
use of org.apache.camel.Exchange in project camel by apache.
the class LuceneIndexAndQueryProducerTest method testLuceneWildcardQueryProducer.
@Test
public void testLuceneWildcardQueryProducer() throws Exception {
MockEndpoint mockSearchEndpoint = getMockEndpoint("mock:searchResult");
context.stop();
context.addRoutes(new RouteBuilder() {
public void configure() {
from("direct:start").setHeader("QUERY", constant("Grouc?? Marx")).to("lucene:searchIndex:query?analyzer=#stdAnalyzer&indexDir=#std&maxHits=20").to("direct:next");
from("direct:next").process(new Processor() {
public void process(Exchange exchange) throws Exception {
Hits hits = exchange.getIn().getBody(Hits.class);
printResults(hits);
}
private void printResults(Hits hits) {
LOG.debug("Number of hits: " + hits.getNumberOfHits());
for (int i = 0; i < hits.getNumberOfHits(); i++) {
LOG.debug("Hit " + i + " Index Location:" + hits.getHit().get(i).getHitLocation());
LOG.debug("Hit " + i + " Score:" + hits.getHit().get(i).getScore());
LOG.debug("Hit " + i + " Data:" + hits.getHit().get(i).getData());
}
}
}).to("mock:searchResult");
}
});
context.start();
LOG.debug("------------Beginning LuceneQueryProducer Wildcard Test---------------");
sendQuery();
mockSearchEndpoint.assertIsSatisfied();
LOG.debug("------------Completed LuceneQueryProducer Wildcard Test---------------");
context.stop();
}
use of org.apache.camel.Exchange in project camel by apache.
the class LdapRouteTest method testLdapRoutePreserveHeaderAndAttachments.
@Test
public void testLdapRoutePreserveHeaderAndAttachments() throws Exception {
camel.addRoutes(createRouteBuilder("ldap:localhost:" + port + "?base=ou=system"));
camel.start();
final DataHandler dataHandler = new DataHandler("test", "text");
Exchange out = template.request("direct:start", new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getIn().setBody("(!(ou=test1))");
exchange.getIn().setHeader("ldapTest", "Camel");
exchange.getIn().addAttachment("ldapAttachment", dataHandler);
}
});
Collection<SearchResult> searchResults = defaultLdapModuleOutAssertions(out);
assertFalse(contains("uid=test1,ou=test,ou=system", searchResults));
assertTrue(contains("uid=test2,ou=test,ou=system", searchResults));
assertTrue(contains("uid=testNoOU,ou=test,ou=system", searchResults));
assertTrue(contains("uid=tcruise,ou=actors,ou=system", searchResults));
assertEquals("Camel", out.getOut().getHeader("ldapTest"));
assertSame(dataHandler, out.getOut().getAttachment("ldapAttachment"));
}
use of org.apache.camel.Exchange in project camel by apache.
the class LdapRouteTest method testLdapRouteReturnedAttributes.
@Test
public void testLdapRouteReturnedAttributes() throws Exception {
// LDAP servers behave differently when it comes to what attributes are returned
// by default (Apache Directory server returns all attributes by default)
// Using the returnedAttributes parameter this behavior can be controlled
camel.addRoutes(createRouteBuilder("ldap:localhost:" + port + "?base=ou=system&returnedAttributes=uid,cn"));
camel.start();
Endpoint endpoint = camel.getEndpoint("direct:start");
Exchange exchange = endpoint.createExchange();
// then we set the LDAP filter on the in body
exchange.getIn().setBody("(uid=tcruise)");
// now we send the exchange to the endpoint, and receives the response from Camel
Exchange out = template.send(endpoint, exchange);
Collection<SearchResult> searchResults = defaultLdapModuleOutAssertions(out);
assertEquals(1, searchResults.size());
assertTrue(contains("uid=tcruise,ou=actors,ou=system", searchResults));
Attributes theOneResultAtts = searchResults.iterator().next().getAttributes();
assertEquals("tcruise", theOneResultAtts.get("uid").get());
assertEquals("Tom Cruise", theOneResultAtts.get("cn").get());
// make sure this att is NOT returned anymore
assertNull(theOneResultAtts.get("sn"));
}
Aggregations