From 8b809a5f5d9a7bfc22e1768c12a909941364debf Mon Sep 17 00:00:00 2001 From: Daniel Serkowski Date: Fri, 15 Dec 2017 15:08:09 +0100 Subject: [PATCH] SYNCT-71: Added test for new logic in SyncAuditService --- .../api/impl/SyncAuditServiceImplTest.java | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/api/src/test/java/org/openmrs/module/sync2/api/impl/SyncAuditServiceImplTest.java b/api/src/test/java/org/openmrs/module/sync2/api/impl/SyncAuditServiceImplTest.java index 2bf42e26..49b2b209 100644 --- a/api/src/test/java/org/openmrs/module/sync2/api/impl/SyncAuditServiceImplTest.java +++ b/api/src/test/java/org/openmrs/module/sync2/api/impl/SyncAuditServiceImplTest.java @@ -138,6 +138,64 @@ public void saveSuccessfulAudit_shouldNotSave() { Assert.assertNull(fetched); } + + @Test + public void saveAuditMessage_shouldSaveSuccessfulAudit() { + AuditMessage auditMessage = new AuditMessage(); + auditMessage.setSuccess(true); + + when(dao.saveItem(any())).thenReturn(auditMessage); + when(configurationService.getSyncConfiguration().getGeneral().isPersistSuccessAudit()).thenReturn(true); + when(configurationService.getSyncConfiguration().getGeneral().isPersistFailureAudit()).thenReturn(false); + + AuditMessage fetched = auditService.saveAuditMessage(auditMessage); + + Assert.assertEquals(auditMessage, fetched); + } + + @Test + public void saveAuditMessage_shouldNotSaveSuccessfulAudit() { + AuditMessage auditMessage = new AuditMessage(); + auditMessage.setSuccess(true); + + + when(dao.saveItem(any())).thenReturn(auditMessage); + when(configurationService.getSyncConfiguration().getGeneral().isPersistSuccessAudit()).thenReturn(false); + when(configurationService.getSyncConfiguration().getGeneral().isPersistFailureAudit()).thenReturn(false); + + AuditMessage fetched = auditService.saveAuditMessage(auditMessage); + + Assert.assertNull(fetched); + } + + @Test + public void saveAuditMessage_shouldSaveFailureAudit() { + AuditMessage auditMessage = new AuditMessage(); + auditMessage.setSuccess(false); + + when(dao.saveItem(any())).thenReturn(auditMessage); + when(configurationService.getSyncConfiguration().getGeneral().isPersistSuccessAudit()).thenReturn(false); + when(configurationService.getSyncConfiguration().getGeneral().isPersistFailureAudit()).thenReturn(true); + + AuditMessage fetched = auditService.saveAuditMessage(auditMessage); + + Assert.assertEquals(auditMessage, fetched); + } + + @Test + public void saveAuditMessage_shouldNotSaveFailureAudit() { + AuditMessage auditMessage = new AuditMessage(); + auditMessage.setSuccess(false); + + + when(dao.saveItem(any())).thenReturn(auditMessage); + when(configurationService.getSyncConfiguration().getGeneral().isPersistSuccessAudit()).thenReturn(false); + when(configurationService.getSyncConfiguration().getGeneral().isPersistFailureAudit()).thenReturn(false); + + AuditMessage fetched = auditService.saveAuditMessage(auditMessage); + + Assert.assertNull(fetched); + } private AuditMessage prepareAuditMessage(Boolean success) throws ParseException { AuditMessage newMessage = new AuditMessage();