[OLINGO-356] Rework EdmPrimitive Type exceptions

This commit is contained in:
Michael Bolz 2014-09-03 11:04:36 +02:00
parent f3289fb103
commit 3ece19c964
41 changed files with 273 additions and 450 deletions

View File

@ -18,7 +18,9 @@
*/
package org.apache.olingo.commons.api.edm;
public class EdmPrimitiveTypeException extends Exception {
import org.apache.olingo.commons.api.ODataException;
public class EdmPrimitiveTypeException extends ODataException {
private static final long serialVersionUID = -93578822384514620L;

View File

@ -112,8 +112,7 @@ public abstract class AbstractEdmEnumType extends EdmTypeImpl implements EdmEnum
}
}
if (memberValueLong == null) {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)");
throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content.");
}
result = result == null ? memberValueLong : result | memberValueLong;
}
@ -127,7 +126,7 @@ public abstract class AbstractEdmEnumType extends EdmTypeImpl implements EdmEnum
if (value == null) {
if (isNullable != null && !isNullable) {
throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_NULL_NOT_ALLOWED");
throw new EdmPrimitiveTypeException("The literal 'null' is not allowed.");
}
return null;
}
@ -135,11 +134,10 @@ public abstract class AbstractEdmEnumType extends EdmTypeImpl implements EdmEnum
try {
return EdmInt64.convertNumber(parseEnumValue(value), returnType);
} catch (final IllegalArgumentException e) {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType), e");
throw new EdmPrimitiveTypeException("The literal '" + value
+ "' cannot be converted to value type " + returnType + ".", e);
} catch (final ClassCastException e) {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e");
throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.", e);
}
}
@ -159,8 +157,7 @@ public abstract class AbstractEdmEnumType extends EdmTypeImpl implements EdmEnum
}
if (remaining != 0) {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)");
throw new EdmPrimitiveTypeException("The value '" + value + "' is not valid.");
}
return result.toString();
}
@ -171,15 +168,14 @@ public abstract class AbstractEdmEnumType extends EdmTypeImpl implements EdmEnum
if (value == null) {
if (isNullable != null && !isNullable) {
throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.VALUE_NULL_NOT_ALLOWED");
throw new EdmPrimitiveTypeException("The value NULL is not allowed.");
}
return null;
}
if (value instanceof Byte || value instanceof Short || value instanceof Integer || value instanceof Long) {
return constructEnumValue(((Number) value).longValue());
} else {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
}
}
@ -199,7 +195,7 @@ public abstract class AbstractEdmEnumType extends EdmTypeImpl implements EdmEnum
&& literal.startsWith(uriPrefix) && literal.endsWith(uriSuffix)) {
return literal.substring(uriPrefix.length(), literal.length() - uriSuffix.length());
} else {
throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(literal)");
throw new EdmPrimitiveTypeException("The literal '" + literal + "' has illegal content.");
}
}

View File

@ -67,7 +67,7 @@ public abstract class AbstractGeospatialType<T extends Geospatial> extends Singl
private Matcher getMatcher(final Pattern pattern, final String value) throws EdmPrimitiveTypeException {
final Matcher matcher = pattern.matcher(value);
if (!matcher.matches()) {
throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)");
throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content.");
}
Geospatial.Dimension _dimension = null;
@ -76,10 +76,10 @@ public abstract class AbstractGeospatialType<T extends Geospatial> extends Singl
_dimension = Geospatial.Dimension.valueOf(matcher.group(1).toUpperCase());
_type = Geospatial.Type.valueOf(matcher.group(3).toUpperCase());
} catch (IllegalArgumentException e) {
throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)", e);
throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content.", e);
}
if (_dimension != this.dimension || (!pattern.equals(COLLECTION_PATTERN) && _type != this.type)) {
throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)");
throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content.");
}
return matcher;
@ -91,7 +91,7 @@ public abstract class AbstractGeospatialType<T extends Geospatial> extends Singl
final String[] pointCoo = StringUtils.split(point, ' ');
if (pointCoo == null || pointCoo.length != 2) {
throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)");
throw new EdmPrimitiveTypeException("The literal '" + point + "' has illegal content.");
}
final Point result = new Point(this.dimension, srid);
@ -309,8 +309,7 @@ public abstract class AbstractGeospatialType<T extends Geospatial> extends Singl
final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
if (dimension != point.getDimension()) {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)");
throw new EdmPrimitiveTypeException("The value '" + point + "' is not valid.");
}
return toStringBuilder(point.getSrid()).
@ -325,8 +324,7 @@ public abstract class AbstractGeospatialType<T extends Geospatial> extends Singl
final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
if (dimension != multiPoint.getDimension()) {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)");
throw new EdmPrimitiveTypeException("The value '" + multiPoint + "' is not valid.");
}
final StringBuilder result = toStringBuilder(multiPoint.getSrid()).
@ -365,8 +363,7 @@ public abstract class AbstractGeospatialType<T extends Geospatial> extends Singl
final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
if (dimension != lineString.getDimension()) {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)");
throw new EdmPrimitiveTypeException("The value '" + lineString + "' is not valid.");
}
return toStringBuilder(lineString.getSrid()).
@ -380,8 +377,7 @@ public abstract class AbstractGeospatialType<T extends Geospatial> extends Singl
final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
if (dimension != multiLineString.getDimension()) {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)");
throw new EdmPrimitiveTypeException("The value '" + multiLineString + "' is not valid.");
}
final StringBuilder result = toStringBuilder(multiLineString.getSrid()).
@ -428,8 +424,7 @@ public abstract class AbstractGeospatialType<T extends Geospatial> extends Singl
final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
if (dimension != polygon.getDimension()) {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)");
throw new EdmPrimitiveTypeException("The value '" + polygon + "' is not valid.");
}
return toStringBuilder(polygon.getSrid()).
@ -443,8 +438,7 @@ public abstract class AbstractGeospatialType<T extends Geospatial> extends Singl
final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
if (dimension != multiPolygon.getDimension()) {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)");
throw new EdmPrimitiveTypeException("The value '" + multiPolygon + "' is not valid.");
}
final StringBuilder result = toStringBuilder(multiPolygon.getSrid()).
@ -467,12 +461,10 @@ public abstract class AbstractGeospatialType<T extends Geospatial> extends Singl
final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
if (dimension != collection.getDimension()) {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)");
throw new EdmPrimitiveTypeException("The value '" + collection + "' is not valid.");
}
final StringBuilder result = toStringBuilder(collection.getSrid()).
append("Collection(");
StringBuilder result = toStringBuilder(collection.getSrid()).append("Collection(");
if (collection.iterator().hasNext()) {
final Geospatial item = collection.iterator().next();

View File

@ -62,7 +62,7 @@ abstract class AbstractPrimitiveType implements EdmPrimitiveType {
if (value == null) {
if (isNullable != null && !isNullable) {
throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_NULL_NOT_ALLOWED");
throw new EdmPrimitiveTypeException("The literal 'null' is not allowed.");
}
return null;
}
@ -79,7 +79,7 @@ abstract class AbstractPrimitiveType implements EdmPrimitiveType {
final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
if (value == null) {
if (isNullable != null && !isNullable) {
throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.VALUE_NULL_NOT_ALLOWED");
throw new EdmPrimitiveTypeException("The value NULL is not allowed.");
}
return null;
}
@ -92,11 +92,8 @@ abstract class AbstractPrimitiveType implements EdmPrimitiveType {
@Override
public String toUriLiteral(final String literal) {
return literal == null
? null
: uriPrefix.isEmpty() && uriSuffix.isEmpty()
? literal
: uriPrefix + literal + uriSuffix;
return literal == null ? null :
uriPrefix.isEmpty() && uriSuffix.isEmpty() ? literal : uriPrefix + literal + uriSuffix;
}
@Override
@ -110,7 +107,7 @@ abstract class AbstractPrimitiveType implements EdmPrimitiveType {
return literal.substring(uriPrefix.length(), literal.length() - uriSuffix.length());
} else {
throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(literal)");
throw new EdmPrimitiveTypeException("The literal '" + literal + "' has illegal content.");
}
}

View File

@ -163,11 +163,10 @@ public class EdmBinary extends SingletonPrimitiveType {
final Integer scale, final Boolean isUnicode, final Class<T> returnType) throws EdmPrimitiveTypeException {
if (value == null || !isBase64(value.getBytes(UTF_8))) {
throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)");
throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content.");
}
if (!validateMaxLength(value, maxLength)) {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.LITERAL_FACETS_NOT_MATCHED.addContent(value, facets)");
throw new EdmPrimitiveTypeException("The literal '" + value + "' does not match the facets' constraints.");
}
final byte[] result = Base64.decodeBase64(value.getBytes(UTF_8));
@ -181,7 +180,7 @@ public class EdmBinary extends SingletonPrimitiveType {
}
return returnType.cast(byteArray);
} else {
throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)");
throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.");
}
}
@ -200,13 +199,11 @@ public class EdmBinary extends SingletonPrimitiveType {
byteArrayValue[i] = ((Byte[]) value)[i].byteValue();
}
} else {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
}
if (maxLength != null && byteArrayValue.length > maxLength) {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_FACETS_NOT_MATCHED.addContent(value, facets)");
throw new EdmPrimitiveTypeException("The value '" + value + "' does not match the facets' constraints.");
}
return new String(Base64.encodeBase64(byteArrayValue, false), UTF_8);

