You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@causeway.apache.org by da...@apache.org on 2026/04/22 11:33:55 UTC

(causeway) 03/08: JDOJPA-281 : adds approval test to check marshalling of all date/time datatypes

This is an automated email from the ASF dual-hosted git repository.

danhaywood pushed a commit to branch JDOJPA-281
in repository https://gitbox.apache.org/repos/asf/causeway.git

commit b4a3acbb8254c4e2068358e0f8720a06e486dd27
Author: Dan Haywood <da...@haywood-associates.co.uk>
AuthorDate: Wed Apr 22 11:48:53 2026 +0100

    JDOJPA-281 : adds approval test to check marshalling of all date/time datatypes
---
 api/applib/pom.xml                                 |  12 ++
 .../CommandDtoUtils_toYaml_Approval_Test.java      | 129 +++++++++++++++++++++
 ...t.marshals_all_date_time_datatypes.approved.txt |  31 +++++
 3 files changed, 172 insertions(+)

diff --git a/api/applib/pom.xml b/api/applib/pom.xml
index fad7c62b386..483863a6218 100644
--- a/api/applib/pom.xml
+++ b/api/applib/pom.xml
@@ -107,6 +107,18 @@
 			<scope>test</scope>
 		</dependency>
 
+        <dependency>
+            <groupId>com.approvaltests</groupId>
+            <artifactId>approvaltests</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <!-- required by com.approvaltests:test (version managed by spring boot) -->
+            <groupId>com.google.code.gson</groupId>
+            <artifactId>gson</artifactId>
+            <scope>test</scope>
+        </dependency>
+
     </dependencies>
 
 </project>
