Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(spin) time zone unit tests fail when run it in non CET timezone in spin module #4660

Merged
merged 2 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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 <ns2:date>2015-04-04T00:00:00+02:00</ns2:date> -> <ns2:date>2015-04-04</ns2:date>
*
* @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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
Loading