OrientKeyStoreDataEntityAdapter extends IterableEntityAdapter<OrientKeyStoreData> { @Nullable @Override public EntityEvent newEvent(final ODocument document, final EventKind eventKind) { EntityMetadata metadata = new AttachedEntityMetadata(this, document); String name = document.field(P_NAME); EntityEvent event; switch (eventKind) { case CREATE: event = new OrientKeyStoreDataCreatedEvent(metadata, name); break; case UPDATE: event = new OrientKeyStoreDataUpdatedEvent(metadata, name); break; default: event = null; } if (event != null) { log.debug("Emitted {} event for key store {} with metadata {}", eventKind, name, metadata); } return event; } OrientKeyStoreDataEntityAdapter(); @Nullable OrientKeyStoreData load(final ODatabaseDocumentTx db, final String name); void save(final ODatabaseDocumentTx db, final OrientKeyStoreData entity); @Override boolean sendEvents(); @Nullable @Override EntityEvent newEvent(final ODocument document, final EventKind eventKind);  }
@Test public void testNewEvent_Create() { try (ODatabaseDocumentTx db = database.getInstance().connect()) { entityAdapter.register(db); OrientKeyStoreData entity = new OrientKeyStoreData(); entity.setName(KEY_STORE_NAME); entity.setBytes(KEY_STORE_DATA); ODocument document = entityAdapter.addEntity(db, entity); EntityEvent event = entityAdapter.newEvent(document, EventKind.CREATE); assertThat(event, is(instanceOf(OrientKeyStoreDataCreatedEvent.class))); assertThat(((KeyStoreDataEvent) event).getKeyStoreName(), is(KEY_STORE_NAME)); } }
@Test public void testNewEvent_Update() { try (ODatabaseDocumentTx db = database.getInstance().connect()) { entityAdapter.register(db); OrientKeyStoreData entity = new OrientKeyStoreData(); entity.setName(KEY_STORE_NAME); entity.setBytes(KEY_STORE_DATA); ODocument document = entityAdapter.addEntity(db, entity); EntityEvent event = entityAdapter.newEvent(document, EventKind.UPDATE); assertThat(event, is(instanceOf(OrientKeyStoreDataUpdatedEvent.class))); assertThat(((KeyStoreDataEvent) event).getKeyStoreName(), is(KEY_STORE_NAME)); } }
@Test public void testNewEvent_Delete() { try (ODatabaseDocumentTx db = database.getInstance().connect()) { entityAdapter.register(db); OrientKeyStoreData entity = new OrientKeyStoreData(); entity.setName(KEY_STORE_NAME); entity.setBytes(KEY_STORE_DATA); ODocument document = entityAdapter.addEntity(db, entity); EntityEvent event = entityAdapter.newEvent(document, EventKind.DELETE); assertThat(event, is(nullValue())); } }