@Test public void consumeDocumentsWithQuery() throws Exception { resultEndpoint.expectedMessageCount(2); Consumer queryBasedConsumer = createConsumerFor(getUrl() + "?query=SELECT * FROM cmis:document"); queryBasedConsumer.start(); resultEndpoint.assertIsSatisfied(); queryBasedConsumer.stop(); }
@Test public void getAllContentFromServerOrderedFromRootToLeaves() throws Exception { resultEndpoint.expectedMessageCount(5); Consumer treeBasedConsumer = createConsumerFor(getUrl()); treeBasedConsumer.start(); resultEndpoint.assertIsSatisfied(); treeBasedConsumer.stop(); List<Exchange> exchanges = resultEndpoint.getExchanges(); assertTrue(getNodeNameForIndex(exchanges, 0).equals("RootFolder")); assertTrue(getNodeNameForIndex(exchanges, 1).equals("Folder1")); assertTrue(getNodeNameForIndex(exchanges, 2).equals("Folder2")); assertTrue(getNodeNameForIndex(exchanges, 3).contains(".txt")); assertTrue(getNodeNameForIndex(exchanges, 4).contains(".txt")); }
@Test public void consumeEntity() throws Exception { setUp("jpa://" + Customer.class.getName() + "?usePersist=" + (usePersist() ? "true" : "false")); final Customer customer = createDefaultCustomer(); save(customer); final CountDownLatch latch = new CountDownLatch(1); consumer = endpoint.createConsumer( new Processor() { public void process(Exchange e) { receivedExchange = e; assertNotNull(e.getIn().getHeader(JpaConstants.ENTITYMANAGER, EntityManager.class)); latch.countDown(); } }); consumer.start(); assertTrue(latch.await(50, TimeUnit.SECONDS)); consumer.stop(); Thread.sleep(1000); assertNotNull(receivedExchange); Customer receivedCustomer = receivedExchange.getIn().getBody(Customer.class); assertEquals(customer.getName(), receivedCustomer.getName()); assertEquals(customer.getId(), receivedCustomer.getId()); assertEquals( customer.getAddress().getAddressLine1(), receivedCustomer.getAddress().getAddressLine1()); assertEquals( customer.getAddress().getAddressLine2(), receivedCustomer.getAddress().getAddressLine2()); assertEquals(customer.getAddress().getId(), receivedCustomer.getAddress().getId()); // give a bit time for consumer to delete after done Thread.sleep(1000); assertEntitiesInDatabase(0, Customer.class.getName()); assertEntitiesInDatabase(0, Address.class.getName()); }
protected void configureConsumer(Consumer consumer) throws Exception { if (consumerProperties != null) { // use a defensive copy of the consumer properties as the methods below will remove the used // properties // and in case we restart routes, we need access to the original consumer properties again Map<String, Object> copy = new HashMap<String, Object>(consumerProperties); // set reference properties first as they use # syntax that fools the regular properties // setter EndpointHelper.setReferenceProperties(getCamelContext(), consumer, copy); EndpointHelper.setProperties(getCamelContext(), consumer, copy); // special consumer.bridgeErrorHandler option Object bridge = copy.remove("bridgeErrorHandler"); if (bridge != null && "true".equals(bridge)) { if (consumer instanceof DefaultConsumer) { DefaultConsumer defaultConsumer = (DefaultConsumer) consumer; defaultConsumer.setExceptionHandler( new BridgeExceptionHandlerToErrorHandler(defaultConsumer)); } else { throw new IllegalArgumentException( "Option consumer.bridgeErrorHandler is only supported by endpoints," + " having their consumer extend DefaultConsumer. The consumer is a " + consumer.getClass().getName() + " class."); } } if (!this.isLenientProperties() && copy.size() > 0) { throw new ResolveEndpointFailedException( this.getEndpointUri(), "There are " + copy.size() + " parameters that couldn't be set on the endpoint consumer." + " Check the uri if the parameters are spelt correctly and that they are properties of the endpoint." + " Unknown consumer parameters=[" + copy + "]"); } } }