Package org.apache.camel.examples

Examples of org.apache.camel.examples.SendEmail


        mock.expectedMessageCount(1);
        ValueBuilder header = mock.message(0).header(JpaConstants.ENTITYMANAGER);
        header.isNotNull();
        header.isInstanceOf(EntityManager.class);

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

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


        Map<Integer, Future<SendEmail>> responses = new HashMap<Integer, Future<SendEmail>>();
        for (int i = 0; i < files; i++) {
            final int index = i;
            Future<SendEmail> out = executor.submit(new Callable<SendEmail>() {
                public SendEmail call() throws Exception {
                    return template.requestBody("direct:start", new SendEmail("user" + index + "@somewhere.org"), SendEmail.class);
                }
            });
            responses.put(index, out);
        }

        assertMockEndpointsSatisfied(30, TimeUnit.SECONDS);

        assertEquals(files, responses.size());

        // get them so they are complete
        for (Future<SendEmail> future : responses.values()) {
            SendEmail sendEmail = future.get();
            assertNotNull(sendEmail);
            log.info("Persisted the SendEmail entity with the id {} and the address {}", sendEmail.getId(), sendEmail.getAddress());
        }

        // assert in the database
        assertEntityInDB(files);
        executor.shutdownNow();
View Full Code Here

    protected static final String SELECT_ALL_STRING = "select x from " + SendEmail.class.getName() + " x";

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

        MockEndpoint mock = getMockEndpoint("mock:result");
        mock.expectedMessageCount(2);
        mock.message(0).property(Exchange.BATCH_INDEX).isEqualTo(0);
        mock.message(0).property(Exchange.BATCH_COMPLETE).isEqualTo(false);
View Full Code Here

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

        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);

        // should not consume 3 at once
View Full Code Here

    private static AtomicInteger kaboom = new AtomicInteger();

    @Test
    public void testNonTXRollback() 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 only rollback the failed
        getMockEndpoint("mock:start").expectedMinimumMessageCount(5);
        // and only the 2 good messages goes here
        getMockEndpoint("mock:result").expectedMessageCount(2);
View Full Code Here

                from("jpa://" + SendEmail.class.getName() + "?consumer.transacted=false&delay=100").routeId("foo").noAutoStartup()
                        .to("mock:start")
                        .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())) {
                                    kaboom.incrementAndGet();
                                    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

        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

    protected ApplicationContext applicationContext;
    protected JpaTemplate jpaTemplate;

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

        MockEndpoint mock = getMockEndpoint("mock:result");
        mock.expectedMessageCount(2);
        mock.message(0).property(Exchange.BATCH_INDEX).isEqualTo(0);
        mock.message(0).property(Exchange.BATCH_COMPLETE).isEqualTo(false);
View Full Code Here

        Map<Integer, Future<Object>> responses = new ConcurrentHashMap<Integer, Future<Object>>();
        for (int i = 0; i < files; i++) {
            final int index = i;
            Future<Object> 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;
                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

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.