View File

@ -57,12 +57,10 @@ public final class EdmBoolean extends SingletonPrimitiveType {
if (returnType.isAssignableFrom(Boolean.class)) {
return returnType.cast(Boolean.valueOf("true".equals(value)));
} else {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)");
throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.");
}
} else {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)");
throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content.");
}
}
@ -74,8 +72,7 @@ public final class EdmBoolean extends SingletonPrimitiveType {
if (value instanceof Boolean) {
return Boolean.toString((Boolean) value);
} else {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
}
}
}

View File

@ -54,22 +54,19 @@ public final class EdmByte extends SingletonPrimitiveType {
try {
valueShort = Short.parseShort(value);
} catch (final NumberFormatException e) {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)", e);
throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content.", e);
}
if (valueShort < 0 || valueShort >= 1 << Byte.SIZE) {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)");
throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content.");
}
try {
return EdmInt64.convertNumber(valueShort, returnType);
} catch (final IllegalArgumentException e) {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType), e");
throw new EdmPrimitiveTypeException("The literal '" + value
+ "' cannot be converted to value type " + returnType + ".", e);
} catch (final ClassCastException e) {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e");
throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.", e);
}
}
@ -82,20 +79,17 @@ public final class EdmByte extends SingletonPrimitiveType {
if (((Number) value).longValue() >= 0 && ((Number) value).longValue() < 1 << Byte.SIZE) {
return value.toString();
} else {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)");
throw new EdmPrimitiveTypeException("The value '" + value + "' is not valid.");
}
} else if (value instanceof BigInteger) {
if (((BigInteger) value).compareTo(BigInteger.ZERO) >= 0
&& ((BigInteger) value).compareTo(BigInteger.valueOf(1 << Byte.SIZE)) < 0) {
return value.toString();
} else {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)");
throw new EdmPrimitiveTypeException("The value '" + value + "' is not valid.");
}
} else {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
}
}
}

View File

@ -53,7 +53,7 @@ public final class EdmDate extends SingletonPrimitiveType {
final Matcher matcher = PATTERN.matcher(value);
if (!matcher.matches()) {
throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)");
throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content.");
}
dateTimeValue.set(
@ -64,11 +64,9 @@ public final class EdmDate extends SingletonPrimitiveType {
try {
return EdmDateTimeOffset.convertDateTime(dateTimeValue, 0, returnType);
} catch (final IllegalArgumentException e) {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)", e);
throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content.", e);
} catch (final ClassCastException e) {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)", e);
throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.", e);
}
}

View File

@ -61,7 +61,7 @@ public final class EdmDateTime extends SingletonPrimitiveType {
try {
date = DATE_FORMAT.get().parse(dateParts[0]);
} catch (ParseException e) {
throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)", e);
throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content.", e);
}
TimeZone timezone = null;
@ -85,8 +85,7 @@ public final class EdmDateTime extends SingletonPrimitiveType {
if (decimals != null) {
if (decimals.length() > (precision == null ? 0 : precision)) {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.LITERAL_FACETS_NOT_MATCHED.addContent(value, facets)");
throw new EdmPrimitiveTypeException("The literal '" + value + "' does not match the facets' constraints.");
}
final String milliSeconds = decimals.length() > 3
? decimals.substring(0, 3)
@ -105,8 +104,8 @@ public final class EdmDateTime extends SingletonPrimitiveType {
} else if (returnType.isAssignableFrom(Timestamp.class)) {
return returnType.cast(timestamp);
} else {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType)");
throw new EdmPrimitiveTypeException("The literal '" + value
+ "' cannot be converted to value type " + returnType + ".");
}
}
@ -130,7 +129,7 @@ public final class EdmDateTime extends SingletonPrimitiveType {
EdmDateTimeOffset.appendFractionalSeconds(result, fractionalSecs, precision);
return result.toString();
} else {
throw new EdmPrimitiveTypeException("EdmDateTime only supports conversion from Calendar and Timestamp");
throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
}
}
}

View File

