[OLINGO-864] use local timezone for technical service

Signed-off-by: Christian Amend <christian.amend@sap.com>
This commit is contained in:
Klaus Straubinger 2016-03-01 14:25:47 +01:00 committed by Christian Amend
parent d566b186ae
commit 9381ecfa56
18 changed files with 200 additions and 239 deletions

View File

@ -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());
}
}

View File

@ -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(

View File

@ -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());
}

View File

@ -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);

View File

@ -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>

View File

@ -113,6 +113,6 @@ abstract class AbstractPrimitiveType implements EdmPrimitiveType {
@Override
public String toString() {
return new FullQualifiedName(getNamespace(), getName()).getFullQualifiedNameAsString();
return getFullQualifiedName().getFullQualifiedNameAsString();
}
}

View File

@ -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.");

View File

@ -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);
}

View File

@ -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));

View File

@ -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");
}
}

View File

@ -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");
}

View File

@ -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");
@ -130,6 +119,14 @@ public class EdmTimeOfDayTest extends PrimitiveTypeBaseTest {
expectTypeErrorInValueOfString(instance, "11:12:13");
}
@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);

View File

@ -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) {

View File

@ -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;
}

View File

@ -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);

View File

@ -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);

View File

@ -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");

View File

@ -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) {