[java-metadata-aggregator] branch main updated: Add a readBytes() helper to BaseTest

Ian Young ian at iay.org.uk
Wed Sep 2 12:40:17 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=614d34bfdbc4056d23bb4137ea4a569aa9d5d426

The following commit(s) were added to refs/heads/main by this push:
       new  614d34b   Add a readBytes() helper to BaseTest
614d34b is described below

commit 614d34bfdbc4056d23bb4137ea4a569aa9d5d426
Author: Ian Young <ian at iay.org.uk>
AuthorDate: Wed Sep 2 13:40:13 2020 +0100

    Add a readBytes() helper to BaseTest
---
 .../java/net/shibboleth/metadata/BaseTest.java     | 20 ++++++++++++++++++
 .../java/net/shibboleth/metadata/BaseTestTest.java | 24 ++++++++++++++++++++++
 .../net/shibboleth/metadata/BaseTest-bytes.txt     |  1 +
 3 files changed, 45 insertions(+)

diff --git a/aggregator-pipeline/src/test/java/net/shibboleth/metadata/BaseTest.java b/aggregator-pipeline/src/test/java/net/shibboleth/metadata/BaseTest.java
index 50a033f..341bb61 100644
--- a/aggregator-pipeline/src/test/java/net/shibboleth/metadata/BaseTest.java
+++ b/aggregator-pipeline/src/test/java/net/shibboleth/metadata/BaseTest.java
@@ -17,6 +17,10 @@
 
 package net.shibboleth.metadata;
 
+import java.io.IOException;
+
+import javax.annotation.Nonnull;
+
 import org.springframework.core.io.ClassPathResource;
 import org.springframework.core.io.Resource;
 
@@ -107,4 +111,20 @@ public abstract class BaseTest {
         return new ClassPathResource(simpleClassRelativeName(resourcePath), testingClass);
     }
 
+    /**
+     * Read a classpath resource as an array of <code>byte</code>s.
+     *
+     * @param resourcePath classpath path to the resource
+     * 
+     * @return the resource as an array of <code>byte</code>s
+     *
+     * @throws IOException on error
+     */
+    public byte[] readBytes(@Nonnull final String resourcePath) throws IOException {
+        final var res = getClasspathResource(resourcePath);
+        try (var stream = res.getInputStream()) {
+            return stream.readAllBytes();
+        }
+    }
+
 }
diff --git a/aggregator-pipeline/src/test/java/net/shibboleth/metadata/BaseTestTest.java b/aggregator-pipeline/src/test/java/net/shibboleth/metadata/BaseTestTest.java
new file mode 100644
index 0000000..2534fdb
--- /dev/null
+++ b/aggregator-pipeline/src/test/java/net/shibboleth/metadata/BaseTestTest.java
@@ -0,0 +1,24 @@
+
+package net.shibboleth.metadata;
+
+import java.nio.charset.StandardCharsets;
+
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+public class BaseTestTest extends BaseTest {
+
+    /**
+     * Constructor.
+     */
+    protected BaseTestTest() {
+        super(BaseTest.class);
+    }
+
+    @Test
+    public void testReadBytes() throws Exception {
+        final var bytes = readBytes("bytes.txt");
+        Assert.assertEquals(bytes.length, 6);
+        Assert.assertEquals(new String(bytes, StandardCharsets.UTF_8), "hello\n");
+    }
+}
diff --git a/aggregator-pipeline/src/test/resources/net/shibboleth/metadata/BaseTest-bytes.txt b/aggregator-pipeline/src/test/resources/net/shibboleth/metadata/BaseTest-bytes.txt
new file mode 100644
index 0000000..ce01362
--- /dev/null
+++ b/aggregator-pipeline/src/test/resources/net/shibboleth/metadata/BaseTest-bytes.txt
@@ -0,0 +1 @@
+hello

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


More information about the commits mailing list