[java-metadata-aggregator] 01/02: MDA-191 - use java.time.Instant instead of Joda-Time DateTime

Ian Young ian at iay.org.uk
Wed Jan 31 12:39:55 EST 2018


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

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

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

commit c225de7f0f307a42e542f5195d754f796afe6053
Author: Ian Young <ian at iay.org.uk>
AuthorDate: Wed Jan 31 17:39:08 2018 +0000

    MDA-191 - use java.time.Instant instead of Joda-Time DateTime
---
 aggregator-pipeline/pom.xml                        |  4 --
 .../metadata/pipeline/ComponentInfo.java           | 23 +++++----
 .../metadata/pipeline/ComponentInfoTest.java       | 54 ++++++++++++++++++++++
 3 files changed, 65 insertions(+), 16 deletions(-)

diff --git a/aggregator-pipeline/pom.xml b/aggregator-pipeline/pom.xml
index 8d85928..f90b111 100644
--- a/aggregator-pipeline/pom.xml
+++ b/aggregator-pipeline/pom.xml
@@ -35,10 +35,6 @@
             <artifactId>cryptacular</artifactId>
         </dependency>
         <dependency>
-            <groupId>joda-time</groupId>
-            <artifactId>joda-time</artifactId>
-        </dependency>
-        <dependency>
             <groupId>net.shibboleth.utilities</groupId>
             <artifactId>java-support</artifactId>
         </dependency>
diff --git a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/pipeline/ComponentInfo.java b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/pipeline/ComponentInfo.java
index e957dcf..06fa5ff 100644
--- a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/pipeline/ComponentInfo.java
+++ b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/pipeline/ComponentInfo.java
@@ -17,6 +17,8 @@
 
 package net.shibboleth.metadata.pipeline;
 
+import java.time.Instant;
+
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 
@@ -25,9 +27,6 @@ import net.shibboleth.utilities.java.support.component.IdentifiedComponent;
 import net.shibboleth.utilities.java.support.logic.Constraint;
 import net.shibboleth.utilities.java.support.primitive.StringSupport;
 
-import org.joda.time.DateTime;
-import org.joda.time.chrono.ISOChronology;
-
 /** Some basic information related to a component's processing of an {@link net.shibboleth.metadata.Item}. */
 public class ComponentInfo implements ItemMetadata {
 
@@ -41,10 +40,10 @@ public class ComponentInfo implements ItemMetadata {
     private Class<?> componentType;
 
     /** Instant when the component operation started. */
-    private DateTime startInstant;
+    private Instant startInstant;
 
     /** Instant when the component operation completed. */
-    private DateTime completeInstant;
+    private Instant completeInstant;
 
     /** Constructor. */
     public ComponentInfo() {
@@ -60,7 +59,7 @@ public class ComponentInfo implements ItemMetadata {
         Constraint.isNotNull(component, "Component can not be null");
         componentId = component.getId();
         componentType = component.getClass();
-        startInstant = new DateTime(ISOChronology.getInstanceUTC());
+        startInstant = Instant.now();
     }
 
     /**
@@ -104,7 +103,7 @@ public class ComponentInfo implements ItemMetadata {
      * 
      * @return instant when the component operation started
      */
-    @Nullable public DateTime getStartInstant() {
+    @Nullable public Instant getStartInstant() {
         return startInstant;
     }
 
@@ -113,7 +112,7 @@ public class ComponentInfo implements ItemMetadata {
      * 
      * @param instant instant when the component operation started
      */
-    public void setStartInstant(@Nullable final DateTime instant) {
+    public void setStartInstant(@Nullable final Instant instant) {
         startInstant = instant;
     }
 
@@ -122,13 +121,13 @@ public class ComponentInfo implements ItemMetadata {
      * 
      * @return instant when the component operation completed
      */
-    @Nullable public DateTime getCompleteInstant() {
+    @Nullable public Instant getCompleteInstant() {
         return completeInstant;
     }
 
     /** Sets the complete instant of the component to now. */
     public void setCompleteInstant() {
-        completeInstant = new DateTime(ISOChronology.getInstanceUTC());
+        completeInstant = Instant.now();
     }
 
     /**
@@ -136,7 +135,7 @@ public class ComponentInfo implements ItemMetadata {
      * 
      * @param instant when the component operation completed
      */
-    public void setCompleteInstant(@Nullable final DateTime instant) {
+    public void setCompleteInstant(@Nullable final Instant instant) {
         completeInstant = instant;
     }
-}
\ No newline at end of file
+}
diff --git a/aggregator-pipeline/src/test/java/net/shibboleth/metadata/pipeline/ComponentInfoTest.java b/aggregator-pipeline/src/test/java/net/shibboleth/metadata/pipeline/ComponentInfoTest.java
new file mode 100644
index 0000000..e6e20f0
--- /dev/null
+++ b/aggregator-pipeline/src/test/java/net/shibboleth/metadata/pipeline/ComponentInfoTest.java
@@ -0,0 +1,54 @@
+
+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 ComponentInfoTest {
+
+    @Test
+    public void testBasicOperation() throws Exception {
+        final Item<String> item = new MockItem("test");
+        final List<Item<String>> items = new ArrayList<>();
+        items.add(item);
+        final CompositeStage<String> comp1 = new CompositeStage<>();
+        comp1.setId("comp1");
+        comp1.initialize();
+        final CompositeStage<String> comp2 = new CompositeStage<>();
+        comp2.setId("comp2");
+        comp2.initialize();
+        final List<Stage<String>> stages = new ArrayList<>();
+        stages.add(comp1);
+        stages.add(comp2);
+        final SimplePipeline<String> pipe = new SimplePipeline<>();
+        pipe.setId("pipe");
+        pipe.setStages(stages);
+        pipe.initialize();
+        pipe.execute(items);
+        final List<ComponentInfo> infos = item.getItemMetadata().get(ComponentInfo.class);
+        // expect one for each CompositeStage and one for the SimplePipeline
+        Assert.assertEquals(infos.size(), 3);
+
+        Assert.assertSame(infos.get(0).getComponentType(), CompositeStage.class, "0");
+        Assert.assertEquals(infos.get(0).getComponentId(), "comp1", "0");
+
+        Assert.assertSame(infos.get(1).getComponentType(), CompositeStage.class, "1");
+        Assert.assertEquals(infos.get(1).getComponentId(), "comp2", "1");
+
+        Assert.assertSame(infos.get(2).getComponentType(), SimplePipeline.class, "2");
+        Assert.assertEquals(infos.get(2).getComponentId(), "pipe", "2");
+
+        // Check that we're getting ISO 8601 Z time out from toString
+        for (final ComponentInfo c : infos) {
+            Assert.assertTrue(c.getStartInstant().toString().matches("\\d\\d\\d\\d-\\d\\d-\\d\\dT.*Z"), "start");
+            Assert.assertTrue(c.getCompleteInstant().toString().matches("\\d\\d\\d\\d-\\d\\d-\\d\\dT.*Z"), "complete");
+        }
+    }
+
+}

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


More information about the commits mailing list