Skip to content
This repository has been archived by the owner on May 17, 2021. It is now read-only.

Commit

Permalink
fixed DateTimeTypeTest
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Eichstädt-Engelen <thomas@openhab.org>
  • Loading branch information
teichsta committed Jul 27, 2015
1 parent f87ea5d commit f25fa3a
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 23 deletions.
44 changes: 44 additions & 0 deletions bundles/core/org.openhab.core.library.test/LibraryTests.launch
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.pde.ui.JunitLaunchConfig">
<booleanAttribute key="append.args" value="true"/>
<stringAttribute key="application" value="org.eclipse.pde.junit.runtime.coretestapplication"/>
<booleanAttribute key="askclear" value="false"/>
<booleanAttribute key="automaticAdd" value="false"/>
<booleanAttribute key="automaticValidate" value="false"/>
<stringAttribute key="bootstrap" value=""/>
<stringAttribute key="checked" value="[NONE]"/>
<booleanAttribute key="clearConfig" value="true"/>
<booleanAttribute key="clearws" value="true"/>
<booleanAttribute key="clearwslog" value="false"/>
<stringAttribute key="configLocation" value="${workspace_loc}/.metadata/.plugins/org.eclipse.pde.core/pde-junit"/>
<booleanAttribute key="default" value="false"/>
<booleanAttribute key="includeOptional" value="false"/>
<stringAttribute key="location" value="${workspace_loc}/../junit-workspace"/>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/org.openhab.core.library.test"/>
</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
<listEntry value="4"/>
</listAttribute>
<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value="=org.openhab.core.library.test"/>
<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/>
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit4"/>
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/>
<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value=""/>
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl} -consoleLog"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.openhab.core.library.test"/>
<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.pde.ui.workbenchClasspathProvider"/>
<stringAttribute key="pde.version" value="3.3"/>
<stringAttribute key="product" value="org.eclipse.platform.ide"/>
<booleanAttribute key="run_in_ui_thread" value="true"/>
<stringAttribute key="selected_target_plugins" value="ch.qos.logback.classic*1.0.0.v20111214-2030@default:default,ch.qos.logback.classic*1.0.7.v20121108-1250@default:default,ch.qos.logback.core*1.0.0.v20111214-2030@default:default,ch.qos.logback.core*1.0.7.v20121108-1250@default:default,ch.qos.logback.slf4j*1.0.7.v20121108-1250@default:false,com.google.guava@default:default,javax.transaction@default:false,org.apache.commons.codec*1.3.0.v201101211617@default:default,org.apache.commons.codec*1.4.0.v201209201156@default:default,org.apache.commons.collections@default:default,org.apache.commons.httpclient@default:default,org.apache.commons.io@default:default,org.apache.commons.lang@default:default,org.apache.commons.logging@default:default,org.eclipse.core.contenttype@default:default,org.eclipse.core.jobs@default:default,org.eclipse.core.runtime.compatibility.registry@default:false,org.eclipse.core.runtime@default:true,org.eclipse.equinox.app@default:default,org.eclipse.equinox.common@2:true,org.eclipse.equinox.preferences@default:default,org.eclipse.equinox.registry@default:default,org.eclipse.equinox.servletbridge.extensionbundle@default:false,org.eclipse.equinox.transforms.hook@default:false,org.eclipse.equinox.weaving.hook@default:false,org.eclipse.osgi*3.8.2.v20130124-134944@-1:true,org.eclipse.osgi.services@default:default,org.hamcrest.core@default:default,org.junit*4.10.0.v4_10_0_v20120426-0900@default:default,org.junit4@default:default,org.slf4j.api*1.7.2.v20121108-1250@default:default,org.slf4j.jul*1.7.2.v20121108-1250@default:default"/>
<stringAttribute key="selected_workspace_plugins" value="org.openhab.core.library.test@default:false,org.openhab.core.library@default:true,org.openhab.core.test@default:false,org.openhab.core@default:default"/>
<booleanAttribute key="show_selected_only" value="false"/>
<booleanAttribute key="tracing" value="false"/>
<booleanAttribute key="useCustomFeatures" value="false"/>
<booleanAttribute key="useDefaultConfig" value="true"/>
<booleanAttribute key="useDefaultConfigArea" value="false"/>
<booleanAttribute key="useProduct" value="false"/>
</launchConfiguration>
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
@RunWith(Parameterized.class)
public class DateTimeTypeTest {

private SimpleDateFormat dateFormatter = new SimpleDateFormat(DateTimeType.DATE_PATTERN);

/**
* parameter test set class.
* each instance of this class represents a test which executes the test once.
Expand Down Expand Up @@ -77,9 +75,7 @@ public static class ParameterSet {
* @param inputTimeZone
* @param expectedResult
*/
public ParameterSet(TimeZone defaultTimeZone,
Map<String, Integer> inputTimeMap, TimeZone inputTimeZone,
String expectedResult) {
public ParameterSet(TimeZone defaultTimeZone, Map<String, Integer> inputTimeMap, TimeZone inputTimeZone, String expectedResult) {
this.defaultTimeZone = defaultTimeZone;
this.inputTimeMap = inputTimeMap;
this.inputTimeZone = inputTimeZone;
Expand All @@ -93,8 +89,7 @@ public ParameterSet(TimeZone defaultTimeZone,
* @param inputTimeString
* @param expectedResult
*/
public ParameterSet(TimeZone defaultTimeZone, String inputTimeString,
String expectedResult) {
public ParameterSet(TimeZone defaultTimeZone, String inputTimeString, String expectedResult) {
this.defaultTimeZone = defaultTimeZone;
this.inputTimeMap = null;
this.inputTimeZone = null;
Expand All @@ -112,25 +107,30 @@ public ParameterSet(TimeZone defaultTimeZone, String inputTimeString,
@Parameters
public static Collection<Object[]> parameters() {
// for simplicity we use always the same input time.
return Arrays.asList(new Object[][] {
{ new ParameterSet(TimeZone.getTimeZone("UTC") , initTimeMap(), TimeZone.getTimeZone("UTC") , "2014-03-30T10:58:47") },
{ new ParameterSet(TimeZone.getTimeZone("UTC") , initTimeMap(), TimeZone.getTimeZone("CET") , "2014-03-30T08:58:47") },
{ new ParameterSet(TimeZone.getTimeZone("UTC") , "2014-03-30T10:58:47UTS" , "2014-03-30T10:58:47") },
{ new ParameterSet(TimeZone.getTimeZone("CET") , initTimeMap(), TimeZone.getTimeZone("UTC") , "2014-03-30T12:58:47") },
{ new ParameterSet(TimeZone.getTimeZone("CET") , initTimeMap(), TimeZone.getTimeZone("CET") , "2014-03-30T10:58:47") },
{ new ParameterSet(TimeZone.getTimeZone("CET") , "2014-03-30T10:58:47UTS" , "2014-03-30T10:58:47") },

{ new ParameterSet(TimeZone.getTimeZone("GMT"), initTimeMap(), TimeZone.getTimeZone("GMT") , "2014-03-30T10:58:47") },
{ new ParameterSet(TimeZone.getTimeZone("GMT+2"), initTimeMap(), TimeZone.getTimeZone("GML") , "2014-03-30T12:58:47") },
{ new ParameterSet(TimeZone.getTimeZone("GMT-2"), initTimeMap(), TimeZone.getTimeZone("GMT+3") , "2014-03-30T05:58:47") },
{ new ParameterSet(TimeZone.getTimeZone("GMT-2"), initTimeMap(), TimeZone.getTimeZone("GMT-4") , "2014-03-30T12:58:47") },
});
}

private static Map<String, Integer> initTimeMap() {
Map<String, Integer> inputTimeMap = new HashMap<String,Integer>();
inputTimeMap.put("year", 2014);
inputTimeMap.put("month", 2);
inputTimeMap.put("date", 30);
inputTimeMap.put("hourOfDay", 4);
inputTimeMap.put("hourOfDay", 10);
inputTimeMap.put("minute", 58);
inputTimeMap.put("second", 47);

return Arrays.asList(new Object[][] {
{ new ParameterSet(TimeZone.getTimeZone("UTC") , inputTimeMap, TimeZone.getTimeZone("UTC") , "2014-03-30T04:58:47") },
{ new ParameterSet(TimeZone.getTimeZone("UTC") , inputTimeMap, TimeZone.getTimeZone("CET") , "2014-03-30T02:58:47") },
{ new ParameterSet(TimeZone.getTimeZone("UTC") , "2014-03-30T04:58:47UTS" , "2014-03-30T04:58:47") },
{ new ParameterSet(TimeZone.getTimeZone("CET") , inputTimeMap, TimeZone.getTimeZone("UTC") , "2014-03-30T04:58:47") },
{ new ParameterSet(TimeZone.getTimeZone("CET") , inputTimeMap, TimeZone.getTimeZone("CET") , "2014-03-30T02:58:47") },
{ new ParameterSet(TimeZone.getTimeZone("CET") , "2014-03-30T04:58:47UTS" , "2014-03-30T04:58:47") },
{ new ParameterSet(TimeZone.getTimeZone("GMT+2"), inputTimeMap, TimeZone.getTimeZone("GMT+3") , "2014-03-30T01:58:47") },
{ new ParameterSet(TimeZone.getTimeZone("GMT-2"), inputTimeMap, TimeZone.getTimeZone("GMT+3") , "2014-03-30T01:58:47") },
{ new ParameterSet(TimeZone.getTimeZone("GMT-2"), inputTimeMap, TimeZone.getTimeZone("GMT-3") , "2014-03-30T07:58:47") },
});
return inputTimeMap;
}

private ParameterSet parameterSet;
Expand All @@ -156,25 +156,29 @@ public void createDate() {

// set default time zone
TimeZone.setDefault(parameterSet.defaultTimeZone);
// get formated time string

// get formatted time string
if (parameterSet.inputTimeString == null) {
final Calendar calendar = Calendar.getInstance(parameterSet.inputTimeZone);
calendar.set(parameterSet.inputTimeMap.get("year"), parameterSet.inputTimeMap.get("month"), parameterSet.inputTimeMap.get("date"), parameterSet.inputTimeMap.get("hourOfDay"), parameterSet.inputTimeMap.get("minute"), parameterSet.inputTimeMap.get("second"));
inputTimeString = dateFormatter.format(calendar.getTime());

inputTimeString = new SimpleDateFormat(DateTimeType.DATE_PATTERN).format(calendar.getTime());
} else {
inputTimeString = parameterSet.inputTimeString;
}

DateTimeType dt = DateTimeType.valueOf(inputTimeString);

// create debug output to reproduce
System.out.println("createDate (Default TimeZone: " + parameterSet.defaultTimeZone.getDisplayName(false, TimeZone.SHORT, Locale.ROOT) + "):");
System.out.println("createDate (Default TimeZone: expected=" + parameterSet.defaultTimeZone.getDisplayName(false, TimeZone.SHORT, Locale.ROOT) + "|current="+TimeZone.getDefault().getDisplayName()+"):");
if (parameterSet.inputTimeZone == null) {
System.out.println("\tInput: " + inputTimeString);
} else {
System.out.println("\tInput: " + inputTimeString+parameterSet.inputTimeZone.getDisplayName(false, TimeZone.SHORT, Locale.ROOT));
}
System.out.println("\tExpected: " + parameterSet.expectedResult);
System.out.println("\tResult : " + dt.toString());

// Test
assertEquals(parameterSet.expectedResult, dt.toString());
}
Expand Down

0 comments on commit f25fa3a

Please sign in to comment.