@ -63,15 +63,14 @@ public final class EdmDateTimeOffset extends SingletonPrimitiveType {
final Matcher matcher = PATTERN.matcher(value);
if (!matcher.matches()) {
throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)");
throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content.");
}
final String timeZoneOffset = matcher.group(9) == null || matcher.group(10) == null
|| matcher.group(10).matches("[-+]0+:0+") ? null : matcher.group(10);
final Calendar dateTimeValue = Calendar.getInstance(TimeZone.getTimeZone("GMT" + timeZoneOffset));
if (dateTimeValue.get(Calendar.ZONE_OFFSET) == 0 && timeZoneOffset != null) {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)");
throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content.");
}
dateTimeValue.clear();
@ -86,13 +85,11 @@ public final class EdmDateTimeOffset extends SingletonPrimitiveType {
int nanoSeconds = 0;
if (matcher.group(7) != null) {
if (matcher.group(7).length() == 1 || matcher.group(7).length() > 13) {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)");
throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content.");
}
final String decimals = matcher.group(8);
if (decimals.length() > (precision == null ? 0 : precision)) {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.LITERAL_FACETS_NOT_MATCHED.addContent(value, facets)");
throw new EdmPrimitiveTypeException("The literal '" + value + "' does not match the facets' constraints.");
}
if (returnType.isAssignableFrom(Timestamp.class)) {
if (!decimals.isEmpty()) {
@ -110,11 +107,9 @@ public final class EdmDateTimeOffset extends SingletonPrimitiveType {
try {
return convertDateTime(dateTimeValue, nanoSeconds, returnType);
} catch (final IllegalArgumentException e) {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)", e);
throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content.", e);
} catch (final ClassCastException e) {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)", e);
throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.", e);
}
}
@ -196,8 +191,7 @@ public final class EdmDateTimeOffset extends SingletonPrimitiveType {
appendMilliseconds(result, fractionalSecs, precision);
}
} catch (final IllegalArgumentException e) {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_FACETS_NOT_MATCHED.addContent(value, facets)", e);
throw new EdmPrimitiveTypeException("The value '" + value + "' does not match the facets' constraints.", e);
}
final int offsetInMinutes = (dateTimeValue.get(Calendar.ZONE_OFFSET)
@ -231,8 +225,7 @@ public final class EdmDateTimeOffset extends SingletonPrimitiveType {
dateTimeValue = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
dateTimeValue.setTimeInMillis((Long) value);
} else {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(" + value.getClass().getName() + ")");
throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
}
return dateTimeValue;
}

View File

@ -89,21 +89,19 @@ public final class EdmDecimal extends SingletonPrimitiveType {
final Integer scale, final Boolean isUnicode, final Class<T> returnType) throws EdmPrimitiveTypeException {
if (!validateLiteral(value)) {
throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)");
throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content.");
}
if (!validatePrecisionAndScale(value, precision, scale)) {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.LITERAL_FACETS_NOT_MATCHED.addContent(value, facets)");
throw new EdmPrimitiveTypeException("The literal '" + value + "' does not match the facets' constraints.");
}
try {
return convertDecimal(new BigDecimal(value), returnType);
} catch (final IllegalArgumentException e) {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType), e");
throw new EdmPrimitiveTypeException("The literal '" + value
+ "' cannot be converted to value type " + returnType + ".", e);
} catch (final ClassCastException e) {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e");
throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.", e);
}
}
@ -168,8 +166,7 @@ public final class EdmDecimal extends SingletonPrimitiveType {
result = value.toString();
final int digits = result.startsWith("-") ? result.length() - 1 : result.length();
if (precision != null && precision < digits) {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_FACETS_NOT_MATCHED.addContent(value, facets)");
throw new EdmPrimitiveTypeException("The value '" + value + "' does not match the facets' constraints.");
}
} else if (value instanceof Double || value instanceof Float || value instanceof BigDecimal) {
@ -178,7 +175,7 @@ public final class EdmDecimal extends SingletonPrimitiveType {
bigDecimalValue = value instanceof Double ? BigDecimal.valueOf((Double) value)
: value instanceof Float ? BigDecimal.valueOf((Float) value) : (BigDecimal) value;
} catch (final NumberFormatException e) {
throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)", e);
throw new EdmPrimitiveTypeException("The value '" + value + "' is not valid.", e);
}
final int digits = bigDecimalValue.scale() >= 0
@ -187,13 +184,11 @@ public final class EdmDecimal extends SingletonPrimitiveType {
if ((precision == null || precision >= digits) && (bigDecimalValue.scale() <= (scale == null ? 0 : scale))) {
result = bigDecimalValue.toPlainString();
} else {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_FACETS_NOT_MATCHED.addContent(value, facets)");
throw new EdmPrimitiveTypeException("The value '" + value + "' does not match the facets' constraints.");
}
} else {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
}
return result;

View File

@ -78,7 +78,7 @@ public final class EdmDouble extends SingletonPrimitiveType {
} else {
// Now only "normal" numbers remain.
if (!PATTERN.matcher(value).matches()) {
throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)");
throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content.");
}
// The number format is checked above, so we don't have to catch NumberFormatException.
@ -87,7 +87,7 @@ public final class EdmDouble extends SingletonPrimitiveType {
// "Real" infinite values have been treated already above, so we can throw an exception
// if the conversion to a double results in an infinite value.
if (result.isInfinite() || BigDecimal.valueOf(result).compareTo(bigDecimalValue) != 0) {
throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)");
throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content.");
}
}
@ -97,18 +97,17 @@ public final class EdmDouble extends SingletonPrimitiveType {
if (returnType.isAssignableFrom(Float.class)) {
return returnType.cast(result.floatValue());
} else {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType)");
throw new EdmPrimitiveTypeException("The literal '" + value
+ "' cannot be converted to value type " + returnType + ".");
}
} else {
try {
return EdmDecimal.convertDecimal(bigDecimalValue, returnType);
} catch (final IllegalArgumentException e) {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType), e");
throw new EdmPrimitiveTypeException("The literal '" + value
+ "' cannot be converted to value type " + returnType + ".", e);
} catch (final ClassCastException e) {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e");
throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.", e);
}
}
}
@ -121,7 +120,7 @@ public final class EdmDouble extends SingletonPrimitiveType {
if (Math.abs((Long) value) < 1L << 51) {
return value.toString();
} else {
throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)");
throw new EdmPrimitiveTypeException("The value '" + value + "' is not valid.");
}
} else if (value instanceof Integer || value instanceof Short || value instanceof Byte) {
return value.toString();
@ -136,11 +135,10 @@ public final class EdmDouble extends SingletonPrimitiveType {
if (!Double.isInfinite(doubleValue) && BigDecimal.valueOf(doubleValue).compareTo((BigDecimal) value) == 0) {
return ((BigDecimal) value).toString();
} else {
throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)");
throw new EdmPrimitiveTypeException("The value '" + value + "' is not valid.");
}
} else {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
}
}
}

View File

