-
Notifications
You must be signed in to change notification settings - Fork 3
MODINVOSTO-216. Add old object for EDIT audit events for Invoice, Invoice Line #270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
dde3bc1
MODINVOSTO-216. Add old object for EDIT audit events for Invoice, Inv…
SerhiiNosko eed0286
MODINVOSTO-216. Add old object for EDIT audit events for Invoice, Inv…
SerhiiNosko cc8b439
MODINVOSTO-216. Code review
SerhiiNosko e876945
MODINVOSTO-216. Remove unnecessary change
SerhiiNosko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/main/java/org/folio/service/audit/AuditEntityWrapper.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package org.folio.service.audit; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Data; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Data | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| public class AuditEntityWrapper<T> { | ||
|
|
||
| private T entity; | ||
| private T originalEntity; | ||
|
|
||
| public static <T> AuditEntityWrapper<T> of(T entity, T originalEntity) { | ||
| return new AuditEntityWrapper<>(entity, originalEntity); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
src/test/java/org/folio/service/audit/AuditEventProducerTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| package org.folio.service.audit; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
| import static org.junit.jupiter.api.Assertions.assertNull; | ||
|
|
||
| import java.util.Date; | ||
| import java.util.UUID; | ||
|
|
||
| import org.folio.rest.jaxrs.model.Invoice; | ||
| import org.folio.rest.jaxrs.model.InvoiceAuditEvent; | ||
| import org.folio.rest.jaxrs.model.InvoiceLine; | ||
| import org.folio.rest.jaxrs.model.InvoiceLineAuditEvent; | ||
| import org.folio.rest.jaxrs.model.Metadata; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| class AuditEventProducerTest { | ||
|
|
||
| private final AuditEventProducer producer = new AuditEventProducer(null); | ||
|
|
||
| @Test | ||
| void invoiceEditEventCarriesOriginalSnapshot() { | ||
| var original = getInvoice("vendor-old", "Open"); | ||
| var updated = getInvoice("vendor-new", "Reviewed"); | ||
|
|
||
| InvoiceAuditEvent event = producer.getAuditEvent(updated, original, InvoiceAuditEvent.Action.EDIT); | ||
|
|
||
| assertEquals(InvoiceAuditEvent.Action.EDIT, event.getAction()); | ||
| assertNotNull(event.getInvoiceSnapshot()); | ||
| assertEquals("vendor-new", event.getInvoiceSnapshot().getVendorInvoiceNo()); | ||
| assertEquals(Invoice.Status.REVIEWED, event.getInvoiceSnapshot().getStatus()); | ||
|
|
||
| assertNotNull(event.getOriginalInvoiceSnapshot()); | ||
| assertEquals("vendor-old", event.getOriginalInvoiceSnapshot().getVendorInvoiceNo()); | ||
| assertEquals(Invoice.Status.OPEN, event.getOriginalInvoiceSnapshot().getStatus()); | ||
| } | ||
|
|
||
| @Test | ||
| void invoiceCreateEventOmitsOriginalSnapshot() { | ||
| InvoiceAuditEvent event = producer.getAuditEvent(getInvoice("v", "Open"), null, InvoiceAuditEvent.Action.CREATE); | ||
|
|
||
| assertEquals(InvoiceAuditEvent.Action.CREATE, event.getAction()); | ||
| assertNotNull(event.getInvoiceSnapshot()); | ||
| assertNull(event.getOriginalInvoiceSnapshot()); | ||
| } | ||
|
|
||
| @Test | ||
| void invoiceLineEditEventCarriesOriginalSnapshot() { | ||
| var original = getInvoiceLine("desc-old", 10d); | ||
| var updated = getInvoiceLine("desc-new", 25d); | ||
|
|
||
| InvoiceLineAuditEvent event = producer.getAuditEvent(updated, original, InvoiceLineAuditEvent.Action.EDIT); | ||
|
|
||
| assertEquals(InvoiceLineAuditEvent.Action.EDIT, event.getAction()); | ||
| assertNotNull(event.getInvoiceLineSnapshot()); | ||
| assertEquals("desc-new", event.getInvoiceLineSnapshot().getDescription()); | ||
| assertEquals(25d, event.getInvoiceLineSnapshot().getSubTotal()); | ||
|
|
||
| assertNotNull(event.getOriginalInvoiceLineSnapshot()); | ||
| assertEquals("desc-old", event.getOriginalInvoiceLineSnapshot().getDescription()); | ||
| assertEquals(10d, event.getOriginalInvoiceLineSnapshot().getSubTotal()); | ||
| } | ||
|
|
||
| @Test | ||
| void invoiceLineCreateEventOmitsOriginalSnapshot() { | ||
| InvoiceLineAuditEvent event = producer.getAuditEvent(getInvoiceLine("d", 1d), null, InvoiceLineAuditEvent.Action.CREATE); | ||
|
|
||
| assertEquals(InvoiceLineAuditEvent.Action.CREATE, event.getAction()); | ||
| assertNotNull(event.getInvoiceLineSnapshot()); | ||
| assertNull(event.getOriginalInvoiceLineSnapshot()); | ||
| } | ||
|
|
||
| private Invoice getInvoice(String vendorInvoiceNo, String status) { | ||
| return new Invoice() | ||
| .withId(UUID.randomUUID().toString()) | ||
| .withVendorInvoiceNo(vendorInvoiceNo) | ||
| .withStatus(Invoice.Status.fromValue(status)) | ||
| .withMetadata(getMetadata()); | ||
| } | ||
|
|
||
| private InvoiceLine getInvoiceLine(String description, double subTotal) { | ||
| return new InvoiceLine() | ||
| .withId(UUID.randomUUID().toString()) | ||
| .withInvoiceId(UUID.randomUUID().toString()) | ||
| .withDescription(description) | ||
| .withSubTotal(subTotal) | ||
| .withMetadata(getMetadata()); | ||
| } | ||
|
|
||
| private Metadata getMetadata() { | ||
| return new Metadata() | ||
| .withUpdatedDate(new Date()) | ||
| .withUpdatedByUserId(UUID.randomUUID().toString()); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest injecting DatabindCodec and using it for decoding, as we usually copy our serialization and deserialization config to this codec during API initialization:
AuditUtils.typeReference():There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
switched to DatabindCodec.mapper()