diff --git a/api/applib/src/test/java/org/apache/causeway/applib/util/schema/CommandDtoUtils_toYaml_Approval_Test.java b/api/applib/src/test/java/org/apache/causeway/applib/util/schema/CommandDtoUtils_toYaml_Approval_Test.java
new file mode 100644
index 00000000000..b00dd2e41f0
--- /dev/null
+++ b/api/applib/src/test/java/org/apache/causeway/applib/util/schema/CommandDtoUtils_toYaml_Approval_Test.java
@@ -0,0 +1,129 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF 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 org.apache.causeway.applib.util.schema;
+
+import java.util.List;
+import java.util.TimeZone;
+
+import javax.xml.datatype.DatatypeFactory;
+import javax.xml.datatype.XMLGregorianCalendar;
+
+import org.approvaltests.Approvals;
+import org.junit.jupiter.api.Test;
+
+import org.apache.causeway.schema.cmd.v2.ActionDto;
+import org.apache.causeway.schema.cmd.v2.CommandDto;
+import org.apache.causeway.schema.cmd.v2.ParamDto;
+import org.apache.causeway.schema.cmd.v2.ParamsDto;
+import org.apache.causeway.schema.common.v2.InteractionType;
+import org.apache.causeway.schema.common.v2.OidDto;
+import org.apache.causeway.schema.common.v2.OidsDto;
+import org.apache.causeway.schema.common.v2.ValueType;
+
+class CommandDtoUtils_toYaml_Approval_Test {
+
+    private static final DatatypeFactory DATATYPE_FACTORY = datatypeFactory();
+
+    @Test
+    void marshals_all_date_time_datatypes() {
+        TimeZone originalDefault = TimeZone.getDefault();
+        TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
+        try {
+            CommandDto command = new CommandDto();
+            command.setMajorVersion("2");
+            command.setMinorVersion("0");
+            command.setInteractionId("approval-datetime-marshalling");
+            command.setUsername("approval-user");
+            command.setTargets(targets("demo.Customer", "123"));
+            command.setMember(actionWithAllDateTimeParams());
+
+            String yaml = CommandDtoUtils.toYaml(List.of(command));
+
+            Approvals.verify(yaml);
+        } finally {
+            TimeZone.setDefault(originalDefault);
+        }
+    }
+
+    private static ActionDto actionWithAllDateTimeParams() {
+        ActionDto action = new ActionDto();
+        action.setLogicalMemberIdentifier("demo.Customer#allDateTimeTypes");
+        action.setInteractionType(InteractionType.ACTION_INVOCATION);
+
+        ParamsDto params = new ParamsDto();
+        params.getParameter().add(param("Local Date", ValueType.LOCAL_DATE, "2026-07-01"));
+        params.getParameter().add(param("Local Date Time", ValueType.LOCAL_DATE_TIME, "2026-07-01T10:15:30"));
+        params.getParameter().add(param("Local Time", ValueType.LOCAL_TIME, "10:15:30"));
+        params.getParameter().add(param("Offset Date Time", ValueType.OFFSET_DATE_TIME, "2026-07-01T10:15:30+02:00"));
+        params.getParameter().add(param("Offset Time", ValueType.OFFSET_TIME, "10:15:30+02:00"));
+        params.getParameter().add(param("Zoned Date Time", ValueType.ZONED_DATE_TIME, "2026-07-01T10:15:30+02:00"));
+        action.setParameters(params);
+        return action;
+    }
+
+    private static ParamDto param(final String name, final ValueType type, final String lexicalValue) {
+        ParamDto param = new ParamDto();
+        param.setName(name);
+        param.setType(type);
+
+        XMLGregorianCalendar value = DATATYPE_FACTORY.newXMLGregorianCalendar(lexicalValue);
+        switch (type) {
+        case LOCAL_DATE:
+            param.setLocalDate(value);
+            break;
+        case LOCAL_DATE_TIME:
+            param.setLocalDateTime(value);
+            break;
+        case LOCAL_TIME:
+            param.setLocalTime(value);
+            break;
+        case OFFSET_DATE_TIME:
+            param.setOffsetDateTime(value);
+            break;
+        case OFFSET_TIME:
+            param.setOffsetTime(value);
+            break;
+        case ZONED_DATE_TIME:
+            param.setZonedDateTime(value);
+            break;
+        default:
+            throw new IllegalArgumentException("Unsupported type: " + type);
+        }
+        return param;
+    }
+
+    private static OidsDto targets(final String type, final String id) {
+        OidDto oid = new OidDto();
+        oid.setType(type);
+        oid.setId(id);
+
+        OidsDto targets = new OidsDto();
+        targets.getOid().add(oid);
+        return targets;
+    }
+
+    private static DatatypeFactory datatypeFactory() {
+        try {
+            return DatatypeFactory.newInstance();
+        } catch (Exception ex) {
+            throw new RuntimeException("Failed to initialize DatatypeFactory", ex);
+        }
+    }
+}
+
diff --git a/api/applib/src/test/java/org/apache/causeway/applib/util/schema/CommandDtoUtils_toYaml_Approval_Test.marshals_all_date_time_datatypes.approved.txt b/api/applib/src/test/java/org/apache/causeway/applib/util/schema/CommandDtoUtils_toYaml_Approval_Test.marshals_all_date_time_datatypes.approved.txt
new file mode 100644
index 00000000000..707903d93f1
--- /dev/null
+++ b/api/applib/src/test/java/org/apache/causeway/applib/util/schema/CommandDtoUtils_toYaml_Approval_Test.marshals_all_date_time_datatypes.approved.txt
@@ -0,0 +1,31 @@
+- majorVersion: "2"
+  minorVersion: "0"
+  interactionId: "approval-datetime-marshalling"
+  username: "approval-user"
+  targets:
+    oid:
+    - type: "demo.Customer"
+      id: "123"
+  member: !<ACT>
+    parameters:
+      parameter:
+      - localDate: "2026-07-01"
+        type: "localDate"
+        name: "Local Date"
+      - localDateTime: "2026-07-01T10:15:30.000+00:00"
+        type: "localDateTime"
+        name: "Local Date Time"
+      - localTime: "1970-01-01T10:15:30.000+00:00"
+        type: "localTime"
+        name: "Local Time"
+      - offsetDateTime: "2026-07-01T08:15:30.000+00:00"
+        type: "offsetDateTime"
+        name: "Offset Date Time"
+      - offsetTime: "1970-01-01T08:15:30.000+00:00"
+        type: "offsetTime"
+        name: "Offset Time"
+      - zonedDateTime: "2026-07-01T08:15:30.000+00:00"
+        type: "zonedDateTime"
+        name: "Zoned Date Time"
+    logicalMemberIdentifier: "demo.Customer#allDateTimeTypes"
+    interactionType: "action_invocation"