@ -56,8 +56,7 @@ public class EdmDuration extends SingletonPrimitiveType {
if (!matcher.matches()
|| matcher.group(1) == null && matcher.group(2) == null && matcher.group(3) == null
&& matcher.group(4) == null) {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(literal)");
throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content.");
}
BigDecimal result = (matcher.group(1) == null ? BigDecimal.ZERO
@ -71,18 +70,16 @@ public class EdmDuration extends SingletonPrimitiveType {
if (result.scale() <= (precision == null ? 0 : precision)) {
result = value.charAt(0) == '-' ? result.negate() : result;
} else {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.LITERAL_FACETS_NOT_MATCHED.addContent(literal, facets)");
throw new EdmPrimitiveTypeException("The literal '" + value + "' does not match the facets' constraints.");
}
try {
return EdmDecimal.convertDecimal(result, returnType);
} catch (final IllegalArgumentException e) {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType), e");
throw new EdmPrimitiveTypeException("The literal '" + value
+ "' cannot be converted to value type " + returnType + ".", e);
} catch (final ClassCastException e) {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e");
throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.", e);
}
}
@ -99,13 +96,11 @@ public class EdmDuration extends SingletonPrimitiveType {
} else if (value instanceof BigInteger) {
valueDecimal = new BigDecimal((BigInteger) value);
} else {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
}
if (valueDecimal.scale() > (precision == null ? 0 : precision)) {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_FACETS_NOT_MATCHED.addContent(value, facets)");
throw new EdmPrimitiveTypeException("The value '" + value + "' does not match the facets' constraints.");
}
final StringBuilder result = new StringBuilder();

View File

@ -38,16 +38,12 @@ public final class EdmGeography extends AbstractGeospatialType<Geospatial> {
protected <T> T internalValueOfString(final String value, final Boolean isNullable, final Integer maxLength,
final Integer precision, final Integer scale, final Boolean isUnicode, final Class<T> returnType)
throws EdmPrimitiveTypeException {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)");
throw new EdmPrimitiveTypeException("Not implemented!");
}
@Override
protected <T> String internalValueToString(final T value, final Boolean isNullable, final Integer maxLength,
final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
throw new EdmPrimitiveTypeException("Not implemented!");
}
}

View File

@ -45,8 +45,7 @@ public final class EdmGeographyCollection extends AbstractGeospatialType<Geospat
if (returnType.isAssignableFrom(GeospatialCollection.class)) {
return returnType.cast(collection);
} else {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)");
throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.");
}
}
@ -58,7 +57,6 @@ public final class EdmGeographyCollection extends AbstractGeospatialType<Geospat
return toString((GeospatialCollection) value, isNullable, maxLength, precision, scale, isUnicode);
}
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
}
}

View File

@ -44,8 +44,7 @@ public final class EdmGeographyLineString extends AbstractGeospatialType<LineStr
if (returnType.isAssignableFrom(LineString.class)) {
return returnType.cast(lineString);
} else {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)");
throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.");
}
}
@ -57,7 +56,6 @@ public final class EdmGeographyLineString extends AbstractGeospatialType<LineStr
return toString((LineString) value, isNullable, maxLength, precision, scale, isUnicode);
}
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
}
}

View File

@ -45,8 +45,7 @@ public final class EdmGeographyMultiLineString extends AbstractGeospatialType<Mu
if (returnType.isAssignableFrom(MultiLineString.class)) {
return returnType.cast(multiLineString);
} else {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)");
throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.");
}
}
@ -58,7 +57,6 @@ public final class EdmGeographyMultiLineString extends AbstractGeospatialType<Mu
return toString((MultiLineString) value, isNullable, maxLength, precision, scale, isUnicode);
}
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
}
}

View File

@ -44,8 +44,7 @@ public final class EdmGeographyMultiPoint extends AbstractGeospatialType<MultiPo
if (returnType.isAssignableFrom(MultiPoint.class)) {
return returnType.cast(point);
} else {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)");
throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.");
}
}
@ -58,8 +57,7 @@ public final class EdmGeographyMultiPoint extends AbstractGeospatialType<MultiPo
return toString((MultiPoint) value, isNullable, maxLength, precision, scale, isUnicode);
}
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
}
}

View File

@ -44,8 +44,7 @@ public final class EdmGeographyMultiPolygon extends AbstractGeospatialType<Multi
if (returnType.isAssignableFrom(MultiPolygon.class)) {
return returnType.cast(multiPolygon);
} else {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)");
throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.");
}
}
@ -57,7 +56,6 @@ public final class EdmGeographyMultiPolygon extends AbstractGeospatialType<Multi
return toString((MultiPolygon) value, isNullable, maxLength, precision, scale, isUnicode);
}
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
}
}

View File

@ -44,8 +44,7 @@ public final class EdmGeographyPoint extends AbstractGeospatialType<Point> {
if (returnType.isAssignableFrom(Point.class)) {
return returnType.cast(point);
} else {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)");
throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.");
}
}
@ -57,8 +56,7 @@ public final class EdmGeographyPoint extends AbstractGeospatialType<Point> {
return toString((Point) value, isNullable, maxLength, precision, scale, isUnicode);
}
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
}
}

View File

@ -44,8 +44,7 @@ public final class EdmGeographyPolygon extends AbstractGeospatialType<Polygon> {
if (returnType.isAssignableFrom(Polygon.class)) {
return returnType.cast(polygon);
} else {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)");
throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.");
}
}
@ -57,7 +56,6 @@ public final class EdmGeographyPolygon extends AbstractGeospatialType<Polygon> {
return toString((Polygon) value, isNullable, maxLength, precision, scale, isUnicode);
}
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
}
}

View File

@ -38,16 +38,12 @@ public final class EdmGeometry extends AbstractGeospatialType<Geospatial> {
protected <T> T internalValueOfString(final String value, final Boolean isNullable, final Integer maxLength,
final Integer precision, final Integer scale, final Boolean isUnicode, final Class<T> returnType)
throws EdmPrimitiveTypeException {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)");
throw new EdmPrimitiveTypeException("Not implemented!");
}
@Override
protected <T> String internalValueToString(final T value, final Boolean isNullable, final Integer maxLength,
final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
throw new EdmPrimitiveTypeException("Not implemented!");
}
}

View File

@ -45,8 +45,7 @@ public final class EdmGeometryCollection extends AbstractGeospatialType<Geospati
if (returnType.isAssignableFrom(GeospatialCollection.class)) {
return returnType.cast(collection);
} else {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)");
throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.");
}
}
@ -58,7 +57,6 @@ public final class EdmGeometryCollection extends AbstractGeospatialType<Geospati
return toString((GeospatialCollection) value, isNullable, maxLength, precision, scale, isUnicode);
}
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
}
}

View File

@ -44,8 +44,7 @@ public final class EdmGeometryLineString extends AbstractGeospatialType<LineStri
if (returnType.isAssignableFrom(LineString.class)) {
return returnType.cast(lineString);
} else {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)");
throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.");
}
}
@ -57,7 +56,6 @@ public final class EdmGeometryLineString extends AbstractGeospatialType<LineStri
return toString((LineString) value, isNullable, maxLength, precision, scale, isUnicode);
}
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
}
}

View File

