Package org.apache.camel.examples

Examples of org.apache.camel.examples.SendEmail


        Map<Integer, Future> responses = new ConcurrentHashMap();
        for (int i = 0; i < files; i++) {
            final int index = i;
            Future out = executor.submit(new Callable<Object>() {
                public Object call() throws Exception {
                    template.sendBody("direct:start", new SendEmail("user" + index + "@somewhere.org"));
                    return null;
                }
            });
            responses.put(index, out);
        }
View Full Code Here


        assertEquals("Should have no results: " + results, 0, results.size());

        // lets produce some objects
        template.send(endpoint, new Processor() {
            public void process(Exchange exchange) {
                exchange.getIn().setBody(new SendEmail("foo@bar.com"));
            }
        });

        // now lets assert that there is a result
        results = jpaTemplate.find(queryText);
        assertEquals("Should have results: " + results, 1, results.size());
        SendEmail mail = (SendEmail) results.get(0);
        assertEquals("address property", "foo@bar.com", mail.getAddress());

        // now lets create a consumer to consume it
        consumer = endpoint.createConsumer(new Processor() {
            public void process(Exchange e) {
                LOG.info("Received exchange: " + e.getIn());
                receivedExchange = e;
                // should have a JpaTemplate
                JpaTemplate template = e.getIn().getHeader(JpaConstants.JPA_TEMPLATE, JpaTemplate.class);
                assertNotNull("Should have a JpaTemplate as header", template);
                latch.countDown();
            }
        });
        consumer.start();

        boolean received = latch.await(50, TimeUnit.SECONDS);
        assertTrue("Did not receive the message!", received);

        assertNotNull(receivedExchange);
        SendEmail result = receivedExchange.getIn().getBody(SendEmail.class);
        assertNotNull("Received a POJO", result);
        assertEquals("address property", "foo@bar.com", result.getAddress());
    }
View Full Code Here

    @Test
    public void testRouteJpa() throws Exception {
        MockEndpoint mock = getMockEndpoint("mock:result");
        mock.expectedMessageCount(1);

        template.sendBody("direct:start", new SendEmail("one@somewhere.org"));

        assertMockEndpointsSatisfied();
    }
View Full Code Here

        assertEquals("Should have no results: " + results, 0, results.size());

        // lets produce some objects
        template.send(endpoint, new Processor() {
            public void process(Exchange exchange) {
                exchange.getIn().setBody(new SendEmail("foo@bar.com"));
            }
        });

        // now lets assert that there is a result
        results = entityManager.createQuery(queryText).getResultList();
        assertEquals("Should have results: " + results, 1, results.size());
        SendEmail mail = (SendEmail) results.get(0);
        assertEquals("address property", "foo@bar.com", mail.getAddress());

        // now lets create a consumer to consume it
        consumer = endpoint.createConsumer(new Processor() {
            public void process(Exchange e) {
                LOG.info("Received exchange: " + e.getIn());
                receivedExchange = e;
                // should have a EntityManager
                EntityManager entityManager = e.getIn().getHeader(JpaConstants.ENTITYMANAGER, EntityManager.class);
                assertNotNull("Should have a EntityManager as header", entityManager);
                latch.countDown();
            }
        });
        consumer.start();

        assertTrue(latch.await(50, TimeUnit.SECONDS));

        assertNotNull(receivedExchange);
        SendEmail result = receivedExchange.getIn().getBody(SendEmail.class);
        assertNotNull("Received a POJO", result);
        assertEquals("address property", "foo@bar.com", result.getAddress());
    }
View Full Code Here

    @Test
    public void testRouteJpa() throws Exception {
        MockEndpoint mock = getMockEndpoint("mock:result");
        mock.expectedMessageCount(2);

        template.sendBody("direct:start", new SendEmail("one@somewhere.org"));
        template.sendBody("direct:start", new SendEmail("two@somewhere.org"));
        template.sendBody("direct:start", new SendEmail("three@somewhere.org"));

        assertMockEndpointsSatisfied();
        assertEntityInDB(3);
    }
View Full Code Here

        JpaEndpoint jpa = context.getEndpoint("jpa://" + SendEmail.class.getName(), JpaEndpoint.class);
        EntityManagerFactory emf = jpa.getEntityManagerFactory();

        // The entity instance is different if it is retrieved from different EntityManager instance
        EntityManager entityManager = emf.createEntityManager();
        template.sendBody("direct:start", new SendEmail("foo@beer.org"));
        Exchange exchange = mock.getReceivedExchanges().get(0);
        SendEmail persistedEntity = exchange.getIn().getBody(SendEmail.class);
        SendEmail emfindEntity = entityManager.find(SendEmail.class, persistedEntity.getId());
        assertNotSame(emfindEntity, persistedEntity);
        entityManager.close();
        mock.reset();

        // The same EntityManager returns same entity instance from its 1st level cache
        entityManager = emf.createEntityManager();
        template.sendBodyAndHeader("direct:start", new SendEmail("bar@beer.org"), JpaConstants.ENTITYMANAGER, entityManager);
        exchange = mock.getReceivedExchanges().get(0);
        persistedEntity = exchange.getIn().getBody(SendEmail.class);
        emfindEntity = entityManager.find(SendEmail.class, persistedEntity.getId());
        assertSame(emfindEntity, persistedEntity);
        entityManager.close();
View Full Code Here

    @Test
    public void testPreConsumed() throws Exception {
        MockEndpoint mock = getMockEndpoint("mock:result");
        mock.expectedMessageCount(1);

        template.sendBody("direct:start", new SendEmail("dummy"));

        assertMockEndpointsSatisfied();

        // @PreConsumed should change the dummy address
        SendEmail email = mock.getReceivedExchanges().get(0).getIn().getBody(SendEmail.class);
        assertEquals("dummy@somewhere.org", email.getAddress());
    }
View Full Code Here

    private static AtomicInteger bar = new AtomicInteger();

    @Test
    public void testTXRollback() throws Exception {
        // first create three records
        template.sendBody("jpa://" + SendEmail.class.getName(), new SendEmail("foo@beer.org"));
        template.sendBody("jpa://" + SendEmail.class.getName(), new SendEmail("bar@beer.org"));
        template.sendBody("jpa://" + SendEmail.class.getName(), new SendEmail("kaboom@beer.org"));

        // should rollback the entire
        MockEndpoint mock = getMockEndpoint("mock:result");
        // we should retry and try again
        mock.expectedMinimumMessageCount(4);
View Full Code Here

            public void configure() throws Exception {
                from("jpa://" + SendEmail.class.getName() + "?consumer.transacted=true&delay=1000").routeId("foo").noAutoStartup()
                        .process(new Processor() {
                            @Override
                            public void process(Exchange exchange) throws Exception {
                                SendEmail send = exchange.getIn().getBody(SendEmail.class);
                                if ("kaboom@beer.org".equals(send.getAddress())) {
                                    throw new IllegalArgumentException("Forced");
                                }

                                if ("foo@beer.org".equals(send.getAddress())) {
                                    foo.incrementAndGet();
                                } else if ("bar@beer.org".equals(send.getAddress())) {
                                    bar.incrementAndGet();
                                }
                            }
                        })
                        .to("mock:result");
View Full Code Here

    @Test
    public void testRouteJpa() throws Exception {
        MockEndpoint mock = getMockEndpoint("mock:result");
        mock.expectedMessageCount(1);

        template.sendBody("direct:start", new SendEmail("someone@somewhere.org"));

        assertMockEndpointsSatisfied();
        assertEntityInDB();
    }
View Full Code Here

TOP

Related Classes of org.apache.camel.examples.SendEmail

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.