[java-metadata-aggregator] branch main updated: MDA-65 - Catch up on unit tests

Ian Young ian at iay.org.uk
Thu Aug 27 16:18:47 UTC 2020


This is an automated email from the git hooks/post-receive script.

iay pushed a commit to branch main
in repository java-metadata-aggregator.

View the commit online:
http://git.shibboleth.net/view/?p=java-metadata-aggregator.git;a=commit;h=89aefba4accd5f1c714549e66e89fc5093da10be

The following commit(s) were added to refs/heads/main by this push:
       new  89aefba   MDA-65 - Catch up on unit tests
89aefba is described below

commit 89aefba4accd5f1c714549e66e89fc5093da10be
Author: Ian Young <ian at iay.org.uk>
AuthorDate: Thu Aug 27 17:18:43 2020 +0100

    MDA-65 - Catch up on unit tests
    
    https://issues.shibboleth.net/jira/browse/MDA-65
---
 .../metadata/pipeline/SerializationStage.java      | 17 +++---
 .../metadata/pipeline/SerializationStageTest.java  | 67 ++++++++++++++++++++++
 2 files changed, 76 insertions(+), 8 deletions(-)

diff --git a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/pipeline/SerializationStage.java b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/pipeline/SerializationStage.java
index 109b19f..06708cd 100644
--- a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/pipeline/SerializationStage.java
+++ b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/pipeline/SerializationStage.java
@@ -136,14 +136,6 @@ public class SerializationStage<T> extends AbstractStage<T> {
         }
     }
 
-    @Override
-    protected void doDestroy() {
-        outputFile = null;
-        serializer = null;
-
-        super.doDestroy();
-    }
-
     @Override
     protected void doInitialize() throws ComponentInitializationException {
         super.doInitialize();
@@ -184,4 +176,13 @@ public class SerializationStage<T> extends AbstractStage<T> {
         }
 
     }
+
+    @Override
+    protected void doDestroy() {
+        outputFile = null;
+        serializer = null;
+
+        super.doDestroy();
+    }
+
 }
diff --git a/aggregator-pipeline/src/test/java/net/shibboleth/metadata/pipeline/SerializationStageTest.java b/aggregator-pipeline/src/test/java/net/shibboleth/metadata/pipeline/SerializationStageTest.java
new file mode 100644
index 0000000..e1f8de3
--- /dev/null
+++ b/aggregator-pipeline/src/test/java/net/shibboleth/metadata/pipeline/SerializationStageTest.java
@@ -0,0 +1,67 @@
+
+package net.shibboleth.metadata.pipeline;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.util.Collection;
+import java.util.List;
+
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import net.shibboleth.metadata.Item;
+import net.shibboleth.metadata.ItemCollectionSerializer;
+import net.shibboleth.metadata.MockItem;
+import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
+
+public class SerializationStageTest {
+    
+    private static class StringSerializer implements ItemCollectionSerializer<String> {
+
+        public void serializeCollection(Collection<Item<String>> items, OutputStream output) throws IOException {
+            for (final var item : items) {
+                output.write(item.unwrap().getBytes(StandardCharsets.UTF_8));
+                output.write('\n');
+            }
+        }
+
+    }
+    
+    @Test
+    public void testNormal() throws Exception {
+        // Create the output file. Note that the default is to be able to
+        // overwrite the output file even if it exists, so that's fine.
+        final var file = File.createTempFile("testNormal", null);
+        final var path = file.toPath();
+
+        try {
+            final var stage = new SerializationStage<String>();
+            stage.setId("test");
+            stage.setOutputFile(file);
+            stage.setSerializer(new StringSerializer());
+            stage.initialize();
+            
+            stage.execute(List.of(new MockItem("one"), new MockItem("two")));
+
+            // Read the file back in.
+            var text = Files.readString(path);
+            Assert.assertEquals(text, "one\ntwo\n");
+            
+            stage.destroy();
+        } finally {
+            Files.delete(path);
+        }
+
+    }
+    
+    @Test(expectedExceptions= {ComponentInitializationException.class})
+    public void testNoFile() throws Exception {
+        final var stage = new SerializationStage<String>();
+        stage.setId("test");
+        stage.setSerializer(new StringSerializer());
+        stage.initialize();
+    }
+}

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list