@ -45,8 +45,7 @@ public final class EdmGeometryMultiLineString extends AbstractGeospatialType<Mul
if (returnType.isAssignableFrom(MultiLineString.class)) {
return returnType.cast(multiLineString);
} else {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)");
throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.");
}
}
@ -58,7 +57,6 @@ public final class EdmGeometryMultiLineString extends AbstractGeospatialType<Mul
return toString((MultiLineString) value, isNullable, maxLength, precision, scale, isUnicode);
}
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
}
}

View File

@ -44,10 +44,8 @@ public final class EdmGeometryMultiPoint extends AbstractGeospatialType<MultiPoi
if (returnType.isAssignableFrom(MultiPoint.class)) {
return returnType.cast(point);
} else {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)");
throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.");
}
}
@Override
@ -58,7 +56,6 @@ public final class EdmGeometryMultiPoint extends AbstractGeospatialType<MultiPoi
return toString((MultiPoint) value, isNullable, maxLength, precision, scale, isUnicode);
}
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
}
}

View File

@ -45,8 +45,7 @@ public final class EdmGeometryMultiPolygon extends AbstractGeospatialType<MultiP
if (returnType.isAssignableFrom(MultiPolygon.class)) {
return returnType.cast(multiPolygon);
} else {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)");
throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.");
}
}
@ -58,7 +57,6 @@ public final class EdmGeometryMultiPolygon extends AbstractGeospatialType<MultiP
return toString((MultiPolygon) value, isNullable, maxLength, precision, scale, isUnicode);
}
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
}
}

View File

@ -44,8 +44,7 @@ public final class EdmGeometryPoint extends AbstractGeospatialType<Point> {
if (returnType.isAssignableFrom(Point.class)) {
return returnType.cast(point);
} else {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)");
throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.");
}
}
@ -57,7 +56,6 @@ public final class EdmGeometryPoint extends AbstractGeospatialType<Point> {
return toString((Point) value, isNullable, maxLength, precision, scale, isUnicode);
}
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
}
}

View File

@ -44,8 +44,7 @@ public final class EdmGeometryPolygon extends AbstractGeospatialType<Polygon> {
if (returnType.isAssignableFrom(Polygon.class)) {
return returnType.cast(polygon);
} else {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)");
throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.");
}
}
@ -57,7 +56,6 @@ public final class EdmGeometryPolygon extends AbstractGeospatialType<Polygon> {
return toString((Polygon) value, isNullable, maxLength, precision, scale, isUnicode);
}
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
}
}

View File

@ -61,15 +61,13 @@ public final class EdmGuid extends SingletonPrimitiveType {
if (validateLiteral(value)) {
result = UUID.fromString(value);
} else {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)");
throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content.");
}
if (returnType.isAssignableFrom(UUID.class)) {
return returnType.cast(result);
} else {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)");
throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.");
}
}
@ -81,8 +79,7 @@ public final class EdmGuid extends SingletonPrimitiveType {
if (value instanceof UUID) {
return ((UUID) value).toString();
} else {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
}
}
}

View File

@ -55,18 +55,16 @@ public final class EdmInt16 extends SingletonPrimitiveType {
try {
valueShort = Short.parseShort(value);
} catch (final NumberFormatException e) {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)", e);
throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content.", e);
}
try {
return EdmInt64.convertNumber(valueShort, returnType);
} catch (final IllegalArgumentException e) {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType), e");
throw new EdmPrimitiveTypeException("The literal '" + value
+ "' cannot be converted to value type " + returnType + ".", e);
} catch (final ClassCastException e) {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e");
throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.", e);
}
}
@ -81,19 +79,16 @@ public final class EdmInt16 extends SingletonPrimitiveType {
&& ((Number) value).longValue() <= Short.MAX_VALUE) {
return value.toString();
} else {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)");
throw new EdmPrimitiveTypeException("The value '" + value + "' is not valid.");
}
} else if (value instanceof BigInteger) {
if (((BigInteger) value).bitLength() < Short.SIZE) {
return value.toString();
} else {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)");
throw new EdmPrimitiveTypeException("The value '" + value + "' is not valid.");
}
} else {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
}
}
}

View File

@ -57,17 +57,16 @@ public final class EdmInt32 extends SingletonPrimitiveType {
try {
valueInteger = Integer.parseInt(value);
} catch (final NumberFormatException e) {
throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)", e);
throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content.", e);
}
try {
return EdmInt64.convertNumber(valueInteger, returnType);
} catch (final IllegalArgumentException e) {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType), e");
throw new EdmPrimitiveTypeException("The literal '" + value
+ "' cannot be converted to value type " + returnType + ".", e);
} catch (final ClassCastException e) {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e");
throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.", e);
}
}
@ -82,19 +81,16 @@ public final class EdmInt32 extends SingletonPrimitiveType {
if ((Long) value >= Integer.MIN_VALUE && (Long) value <= Integer.MAX_VALUE) {
return value.toString();
} else {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)");
throw new EdmPrimitiveTypeException("The value '" + value + "' is not valid.");
}
} else if (value instanceof BigInteger) {
if (((BigInteger) value).bitLength() < Integer.SIZE) {
return value.toString();
} else {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)");
throw new EdmPrimitiveTypeException("The value '" + value + "' is not valid.");
}
} else {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
}
}
}

View File

@ -58,18 +58,16 @@ public final class EdmInt64 extends SingletonPrimitiveType {
try {
valueLong = Long.parseLong(value);
} catch (final NumberFormatException e) {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)", e);
throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content.", e);
}
try {
return convertNumber(valueLong, returnType);
} catch (final IllegalArgumentException e) {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType), e");
throw new EdmPrimitiveTypeException("The literal '" + value
+ "' cannot be converted to value type " + returnType + ".", e);
} catch (final ClassCastException e) {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e");
throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.", e);
}
}
@ -124,12 +122,10 @@ public final class EdmInt64 extends SingletonPrimitiveType {
if (((BigInteger) value).bitLength() < Long.SIZE) {
return value.toString();
} else {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)");
throw new EdmPrimitiveTypeException("The value '" + value + "' is not valid.");
}
} else {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
}
}
}

View File

@ -54,15 +54,13 @@ public final class EdmSByte extends SingletonPrimitiveType {
try {
valueByte = Byte.parseByte(value);
} catch (final NumberFormatException e) {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)", e);
throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content.", e);
}
try {
return EdmInt64.convertNumber(valueByte, returnType);
} catch (final ClassCastException e) {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e");
throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.", e);
}
}
@ -77,19 +75,16 @@ public final class EdmSByte extends SingletonPrimitiveType {
if (((Number) value).longValue() >= Byte.MIN_VALUE && ((Number) value).longValue() <= Byte.MAX_VALUE) {
return value.toString();
} else {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)");
throw new EdmPrimitiveTypeException("The value '" + value + "' is not valid.");
}
} else if (value instanceof BigInteger) {
if (((BigInteger) value).bitLength() < Byte.SIZE) {
return value.toString();
} else {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)");
throw new EdmPrimitiveTypeException("The value '" + value + "' is not valid.");
}
} else {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
}
}
}

