Package org.camelcookbook.transactions.dao

Examples of org.camelcookbook.transactions.dao.AuditLogDao


        return new ClassPathXmlApplicationContext("META-INF/spring/rollbackMarkRollbackOnly-context.xml");
    }

    @Test
    public void testTransactedRollback() throws InterruptedException {
        AuditLogDao auditLogDao = getMandatoryBean(AuditLogDao.class, "auditLogDao");
        String message = "this message will explode";
        assertEquals(0, auditLogDao.getAuditCount(message));

        // the message does not proceed further down the route after the rollback statement
        MockEndpoint mockCompleted = getMockEndpoint("mock:out");
        mockCompleted.setExpectedMessageCount(0);

        // no exception is thrown despite the transaction rolling back
        template.sendBody("direct:transacted", message);

        assertMockEndpointsSatisfied();
        assertEquals(0, auditLogDao.getAuditCount(message)); // the insert was rolled back
    }
View Full Code Here


        SpringTransactionPolicy propagationRequired = new SpringTransactionPolicy();
        propagationRequired.setTransactionManager(transactionManager);
        propagationRequired.setPropagationBehaviorName("PROPAGATION_REQUIRED");
        registry.put("PROPAGATION_REQUIRED", propagationRequired);

        auditLogDao = new AuditLogDao(auditDataSource);

        TransactionTemplate transactionTemplate = new TransactionTemplate();
        transactionTemplate.setTransactionManager(transactionManager);
        transactionTemplate.setPropagationBehaviorName("PROPAGATION_REQUIRES_NEW");
View Full Code Here

        return new ClassPathXmlApplicationContext("META-INF/spring/rollback-context.xml");
    }

    @Test
    public void testTransactedRollback() throws InterruptedException {
        AuditLogDao auditLogDao = getMandatoryBean(AuditLogDao.class, "auditLogDao");
        String message = "this message will explode";
        assertEquals(0, auditLogDao.getAuditCount(message));

        MockEndpoint mockCompleted = getMockEndpoint("mock:out");
        mockCompleted.setExpectedMessageCount(0);

        try {
            template.sendBody("direct:transacted", message);
            fail();
        } catch (CamelExecutionException cee) {
            Throwable rootCause = ExceptionUtils.getRootCause(cee);
            assertTrue(rootCause instanceof org.apache.camel.RollbackExchangeException);
            assertTrue(rootCause.getMessage().startsWith("Message contained word 'explode'"));
        }

        assertMockEndpointsSatisfied();
        assertEquals(0, auditLogDao.getAuditCount(message)); // the insert was rolled back
    }
View Full Code Here

        return new ClassPathXmlApplicationContext("META-INF/spring/idempotentConsumerInTransaction-context.xml");
    }

    @Test
    public void testTransactedExceptionThrown() throws InterruptedException {
        AuditLogDao auditLogDao = getMandatoryBean(AuditLogDao.class, "auditLogDao");
        String message = "this message will explode";
        assertEquals(0, auditLogDao.getAuditCount(message));

        MockEndpoint mockCompleted = getMockEndpoint("mock:out");
        mockCompleted.setExpectedMessageCount(1);
        mockCompleted.whenAnyExchangeReceived(new ExceptionThrowingProcessor());

        try {
            template.sendBodyAndHeader("direct:transacted", message, "messageId", "foo");
            fail();
        } catch (CamelExecutionException cee) {
            assertEquals("boom!", ExceptionUtils.getRootCause(cee).getMessage());
        }

        assertMockEndpointsSatisfied();
        assertEquals(0, auditLogDao.getAuditCount(message)); // the insert was rolled back
        IdempotentRepository idempotentRepository = getMandatoryBean(IdempotentRepository.class, "jdbcIdempotentRepository");

        // even though the transaction rolled back, the repository should still contain an entry for this messageId
        assertTrue(idempotentRepository.contains("foo"));
    }
View Full Code Here

        SpringTransactionPolicy propagationRequired = new SpringTransactionPolicy();
        propagationRequired.setTransactionManager(transactionManager);
        propagationRequired.setPropagationBehaviorName("PROPAGATION_REQUIRED");
        registry.put("PROPAGATION_REQUIRED", propagationRequired);

        auditLogDao = new AuditLogDao(auditDataSource);

        CamelContext camelContext = new DefaultCamelContext(registry);

        SqlComponent sqlComponent = new SqlComponent();
        sqlComponent.setDataSource(auditDataSource);
