From f918bf020dc990afbe6075a9c881fc13493bfcff Mon Sep 17 00:00:00 2001 From: prajwolbhandari1 <147008971+prajwolbhandari1@users.noreply.github.com> Date: Fri, 22 Nov 2024 10:00:54 -0700 Subject: [PATCH] test(spin): exclude time zone from unit tests as it is hard coded (#4660) related to: https://github.com/camunda/camunda-bpm-platform/issues/4606 --- .../org/camunda/spin/xml/XmlTestUtil.java | 46 +++++++++++++++++++ .../xml/dom/XmlDomMapJavaToXmlScriptTest.java | 7 ++- .../spin/xml/dom/XmlDomMapJavaToXmlTest.java | 8 +++- 3 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 spin/dataformat-xml-dom/src/test/java/org/camunda/spin/xml/XmlTestUtil.java diff --git a/spin/dataformat-xml-dom/src/test/java/org/camunda/spin/xml/XmlTestUtil.java b/spin/dataformat-xml-dom/src/test/java/org/camunda/spin/xml/XmlTestUtil.java new file mode 100644 index 00000000000..beee885fc05 --- /dev/null +++ b/spin/dataformat-xml-dom/src/test/java/org/camunda/spin/xml/XmlTestUtil.java @@ -0,0 +1,46 @@ +/* + * Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH + * under one or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information regarding copyright + * ownership. Camunda licenses this file to you under the Apache License, + * Version 2.0; 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.camunda.spin.xml; + +public class XmlTestUtil { + /** + * Example input 2015-04-04T00:00:00+02:00 -> 2015-04-04 + * + * @param input a string containing timezone offset + * @return same as input string without the timezone offset + */ + public static String removeTimeZone(String input) { + if (input == null) { + return null; + } + + final String TIMEZONE = "T00:00:00"; + final String CLOSING_BRACKET = "<"; + + int indexOfTimezone = input.indexOf(TIMEZONE); + if (indexOfTimezone == -1) { + return input; + } + + int indexOfClosingBracket = input.indexOf(CLOSING_BRACKET, indexOfTimezone); + if (indexOfClosingBracket == -1) { + return input; + } + + return input.substring(0, indexOfTimezone) + input.substring(indexOfClosingBracket); + } +} diff --git a/spin/dataformat-xml-dom/src/test/java/org/camunda/spin/xml/dom/XmlDomMapJavaToXmlScriptTest.java b/spin/dataformat-xml-dom/src/test/java/org/camunda/spin/xml/dom/XmlDomMapJavaToXmlScriptTest.java index ec38ae07a6a..b232461542c 100644 --- a/spin/dataformat-xml-dom/src/test/java/org/camunda/spin/xml/dom/XmlDomMapJavaToXmlScriptTest.java +++ b/spin/dataformat-xml-dom/src/test/java/org/camunda/spin/xml/dom/XmlDomMapJavaToXmlScriptTest.java @@ -22,6 +22,7 @@ import org.camunda.spin.impl.test.Script; import org.camunda.spin.impl.test.ScriptTest; +import org.camunda.spin.xml.XmlTestUtil; import org.camunda.spin.xml.mapping.Order; import org.junit.Test; @@ -36,7 +37,11 @@ public void shouldMapJavaToXml() throws Throwable { script.execute(); String xml = script.getVariable("xml"); - assertThat(xml).isXmlEqualTo(EXAMPLE_VALIDATION_XML); + //In EXAMPLE_VALIDATION_XML, expected date is hardcoded in CET timezone, ignoring it so that it passes when ran in + //different timezone + String exampleValidationXmlWoTimezone = XmlTestUtil.removeTimeZone(EXAMPLE_VALIDATION_XML); + xml = XmlTestUtil.removeTimeZone(xml); + assertThat(xml).isXmlEqualTo(exampleValidationXmlWoTimezone); } @Test(expected = IllegalArgumentException.class) diff --git a/spin/dataformat-xml-dom/src/test/java/org/camunda/spin/xml/dom/XmlDomMapJavaToXmlTest.java b/spin/dataformat-xml-dom/src/test/java/org/camunda/spin/xml/dom/XmlDomMapJavaToXmlTest.java index d259dc29464..09403c785e9 100644 --- a/spin/dataformat-xml-dom/src/test/java/org/camunda/spin/xml/dom/XmlDomMapJavaToXmlTest.java +++ b/spin/dataformat-xml-dom/src/test/java/org/camunda/spin/xml/dom/XmlDomMapJavaToXmlTest.java @@ -22,6 +22,7 @@ import static org.camunda.spin.xml.XmlTestConstants.EXAMPLE_VALIDATION_XML; import static org.camunda.spin.xml.XmlTestConstants.createExampleOrder; +import org.camunda.spin.xml.XmlTestUtil; import org.camunda.spin.xml.mapping.NonXmlRootElementType; import org.camunda.spin.xml.mapping.Order; import org.junit.Test; @@ -32,8 +33,11 @@ public class XmlDomMapJavaToXmlTest { public void shouldMapJavaToXml() { Order order = createExampleOrder(); String orderAsString = XML(order).toString(); - - assertThat(orderAsString).isXmlEqualTo(EXAMPLE_VALIDATION_XML); + //In EXAMPLE_VALIDATION_XML, expected date is hardcoded in CET timezone, ignoring it so that it passes when ran in + //different timezone + String exampleValidationXmlWoTimezone = XmlTestUtil.removeTimeZone(EXAMPLE_VALIDATION_XML); + orderAsString = XmlTestUtil.removeTimeZone(orderAsString); + assertThat(orderAsString).isXmlEqualTo(exampleValidationXmlWoTimezone); } @Test