View File

@ -71,7 +71,7 @@ public final class EdmSingle extends SingletonPrimitiveType {
} else {
// Now only "normal" numbers remain.
if (!PATTERN.matcher(value).matches()) {
throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)");
throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content.");
}
// The number format is checked above, so we don't have to catch NumberFormatException.
@ -80,7 +80,7 @@ public final class EdmSingle extends SingletonPrimitiveType {
// "Real" infinite values have been treated already above, so we can throw an exception
// if the conversion to a float results in an infinite value.
if (result.isInfinite() || bigDecimalValue.compareTo(new BigDecimal(result.toString())) != 0) {
throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)");
throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content.");
}
}
@ -90,18 +90,17 @@ public final class EdmSingle extends SingletonPrimitiveType {
if (returnType.isAssignableFrom(Double.class)) {
return returnType.cast(result.doubleValue());
} else {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType)");
throw new EdmPrimitiveTypeException("The literal '" + value
+ "' cannot be converted to value type " + returnType + ".");
}
} else {
try {
return EdmDecimal.convertDecimal(bigDecimalValue, returnType);
} catch (final IllegalArgumentException e) {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE.addContent(value, returnType), e");
throw new EdmPrimitiveTypeException("The literal '" + value
+ "' cannot be converted to value type " + returnType + ".", e);
} catch (final ClassCastException e) {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType), e");
throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.", e);
}
}
}
@ -115,7 +114,7 @@ public final class EdmSingle extends SingletonPrimitiveType {
if (Math.abs(((Number) value).longValue()) < 1L << 22) {
return value.toString();
} else {
throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)");
throw new EdmPrimitiveTypeException("The value '" + value + "' is not valid.");
}
} else if (value instanceof Short || value instanceof Byte) {
return value.toString();
@ -127,7 +126,7 @@ public final class EdmSingle extends SingletonPrimitiveType {
if (floatString.equals(((Double) value).toString())) {
return floatString;
} else {
throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)");
throw new EdmPrimitiveTypeException("The value '" + value + "' is not valid.");
}
}
} else if (value instanceof Float) {
@ -138,11 +137,10 @@ public final class EdmSingle extends SingletonPrimitiveType {
if (!Float.isInfinite(floatValue) && BigDecimal.valueOf(floatValue).compareTo((BigDecimal) value) == 0) {
return ((BigDecimal) value).toString();
} else {
throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT.addContent(value)");
throw new EdmPrimitiveTypeException("The value '" + value + "' is not valid.");
}
} else {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
}
}
}

View File

@ -64,14 +64,13 @@ public final class EdmStream extends SingletonPrimitiveType {
try {
stream = new URI(value);
} catch (final URISyntaxException e) {
throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)", e);
throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content.", e);
}
if (returnType.isAssignableFrom(URI.class)) {
return returnType.cast(stream);
} else {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)");
throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.");
}
}
@ -83,8 +82,7 @@ public final class EdmStream extends SingletonPrimitiveType {
if (value instanceof URI) {
return ((URI) value).toASCIIString();
} else {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(value.getClass())");
throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");
}
}
}

View File