View Full Code Here

        assertTrue(idempotentRepository.contains("foo"));
    }

    @Test
    public void testTransactedExceptionNotThrown() throws InterruptedException {
        AuditLogDao auditLogDao = getMandatoryBean(AuditLogDao.class, "auditLogDao");
        String message = "this message will be OK";
        assertEquals(0, auditLogDao.getAuditCount(message));

        MockEndpoint mockCompleted = getMockEndpoint("mock:out");
        mockCompleted.setExpectedMessageCount(1);

        template.sendBodyAndHeader("direct:transacted", message, "messageId", "foo");

        assertMockEndpointsSatisfied();
        assertEquals(1, auditLogDao.getAuditCount(message)); // the insert was successful
        IdempotentRepository idempotentRepository = getMandatoryBean(IdempotentRepository.class, "jdbcIdempotentRepository");

        // even though the transaction rolled back, the repository should still contain an entry for this messageId
        assertTrue(idempotentRepository.contains("foo"));
    }
View Full Code Here

        assertTrue(idempotentRepository.contains("foo"));
    }

    @Test
    public void testWebserviceExceptionRollsBackTransactionAndIdempotentRepository() throws InterruptedException {
        AuditLogDao auditLogDao = getMandatoryBean(AuditLogDao.class, "auditLogDao");
        String message = "this message will be OK";
        assertEquals(0, auditLogDao.getAuditCount(message));

        MockEndpoint mockCompleted = getMockEndpoint("mock:out");
        mockCompleted.setExpectedMessageCount(0);

        MockEndpoint mockWs = getMockEndpoint("mock:ws");
        mockWs.whenAnyExchangeReceived(new ExceptionThrowingProcessor("ws is down"));

        try {
            template.sendBodyAndHeader("direct:transacted", message, "messageId", "foo");
            fail();
        } catch (CamelExecutionException cee) {
            assertEquals("ws is down", ExceptionUtils.getRootCause(cee).getMessage());
        }

        assertMockEndpointsSatisfied();
        assertEquals(0, auditLogDao.getAuditCount(message)); // the insert was successful
        IdempotentRepository idempotentRepository = getMandatoryBean(IdempotentRepository.class, "jdbcIdempotentRepository");

        // the repository has not seen this messageId
        assertTrue(!idempotentRepository.contains("foo"));
    }
View Full Code Here

            propagationNotSupported.setTransactionManager(transactionManager);
            propagationNotSupported.setPropagationBehaviorName("PROPAGATION_NOT_SUPPORTED");
            registry.put("PROPAGATION_NOT_SUPPORTED", propagationNotSupported);
        }

        auditLogDao = new AuditLogDao(dataSource);
        messageDao = new MessageDao(dataSource);

        CamelContext camelContext = new DefaultCamelContext(registry);

        SqlComponent sqlComponent = new SqlComponent();
View Full Code Here

            propagationRequiresNew2.setTransactionManager(transactionManager);
            propagationRequiresNew2.setPropagationBehaviorName("PROPAGATION_REQUIRES_NEW");
            registry.put("PROPAGATION_REQUIRES_NEW-2", propagationRequiresNew2);
        }

        auditLogDao = new AuditLogDao(dataSource);
        messageDao = new MessageDao(dataSource);

        CamelContext camelContext = new DefaultCamelContext(registry);

        SqlComponent sqlComponent = new SqlComponent();
View Full Code Here

        return new ClassPathXmlApplicationContext("META-INF/spring/databaseTransaction-context.xml");
    }

    @Test
    public void testNonTransactedSuccess() throws InterruptedException {
        AuditLogDao auditLogDao = getMandatoryBean(AuditLogDao.class, "auditLogDao");
        String message = "sample message";
        assertEquals(0, auditLogDao.getAuditCount(message));

        MockEndpoint mockCompleted = getMockEndpoint("mock:out");
        mockCompleted.setExpectedMessageCount(1);

        template.sendBody("direct:nonTransacted", message);

        assertMockEndpointsSatisfied();
        assertEquals(1, auditLogDao.getAuditCount(message));
    }
View Full Code Here

TOP

Related Classes of org.camelcookbook.transactions.dao.AuditLogDao

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.