-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed parsing of timestamp in the TCK
- sometimes the date or time is truncated, which makes problems to JAXB. Signed-off-by: David Matějček <david.matejcek@omnifish.ee>
- Loading branch information
Showing
5 changed files
with
160 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...s/tck/tck-runner/src/main/java/org/glassfish/main/tests/tck/ant/xml/TimestampAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright (c) 2022 Eclipse Foundation and/or its affiliates. All rights reserved. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0, which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the | ||
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License, | ||
* version 2 with the GNU Classpath Exception, which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
*/ | ||
|
||
package org.glassfish.main.tests.tck.ant.xml; | ||
|
||
import jakarta.xml.bind.annotation.adapters.XmlAdapter; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import java.time.ZoneId; | ||
import java.time.ZonedDateTime; | ||
import java.util.regex.Pattern; | ||
|
||
/** | ||
* @author David Matejcek | ||
*/ | ||
public class TimestampAdapter extends XmlAdapter<String, LocalDateTime> { | ||
private static final Pattern P_LDT = Pattern.compile("[0-9T:\\-.]+"); | ||
|
||
@Override | ||
public LocalDateTime unmarshal(final String value) { | ||
if (value == null) { | ||
return null; | ||
} | ||
if (value.length() < 11) { | ||
return LocalDate.parse(value).atStartOfDay(); | ||
} | ||
if (P_LDT.matcher(value).matches()) { | ||
return LocalDateTime.parse(value); | ||
} | ||
return ZonedDateTime.parse(value).withZoneSameLocal(ZoneId.systemDefault()).toLocalDateTime(); | ||
} | ||
|
||
|
||
@Override | ||
public String marshal(final LocalDateTime value) { | ||
return value == null ? null : value.toString(); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
appserver/tests/tck/tck-runner/src/main/resources/junit-results.xjb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright (c) 2022 Contributors to the Eclipse Foundation. All rights reserved. | ||
This program and the accompanying materials are made available under the | ||
terms of the Eclipse Public License v. 2.0, which is available at | ||
http://www.eclipse.org/legal/epl-2.0. | ||
This Source Code may also be made available under the following Secondary | ||
Licenses when the conditions for such availability set forth in the | ||
Eclipse Public License v. 2.0 are satisfied: GNU General Public License, | ||
version 2 with the GNU Classpath Exception, which is available at | ||
https://www.gnu.org/software/classpath/license.html. | ||
SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
--> | ||
<!-- | ||
Note that this XSD file reflects just TCK results and should not be used to parse generic JUnit reports. | ||
--> | ||
<jaxb:bindings | ||
xmlns:xsd="http://www.w3.org/2001/XMLSchema" | ||
xmlns:jaxb="https://jakarta.ee/xml/ns/jaxb" | ||
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" | ||
version="3.0" | ||
> | ||
<jaxb:bindings schemaLocation="junit-results.xsd" node="/xsd:schema"> | ||
<jaxb:bindings node="//xsd:element[@name='testsuite']/xsd:complexType/xsd:attribute[@name='timestamp']"> | ||
<jaxb:property> | ||
<jaxb:baseType> | ||
<xjc:javaType | ||
name="java.time.LocalDateTime" | ||
adapter="org.glassfish.main.tests.tck.ant.xml.TimestampAdapter" | ||
/> | ||
</jaxb:baseType> | ||
</jaxb:property> | ||
</jaxb:bindings> | ||
</jaxb:bindings> | ||
</jaxb:bindings> |
64 changes: 64 additions & 0 deletions
64
...k/tck-runner/src/test/java/org/glassfish/main/tests/tck/ant/xml/TimestampAdapterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright (c) 2022 Eclipse Foundation and/or its affiliates. All rights reserved. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0, which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the | ||
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License, | ||
* version 2 with the GNU Classpath Exception, which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
*/ | ||
|
||
package org.glassfish.main.tests.tck.ant.xml; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import java.time.OffsetDateTime; | ||
import java.time.ZoneId; | ||
import java.time.ZoneOffset; | ||
import java.time.ZonedDateTime; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertAll; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
|
||
/** | ||
* @author David Matejcek | ||
*/ | ||
public class TimestampAdapterTest { | ||
|
||
private final TimestampAdapter adapter = new TimestampAdapter(); | ||
|
||
@Test | ||
public void unmarshall() { | ||
LocalDateTime now = LocalDateTime.now(); | ||
LocalDate today = now.toLocalDate(); | ||
ZonedDateTime zoned = now.atZone(ZoneId.systemDefault()); | ||
OffsetDateTime offsetNow = now.atOffset(ZoneOffset.of("+05:00")); | ||
assertAll( | ||
() -> assertEquals(now, adapter.unmarshal(now.toString())), | ||
() -> assertEquals(now, adapter.unmarshal(offsetNow.toString())), | ||
() -> assertEquals(now, adapter.unmarshal(zoned.toString())), | ||
() -> assertEquals(today.atStartOfDay(), adapter.unmarshal(today.toString())), | ||
() -> assertEquals(LocalDateTime.of(2022, 9, 20, 10, 42, 0), adapter.unmarshal("2022-09-20T10:42")), | ||
() -> assertNull(adapter.unmarshal(null)) | ||
); | ||
} | ||
|
||
|
||
@Test | ||
public void marshall() { | ||
LocalDateTime now = LocalDateTime.now(); | ||
assertAll( | ||
() -> assertEquals(now.toString(), adapter.marshal(now)), | ||
() -> assertNull(adapter.marshal(null)) | ||
); | ||
} | ||
} |