@ -52,15 +52,13 @@ public final class EdmString extends SingletonPrimitiveType {
if (isUnicode != null && !isUnicode && !PATTERN_ASCII.matcher(value).matches()
|| maxLength != null && maxLength < value.length()) {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.LITERAL_FACETS_NOT_MATCHED.addContent(value, facets)");
throw new EdmPrimitiveTypeException("The literal '" + value + "' does not match the facets' constraints.");
}
if (returnType.isAssignableFrom(String.class)) {
return returnType.cast(value);
} else {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)");
throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.");
}
}
@ -73,8 +71,7 @@ public final class EdmString extends SingletonPrimitiveType {
if (isUnicode != null && !isUnicode && !PATTERN_ASCII.matcher(result).matches()
|| maxLength != null && maxLength < result.length()) {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_FACETS_NOT_MATCHED.addContent(value, facets)");
throw new EdmPrimitiveTypeException("The value '" + value + "' does not match the facets' constraints.");
}
return result;

View File

@ -49,7 +49,7 @@ public final class EdmTimeOfDay extends SingletonPrimitiveType {
final Matcher matcher = PATTERN.matcher(value);
if (!matcher.matches()) {
throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)");
throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content.");
}
final Calendar dateTimeValue = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
@ -61,12 +61,11 @@ public final class EdmTimeOfDay extends SingletonPrimitiveType {
int nanoSeconds = 0;
if (matcher.group(4) != null) {
if (matcher.group(4).length() == 1 || matcher.group(4).length() > 13) {
throw new EdmPrimitiveTypeException("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)");
throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content.");
}
final String decimals = matcher.group(5);
if (decimals.length() > (precision == null ? 0 : precision)) {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.LITERAL_FACETS_NOT_MATCHED.addContent(value, facets)");
throw new EdmPrimitiveTypeException("The literal '" + value + "' does not match the facets' constraints.");
}
final String milliSeconds = decimals.length() > 3 ?
decimals.substring(0, 3) :
@ -82,11 +81,9 @@ public final class EdmTimeOfDay extends SingletonPrimitiveType {
try {
return EdmDateTimeOffset.convertDateTime(dateTimeValue, nanoSeconds, returnType);
} catch (final IllegalArgumentException e) {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT.addContent(value)", e);
throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content.", e);
} catch (final ClassCastException e) {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED.addContent(returnType)", e);
throw new EdmPrimitiveTypeException("The value type " + returnType + " is not supported.", e);
}
}
@ -121,8 +118,7 @@ public final class EdmTimeOfDay extends SingletonPrimitiveType {
EdmDateTimeOffset.appendMilliseconds(result, fractionalSecs, precision);
}
} catch (final IllegalArgumentException e) {
throw new EdmPrimitiveTypeException(
"EdmPrimitiveTypeException.VALUE_FACETS_NOT_MATCHED.addContent(value, facets)", e);
throw new EdmPrimitiveTypeException("The value '" + value + "' does not match the facets' constraints.", e);
}
return result.toString();

View File

@ -18,93 +18,91 @@
*/
package org.apache.olingo.commons.core.edm.primitivetype;
import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
public abstract class PrimitiveTypeBaseTest {
private void expectErrorInValueToString(final EdmPrimitiveType instance,
final Object value, final Boolean isNullable, final Integer maxLength,
final Integer precision, final Integer scale, final Boolean isUnicode,
final String messageReferenceString) {
final String message) {
try {
instance.valueToString(value, isNullable, maxLength, precision, scale, isUnicode);
fail("Expected exception not thrown");
} catch (final EdmPrimitiveTypeException e) {
assertNotNull(e.getLocalizedMessage());
assertTrue(e.getLocalizedMessage().startsWith(messageReferenceString));
assertThat(e.getLocalizedMessage(), containsString(message));
}
}
private void expectErrorInValueToString(final EdmPrimitiveType instance, final Object value,
final String messageReference) {
expectErrorInValueToString(instance, value, null, null, null, null, null, messageReference);
private void expectErrorInValueToString(final EdmPrimitiveType instance, final Object value, final String message) {
expectErrorInValueToString(instance, value, null, null, null, null, null, message);
}
protected void expectTypeErrorInValueToString(final EdmPrimitiveType instance, final Object value) {
expectErrorInValueToString(instance, value, "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED");
expectErrorInValueToString(instance, value, "value type");
}
protected void expectContentErrorInValueToString(final EdmPrimitiveType instance, final Object value) {
expectErrorInValueToString(instance, value, "EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT");
expectErrorInValueToString(instance, value, "' is not valid.");
}
protected void expectFacetsErrorInValueToString(final EdmPrimitiveType instance, final Object value,
final Boolean isNullable, final Integer maxLength, final Integer precision,
final Integer scale, final Boolean isUnicode) {
expectErrorInValueToString(instance, value, isNullable, maxLength, precision, scale, isUnicode,
"EdmPrimitiveTypeException.VALUE_FACETS_NOT_MATCHED");
"facets' constraints");
}
protected void expectNullErrorInValueToString(final EdmPrimitiveType instance) {
expectErrorInValueToString(instance, null, false, null, null, null, null,
"EdmPrimitiveTypeException.VALUE_NULL_NOT_ALLOWED");
expectErrorInValueToString(instance, null, false, null, null, null, null, "The value NULL is not allowed.");
}
private void expectErrorInValueOfString(final EdmPrimitiveType instance,
final String value, final Boolean isNullable, final Integer maxLength, final Integer precision,
final Integer scale, final Boolean isUnicode, final Class<?> returnType,
final String messageReferenceString) {
final String message) {
try {
instance.valueOfString(value, isNullable, maxLength, precision, scale, isUnicode, returnType);
fail("Expected exception not thrown");
} catch (final EdmPrimitiveTypeException e) {
assertNotNull(e.getLocalizedMessage());
assertTrue(e.getLocalizedMessage().startsWith(messageReferenceString));
assertThat(e.getLocalizedMessage(), containsString(message));
}
}
protected void expectTypeErrorInValueOfString(final EdmPrimitiveType instance, final String value) {
expectErrorInValueOfString(instance, value, null, null, null, null, null, Class.class,
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED");
"The value type class java.lang.Class is not supported.");
}
protected void expectUnconvertibleErrorInValueOfString(final EdmPrimitiveType instance, final String value,
final Class<?> type) {
expectErrorInValueOfString(instance, value, null, null, null, null, null, type,
"EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE");
expectErrorInValueOfString(instance, value, null, null, null, null, null, type, "cannot be converted to");
}
protected void expectContentErrorInValueOfString(final EdmPrimitiveType instance, final String value) {
expectErrorInValueOfString(instance, value, null, null, null, null, null, instance.getDefaultType(),
"EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT");
"illegal content");
}
protected void expectFacetsErrorInValueOfString(final EdmPrimitiveType instance, final String value,
final Boolean isNullable, final Integer maxLength, final Integer precision,
final Integer scale, final Boolean isUnicode) {
expectErrorInValueOfString(instance, value, isNullable, maxLength, precision, scale, isUnicode,
instance.getDefaultType(), "EdmPrimitiveTypeException.LITERAL_FACETS_NOT_MATCHED");
instance.getDefaultType(), "facets' constraints");
}
protected void expectNullErrorInValueOfString(final EdmPrimitiveType instance) {
expectErrorInValueOfString(instance, null, false, null, null, null, null, instance.getDefaultType(),
"EdmPrimitiveTypeException.LITERAL_NULL_NOT_ALLOWED");
"The literal 'null' is not allowed.");
}
protected void expectErrorInFromUriLiteral(final EdmPrimitiveType instance, final String value) {
@ -113,7 +111,7 @@ public abstract class PrimitiveTypeBaseTest {
fail("Expected exception not thrown");
} catch (final EdmPrimitiveTypeException e) {
assertNotNull(e.getLocalizedMessage());
assertTrue(e.getLocalizedMessage().startsWith("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT"));
assertThat(e.getLocalizedMessage(), containsString("' has illegal content."));
}
}
}

View File

