use of org.nhindirect.monitor.aggregator.repository.ConcurrentJPAAggregationRepository in project nhin-d by DirectProject.
the class ConcurrentJPAAggregationRepository_removeTest method testRemove_exchangeWithCollectionBodyInRepo_assertRemovedAndCompletedAdded.
@Test
@SuppressWarnings("unchecked")
public void testRemove_exchangeWithCollectionBodyInRepo_assertRemovedAndCompletedAdded() {
final Tx tx1 = TestUtils.makeMessage(TxMessageType.IMF, "12345", "", "me@test.com", "you@test.com", "", "", "");
final Tx tx2 = TestUtils.makeMessage(TxMessageType.IMF, "67890", "", "me@test2.com", "you@test2.com", "", "", "");
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);
assertNull(repo.get(context, "12345"));
final Exchange completedExchange = repo.recover(context, exchange.getExchangeId());
assertNotNull(completedExchange);
final Collection<Tx> retrievedTxs = (Collection<Tx>) completedExchange.getIn().getBody();
assertEquals(2, retrievedTxs.size());
assertEquals("12345", retrievedTxs.iterator().next().getDetail(TxDetailType.MSG_ID).getDetailValue());
}
use of org.nhindirect.monitor.aggregator.repository.ConcurrentJPAAggregationRepository in project nhin-d by DirectProject.
the class ConcurrentJPAAggregationRepository_scanTest method testScan_singleEntryInRepository_assertSingleKey.
@Test
public void testScan_singleEntryInRepository_assertSingleKey() {
final Tx tx1 = TestUtils.makeMessage(TxMessageType.IMF, "12345", "", "me@test.com", "you@test.com", "", "", "");
final Tx tx2 = TestUtils.makeMessage(TxMessageType.IMF, "67890", "", "me@test2.com", "you@test2.com", "", "", "");
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());
}
use of org.nhindirect.monitor.aggregator.repository.ConcurrentJPAAggregationRepository in project nhin-d by DirectProject.
the class ConcurrentJPAAggregationRepository_scanTest method testScan_nullKeys_assertEmptySet.
@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());
}
use of org.nhindirect.monitor.aggregator.repository.ConcurrentJPAAggregationRepository in project nhin-d by DirectProject.
the class ConcurrentJPAAggregationRepository_addTest method testAdd_existingExchange_invalidVersion_assertExchangeAdded.
@Test
public void testAdd_existingExchange_invalidVersion_assertExchangeAdded() {
final Tx tx = TestUtils.makeMessage(TxMessageType.IMF, "12345", "", "me@test.com", "you@test.com", "", "", "");
final Exchange exchange = new DefaultExchange(context);
exchange.getIn().setBody(tx);
final ConcurrentJPAAggregationRepository repo = new ConcurrentJPAAggregationRepository();
repo.setAggreationDAO(notifDao);
repo.add(context, "12345", exchange);
// now try to update it
Exchange retrievedEx = repo.get(context, "12345");
final Tx tx1 = TestUtils.makeMessage(TxMessageType.IMF, "12345", "", "me@test.com", "you@test.com", "", "", "");
final Tx tx2 = TestUtils.makeMessage(TxMessageType.IMF, "67890", "", "me@test2.com", "you@test2.com", "", "", "");
final Collection<Tx> txs = Arrays.asList(tx1, tx2);
retrievedEx.getIn().setBody(txs);
retrievedEx.setProperty(ConcurrentJPAAggregationRepository.AGGREGATION_ENTITY_VERSON, 35);
boolean exceptionOccured = false;
try {
repo.add(context, "12345", retrievedEx);
} catch (RuntimeException e) {
exceptionOccured = true;
}
assertTrue(exceptionOccured);
// make sure id didn't change
final Exchange ex = repo.get(context, "12345");
assertNotNull(ex);
final Tx retrievedTx = (Tx) ex.getIn().getBody();
assertEquals("12345", retrievedTx.getDetail(TxDetailType.MSG_ID).getDetailValue());
final Integer version = (Integer) ex.getProperty(ConcurrentJPAAggregationRepository.AGGREGATION_ENTITY_VERSON);
assertEquals(1, version.intValue());
}
use of org.nhindirect.monitor.aggregator.repository.ConcurrentJPAAggregationRepository in project nhin-d by DirectProject.
the class ConcurrentJPAAggregationRepository_addTest method testAdd_emptyRepository_addExchangeWithTxBody_assertExchangeAdded.
@Test
public void testAdd_emptyRepository_addExchangeWithTxBody_assertExchangeAdded() {
final Tx tx = TestUtils.makeMessage(TxMessageType.IMF, "12345", "", "me@test.com", "you@test.com", "", "", "");
final Exchange exchange = new DefaultExchange(context);
exchange.getIn().setBody(tx);
final ConcurrentJPAAggregationRepository repo = new ConcurrentJPAAggregationRepository(notifDao);
repo.add(context, "12345", exchange);
final Exchange ex = repo.get(context, "12345");
assertNotNull(ex);
final Tx retrievedTx = (Tx) ex.getIn().getBody();
assertEquals("12345", retrievedTx.getDetail(TxDetailType.MSG_ID).getDetailValue());
final Integer version = (Integer) ex.getProperty(ConcurrentJPAAggregationRepository.AGGREGATION_ENTITY_VERSON);
assertEquals(1, version.intValue());
}
Aggregations