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

Ian Young ian at iay.org.uk
Wed Aug 26 16:49:36 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=5dc1da7af17f61a7a1d635e9fd8f9c87f71c2bdd

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

commit 5dc1da7af17f61a7a1d635e9fd8f9c87f71c2bdd
Author: Ian Young <ian at iay.org.uk>
AuthorDate: Wed Aug 26 17:49:24 2020 +0100

    MDA-65 - Catch up on unit tests
    
    https://issues.shibboleth.net/jira/browse/MDA-65
---
 .../java/net/shibboleth/metadata/TestMarker.java   | 50 +++++++++++++++
 .../metadata/pipeline/CompositeStageTest.java      | 75 ++++++++++++++++++++++
 .../shibboleth/metadata/pipeline/MarkerStage.java  | 33 ++++++++++
 .../metadata/pipeline/SimplePipelineTest.java      |  2 +-
 .../pipeline/StaticItemSourceStageTest.java        | 33 ++++++++++
 5 files changed, 192 insertions(+), 1 deletion(-)

diff --git a/aggregator-pipeline/src/test/java/net/shibboleth/metadata/TestMarker.java b/aggregator-pipeline/src/test/java/net/shibboleth/metadata/TestMarker.java
new file mode 100644
index 0000000..8104091
--- /dev/null
+++ b/aggregator-pipeline/src/test/java/net/shibboleth/metadata/TestMarker.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements.  See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID licenses this file to You under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.shibboleth.metadata;
+
+import javax.annotation.Nonnull;
+import javax.annotation.concurrent.Immutable;
+
+import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
+import net.shibboleth.utilities.java.support.logic.Constraint;
+import net.shibboleth.utilities.java.support.primitive.StringSupport;
+
+/** A {@link ItemMetadata} that can be used as a marker in tests. */
+ at Immutable
+public class TestMarker implements ItemMetadata {
+
+    @Nonnull @NotEmpty private final String marker;
+
+    /**
+     * Constructor.
+     * 
+     * @param mark a marker for an item, must not be either null or empty
+     */
+    public TestMarker(@Nonnull @NotEmpty final String mark) {
+        marker = Constraint.isNotNull(StringSupport.trimOrNull(mark), "marker may not be null or empty");
+    }
+
+    /**
+     * Gets the tag for the item.
+     * 
+     * @return tag for the item, never null or empty
+     */
+    @Nonnull @NotEmpty public String getMarker() {
+        return marker;
+    }
+}
diff --git a/aggregator-pipeline/src/test/java/net/shibboleth/metadata/pipeline/CompositeStageTest.java b/aggregator-pipeline/src/test/java/net/shibboleth/metadata/pipeline/CompositeStageTest.java
new file mode 100644
index 0000000..283e7d4
--- /dev/null
+++ b/aggregator-pipeline/src/test/java/net/shibboleth/metadata/pipeline/CompositeStageTest.java
@@ -0,0 +1,75 @@
+
+package net.shibboleth.metadata.pipeline;
+
+import java.util.List;
+
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import net.shibboleth.metadata.Item;
+import net.shibboleth.metadata.MockItem;
+import net.shibboleth.metadata.TestMarker;
+
+public class CompositeStageTest {
+
+    @Test
+    public void doExecute0Test() throws Exception {
+        final var stage = new CompositeStage<String>();
+        stage.setId("test");
+        stage.initialize();
+        Assert.assertEquals(stage.getComposedStages().size(), 0);
+        
+        final var items = List.<Item<String>>of(new MockItem("hello"));
+        stage.execute(items);
+        Assert.assertEquals(items.size(), 1);
+        // No stages --> no errors added
+        Assert.assertEquals(items.get(0).getItemMetadata().get(TestMarker.class).size(), 0);
+    }
+
+    @Test
+    public void doExecute1Test() throws Exception {
+        final var marker = new MarkerStage<String>();
+        marker.setId("marker");
+        marker.initialize();
+
+        final var stage = new CompositeStage<String>();
+        stage.setId("test");
+        stage.setComposedStages(List.of(marker));
+        stage.initialize();
+        Assert.assertEquals(stage.getComposedStages().size(), 1);
+
+        final var items = List.<Item<String>>of(new MockItem("hello"));
+        stage.execute(items);
+        Assert.assertEquals(items.size(), 1);
+        // One stage --> one error added
+        Assert.assertEquals(items.get(0).getItemMetadata().get(TestMarker.class).size(), 1);
+    }
+
+    @Test
+    public void doExecute2Test() throws Exception {
+        final var marker = new MarkerStage<String>();
+        marker.setId("marker");
+        marker.initialize();
+
+        final var stage = new CompositeStage<String>();
+        stage.setId("test");
+        stage.setComposedStages(List.of(marker, marker));
+        stage.initialize();
+        Assert.assertEquals(stage.getComposedStages().size(), 2);
+
+        final var items = List.<Item<String>>of(new MockItem("hello"));
+        stage.execute(items);
+        Assert.assertEquals(items.size(), 1);
+        // Two stages --> two errors added
+        Assert.assertEquals(items.get(0).getItemMetadata().get(TestMarker.class).size(), 2);
+    }
+
+    @Test
+    public void doDestroyTest() throws Exception {
+        final var stage = new CompositeStage<String>();
+        stage.setId("test");
+        stage.initialize();
+        stage.destroy();
+    }
+
+}
diff --git a/aggregator-pipeline/src/test/java/net/shibboleth/metadata/pipeline/MarkerStage.java b/aggregator-pipeline/src/test/java/net/shibboleth/metadata/pipeline/MarkerStage.java
new file mode 100644
index 0000000..06cae12
--- /dev/null
+++ b/aggregator-pipeline/src/test/java/net/shibboleth/metadata/pipeline/MarkerStage.java
@@ -0,0 +1,33 @@
+package net.shibboleth.metadata.pipeline;
+
+import javax.annotation.concurrent.GuardedBy;
+import javax.annotation.concurrent.ThreadSafe;
+
+import net.shibboleth.metadata.Item;
+import net.shibboleth.metadata.TestMarker;
+
+/**
+ * A stage which adds a sequentially numbered {link @TestMarker} to item metadata.
+ * 
+ * <p>
+ * An instance of this class applies a <em>different</em> marker every time
+ * it is applied to an item.
+ * </p>
+ *
+ * @param <T> type of item to be processed by the stage
+ */
+ at ThreadSafe
+public class MarkerStage<T> extends AbstractIteratingStage<T> {
+
+    @GuardedBy("this") private int sequence = 1;
+    
+    private final synchronized String nextMessage() {
+        return "marker #" + sequence++;
+    }
+
+    @Override
+    protected void doExecute(Item<T> item) throws StageProcessingException {
+        item.getItemMetadata().put(new TestMarker(nextMessage()));
+    }
+
+}
diff --git a/aggregator-pipeline/src/test/java/net/shibboleth/metadata/pipeline/SimplePipelineTest.java b/aggregator-pipeline/src/test/java/net/shibboleth/metadata/pipeline/SimplePipelineTest.java
index 288547f..2fe83af 100644
--- a/aggregator-pipeline/src/test/java/net/shibboleth/metadata/pipeline/SimplePipelineTest.java
+++ b/aggregator-pipeline/src/test/java/net/shibboleth/metadata/pipeline/SimplePipelineTest.java
@@ -127,4 +127,4 @@ public class SimplePipelineTest {
         list.add(stage2);
         return list;
     }
