@Test public void testScan_singleEntryInRepository_assertSingleKey() { final Tx tx1 = TestUtils.makeMessage( TxMessageType.IMF, "12345", "", "*****@*****.**", "*****@*****.**", "", "", ""); final Tx tx2 = TestUtils.makeMessage( TxMessageType.IMF, "67890", "", "*****@*****.**", "*****@*****.**", "", "", ""); final Collection<Tx> txs = Arrays.asList(tx1, tx2); final Exchange exchange = new DefaultExchange(context); exchange.getIn().setBody(txs); final ConcurrentJPAAggregationRepository repo = new ConcurrentJPAAggregationRepository(notifDao); repo.add(context, "12345", exchange); repo.remove(context, "12345", exchange); final Set<String> ids = repo.scan(context); assertEquals(1, ids.size()); assertEquals(exchange.getExchangeId(), ids.iterator().next()); }
@Test public void testScan_emptyRepository_assertEmptySet() { final ConcurrentJPAAggregationRepository repo = new ConcurrentJPAAggregationRepository(notifDao); final Set<String> ids = repo.scan(context); assertEquals(0, ids.size()); }
@Test public void testScan_nullKeys_assertEmptySet() throws Exception { AggregationDAO dao = mock(AggregationDAO.class); when(dao.getAggregationCompletedKeys()).thenReturn(null); final ConcurrentJPAAggregationRepository repo = new ConcurrentJPAAggregationRepository(notifDao); final Set<String> ids = repo.scan(context); assertEquals(0, ids.size()); }
@Test public void testScan_daoException_assertException() throws Exception { AggregationDAO dao = mock(AggregationDAO.class); doThrow(new RuntimeException()).when(dao).getAggregationCompletedKeys(); final ConcurrentJPAAggregationRepository repo = new ConcurrentJPAAggregationRepository(dao); boolean exceptionOccured = false; try { repo.scan(context); } catch (RuntimeException e) { exceptionOccured = true; } assertTrue(exceptionOccured); }