summaryrefslogtreecommitdiffstats
path: root/infra/translate-impl/src/test/java/io/fd/honeycomb/translate/impl/write/GenericWriterTest.java
diff options
context:
space:
mode:
authorMarek Gradzki <mgradzki@cisco.com>2018-04-13 13:38:16 +0200
committerMarek Gradzki <mgradzki@cisco.com>2018-08-17 10:17:58 +0000
commitd1b102f6fafced3c7badb09ecc78fec590704c8a (patch)
treefb9c7041b25cdd36b46cf25e789c850db38f2349 /infra/translate-impl/src/test/java/io/fd/honeycomb/translate/impl/write/GenericWriterTest.java
parentfa641a3e06a905cb3222ebd15a2b4ab90b599efc (diff)
HONEYCOMB-431: add validation support to Writers
This patch introduces FlatWriterRegistry.validateModifications. Implementation iterates over writersOrder following bulkUpdate logic to properly support subtree writers case. Writers are now cabable of validating modifications. Commonly used implementations (GenericWriter and GenericListWriter) delegate validation capbility to Validators. Change-Id: If7a0bb0838c0b8f2c0393c989f3b03853a2ea679 Signed-off-by: Marek Gradzki <mgradzki@cisco.com>
Diffstat (limited to 'infra/translate-impl/src/test/java/io/fd/honeycomb/translate/impl/write/GenericWriterTest.java')
-rw-r--r--infra/translate-impl/src/test/java/io/fd/honeycomb/translate/impl/write/GenericWriterTest.java21
1 files changed, 19 insertions, 2 deletions
diff --git a/infra/translate-impl/src/test/java/io/fd/honeycomb/translate/impl/write/GenericWriterTest.java b/infra/translate-impl/src/test/java/io/fd/honeycomb/translate/impl/write/GenericWriterTest.java
index c9d381ad4..1c0927b89 100644
--- a/infra/translate-impl/src/test/java/io/fd/honeycomb/translate/impl/write/GenericWriterTest.java
+++ b/infra/translate-impl/src/test/java/io/fd/honeycomb/translate/impl/write/GenericWriterTest.java
@@ -23,6 +23,7 @@ import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.verify;
import io.fd.honeycomb.translate.spi.write.WriterCustomizer;
+import io.fd.honeycomb.translate.write.Validator;
import io.fd.honeycomb.translate.write.WriteContext;
import io.fd.honeycomb.translate.write.WriteFailedException;
import org.junit.Before;
@@ -40,16 +41,19 @@ public class GenericWriterTest {
private WriterCustomizer<DataObject> customizer;
@Mock
private WriteContext ctx;
- private GenericWriter<DataObject> writer;
@Mock
private DataObject before;
@Mock
private DataObject after;
+ @Mock
+ private Validator<DataObject> validator;
+
+ private GenericWriter<DataObject> writer;
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
- writer = new GenericWriter<>(DATA_OBJECT_ID, customizer);
+ writer = new GenericWriter<>(DATA_OBJECT_ID, customizer, validator);
}
@Test
@@ -94,4 +98,17 @@ public class GenericWriterTest {
assertTrue(GenericWriter.isUpdateSupported(new NoopWriters.DirectUpdateWriterCustomizer()));
assertTrue(GenericWriter.isUpdateSupported(new NoopWriters.ParentImplDirectUpdateWriterCustomizer()));
}
+
+ @Test
+ public void testValidate() throws Exception {
+ assertEquals(DATA_OBJECT_ID, writer.getManagedDataObjectType());
+ writer.validate(DATA_OBJECT_ID, before, after, ctx);
+ verify(validator).validateUpdate(DATA_OBJECT_ID, before, after, ctx);
+
+ writer.validate(DATA_OBJECT_ID, before, null, ctx);
+ verify(validator).validateDelete(DATA_OBJECT_ID, before, ctx);
+
+ writer.validate(DATA_OBJECT_ID, null, after, ctx);
+ verify(validator).validateWrite(DATA_OBJECT_ID, after, ctx);
+ }
} \ No newline at end of file