-}
\ No newline at end of file
+}
diff --git a/aggregator-pipeline/src/test/java/net/shibboleth/metadata/pipeline/StaticItemSourceStageTest.java b/aggregator-pipeline/src/test/java/net/shibboleth/metadata/pipeline/StaticItemSourceStageTest.java
new file mode 100644
index 0000000..b9a1a8e
--- /dev/null
+++ b/aggregator-pipeline/src/test/java/net/shibboleth/metadata/pipeline/StaticItemSourceStageTest.java
@@ -0,0 +1,33 @@
+
+package net.shibboleth.metadata.pipeline;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import net.shibboleth.metadata.Item;
+import net.shibboleth.metadata.MockItem;
+
+public class StaticItemSourceStageTest {
+    
+    @Test
+    public void testExecute() throws Exception {
+        final var stage = new StaticItemSourceStage<String>();
+        stage.setId("test");
+        stage.setSourceItems(List.of(new MockItem("one"), new MockItem("two")));
+        stage.initialize();
+        final var items = new ArrayList<Item<String>>();
+        stage.execute(items);
+        Assert.assertEquals(items.size(), 2);
+    }
+    
+    @Test
+    public void testDestroy() throws Exception {
+        final var stage = new StaticItemSourceStage<String>();
+        stage.setId("test");
+        stage.initialize();
+        stage.destroy();
+    }
+}

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


More information about the commits mailing list