You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by mi...@apache.org on 2016/03/04 21:37:18 UTC
[35/39] olingo-odata4 git commit: [OLINGO-864] use local timezone for
technical service
[OLINGO-864] use local timezone for technical service
Signed-off-by: Christian Amend <ch...@sap.com>
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/9381ecfa
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/9381ecfa
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/9381ecfa
Branch: refs/heads/OLINGO-856_ODataHandlerInAPI
Commit: 9381ecfa567b9ce3381ce7c901173701d39c42fc
Parents: d566b18
Author: Klaus Straubinger <kl...@sap.com>
Authored: Tue Mar 1 14:25:47 2016 +0100
Committer: Christian Amend <ch...@sap.com>
Committed: Tue Mar 1 15:38:05 2016 +0100
----------------------------------------------------------------------
.../client/AbstractParamTecSvcITCase.java | 13 --
.../fit/tecsvc/client/ActionImportITCase.java | 5 +-
.../fit/tecsvc/client/ExpandSelectITCase.java | 6 +-
.../tecsvc/client/FilterSystemQueryITCase.java | 4 +-
.../commons/api/edm/EdmPrimitiveType.java | 9 +-
.../primitivetype/AbstractPrimitiveType.java | 2 +-
.../edm/primitivetype/EdmDateTimeOffset.java | 71 ++++------
.../core/edm/primitivetype/EdmTimeOfDay.java | 35 +++--
.../core/edm/primitivetype/EdmDateTest.java | 15 +-
.../primitivetype/EdmDateTimeOffsetTest.java | 18 +--
.../core/edm/primitivetype/EdmDurationTest.java | 2 +-
.../edm/primitivetype/EdmTimeOfDayTest.java | 79 +++++------
.../primitivetype/PrimitiveTypeBaseTest.java | 3 +-
.../olingo/server/tecsvc/data/DataCreator.java | 142 ++++++++++---------
.../tecsvc/data/ActionDataProviderTest.java | 3 +-
.../server/tecsvc/data/DataProviderTest.java | 13 --
.../json/ODataJsonSerializerTest.java | 15 +-
.../serializer/xml/ODataXmlSerializerTest.java | 4 +-
18 files changed, 200 insertions(+), 239 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9381ecfa/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/AbstractParamTecSvcITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/AbstractParamTecSvcITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/AbstractParamTecSvcITCase.java
index ef9e2d3..d6e35a3 100644
--- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/AbstractParamTecSvcITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/AbstractParamTecSvcITCase.java
@@ -25,11 +25,8 @@ import static org.junit.Assert.assertTrue;
import java.util.Arrays;
import java.util.List;
-import java.util.TimeZone;
import org.apache.olingo.commons.api.format.ContentType;
-import org.junit.After;
-import org.junit.Before;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@@ -66,14 +63,4 @@ public abstract class AbstractParamTecSvcITCase extends AbstractTecSvcITCase {
assertTrue(n instanceof Number);
assertEquals(value, ((Number) n).intValue());
}
-
- @Before
- public void setup() {
- TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
- }
-
- @After
- public void teardown() {
- TimeZone.setDefault(TimeZone.getDefault());
- }
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9381ecfa/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/ActionImportITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/ActionImportITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/ActionImportITCase.java
index bb17242..d0674d1 100644
--- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/ActionImportITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/ActionImportITCase.java
@@ -30,7 +30,6 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
-import java.util.TimeZone;
import org.apache.olingo.client.api.communication.ODataClientErrorException;
import org.apache.olingo.client.api.communication.request.invoke.ODataInvokeRequest;
@@ -205,7 +204,7 @@ public class ActionImportITCase extends AbstractParamTecSvcITCase {
@Test
public void entityCollectionActionETAllPrim() throws Exception {
- Calendar time = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
+ Calendar time = Calendar.getInstance();
time.clear();
time.set(Calendar.HOUR_OF_DAY, 3);
time.set(Calendar.MINUTE, 0);
@@ -228,7 +227,7 @@ public class ActionImportITCase extends AbstractParamTecSvcITCase {
@Test
public void entityActionETAllPrim() throws Exception {
- Calendar dateTime = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
+ Calendar dateTime = Calendar.getInstance();
dateTime.clear();
dateTime.set(1012, 2, 0, 0, 0, 0);
final Map<String, ClientValue> parameters = Collections.singletonMap(
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9381ecfa/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/ExpandSelectITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/ExpandSelectITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/ExpandSelectITCase.java
index 84558db..149966c 100644
--- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/ExpandSelectITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/ExpandSelectITCase.java
@@ -23,6 +23,7 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
+import java.util.Calendar;
import java.util.List;
import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest;
@@ -115,7 +116,10 @@ public class ExpandSelectITCase extends AbstractParamTecSvcITCase {
final ClientEntity inlineEntity = entities.get(0);
assertEquals(2, inlineEntity.getProperties().size());
assertShortOrInt(-128, inlineEntity.getProperty("PropertySByte").getPrimitiveValue().toValue());
- assertEquals(new java.sql.Timestamp(85754000),
+ Calendar time = Calendar.getInstance();
+ time.clear();
+ time.set(1970, Calendar.JANUARY, 1, 23, 49, 14);
+ assertEquals(new java.sql.Timestamp(time.getTimeInMillis()),
inlineEntity.getProperty("PropertyTimeOfDay").getPrimitiveValue().toValue());
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9381ecfa/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/FilterSystemQueryITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/FilterSystemQueryITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/FilterSystemQueryITCase.java
index ca66db5..40dbfd1 100644
--- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/FilterSystemQueryITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/FilterSystemQueryITCase.java
@@ -806,7 +806,7 @@ public class FilterSystemQueryITCase extends AbstractParamTecSvcITCase {
@Test
public void dateAddDuration() {
ODataRetrieveResponse<ClientEntitySet> response =
- sendRequest(ES_ALL_PRIM, "PropertyDateTimeOffset eq 2012-12-02 add duration'P1DT7H16M23S'");
+ sendRequest(ES_ALL_PRIM, "PropertyDateTimeOffset ge 2012-12-01 add duration'P1DT7H16M23S'");
assertEquals(1, response.getBody().getEntities().size());
final ClientEntity clientEntity = response.getBody().getEntities().get(0);
@@ -836,7 +836,7 @@ public class FilterSystemQueryITCase extends AbstractParamTecSvcITCase {
@Test
public void dateSubDuration() {
ODataRetrieveResponse<ClientEntitySet> response =
- sendRequest(ES_ALL_PRIM, "PropertyDateTimeOffset eq 2012-12-04 sub duration'P0DT16H43M37S'");
+ sendRequest(ES_ALL_PRIM, "PropertyDateTimeOffset ge 2012-12-03 sub duration'P0DT16H43M37S'");
assertEquals(1, response.getBody().getEntities().size());
final ClientEntity clientEntity = response.getBody().getEntities().get(0);
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9381ecfa/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmPrimitiveType.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmPrimitiveType.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmPrimitiveType.java
index 2f14b3f..8e4b6b5 100644
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmPrimitiveType.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmPrimitiveType.java
@@ -32,8 +32,10 @@ package org.apache.olingo.commons.api.edm;
* <tr><td>Boolean</td><td>{@link Boolean}</td></tr>
* <tr><td>Byte</td><td>{@link Short}, {@link Byte}, {@link Integer}, {@link Long}, {@link java.math.BigInteger}
* </td></tr>
- * <tr><td>Date</td><td>{@link java.util.Calendar}, {@link java.util.Date}, {@link Long}</td></tr>
- * <tr><td>DateTimeOffset</td><td>{@link java.util.Calendar}, {@link java.util.Date}, {@link Long}</td></tr>
+ * <tr><td>Date</td><td>{@link java.util.Calendar}, {@link java.util.Date}, {@link java.sql.Timestamp},
+ * {@link java.sql.Time}, {@link Long}</td></tr>
+ * <tr><td>DateTimeOffset</td><td>{@link java.sql.Timestamp}, {@link java.util.Calendar}, {@link java.util.Date},
+ * {@link java.sql.Time}, {@link Long}</td></tr>
* <tr><td>Decimal</td><td>{@link java.math.BigDecimal}, {@link java.math.BigInteger}, {@link Double}, {@link Float},
* {@link Byte}, {@link Short}, {@link Integer}, {@link Long}</td></tr>
* <tr><td>Double</td><td>{@link Double}, {@link Float}, {@link java.math.BigDecimal}, {@link Byte}, {@link Short},
@@ -52,7 +54,8 @@ package org.apache.olingo.commons.api.edm;
* <tr><td>Single</td><td>{@link Float}, {@link Double}, {@link java.math.BigDecimal}, {@link Byte}, {@link Short},
* {@link Integer}, {@link Long}</td></tr>
* <tr><td>String</td><td>{@link String}</td></tr>
- * <tr><td>TimeOfDay</td><td>{@link java.util.Calendar}, {@link java.util.Date}, {@link Long}</td></tr>
+ * <tr><td>TimeOfDay</td><td>{@link java.util.Calendar}, {@link java.util.Date}, {@link java.sql.Timestamp},
+ * {@link java.sql.Time}, {@link Long}</td></tr>
* </tbody>
* </table>
* <p>
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9381ecfa/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/AbstractPrimitiveType.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/AbstractPrimitiveType.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/AbstractPrimitiveType.java
index feae934..ffba99e 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/AbstractPrimitiveType.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/AbstractPrimitiveType.java
@@ -113,6 +113,6 @@ abstract class AbstractPrimitiveType implements EdmPrimitiveType {
@Override
public String toString() {
- return new FullQualifiedName(getNamespace(), getName()).getFullQualifiedNameAsString();
+ return getFullQualifiedName().getFullQualifiedNameAsString();
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9381ecfa/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDateTimeOffset.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDateTimeOffset.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDateTimeOffset.java
index 990e1f5..5f4645d 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDateTimeOffset.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDateTimeOffset.java
@@ -18,8 +18,6 @@
*/
package org.apache.olingo.commons.core.edm.primitivetype;
-import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
-
import java.sql.Time;
import java.sql.Timestamp;
import java.util.Calendar;
@@ -28,6 +26,7 @@ import java.util.TimeZone;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
/**
* Implementation of the EDM primitive type DateTimeOffset.
@@ -61,10 +60,9 @@ public final class EdmDateTimeOffset extends SingletonPrimitiveType {
}
final String timeZoneOffset = matcher.group(9) == null || matcher.group(10) == null
- || matcher.group(10).matches("[-+]0+:0+") ? null : matcher.group(10);
- final TimeZone tz = TimeZone.getTimeZone("GMT" + ((timeZoneOffset == null) ? "" : timeZoneOffset));
- final Calendar dateTimeValue = Calendar.getInstance(tz);
- if (dateTimeValue.get(Calendar.ZONE_OFFSET) == 0 && timeZoneOffset != null) {
+ || matcher.group(10).matches("[-+]0+:0+") ? "" : matcher.group(10);
+ final Calendar dateTimeValue = Calendar.getInstance(TimeZone.getTimeZone("GMT" + timeZoneOffset));
+ if (dateTimeValue.get(Calendar.ZONE_OFFSET) == 0 && !timeZoneOffset.isEmpty()) {
throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content.");
}
dateTimeValue.clear();
@@ -87,16 +85,20 @@ public final class EdmDateTimeOffset extends SingletonPrimitiveType {
throw new EdmPrimitiveTypeException("The literal '" + value + "' does not match the facets' constraints.");
}
if (returnType.isAssignableFrom(Timestamp.class)) {
- if (!decimals.isEmpty()) {
- nanoSeconds = Integer.parseInt(decimals.length() > 9 ?
- decimals.substring(0, 9) :
- decimals + "000000000".substring(decimals.length()));
+ if (decimals.length() <= 9) {
+ nanoSeconds = Integer.parseInt(decimals + "000000000".substring(decimals.length()));
+ } else {
+ throw new EdmPrimitiveTypeException("The literal '" + value
+ + "' cannot be converted to value type " + returnType + ".");
}
} else {
- final String milliSeconds = decimals.length() > 3 ?
- decimals.substring(0, 3) :
- decimals + "000".substring(decimals.length());
- dateTimeValue.set(Calendar.MILLISECOND, Short.parseShort(milliSeconds));
+ if (decimals.length() <= 3) {
+ final String milliSeconds = decimals + "000".substring(decimals.length());
+ dateTimeValue.set(Calendar.MILLISECOND, Short.parseShort(milliSeconds));
+ } else {
+ throw new EdmPrimitiveTypeException("The literal '" + value
+ + "' cannot be converted to value type " + returnType + ".");
+ }
}
}
@@ -110,13 +112,13 @@ public final class EdmDateTimeOffset extends SingletonPrimitiveType {
}
/**
- * Converts a {@link Calendar} value into the requested return type if possible.
- * <br>It is expected that the {@link Calendar} value will already be in the desired time zone.
- *
+ * <p>Converts a {@link Calendar} value into the requested return type if possible.</p>
+ * <p>It is expected that the {@link Calendar} value will already be in the desired time zone.</p>
* @param dateTimeValue the value
* @param nanoSeconds nanoseconds part of the value; only used for the {@link Timestamp} return type
- * @param returnType the class of the returned value; it must be one of {@link Calendar}, {@link Long}, {@link Date},
- * or {@link Timestamp}
+ * @param returnType the class of the returned value;
+ * it must be one of {@link Calendar}, {@link Long}, {@link Date},
+ * {@link Time}, or {@link Timestamp}
* @return the converted value
* @throws IllegalArgumentException if the Calendar value is not valid
* @throws ClassCastException if the return type is not allowed
@@ -145,14 +147,14 @@ public final class EdmDateTimeOffset extends SingletonPrimitiveType {
timestamp.setNanos(nanoSeconds);
return returnType.cast(timestamp);
} else if (returnType.isAssignableFrom(Time.class)) {
- //normalize the value
+ // Normalize the value.
dateTimeValue.set(Calendar.YEAR, 1970);
dateTimeValue.set(Calendar.MONTH, Calendar.JANUARY);
dateTimeValue.set(Calendar.DAY_OF_MONTH, 1);
dateTimeValue.set(Calendar.MILLISECOND, 0);
return returnType.cast(new Time(dateTimeValue.getTimeInMillis())); // may throw IllegalArgumentException
} else if (returnType.isAssignableFrom(java.sql.Date.class)) {
- //normalize the value
+ // Normalize the value.
dateTimeValue.set(Calendar.HOUR_OF_DAY, 0);
dateTimeValue.set(Calendar.MINUTE, 0);
dateTimeValue.set(Calendar.SECOND, 0);
@@ -169,8 +171,8 @@ public final class EdmDateTimeOffset extends SingletonPrimitiveType {
final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
final Calendar dateTimeValue = createDateTime(value, false);
-
- final StringBuilder result = new StringBuilder();
+
+ StringBuilder result = new StringBuilder();
final int year = dateTimeValue.get(Calendar.YEAR);
appendTwoDigits(result, year / 100);
appendTwoDigits(result, year % 100);
@@ -207,31 +209,20 @@ public final class EdmDateTimeOffset extends SingletonPrimitiveType {
/**
* Creates a date/time value from the given value.
*
- * @param value the value as {@link Calendar}, {@link Date}, or {@link Long}
- * @return the value as {@link Calendar}
+ * @param value the value as {@link Calendar}, {@link Date}, or {@link Long}
+ * @param isLocal whether the value is to be in the default time zone (or in GMT)
+ * @return the value as {@link Calendar} in the desired time zone
* @throws EdmPrimitiveTypeException if the type of the value is not supported
*/
- protected static <T> Calendar createDateTime(final T value, boolean isLocal) throws EdmPrimitiveTypeException {
+ protected static <T> Calendar createDateTime(final T value, final boolean isLocal) throws EdmPrimitiveTypeException {
Calendar dateTimeValue;
if (value instanceof Date) {
- TimeZone tz;
- if (isLocal) {
- tz = TimeZone.getDefault();
- } else {
- tz = TimeZone.getTimeZone("GMT");
- }
- dateTimeValue = Calendar.getInstance(tz);
+ dateTimeValue = Calendar.getInstance(isLocal ? TimeZone.getDefault() : TimeZone.getTimeZone("GMT"));
dateTimeValue.setTime((Date) value);
} else if (value instanceof Calendar) {
dateTimeValue = (Calendar) ((Calendar) value).clone();
} else if (value instanceof Long) {
- TimeZone tz;
- if (isLocal) {
- tz = TimeZone.getDefault();
- } else {
- tz = TimeZone.getTimeZone("GMT");
- }
- dateTimeValue = Calendar.getInstance(tz);
+ dateTimeValue = Calendar.getInstance(isLocal ? TimeZone.getDefault() : TimeZone.getTimeZone("GMT"));
dateTimeValue.setTimeInMillis((Long) value);
} else {
throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9381ecfa/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmTimeOfDay.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmTimeOfDay.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmTimeOfDay.java
index de0d8d6..86934b8 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmTimeOfDay.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmTimeOfDay.java
@@ -66,15 +66,22 @@ public final class EdmTimeOfDay extends SingletonPrimitiveType {
if (decimals.length() > (precision == null ? 0 : precision)) {
throw new EdmPrimitiveTypeException("The literal '" + value + "' does not match the facets' constraints.");
}
- final String milliSeconds = decimals.length() > 3 ?
- decimals.substring(0, 3) :
- decimals + "000".substring(decimals.length());
- final short millis = Short.parseShort(milliSeconds);
- if (returnType.isAssignableFrom(Timestamp.class)) {
- nanoSeconds = millis * 1000 * 1000;
- } else {
- dateTimeValue.set(Calendar.MILLISECOND, millis);
- }
+ if (returnType.isAssignableFrom(Timestamp.class)) {
+ if (decimals.length() <= 9) {
+ nanoSeconds = Integer.parseInt(decimals + "000000000".substring(decimals.length()));
+ } else {
+ throw new EdmPrimitiveTypeException("The literal '" + value
+ + "' cannot be converted to value type " + returnType + ".");
+ }
+ } else {
+ if (decimals.length() <= 3) {
+ final String milliSeconds = decimals + "000".substring(decimals.length());
+ dateTimeValue.set(Calendar.MILLISECOND, Short.parseShort(milliSeconds));
+ } else {
+ throw new EdmPrimitiveTypeException("The literal '" + value
+ + "' cannot be converted to value type " + returnType + ".");
+ }
+ }
}
try {
@@ -92,17 +99,19 @@ public final class EdmTimeOfDay extends SingletonPrimitiveType {
final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
final Calendar dateTimeValue = EdmDateTimeOffset.createDateTime(value, true);
-
- final StringBuilder result = new StringBuilder();
+
+ StringBuilder result = new StringBuilder();
EdmDateTimeOffset.appendTwoDigits(result, dateTimeValue.get(Calendar.HOUR_OF_DAY));
result.append(':');
EdmDateTimeOffset.appendTwoDigits(result, dateTimeValue.get(Calendar.MINUTE));
result.append(':');
EdmDateTimeOffset.appendTwoDigits(result, dateTimeValue.get(Calendar.SECOND));
+ final int fractionalSecs = value instanceof Timestamp ?
+ ((Timestamp) value).getNanos() :
+ dateTimeValue.get(Calendar.MILLISECOND);
try {
- EdmDateTimeOffset.appendFractionalSeconds(result,
- dateTimeValue.get(Calendar.MILLISECOND), value instanceof Timestamp, precision);
+ EdmDateTimeOffset.appendFractionalSeconds(result, fractionalSecs, value instanceof Timestamp, precision);
} catch (final IllegalArgumentException e) {
throw new EdmPrimitiveTypeException("The value '" + value + "' does not match the facets' constraints.", e);
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9381ecfa/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDateTest.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDateTest.java b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDateTest.java
index fad0aba..ec88c4f 100644
--- a/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDateTest.java
+++ b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDateTest.java
@@ -26,24 +26,12 @@ import java.util.TimeZone;
import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
-import org.junit.After;
-import org.junit.Before;
import org.junit.Test;
public class EdmDateTest extends PrimitiveTypeBaseTest {
private final EdmPrimitiveType instance = EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Date);
- @Before
- public void setup() {
- TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
- }
-
- @After
- public void teardown() {
- TimeZone.setDefault(null);
- }
-
@Test
public void toUriLiteral() throws Exception {
assertEquals("2009-12-26", instance.toUriLiteral("2009-12-26"));
@@ -64,7 +52,8 @@ public class EdmDateTest extends PrimitiveTypeBaseTest {
dateTime.set(2012, 1, 29, 13, 0, 0);
assertEquals("2012-02-29", instance.valueToString(dateTime, null, null, null, null, null));
- final Long millis = 1330558323007L;
+ Long millis = 1330558323007L;
+ millis -= TimeZone.getDefault().getOffset(millis);
assertEquals("2012-02-29", instance.valueToString(millis, null, null, null, null, null));
assertEquals("1969-12-31", instance.valueToString(new Date(-43200000), null, null, null, null, null));
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9381ecfa/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDateTimeOffsetTest.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDateTimeOffsetTest.java b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDateTimeOffsetTest.java
index 5f2da25..4fe6bf1 100644
--- a/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDateTimeOffsetTest.java
+++ b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDateTimeOffsetTest.java
@@ -75,11 +75,11 @@ public class EdmDateTimeOffsetTest extends PrimitiveTypeBaseTest {
assertEquals("2012-02-29T23:32:03.007Z", instance.valueToString(millis, null, null, 3, null, null));
assertEquals("1969-12-31T23:59:59.9Z", instance.valueToString(-100L, null, null, 1, null, null));
assertEquals("1969-12-31T23:59:59.98Z", instance.valueToString(-20L, null, null, 2, null, null));
-
+
assertEquals("2012-02-29T23:32:03.007Z", instance.valueToString(new Time(millis), null, null, 3, null, null));
assertEquals("1969-12-31T23:59:59.9Z", instance.valueToString(new Time(-100L), null, null, 1, null, null));
assertEquals("1969-12-31T23:59:59.98Z", instance.valueToString(new Time(-20L), null, null, 2, null, null));
-
+
final Date date = new Date(millis);
assertEquals("2012-02-29T23:32:03.007Z", instance.valueToString(date, null, null, 3, null, null));
@@ -131,15 +131,14 @@ public class EdmDateTimeOffsetTest extends PrimitiveTypeBaseTest {
Long.class));
assertEquals(Long.valueOf(120L), instance.valueOfString("1970-01-01T00:00:00.12", null, null, 2, null, null,
Long.class));
-
+
assertEquals(new Time(120000L), instance.valueOfString("1970-01-01T00:02", null, null, null, null, null,
Time.class));
- // 0L because java.sql.Time does not keep track of fraction of milliseconds
- assertEquals(new Time(0L), instance.valueOfString("1970-01-01T00:00:00.012", null, null, 3, null, null,
+ // java.sql.Time does not keep track of milliseconds.
+ assertEquals(new Time(0), instance.valueOfString("1970-01-01T00:00:00.012", null, null, 3, null, null,
Time.class));
- assertEquals(new Time(0L), instance.valueOfString("1970-01-01T00:00:00.12", null, null, 2, null, null,
- Time.class));
-
+ assertEquals(new Time(0), instance.valueOfString("1970-01-01T00:00:00.12", null, null, 2, null, null, Time.class));
+
expectFacetsErrorInValueOfString(instance, "2012-02-29T23:32:02.9Z", null, null, null, null, null);
expectFacetsErrorInValueOfString(instance, "2012-02-29T23:32:02.9Z", null, null, 0, null, null);
expectContentErrorInValueOfString(instance, "2012-02-29T23:32:02X");
@@ -148,6 +147,9 @@ public class EdmDateTimeOffsetTest extends PrimitiveTypeBaseTest {
expectContentErrorInValueOfString(instance, "2012-02-29T23:32:02.");
expectContentErrorInValueOfString(instance, "2012-02-29T23:32:02.0000000000000");
+ expectUnconvertibleErrorInValueOfString(instance, "2012-02-29T23:32:02.1234", Calendar.class);
+ expectUnconvertibleErrorInValueOfString(instance, "2012-02-29T23:32:02.0123456789", Timestamp.class);
+
expectTypeErrorInValueOfString(instance, "2012-02-29T01:02:03Z");
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9381ecfa/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDurationTest.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDurationTest.java b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDurationTest.java
index 32e75f5..4640e20 100644
--- a/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDurationTest.java
+++ b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDurationTest.java
@@ -98,7 +98,7 @@ public class EdmDurationTest extends PrimitiveTypeBaseTest {
expectUnconvertibleErrorInValueOfString(instance, "PT10H", Short.class);
expectUnconvertibleErrorInValueOfString(instance, "P25000D", Integer.class);
expectUnconvertibleErrorInValueOfString(instance, "P123456789012345D", Long.class);
- // expectUnconvertibleErrorInValueOfString(instance, "PT1.1S", BigInteger.class);
+ expectUnconvertibleErrorInValueOfString(instance, "PT1.1S", BigInteger.class);
expectTypeErrorInValueOfString(instance, "PT0S");
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9381ecfa/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/primitivetype/EdmTimeOfDayTest.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/primitivetype/EdmTimeOfDayTest.java b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/primitivetype/EdmTimeOfDayTest.java
index 170297e..14857c6 100644
--- a/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/primitivetype/EdmTimeOfDayTest.java
+++ b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/primitivetype/EdmTimeOfDayTest.java
@@ -6,9 +6,9 @@
* 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
@@ -21,6 +21,7 @@ package org.apache.olingo.commons.core.edm.primitivetype;
import static org.junit.Assert.assertEquals;
import java.sql.Time;
+import java.sql.Timestamp;
import java.util.Calendar;
import java.util.TimeZone;
@@ -56,50 +57,25 @@ public class EdmTimeOfDayTest extends PrimitiveTypeBaseTest {
assertEquals("04:05:06.042", instance.valueToString(dateTime, null, null, 3, null, null));
assertEquals("04:05:06.042", instance.valueToString(dateTime, null, null, 4, null, null));
+ Calendar dateTime2 = Calendar.getInstance();
+ dateTime2.clear();
+ dateTime2.setTimeZone(TimeZone.getDefault());
+ dateTime2.set(Calendar.HOUR, 5);
+ dateTime2.set(Calendar.MINUTE, 59);
+ dateTime2.set(Calendar.SECOND, 23);
+ final Time time = new Time(dateTime2.getTimeInMillis());
+ assertEquals("05:59:23", instance.valueToString(time, null, null, null, null, null));
+
+ assertEquals("05:59:23", instance.valueToString(dateTime2.getTimeInMillis(), null, null, null, null, null));
+
expectFacetsErrorInValueToString(instance, dateTime, null, null, null, null, null);
expectFacetsErrorInValueToString(instance, dateTime, null, null, 2, null, null);
+ Timestamp timestamp = new Timestamp(0);
+ timestamp.setNanos(42);
+ expectFacetsErrorInValueToString(instance, timestamp, null, null, 8, null, null);
expectTypeErrorInValueToString(instance, 0);
}
-
- @Test
- public void valueToStringWithGMT() throws Exception {
- Calendar dateTime = Calendar.getInstance();
- dateTime.clear();
- dateTime.setTimeZone(TimeZone.getTimeZone("GMT+11:30"));
- dateTime.set(1, 2, 3, 4, 5, 6);
- assertEquals("04:05:06", instance.valueToString(dateTime, null, null, null, null, null));
- }
-
- @Test
- public void testRoundTripTime() throws Exception {
- java.sql.Time time = instance.valueOfString("04:05:06.002", true,
- 4000, 3, 0, true, java.sql.Time.class);
- String val = instance.valueToString(time, true, 4000, 3, 0, true);
- assertEquals("04:05:06", val);
- }
-
- @Test
- public void toTimeObject() throws Exception {
- Calendar dateTime = Calendar.getInstance();
- dateTime.clear();
- dateTime.set(Calendar.HOUR, 12);
-
- Time timeValue = instance.valueOfString("12:00:00", null, null, null, null, null, Time.class);
- assertEquals(dateTime.getTimeInMillis(), timeValue.getTime());
- }
-
- @Test
- public void fromTimeObject() throws Exception {
- Calendar dateTime = Calendar.getInstance();
- dateTime.clear();
- dateTime.set(Calendar.HOUR, 5);
- dateTime.set(Calendar.MINUTE, 59);
- dateTime.set(Calendar.SECOND, 23);
-
- Time time = new Time(dateTime.getTimeInMillis());
- assertEquals("05:59:23", instance.valueToString(time, null, null, null, null, null));
- }
@Test
public void valueOfString() throws Exception {
@@ -111,13 +87,26 @@ public class EdmTimeOfDayTest extends PrimitiveTypeBaseTest {
assertEquals(dateTime, instance.valueOfString("00:00:00.000000000000", null, null, null, null, null,
Calendar.class));
+ final Time timeValue = instance.valueOfString("00:00:00.999", null, null, 3, null, null, Time.class);
+ assertEquals(dateTime.getTimeInMillis(), timeValue.getTime());
+
dateTime.set(Calendar.MILLISECOND, 999);
assertEquals(dateTime, instance.valueOfString("00:00:00.999", null, null, 3, null, null, Calendar.class));
assertEquals(dateTime, instance.valueOfString("00:00:00.999", null, null, 3, null, null, Calendar.class));
+ assertEquals(Long.valueOf(dateTime.getTimeInMillis()),
+ instance.valueOfString("00:00:00.999", null, null, 3, null, null, Long.class));
+
+ final Timestamp timestamp = instance.valueOfString("00:00:00.999888777", null, null, 9, null, null,
+ Timestamp.class);
+ assertEquals(dateTime.getTimeInMillis(), timestamp.getTime());
+ assertEquals(999888777, timestamp.getNanos());
expectFacetsErrorInValueOfString(instance, "11:12:13.123", null, null, null, null, null);
expectFacetsErrorInValueOfString(instance, "11:12:13.123", null, null, 2, null, null);
+ expectUnconvertibleErrorInValueOfString(instance, "11:12:13.1234", Calendar.class);
+ expectUnconvertibleErrorInValueOfString(instance, "11:12:13.0123456789", Timestamp.class);
+
expectContentErrorInValueOfString(instance, "24:32:02");
expectContentErrorInValueOfString(instance, "011:12:13");
expectContentErrorInValueOfString(instance, "11:12:13:14");
@@ -131,6 +120,14 @@ public class EdmTimeOfDayTest extends PrimitiveTypeBaseTest {
}
@Test
+ public void testRoundTripTime() throws Exception {
+ java.sql.Time time = instance.valueOfString("04:05:06.002", true,
+ 4000, 3, 0, true, java.sql.Time.class);
+ String val = instance.valueToString(time, true, 4000, 3, 0, true);
+ assertEquals("04:05:06", val);
+ }
+
+ @Test
public void tests() throws Exception {
instance.validate("12:34:55", null, null, null, null, null);
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9381ecfa/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/primitivetype/PrimitiveTypeBaseTest.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/primitivetype/PrimitiveTypeBaseTest.java b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/primitivetype/PrimitiveTypeBaseTest.java
index 7022f73..40152c9 100644
--- a/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/primitivetype/PrimitiveTypeBaseTest.java
+++ b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/primitivetype/PrimitiveTypeBaseTest.java
@@ -85,7 +85,8 @@ public abstract class PrimitiveTypeBaseTest {
protected void expectUnconvertibleErrorInValueOfString(final EdmPrimitiveType instance, final String value,
final Class<?> type) {
- expectErrorInValueOfString(instance, value, null, null, null, null, null, type, "cannot be converted to");
+ expectErrorInValueOfString(instance, value, true, Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE, true,
+ type, "cannot be converted to");
}
protected void expectContentErrorInValueOfString(final EdmPrimitiveType instance, final String value) {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9381ecfa/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java
index 376d916..1241bc5 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java
@@ -28,6 +28,7 @@ import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.TimeZone;
import java.util.UUID;
import org.apache.olingo.commons.api.Constants;
@@ -257,9 +258,9 @@ public class DataCreator {
new byte[] { 84, 103, -119 }
),
createPrimitiveCollection("CollPropertyDate",
- getDateTime(1958, 12, 3, 0, 0, 0),
- getDateTime(1999, 8, 5, 0, 0, 0),
- getDateTime(2013, 6, 25, 0, 0, 0)
+ getDate(1958, 12, 3),
+ getDate(1999, 8, 5),
+ getDate(2013, 6, 25)
),
createPrimitiveCollection("CollPropertyDateTimeOffset",
getDateTime(2015, 8, 12, 3, 8, 34),
@@ -288,19 +289,19 @@ public class DataCreator {
final EntityCollection entityCollection = new EntityCollection();
entityCollection.getEntities().add(
createESTwoKeyNavEntity((short) 1, "1")
- .addProperty(createPrimitive("PropertyDate", getDateTime(2013, 12, 12, 0, 0, 0))));
+ .addProperty(createPrimitive("PropertyDate", getDate(2013, 12, 12))));
entityCollection.getEntities().add(
createESTwoKeyNavEntity((short) 1, "2")
- .addProperty(createPrimitive("PropertyDate", getDateTime(2013, 12, 12, 0, 0, 0))));
+ .addProperty(createPrimitive("PropertyDate", getDate(2013, 12, 12))));
entityCollection.getEntities().add(
createESTwoKeyNavEntity((short) 2, "1")
- .addProperty(createPrimitive("PropertyDate", getDateTime(2013, 12, 12, 0, 0, 0))));
+ .addProperty(createPrimitive("PropertyDate", getDate(2013, 12, 12))));
entityCollection.getEntities().add(
createESTwoKeyNavEntity((short) 3, "1")
- .addProperty(createPrimitive("PropertyDate", getDateTime(2013, 12, 12, 0, 0, 0))));
+ .addProperty(createPrimitive("PropertyDate", getDate(2013, 12, 12))));
setEntityType(entityCollection, edm.getEntityType(EntityTypeProvider.nameETBaseTwoKeyNav));
createEntityId(edm, odata, "ESBaseTwoKeyNav", entityCollection);
@@ -400,9 +401,9 @@ public class DataCreator {
null,
new byte[] { 84, 103, -119 }))
.addProperty(createPrimitiveCollection("CollPropertyDate",
- getDateTime(1958, 12, 3, 0, 0, 0),
+ getDate(1958, 12, 3),
null,
- getDateTime(2013, 6, 25, 0, 0, 0)))
+ getDate(2013, 6, 25)))
.addProperty(createPrimitiveCollection("CollPropertyDateTimeOffset",
getDateTime(2015, 8, 12, 3, 8, 34),
null,
@@ -418,8 +419,7 @@ public class DataCreator {
.addProperty(createPrimitiveCollection("CollPropertyTimeOfDay",
getTime(4, 14, 13),
null,
- getTime(0, 37, 13))
- ));
+ getTime(0, 37, 13))));
setEntityType(entityCollection, edm.getEntityType(EntityTypeProvider.nameETAllNullable));
createEntityId(edm, odata, "ESAllNullable", entityCollection);
@@ -537,7 +537,7 @@ public class DataCreator {
createPrimitive("PropertyBinary", new byte[] { 1, 35, 69, 103, -119, -85, -51, -17 }),
createPrimitive("PropertyBoolean", true),
createPrimitive("PropertyByte", (short) 255),
- createPrimitive("PropertyDate", getDateTime(2012, 12, 3, 7, 16, 23)),
+ createPrimitive("PropertyDate", getDate(2012, 12, 3)),
createPrimitive("PropertyDecimal", BigDecimal.valueOf(34)),
createPrimitive("PropertySingle", (float) 179000000000000000000D),
createPrimitive("PropertyDouble", -179000000000000000000D),
@@ -569,7 +569,7 @@ public class DataCreator {
createPrimitive("PropertyBinary", new byte[] { 1, 35, 69, 103, -119, -85, -51, -17 }),
createPrimitive("PropertyBoolean", true),
createPrimitive("PropertyByte", (short) 255),
- createPrimitive("PropertyDate", getDateTime(2012, 12, 3, 7, 16, 23)),
+ createPrimitive("PropertyDate", getDate(2012, 12, 3)),
createPrimitive("PropertyDateTimeOffset", getTimestamp(2012, 12, 3, 7, 16, 23, 0)),
createPrimitive("PropertyDecimal", 34),
createPrimitive("PropertySingle", (float) 179000000000000000000D),
@@ -665,7 +665,7 @@ public class DataCreator {
.addProperty(createPrimitive("PropertyDecimal", BigDecimal.valueOf(34)))
.addProperty(createPrimitive("PropertyBinary",
new byte[] { 0x01, 0x23, 0x45, 0x67, (byte) 0x89, (byte) 0xAB, (byte) 0xCD, (byte) 0xEF }))
- .addProperty(createPrimitive("PropertyDate", getDateTime(2012, 12, 3, 0, 0, 0)))
+ .addProperty(createPrimitive("PropertyDate", getDate(2012, 12, 3)))
.addProperty(createPrimitive("PropertyDateTimeOffset", getDateTime(2012, 12, 3, 7, 16, 23)))
.addProperty(createPrimitive("PropertyDuration", BigDecimal.valueOf(6)))
.addProperty(createPrimitive("PropertyGuid", GUID))
@@ -684,7 +684,7 @@ public class DataCreator {
.addProperty(createPrimitive("PropertyDecimal", BigDecimal.valueOf(-34)))
.addProperty(createPrimitive("PropertyBinary",
new byte[] { 0x01, 0x23, 0x45, 0x67, (byte) 0x89, (byte) 0xAB, (byte) 0xCD, (byte) 0xEF }))
- .addProperty(createPrimitive("PropertyDate", getDateTime(2015, 11, 5, 0, 0, 0)))
+ .addProperty(createPrimitive("PropertyDate", getDate(2015, 11, 5)))
.addProperty(createPrimitive("PropertyDateTimeOffset", getDateTime(2005, 12, 3, 7, 17, 8)))
.addProperty(createPrimitive("PropertyDuration", BigDecimal.valueOf(9)))
.addProperty(createPrimitive("PropertyGuid", UUID.fromString("76543201-23ab-cdef-0123-456789dddfff")))
@@ -702,7 +702,7 @@ public class DataCreator {
.addProperty(createPrimitive("PropertyDouble", 0D))
.addProperty(createPrimitive("PropertyDecimal", BigDecimal.valueOf(0)))
.addProperty(createPrimitive("PropertyBinary", new byte[] {}))
- .addProperty(createPrimitive("PropertyDate", getDateTime(1970, 1, 1, 0, 0, 0)))
+ .addProperty(createPrimitive("PropertyDate", getDate(1970, 1, 1)))
.addProperty(createPrimitive("PropertyDateTimeOffset", getDateTime(2005, 12, 3, 0, 0, 0)))
.addProperty(createPrimitive("PropertyDuration", BigDecimal.valueOf(0)))
.addProperty(createPrimitive("PropertyGuid", UUID.fromString("76543201-23ab-cdef-0123-456789cccddd")))
@@ -725,7 +725,7 @@ public class DataCreator {
new byte[] { 0x01, 0x23, 0x45, 0x67, (byte) 0x89, (byte) 0xAB, (byte) 0xCD, (byte) 0xEF }),
createPrimitive("PropertyBoolean", true),
createPrimitive("PropertyByte", (short) 255),
- createPrimitive("PropertyDate", getDateTime(2012, 10, 3, 0, 0, 0)),
+ createPrimitive("PropertyDate", getDate(2012, 10, 3)),
createPrimitive("PropertyDateTimeOffset", getTimestamp(2012, 10, 3, 7, 16, 23, 123456700)),
createPrimitive("PropertyDecimal", BigDecimal.valueOf(34.27)),
createPrimitive("PropertySingle", (float) 1.79000000E+20),
@@ -748,7 +748,7 @@ public class DataCreator {
new byte[] { 0x01, 0x23, 0x45, 0x67, (byte) 0x89, (byte) 0xAB, (byte) 0xCD, (byte) 0xEF }),
createPrimitive("PropertyBoolean", true),
createPrimitive("PropertyByte", (short) 255),
- createPrimitive("PropertyDate", getDateTime(2013, 11, 4, 0, 0, 0)),
+ createPrimitive("PropertyDate", getDate(2013, 11, 4)),
createPrimitive("PropertyDateTimeOffset", getDateTime(2013, 11, 4, 7, 16, 23)),
createPrimitive("PropertyDecimal", BigDecimal.valueOf(34.27)),
createPrimitive("PropertySingle", (float) 1.79000000E+20),
@@ -759,7 +759,7 @@ public class DataCreator {
createPrimitive("PropertyInt32", Integer.MAX_VALUE),
createPrimitive("PropertyInt64", Long.MAX_VALUE),
createPrimitive("PropertySByte", Byte.MAX_VALUE),
- createPrimitive("PropertyTimeOfDay", getTimestamp(1, 1, 1, 7, 45, 12, 765432100))));
+ createPrimitive("PropertyTimeOfDay", getTimestamp(1970, 1, 1, 7, 45, 12, 765432100))));
entity.setETag("W/\"7\"");
entityCollection.getEntities().add(entity);
@@ -771,7 +771,7 @@ public class DataCreator {
new byte[] { 0x01, 0x23, 0x45, 0x67, (byte) 0x89, (byte) 0xAB, (byte) 0xCD, (byte) 0xEF }),
createPrimitive("PropertyBoolean", true),
createPrimitive("PropertyByte", (short) 255),
- createPrimitive("PropertyDate", getDateTime(2014, 12, 5, 0, 0, 0)),
+ createPrimitive("PropertyDate", getDate(2014, 12, 5)),
createPrimitive("PropertyDateTimeOffset", getTimestamp(2014, 12, 5, 8, 17, 45, 123456700)),
createPrimitive("PropertyDecimal", BigDecimal.valueOf(17.98)),
createPrimitive("PropertySingle", 1.79000000E+20),
@@ -875,9 +875,9 @@ public class DataCreator {
new byte[] { 0x01, 0x23, 0x45 },
new byte[] { 0x54, 0x67, (byte) 0x89 }))
.addProperty(createPrimitiveCollection("CollPropertyDate",
- getDateTime(1958, 12, 3, 0, 0, 0),
- getDateTime(1999, 8, 5, 0, 0, 0),
- getDateTime(2013, 6, 25, 0, 0, 0)))
+ getDate(1958, 12, 3),
+ getDate(1999, 8, 5),
+ getDate(2013, 6, 25)))
.addProperty(createPrimitiveCollection("CollPropertyDateTimeOffset",
getDateTime(2015, 8, 12, 3, 8, 34),
getDateTime(1970, 3, 28, 12, 11, 10),
@@ -908,7 +908,7 @@ public class DataCreator {
.addProperty(createComplex("PropertyComp",
createPrimitive("PropertyInt16", (short) 111),
createPrimitive("PropertyString", "TEST A")))
- .addProperty(createColPropertyComp()));
+ .addProperty(createCollPropertyComp()));
entityCollection.getEntities().add(new Entity()
.addProperty(createPrimitive("PropertyInt16", (short) 7))
@@ -919,7 +919,7 @@ public class DataCreator {
.addProperty(createComplex("PropertyComp",
createPrimitive("PropertyInt16", (short) 222),
createPrimitive("PropertyString", "TEST B")))
- .addProperty(createColPropertyComp()));
+ .addProperty(createCollPropertyComp()));
entityCollection.getEntities().add(new Entity()
.addProperty(createPrimitive("PropertyInt16", (short) 0))
@@ -930,7 +930,7 @@ public class DataCreator {
.addProperty(createComplex("PropertyComp",
createPrimitive("PropertyInt16", (short) 333),
createPrimitive("PropertyString", "TEST C")))
- .addProperty(createColPropertyComp()));
+ .addProperty(createCollPropertyComp()));
setEntityType(entityCollection, edm.getEntityType(EntityTypeProvider.nameETMixPrimCollComp));
createEntityId(edm, odata, "ESMixPrimCollComp", entityCollection);
@@ -942,37 +942,37 @@ public class DataCreator {
EntityCollection entityCollection = new EntityCollection();
entityCollection.getEntities().add(new Entity()
- .addProperty(createPrimitive("PropertyInt16", Short.MAX_VALUE))
- .addProperty(createPrimitiveCollection("CollPropertyString",
- "Streamed-Employee1@company.example",
- "Streamed-Employee2@company.example",
- "Streamed-Employee3@company.example"))
- .addProperty(createComplex("PropertyComp",
- createPrimitive("PropertyInt16", (short) 111),
- createPrimitive("PropertyString", "TEST A")))
- .addProperty(createColPropertyComp()));
+ .addProperty(createPrimitive("PropertyInt16", Short.MAX_VALUE))
+ .addProperty(createPrimitiveCollection("CollPropertyString",
+ "Streamed-Employee1@company.example",
+ "Streamed-Employee2@company.example",
+ "Streamed-Employee3@company.example"))
+ .addProperty(createComplex("PropertyComp",
+ createPrimitive("PropertyInt16", (short) 111),
+ createPrimitive("PropertyString", "TEST A")))
+ .addProperty(createCollPropertyComp()));
entityCollection.getEntities().add(new Entity()
- .addProperty(createPrimitive("PropertyInt16", (short) 7))
- .addProperty(createPrimitiveCollection("CollPropertyString",
- "Streamed-Employee1@company.example",
- "Streamed-Employee2@company.example",
- "Streamed-Employee3@company.example"))
- .addProperty(createComplex("PropertyComp",
- createPrimitive("PropertyInt16", (short) 222),
- createPrimitive("PropertyString", "TEST B")))
- .addProperty(createColPropertyComp()));
+ .addProperty(createPrimitive("PropertyInt16", (short) 7))
+ .addProperty(createPrimitiveCollection("CollPropertyString",
+ "Streamed-Employee1@company.example",
+ "Streamed-Employee2@company.example",
+ "Streamed-Employee3@company.example"))
+ .addProperty(createComplex("PropertyComp",
+ createPrimitive("PropertyInt16", (short) 222),
+ createPrimitive("PropertyString", "TEST B")))
+ .addProperty(createCollPropertyComp()));
entityCollection.getEntities().add(new Entity()
- .addProperty(createPrimitive("PropertyInt16", (short) 0))
- .addProperty(createPrimitiveCollection("CollPropertyString",
- "Streamed-Employee1@company.example",
- "Streamed-Employee2@company.example",
- "Streamed-Employee3@company.example"))
- .addProperty(createComplex("PropertyComp",
- createPrimitive("PropertyInt16", (short) 333),
- createPrimitive("PropertyString", "TEST C")))
- .addProperty(createColPropertyComp()));
+ .addProperty(createPrimitive("PropertyInt16", (short) 0))
+ .addProperty(createPrimitiveCollection("CollPropertyString",
+ "Streamed-Employee1@company.example",
+ "Streamed-Employee2@company.example",
+ "Streamed-Employee3@company.example"))
+ .addProperty(createComplex("PropertyComp",
+ createPrimitive("PropertyInt16", (short) 333),
+ createPrimitive("PropertyString", "TEST C")))
+ .addProperty(createCollPropertyComp()));
setEntityType(entityCollection, edm.getEntityType(EntityTypeProvider.nameETMixPrimCollComp));
createEntityId(edm, odata, "ESStream", entityCollection);
@@ -981,7 +981,7 @@ public class DataCreator {
}
@SuppressWarnings("unchecked")
- private Property createColPropertyComp() {
+ private Property createCollPropertyComp() {
return createComplexCollection("CollPropertyComp",
Arrays.asList(
createPrimitive("PropertyInt16", (short) 123),
@@ -1006,7 +1006,7 @@ public class DataCreator {
.addProperty(createPrimitive("PropertyInt32", Integer.MAX_VALUE))
.addProperty(createPrimitive("PropertyInt64", Long.MAX_VALUE))
.addProperty(createPrimitive("PropertyDecimal", BigDecimal.valueOf(34)))
- .addProperty(createPrimitive("PropertyDate", getDateTime(2012, 12, 3, 0, 0, 0)))
+ .addProperty(createPrimitive("PropertyDate", getDate(2012, 12, 3)))
.addProperty(createPrimitive("PropertyDateTimeOffset", getDateTime(2012, 12, 3, 7, 16, 23)))
.addProperty(createPrimitive("PropertyDuration", BigDecimal.valueOf(6)))
.addProperty(createPrimitive("PropertyGuid", GUID))
@@ -1021,7 +1021,7 @@ public class DataCreator {
.addProperty(createPrimitive("PropertyInt32", 2147483644))
.addProperty(createPrimitive("PropertyInt64", 9223372036854775804L))
.addProperty(createPrimitive("PropertyDecimal", BigDecimal.valueOf(34)))
- .addProperty(createPrimitive("PropertyDate", getDateTime(2012, 12, 3, 0, 0, 0)))
+ .addProperty(createPrimitive("PropertyDate", getDate(2012, 12, 3)))
.addProperty(createPrimitive("PropertyDateTimeOffset", getDateTime(2012, 12, 3, 7, 16, 23)))
.addProperty(createPrimitive("PropertyDuration", BigDecimal.valueOf(6)))
.addProperty(createPrimitive("PropertyGuid", GUID))
@@ -1051,7 +1051,7 @@ public class DataCreator {
createComplex("PropertyComp",
createPrimitive("PropertyInt16", (short) 987),
createPrimitive("PropertyString", "String 2")),
- createPrimitive("PropertyDate", getDateTime(2012, 12, 3, 0, 0, 0))));
+ createPrimitive("PropertyDate", getDate(2012, 12, 3))));
entityCollection.getEntities().add(entity);
setEntityType(entityCollection, edm.getEntityType(EntityTypeProvider.nameETCompComp));
@@ -1238,32 +1238,38 @@ public class DataCreator {
return new Property(null, name, ValueType.COLLECTION_COMPLEX, complexCollection);
}
- protected static Calendar getDateTime(final int year, final int month, final int day,
+ private static Calendar getDateTime(final int year, final int month, final int day,
final int hour, final int minute, final int second) {
- Calendar dateTime = Calendar.getInstance();
+ // Date/Time values are serialized with a timezone offset, so we choose a predictable timezone.
+ Calendar dateTime = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
dateTime.clear();
dateTime.set(year, month - 1, day, hour, minute, second);
dateTime.set(Calendar.MILLISECOND, 0);
return dateTime;
}
- protected static int getDuration(final int days, final int hours, final int minutes, final int seconds) {
+ private static int getDuration(final int days, final int hours, final int minutes, final int seconds) {
return days * 24 * 60 * 60
+ hours * 60 * 60
+ minutes * 60
+ seconds;
}
- protected static Calendar getTime(final int hour, final int minute, final int second) {
+ private static Calendar getDate(final int year, final int month, final int day) {
+ // Date values are always in the local timezone.
+ Calendar date = Calendar.getInstance();
+ date.clear();
+ date.set(year, month - 1, day, 0, 0, 0);
+ date.set(Calendar.MILLISECOND, 0);
+ return date;
+ }
+
+ private static Calendar getTime(final int hour, final int minute, final int second) {
+ // Time values are always in the local timezone.
Calendar time = Calendar.getInstance();
time.clear();
- time.set(Calendar.YEAR, 1970);
- time.set(Calendar.MONTH, Calendar.JANUARY);
- time.set(Calendar.DAY_OF_MONTH, 1);
- time.set(Calendar.MILLISECOND, 0);
- time.set(Calendar.HOUR_OF_DAY, hour);
- time.set(Calendar.MINUTE, minute);
- time.set(Calendar.SECOND, second);
+ time.set(1970, Calendar.JANUARY, 1, hour, minute, second);
+ time.set(Calendar.MILLISECOND, 0);
return time;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9381ecfa/lib/server-tecsvc/src/test/java/org/apache/olingo/server/tecsvc/data/ActionDataProviderTest.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/test/java/org/apache/olingo/server/tecsvc/data/ActionDataProviderTest.java b/lib/server-tecsvc/src/test/java/org/apache/olingo/server/tecsvc/data/ActionDataProviderTest.java
index 3cb1b09..314ab8a 100644
--- a/lib/server-tecsvc/src/test/java/org/apache/olingo/server/tecsvc/data/ActionDataProviderTest.java
+++ b/lib/server-tecsvc/src/test/java/org/apache/olingo/server/tecsvc/data/ActionDataProviderTest.java
@@ -29,7 +29,6 @@ import java.util.Calendar;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
-import java.util.TimeZone;
import org.apache.olingo.commons.api.data.ComplexValue;
import org.apache.olingo.commons.api.data.EntityCollection;
@@ -238,7 +237,7 @@ public class ActionDataProviderTest {
}
private Calendar getTime(final int hour, final int minute, final int second) {
- Calendar time = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
+ Calendar time = Calendar.getInstance();
time.clear();
time.set(Calendar.HOUR_OF_DAY, hour);
time.set(Calendar.MINUTE, minute);
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9381ecfa/lib/server-tecsvc/src/test/java/org/apache/olingo/server/tecsvc/data/DataProviderTest.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/test/java/org/apache/olingo/server/tecsvc/data/DataProviderTest.java b/lib/server-tecsvc/src/test/java/org/apache/olingo/server/tecsvc/data/DataProviderTest.java
index dddafa2..f71f1a3 100644
--- a/lib/server-tecsvc/src/test/java/org/apache/olingo/server/tecsvc/data/DataProviderTest.java
+++ b/lib/server-tecsvc/src/test/java/org/apache/olingo/server/tecsvc/data/DataProviderTest.java
@@ -21,7 +21,6 @@ package org.apache.olingo.server.tecsvc.data;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
-import java.util.TimeZone;
import org.apache.olingo.commons.api.data.ComplexValue;
import org.apache.olingo.commons.api.data.Entity;
@@ -34,9 +33,7 @@ import org.apache.olingo.server.api.OData;
import org.apache.olingo.server.api.edmx.EdmxReference;
import org.apache.olingo.server.api.uri.UriParameter;
import org.apache.olingo.server.tecsvc.provider.EdmTechProvider;
-import org.junit.After;
import org.junit.Assert;
-import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
@@ -55,16 +52,6 @@ public class DataProviderTest {
private final EdmEntitySet esMixPrimCollComp = entityContainer.getEntitySet("ESMixPrimCollComp");
private final EdmEntitySet esMedia = entityContainer.getEntitySet("ESMedia");
- @Before
- public void setup() {
- TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
- }
-
- @After
- public void teardown() {
- TimeZone.setDefault(TimeZone.getDefault());
- }
-
@Test
public void esAllPrimEntity() throws Exception {
final DataProvider dataProvider = new DataProvider(oData, edm);
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9381ecfa/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
index e37cf7e..76ba154 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
@@ -26,7 +26,6 @@ import java.nio.channels.WritableByteChannel;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
-import java.util.TimeZone;
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.output.ByteArrayOutputStream;
@@ -47,9 +46,9 @@ import org.apache.olingo.commons.api.edm.EdmProperty;
import org.apache.olingo.commons.api.format.ContentType;
import org.apache.olingo.server.api.OData;
import org.apache.olingo.server.api.ODataContent;
-import org.apache.olingo.server.api.ServiceMetadata;
import org.apache.olingo.server.api.ODataContentWriteErrorCallback;
import org.apache.olingo.server.api.ODataContentWriteErrorContext;
+import org.apache.olingo.server.api.ServiceMetadata;
import org.apache.olingo.server.api.edmx.EdmxReference;
import org.apache.olingo.server.api.serializer.ComplexSerializerOptions;
import org.apache.olingo.server.api.serializer.EntityCollectionSerializerOptions;
@@ -72,9 +71,7 @@ import org.apache.olingo.server.tecsvc.MetadataETagSupport;
import org.apache.olingo.server.tecsvc.data.DataProvider;
import org.apache.olingo.server.tecsvc.provider.EdmTechProvider;
import org.hamcrest.CoreMatchers;
-import org.junit.After;
import org.junit.Assert;
-import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
@@ -90,16 +87,6 @@ public class ODataJsonSerializerTest {
new ODataJsonSerializer(ContentType.create(ContentType.JSON, ContentType.PARAMETER_IEEE754_COMPATIBLE, "true"));
private final UriHelper helper = odata.createUriHelper();
- @Before
- public void setup() {
- TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
- }
-
- @After
- public void teardown() {
- TimeZone.setDefault(TimeZone.getDefault());
- }
-
@Test
public void entitySimple() throws Exception {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim");
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9381ecfa/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializerTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializerTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializerTest.java
index 07b5e56..ae22ea4 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializerTest.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializerTest.java
@@ -1984,12 +1984,12 @@ public class ODataXmlSerializerTest {
checkXMLEqual(expected, resultString);
}
- private void checkXMLEqual(String resultString, String expected) throws SAXException, IOException {
+ private void checkXMLEqual(final String expected, final String resultString) throws SAXException, IOException {
Diff diff = XMLUnit.compareXML(expected, resultString);
diff.overrideDifferenceListener(DIFFERENCE_LISTENER);
XMLAssert.assertXMLEqual(diff, true);
}
-
+
public static class CustomDifferenceListener implements DifferenceListener {
@Override
public int differenceFound(Difference difference) {