@Before public void setUp() throws Exception { cluster = CassandraUnitUtils.cassandraCluster(); session = cluster.connect(CassandraUnitUtils.KEYSPACE); idempotentRepository = new CassandraIdempotentRepository<String>(session); idempotentRepository.start(); }
@AfterClass public static void tearDownClass() throws Exception { CassandraUnitUtils.cleanEmbeddedCassandra(); }
@BeforeClass public static void setUpClass() throws Exception { CassandraUnitUtils.startEmbeddedCassandra(); }
/** Unit test for {@link CassandraIdempotentRepository} */ public class CassandraIdempotentRepositoryTest { @Rule public CassandraCQLUnit cassandraRule = CassandraUnitUtils.cassandraCQLUnit("IdempotentDataSet.cql"); private Cluster cluster; private Session session; private CassandraIdempotentRepository<String> idempotentRepository; @BeforeClass public static void setUpClass() throws Exception { CassandraUnitUtils.startEmbeddedCassandra(); } @Before public void setUp() throws Exception { cluster = CassandraUnitUtils.cassandraCluster(); session = cluster.connect(CassandraUnitUtils.KEYSPACE); idempotentRepository = new CassandraIdempotentRepository<String>(session); idempotentRepository.start(); } @After public void tearDown() throws Exception { idempotentRepository.stop(); session.close(); cluster.close(); } @AfterClass public static void tearDownClass() throws Exception { CassandraUnitUtils.cleanEmbeddedCassandra(); } private boolean exists(String key) { return session.execute("select KEY from CAMEL_IDEMPOTENT where KEY=?", key).one() != null; } @Test public void testAddNotExists() { // Given String key = "Add_NotExists"; assertFalse(exists(key)); // When boolean result = idempotentRepository.add(key); // Then assertTrue(result); assertTrue(exists(key)); } @Test public void testAddExists() { // Given String key = "Add_Exists"; assertTrue(exists(key)); // When boolean result = idempotentRepository.add(key); // Then assertFalse(result); assertTrue(exists(key)); } @Test public void testContainsNotExists() { // Given String key = "Contains_NotExists"; assertFalse(exists(key)); // When boolean result = idempotentRepository.contains(key); // Then assertFalse(result); } @Test public void testContainsExists() { // Given String key = "Contains_Exists"; assertTrue(exists(key)); // When boolean result = idempotentRepository.contains(key); // Then assertTrue(result); } @Test public void testRemoveNotExists() { // Given String key = "Remove_NotExists"; assertFalse(exists(key)); // When boolean result = idempotentRepository.contains(key); // Then assertFalse(result); } @Test public void testRemoveExists() { // Given String key = "Remove_Exists"; assertTrue(exists(key)); // When boolean result = idempotentRepository.remove(key); // Then assertTrue(result); } }