@ -19,6 +19,8 @@
package org.apache.olingo.server.core.edm.provider;
import org.apache.olingo.commons.api.edm.EdmEnumType;
import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
@ -27,47 +29,39 @@ import org.apache.olingo.server.api.edm.provider.EnumMember;
import org.apache.olingo.server.api.edm.provider.EnumType;
import org.junit.Test;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
public class EdmEnumTest extends PrimitiveTypeBaseTest {
public class EdmEnumTest {
private final EdmEnumType instance;
private final EdmEnumType nonFlagsInstance;
public EdmEnumTest() {
List<EnumMember> memberList = new ArrayList<EnumMember>();
memberList.add(new EnumMember().setName("first").setValue("1"));
memberList.add(new EnumMember().setName("second").setValue("64"));
final List<EnumMember> memberList = Arrays.asList(
new EnumMember().setName("first").setValue("1"),
new EnumMember().setName("second").setValue("64"));
EnumType enumType =
new EnumType().setName("name").setMembers(memberList).setFlags(true).setUnderlyingType(
EdmPrimitiveTypeKind.SByte.getFullQualifiedName());
final FullQualifiedName enumName = new FullQualifiedName("namespace", "name");
FullQualifiedName enumName = new FullQualifiedName("namespace", "name");
instance = new EdmEnumTypeImpl(mock(EdmProviderImpl.class), enumName, enumType);
instance = new EdmEnumTypeImpl(mock(EdmProviderImpl.class), enumName,
new EnumType().setName("name").setMembers(memberList).setFlags(true)
.setUnderlyingType(EdmPrimitiveTypeKind.SByte.getFullQualifiedName()));
EnumType enumType2 = new EnumType().setName("name").setMembers(memberList).setFlags(false).setUnderlyingType(
EdmPrimitiveTypeKind.SByte.getFullQualifiedName());
nonFlagsInstance = new EdmEnumTypeImpl(mock(EdmProviderImpl.class), enumName, enumType2);
// EdmMember member1 = mock(EdmMember.class);
// when(member1.getName()).thenReturn("first");
// when(member1.getValue()).thenReturn("1");
// EdmMember member2 = mock(EdmMember.class);
// when(member2.getName()).thenReturn("second");
// when(member2.getValue()).thenReturn("64");
// instance = new EdmEnumImpl("namespace", "name",
// EdmPrimitiveTypeKind.SByte),
// Arrays.asList(member1, member2),
// true);
nonFlagsInstance = new EdmEnumTypeImpl(mock(EdmProviderImpl.class), enumName,
new EnumType().setName("name").setMembers(memberList).setFlags(false)
.setUnderlyingType(EdmPrimitiveTypeKind.SByte.getFullQualifiedName()));
}
@Test
@ -175,4 +169,68 @@ public class EdmEnumTest extends PrimitiveTypeBaseTest {
expectContentErrorInValueOfString(instance, ",1");
expectTypeErrorInValueOfString(instance, "1");
}
protected void expectErrorInFromUriLiteral(final EdmPrimitiveType instance, final String value) {
try {
instance.fromUriLiteral(value);
fail("Expected exception not thrown");
} catch (final EdmPrimitiveTypeException e) {
assertNotNull(e.getLocalizedMessage());
assertThat(e.getLocalizedMessage(), containsString("' has illegal content."));
}
}
private void expectErrorInValueToString(final EdmPrimitiveType instance,
final Object value, final Boolean isNullable, final Integer maxLength,
final Integer precision, final Integer scale, final Boolean isUnicode,
final String message) {
try {
instance.valueToString(value, isNullable, maxLength, precision, scale, isUnicode);
fail("Expected exception not thrown");
} catch (final EdmPrimitiveTypeException e) {
assertNotNull(e.getLocalizedMessage());
assertThat(e.getLocalizedMessage(), containsString(message));
}
}
protected void expectNullErrorInValueToString(final EdmPrimitiveType instance) {
expectErrorInValueToString(instance, null, false, null, null, null, null, "The value NULL is not allowed.");
}
protected void expectTypeErrorInValueToString(final EdmPrimitiveType instance, final Object value) {
expectErrorInValueToString(instance, value, null, null, null, null, null, "value type");
}
protected void expectContentErrorInValueToString(final EdmPrimitiveType instance, final Object value) {
expectErrorInValueToString(instance, value, null, null, null, null, null, "' is not valid.");
}
private void expectErrorInValueOfString(final EdmPrimitiveType instance,
final String value, final Boolean isNullable, final Integer maxLength, final Integer precision,
final Integer scale, final Boolean isUnicode, final Class<?> returnType,
final String message) {
try {
instance.valueOfString(value, isNullable, maxLength, precision, scale, isUnicode, returnType);
fail("Expected exception not thrown");
} catch (final EdmPrimitiveTypeException e) {
assertNotNull(e.getLocalizedMessage());
assertThat(e.getLocalizedMessage(), containsString(message));
}
}
protected void expectTypeErrorInValueOfString(final EdmPrimitiveType instance, final String value) {
expectErrorInValueOfString(instance, value, null, null, null, null, null, Class.class,
"The value type class java.lang.Class is not supported.");
}
protected void expectContentErrorInValueOfString(final EdmPrimitiveType instance, final String value) {
expectErrorInValueOfString(instance, value, null, null, null, null, null, instance.getDefaultType(),
"illegal content");
}
protected void expectNullErrorInValueOfString(final EdmPrimitiveType instance) {
expectErrorInValueOfString(instance, null, false, null, null, null, null, instance.getDefaultType(),
"The literal 'null' is not allowed.");
}
}

View File

@ -1,117 +0,0 @@
/*******************************************************************************
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* 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
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
******************************************************************************/
package org.apache.olingo.server.core.edm.provider;
import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
public abstract class PrimitiveTypeBaseTest {
private void expectErrorInValueToString(final EdmPrimitiveType instance,
final Object value, final Boolean isNullable, final Integer maxLength,
final Integer precision, final Integer scale, final Boolean isUnicode,
final String messageReferenceString) {
try {
instance.valueToString(value, isNullable, maxLength, precision, scale, isUnicode);
fail("Expected exception not thrown");
} catch (final EdmPrimitiveTypeException e) {
assertNotNull(e.getLocalizedMessage());
assertTrue(e.getLocalizedMessage().startsWith(messageReferenceString));
}
}
private void expectErrorInValueToString(final EdmPrimitiveType instance, final Object value,
final String messageReference) {
expectErrorInValueToString(instance, value, null, null, null, null, null, messageReference);
}
protected void expectTypeErrorInValueToString(final EdmPrimitiveType instance, final Object value) {
expectErrorInValueToString(instance, value, "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED");
}
protected void expectContentErrorInValueToString(final EdmPrimitiveType instance, final Object value) {
expectErrorInValueToString(instance, value, "EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT");
}
protected void expectFacetsErrorInValueToString(final EdmPrimitiveType instance, final Object value,
final Boolean isNullable, final Integer maxLength, final Integer precision,
final Integer scale, final Boolean isUnicode) {
expectErrorInValueToString(instance, value, isNullable, maxLength, precision, scale, isUnicode,
"EdmPrimitiveTypeException.VALUE_FACETS_NOT_MATCHED");
}
protected void expectNullErrorInValueToString(final EdmPrimitiveType instance) {
expectErrorInValueToString(instance, null, false, null, null, null, null,
"EdmPrimitiveTypeException.VALUE_NULL_NOT_ALLOWED");
}
private void expectErrorInValueOfString(final EdmPrimitiveType instance,
final String value, final Boolean isNullable, final Integer maxLength, final Integer precision,
final Integer scale, final Boolean isUnicode, final Class<?> returnType, final String messageReferenceString) {
try {
instance.valueOfString(value, isNullable, maxLength, precision, scale, isUnicode, returnType);
fail("Expected exception not thrown");
} catch (final EdmPrimitiveTypeException e) {
assertNotNull(e.getLocalizedMessage());
assertTrue(e.getLocalizedMessage().startsWith(messageReferenceString));
}
}
protected void expectTypeErrorInValueOfString(final EdmPrimitiveType instance, final String value) {
expectErrorInValueOfString(instance, value, null, null, null, null, null, Class.class,
"EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED");
}
protected void expectUnconvertibleErrorInValueOfString(final EdmPrimitiveType instance, final String value,
final Class<?> type) {
expectErrorInValueOfString(instance, value, null, null, null, null, null, type,
"EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE");
}
protected void expectContentErrorInValueOfString(final EdmPrimitiveType instance, final String value) {
expectErrorInValueOfString(instance, value, null, null, null, null, null, instance.getDefaultType(),
"EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT");
}
protected void expectFacetsErrorInValueOfString(final EdmPrimitiveType instance, final String value,
final Boolean isNullable, final Integer maxLength, final Integer precision,
final Integer scale, final Boolean isUnicode) {
expectErrorInValueOfString(instance, value, isNullable, maxLength, precision, scale, isUnicode,
instance.getDefaultType(), "EdmPrimitiveTypeException.LITERAL_FACETS_NOT_MATCHED");
}
protected void expectNullErrorInValueOfString(final EdmPrimitiveType instance) {
expectErrorInValueOfString(instance, null, false, null, null, null, null, instance.getDefaultType(),
"EdmPrimitiveTypeException.LITERAL_NULL_NOT_ALLOWED");
}
protected void expectErrorInFromUriLiteral(final EdmPrimitiveType instance, final String value) {
try {
instance.fromUriLiteral(value);
fail("Expected exception not thrown");
} catch (final EdmPrimitiveTypeException e) {
assertNotNull(e.getLocalizedMessage());
assertTrue(e.getLocalizedMessage().startsWith("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT"));
}
}
}