use of com.yahoo.elide.core.lifecycle.CRUDEvent in project elide by yahoo.
the class NotifyTopicLifeCycleHookTest method testManagedModelNotification.
@Test
public void testManagedModelNotification() {
NotifyTopicLifeCycleHook<Book> bookHook = new NotifyTopicLifeCycleHook<Book>(connectionFactory, JMSContext::createProducer, new GsonBuilder().create());
Book book = new Book();
PersistentResource<Book> resource = new PersistentResource<>(book, "123", scope);
bookHook.execute(LifeCycleHookBinding.Operation.CREATE, LifeCycleHookBinding.TransactionPhase.PRECOMMIT, new CRUDEvent(LifeCycleHookBinding.Operation.CREATE, resource, "", Optional.empty()));
ArgumentCaptor<String> topicCaptor = ArgumentCaptor.forClass(String.class);
verify(context).createTopic(topicCaptor.capture());
assertEquals("bookAdded", topicCaptor.getValue());
verify(producer, times(1)).send(isA(Destination.class), isA(String.class));
}
use of com.yahoo.elide.core.lifecycle.CRUDEvent in project elide by yahoo.
the class PersistentResourceTest method testUpdateComplexAttributeCloneWithHook.
@Test
public void testUpdateComplexAttributeCloneWithHook() {
reset(bookUpdatePrice);
Book book = new Book();
Price originalPrice = new Price();
originalPrice.setUnits(new BigDecimal(1.0));
originalPrice.setCurrency(Currency.getInstance("USD"));
book.setPrice(originalPrice);
Map<String, Object> newPrice = new HashMap<>();
newPrice.put("units", new BigDecimal(2.0));
newPrice.put("currency", Currency.getInstance("CNY"));
RequestScope goodScope = buildRequestScope(tx, goodUser);
PersistentResource<Book> bookResource = new PersistentResource<>(book, "1", goodScope);
bookResource.updateAttribute("price", newPrice);
// check that original value was unmodified.
assertEquals(Currency.getInstance("USD"), originalPrice.getCurrency());
assertEquals(new BigDecimal(1.0), originalPrice.getUnits());
// check that new value matches expected.
assertEquals(Currency.getInstance("CNY"), book.getPrice().getCurrency());
assertEquals(new BigDecimal(2.0), book.getPrice().getUnits());
goodScope.saveOrCreateObjects();
verify(tx, times(1)).save(book, goodScope);
ArgumentCaptor<CRUDEvent> eventCapture = ArgumentCaptor.forClass(CRUDEvent.class);
verify(bookUpdatePrice, times(1)).execute(eq(UPDATE), eq(PRESECURITY), eventCapture.capture());
assertEquals(originalPrice, eventCapture.getValue().getChanges().get().getOriginal());
assertEquals(book.getPrice(), eventCapture.getValue().getChanges().get().getModified());
}
Aggregations