You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by mi...@apache.org on 2014/08/07 15:39:10 UTC
[1/2] git commit: [OLINGO-356] URIParser untit tests check error
message key
Repository: olingo-odata4
Updated Branches:
refs/heads/master d19afa013 -> 266c7b4ae
[OLINGO-356] URIParser untit tests check error message key
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/9048d725
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/9048d725
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/9048d725
Branch: refs/heads/master
Commit: 9048d725a2f7d0c70064d897cf44300e490f078f
Parents: d19afa0
Author: Michael Bolz <mi...@sap.com>
Authored: Thu Aug 7 13:31:50 2014 +0200
Committer: Michael Bolz <mi...@sap.com>
Committed: Thu Aug 7 13:31:50 2014 +0200
----------------------------------------------------------------------
.../server/core/uri/validator/UriValidator.java | 1 -
.../core/uri/antlr/TestFullResourcePath.java | 144 +++++++++++--------
.../core/uri/antlr/TestUriParserImpl.java | 13 +-
.../core/uri/testutil/ExpandValidator.java | 31 ++--
.../core/uri/testutil/FilterValidator.java | 6 +-
.../core/uri/testutil/ResourceValidator.java | 6 +-
.../core/uri/testutil/TestUriValidator.java | 44 +++---
7 files changed, 136 insertions(+), 109 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9048d725/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/validator/UriValidator.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/validator/UriValidator.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/validator/UriValidator.java
index 0cbabbc..24c9462 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/validator/UriValidator.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/validator/UriValidator.java
@@ -41,7 +41,6 @@ import org.apache.olingo.server.api.uri.UriResourceKind;
import org.apache.olingo.server.api.uri.UriResourceNavigation;
import org.apache.olingo.server.api.uri.UriResourcePartTyped;
import org.apache.olingo.server.api.uri.UriResourceSingleton;
-import org.apache.olingo.server.api.uri.queryoption.CustomQueryOption;
import org.apache.olingo.server.api.uri.queryoption.SystemQueryOption;
import org.apache.olingo.server.api.uri.queryoption.SystemQueryOptionKind;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9048d725/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
index 37da223..0238a20 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
@@ -28,6 +28,9 @@ import org.apache.olingo.server.api.uri.queryoption.expression.ExpressionVisitEx
import org.apache.olingo.server.api.uri.queryoption.expression.MethodKind;
import org.apache.olingo.server.core.edm.provider.EdmProviderImpl;
import org.apache.olingo.server.core.uri.parser.UriParserException;
+import org.apache.olingo.server.core.uri.parser.UriParserSemanticException;
+import org.apache.olingo.server.core.uri.parser.UriParserSyntaxException;
+import org.apache.olingo.server.core.uri.validator.UriValidationException;
import org.apache.olingo.server.core.uri.testutil.EdmTechTestProvider;
import org.apache.olingo.server.core.uri.testutil.FilterValidator;
import org.apache.olingo.server.core.uri.testutil.ResourceValidator;
@@ -896,10 +899,11 @@ public class TestFullResourcePath {
@Test
public void runCrossjoinError() throws Exception {
- testUri.runEx("$crossjoin").isExSyntax(0);
- testUri.runEx("$crossjoin/error").isExSyntax(0);
- testUri.runEx("$crossjoin()").isExSyntax(0);
- // testUri.runEx("$crossjoin(ESKeyNav, ESTwoKeyNav)/invalid").isExSyntax(0);
+ testUri.runEx("$crossjoin").isExSyntax(UriParserSyntaxException.MessageKeys.TEST);
+ testUri.runEx("$crossjoin/error").isExSyntax(UriParserSyntaxException.MessageKeys.TEST);
+ testUri.runEx("$crossjoin()").isExSyntax(UriParserSyntaxException.MessageKeys.TEST);
+ // testUri.runEx("$crossjoin(ESKeyNav, ESTwoKeyNav)/invalid")
+ // .isExSyntax(UriParserSyntaxException.MessageKeys.TEST);
}
@Test
@@ -942,43 +946,44 @@ public class TestFullResourcePath {
@Test
public void runEsNameError() {
- testUri.runEx("ESAllPrim/$count/$ref").isExSemantic(0);
- testUri.runEx("ESAllPrim/$ref/$count").isExSemantic(0);
- testUri.runEx("ESAllPrim/$ref/invalid").isExSemantic(0);
- testUri.runEx("ESAllPrim/$count/invalid").isExSemantic(0);
- testUri.runEx("ESAllPrim(1)/whatever").isExSemantic(0);
- // testUri.runEx("ESAllPrim(PropertyInt16='1')").isExSemantic(0);
- testUri.runEx("ESAllPrim(PropertyInt16)").isExSemantic(0);
- testUri.runEx("ESAllPrim(PropertyInt16=)").isExSyntax(0);
- testUri.runEx("ESAllPrim(PropertyInt16=1,Invalid='1')").isExSemantic(0);
+ testUri.runEx("ESAllPrim/$count/$ref").isExSemantic(UriParserSemanticException.MessageKeys.TEST);
+ testUri.runEx("ESAllPrim/$ref/$count").isExSemantic(UriParserSemanticException.MessageKeys.TEST);
+ testUri.runEx("ESAllPrim/$ref/invalid").isExSemantic(UriParserSemanticException.MessageKeys.TEST);
+ testUri.runEx("ESAllPrim/$count/invalid").isExSemantic(UriParserSemanticException.MessageKeys.TEST);
+ testUri.runEx("ESAllPrim(1)/whatever").isExSemantic(UriParserSemanticException.MessageKeys.TEST);
+ // testUri.runEx("ESAllPrim(PropertyInt16='1')").isExSemantic(UriParserSemanticException.MessageKeys.TEST);
+ testUri.runEx("ESAllPrim(PropertyInt16)").isExSemantic(UriParserSemanticException.MessageKeys.TEST);
+ testUri.runEx("ESAllPrim(PropertyInt16=)").isExSyntax(UriParserSyntaxException.MessageKeys.TEST);
+ testUri.runEx("ESAllPrim(PropertyInt16=1,Invalid='1')").isExSemantic(UriParserSemanticException.MessageKeys.TEST);
testUri.runEx("ETBaseTwoKeyTwoPrim/com.sap.odata.test1.ETBaseTwoKeyTwoPrim"
- + "/com.sap.odata.test1.ETTwoBaseTwoKeyTwoPrim").isExSemantic(0);
+ + "/com.sap.odata.test1.ETTwoBaseTwoKeyTwoPrim").isExSemantic(UriParserSemanticException.MessageKeys.TEST);
testUri.runEx("ETBaseTwoKeyTwoPrim/com.sap.odata.test1.ETBaseTwoKeyTwoPrim(1)/com.sap.odata.test1.ETAllKey")
- .isExSemantic(0);
+ .isExSemantic(UriParserSemanticException.MessageKeys.TEST);
testUri.runEx("ETBaseTwoKeyTwoPrim(1)/com.sap.odata.test1.ETBaseTwoKeyTwoPrim('1')/com.sap.odata.test1.ETAllKey")
- .isExSemantic(0);
+ .isExSemantic(UriParserSemanticException.MessageKeys.TEST);
testUri.runEx("ETBaseTwoKeyTwoPrim(1)/com.sap.odata.test1.ETBaseTwoKeyTwoPrim"
+ "/com.sap.odata.test1.ETTwoBaseTwoKeyTwoPrim")
- .isExSemantic(0);
+ .isExSemantic(UriParserSemanticException.MessageKeys.TEST);
testUri.runEx("ETBaseTwoKeyTwoPrim/com.sap.odata.test1.ETBaseTwoKeyTwoPrim"
+ "/com.sap.odata.test1.ETTwoBaseTwoKeyTwoPrim(1)")
- .isExSemantic(0);
+ .isExSemantic(UriParserSemanticException.MessageKeys.TEST);
testUri.runEx("ETBaseTwoKeyTwoPrim/com.sap.odata.test1.ETAllKey")
- .isExSemantic(0);
+ .isExSemantic(UriParserSemanticException.MessageKeys.TEST);
testUri.runEx("ETBaseTwoKeyTwoPrim()")
- .isExSemantic(0);
+ .isExSemantic(UriParserSemanticException.MessageKeys.TEST);
testUri.runEx("ESAllNullable(1)/CollPropertyString/$value")
- .isExSemantic(0);
+ .isExSemantic(UriParserSemanticException.MessageKeys.TEST);
- testUri.runEx("ETMixPrimCollComp(1)/ComplexProperty/$value").isExSemantic(0);
+ testUri.runEx("ETMixPrimCollComp(1)/ComplexProperty/$value")
+ .isExSemantic(UriParserSemanticException.MessageKeys.TEST);
}
@Test
@@ -1067,7 +1072,7 @@ public class TestFullResourcePath {
.isKeyPredicate(2, "KeyAlias2", "'3'")
.isKeyPredicate(3, "KeyAlias3", "'4'");
- testUri.runEx("ESCollAllPrim(null)").isExValidation("");
+ testUri.runEx("ESCollAllPrim(null)").isExValidation(UriValidationException.MessageKeys.INVALID_KEY_PROPERTY);
}
@Test
@@ -1800,8 +1805,8 @@ public class TestFullResourcePath {
@Test
public void runFunctionImpError() {
- testUri.runEx("FICRTCollCTTwoPrimParam()").isExSemantic(0);
- testUri.runEx("FICRTCollCTTwoPrimParam(invalidParam=2)").isExSemantic(0);
+ testUri.runEx("FICRTCollCTTwoPrimParam()").isExSemantic(UriParserSemanticException.MessageKeys.TEST);
+ testUri.runEx("FICRTCollCTTwoPrimParam(invalidParam=2)").isExSemantic(UriParserSemanticException.MessageKeys.TEST);
}
@Test
@@ -2049,18 +2054,18 @@ public class TestFullResourcePath {
testUri.run("ESKeyNav(1)?$expand=*")
.isKind(UriInfoKind.resource).goPath().goExpand()
.first()
- .isSegmentStar(0);
+ .isSegmentStar();
testUri.run("ESKeyNav(1)?$expand=*/$ref")
.isKind(UriInfoKind.resource).goPath().goExpand()
.first()
- .isSegmentStar(0)
- .isSegmentRef(1);
+ .isSegmentStar()
+ .isSegmentRef();
testUri.run("ESKeyNav(1)?$expand=*/$ref,NavPropertyETKeyNavMany")
.isKind(UriInfoKind.resource).goPath().goExpand()
.first()
- .isSegmentStar(0).isSegmentRef(1)
+ .isSegmentStar().isSegmentRef()
.next()
.goPath().first()
.isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true);
@@ -2068,13 +2073,13 @@ public class TestFullResourcePath {
testUri.run("ESKeyNav(1)?$expand=*($levels=3)")
.isKind(UriInfoKind.resource).goPath().goExpand()
.first()
- .isSegmentStar(0)
+ .isSegmentStar()
.isLevelText("3");
testUri.run("ESKeyNav(1)?$expand=*($levels=max)")
.isKind(UriInfoKind.resource).goPath().goExpand()
.first()
- .isSegmentStar(0)
+ .isSegmentStar()
.isLevelText("max");
testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavMany/$ref")
@@ -2882,14 +2887,19 @@ public class TestFullResourcePath {
.root().right()
.isLiteral("'SomeString'");
- testFilter.runOnETTwoKeyNavEx("invalid").isExSemantic(0);
- testFilter.runOnETTwoKeyNavEx("PropertyComp/invalid").isExSemantic(0);
- testFilter.runOnETTwoKeyNavEx("concat('a','b')/invalid").isExSyntax(0);
- testFilter.runOnETTwoKeyNavEx("PropertyComp/concat('a','b')").isExSyntax(0);
- testFilter.runOnETTwoKeyNavEx("PropertyCompAllPrim/PropertyInt16 eq '1'").isExSemantic(0);
- testFilter.runOnETTwoKeyNavEx("PropertyCompAllPrim/PropertyDate eq 1").isExSemantic(0);
- testFilter.runOnETTwoKeyNavEx("PropertyCompAllPrim/PropertyString eq 1").isExSemantic(0);
- testFilter.runOnETTwoKeyNavEx("PropertyCompAllPrim/PropertyDate eq 1").isExSemantic(0);
+ testFilter.runOnETTwoKeyNavEx("invalid").isExSemantic(UriParserSemanticException.MessageKeys.TEST);
+ testFilter.runOnETTwoKeyNavEx("PropertyComp/invalid").isExSemantic(UriParserSemanticException.MessageKeys.TEST);
+ testFilter.runOnETTwoKeyNavEx("concat('a','b')/invalid").isExSyntax(UriParserSyntaxException.MessageKeys.TEST);
+ testFilter.runOnETTwoKeyNavEx("PropertyComp/concat('a','b')")
+ .isExSyntax(UriParserSyntaxException.MessageKeys.TEST);
+ testFilter.runOnETTwoKeyNavEx("PropertyCompAllPrim/PropertyInt16 eq '1'")
+ .isExSemantic(UriParserSemanticException.MessageKeys.TEST);
+ testFilter.runOnETTwoKeyNavEx("PropertyCompAllPrim/PropertyDate eq 1")
+ .isExSemantic(UriParserSemanticException.MessageKeys.TEST);
+ testFilter.runOnETTwoKeyNavEx("PropertyCompAllPrim/PropertyString eq 1")
+ .isExSemantic(UriParserSemanticException.MessageKeys.TEST);
+ testFilter.runOnETTwoKeyNavEx("PropertyCompAllPrim/PropertyDate eq 1")
+ .isExSemantic(UriParserSemanticException.MessageKeys.TEST);
testFilter.runOnETAllPrim("PropertySByte eq PropertySByte")
.is("<<PropertySByte> eq <PropertySByte>>")
@@ -4087,7 +4097,8 @@ public class TestFullResourcePath {
.goUpFilterValidator().root()
.goParameter(1).isTypedLiteral(EntityTypeProvider.nameETKeyPrimNav);
- testFilter.runOnETKeyNavEx("cast(NavPropertyETKeyPrimNavOne,com.sap.odata.test1.ETKeyNav)").isExSemantic(0);
+ testFilter.runOnETKeyNavEx("cast(NavPropertyETKeyPrimNavOne,com.sap.odata.test1.ETKeyNav)")
+ .isExSemantic(UriParserSemanticException.MessageKeys.TEST);
testFilter.runOnETKeyNav("any()")
.isMember().goPath().first().isUriPathInfoKind(UriResourceKind.lambdaAny);
@@ -5000,10 +5011,14 @@ public class TestFullResourcePath {
.goOrder(0).left().goPath().isComplex("PropertyEnumString").goUpFilterValidator()
.goOrder(0).right().isEnum(EnumTypeProvider.nameENString, Arrays.asList("String1"));
- testFilter.runOrderByOnETTwoKeyNavEx("PropertyInt16 1").isExSyntax(0);
- testFilter.runOrderByOnETTwoKeyNavEx("PropertyInt16, PropertyInt32 PropertyDuration").isExSyntax(0);
- testFilter.runOrderByOnETTwoKeyNavEx("PropertyInt16 PropertyInt32, PropertyDuration desc").isExSyntax(0);
- testFilter.runOrderByOnETTwoKeyNavEx("PropertyInt16 asc, PropertyInt32 PropertyDuration desc").isExSyntax(0);
+ testFilter.runOrderByOnETTwoKeyNavEx("PropertyInt16 1")
+ .isExSyntax(UriParserSyntaxException.MessageKeys.TEST);
+ testFilter.runOrderByOnETTwoKeyNavEx("PropertyInt16, PropertyInt32 PropertyDuration")
+ .isExSyntax(UriParserSyntaxException.MessageKeys.TEST);
+ testFilter.runOrderByOnETTwoKeyNavEx("PropertyInt16 PropertyInt32, PropertyDuration desc")
+ .isExSyntax(UriParserSyntaxException.MessageKeys.TEST);
+ testFilter.runOrderByOnETTwoKeyNavEx("PropertyInt16 asc, PropertyInt32 PropertyDuration desc")
+ .isExSyntax(UriParserSyntaxException.MessageKeys.TEST);
}
@Test
@@ -5045,43 +5060,53 @@ public class TestFullResourcePath {
@Test
public void testErrors() {
- testUri.runEx("FICRTString(wrong1='ABC')/com.sap.odata.test1.BFCStringRTESTwoKeyNav()").isExSemantic(0);
- testUri.runEx("FICRTString(wrong1='ABC', wrong2=1)/com.sap.odata.test1.BFCStringRTESTwoKeyNav()").isExSemantic(0);
+ testUri.runEx("FICRTString(wrong1='ABC')/com.sap.odata.test1.BFCStringRTESTwoKeyNav()")
+ .isExSemantic(UriParserSemanticException.MessageKeys.TEST);
+ testUri.runEx("FICRTString(wrong1='ABC', wrong2=1)/com.sap.odata.test1.BFCStringRTESTwoKeyNav()")
+ .isExSemantic(UriParserSemanticException.MessageKeys.TEST);
// type filter for entity incompatible
- testUri.runEx("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/com.sap.odata.test1.ETBase").isExSemantic(0);
+ testUri.runEx("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/com.sap.odata.test1.ETBase")
+ .isExSemantic(UriParserSemanticException.MessageKeys.TEST);
// type filter for entity double on entry
testUri.runEx("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')"
- + "/com.sap.odata.test1.ETBaseTwoKeyNav/com.sap.odata.test1.ETBaseTwoKeyNav").isExSemantic(0);
+ + "/com.sap.odata.test1.ETBaseTwoKeyNav/com.sap.odata.test1.ETBaseTwoKeyNav")
+ .isExSemantic(UriParserSemanticException.MessageKeys.TEST);
// type filter for entity double on collection
testUri.runEx("ESTwoKeyNav/com.sap.odata.test1.ETBaseTwoKeyNav/com.sap.odata.test1.ETBaseTwoKeyNav")
- .isExSemantic(0);
+ .isExSemantic(UriParserSemanticException.MessageKeys.TEST);
// type filter for entity double on non key pred
- testUri.runEx("SINav/com.sap.odata.test1.ETBaseTwoKeyNav/com.sap.odata.test1.ETBaseTwoKeyNav").isExSemantic(0);
+ testUri.runEx("SINav/com.sap.odata.test1.ETBaseTwoKeyNav/com.sap.odata.test1.ETBaseTwoKeyNav")
+ .isExSemantic(UriParserSemanticException.MessageKeys.TEST);
// type filter for complex incompatible
testUri.runEx("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/PropertyCompTwoPrim"
- + "/com.sap.odata.test1.CTCollAllPrim").isExSemantic(0);
+ + "/com.sap.odata.test1.CTCollAllPrim").isExSemantic(UriParserSemanticException.MessageKeys.TEST);
// type filter for complex double on entry
testUri.runEx("FICRTCTTwoPrimParam(ParameterInt16=1,ParameterString='2')"
- + "/com.sap.odata.test1.CTBase/com.sap.odata.test1.CTBase").isExSemantic(0);
+ + "/com.sap.odata.test1.CTBase/com.sap.odata.test1.CTBase")
+ .isExSemantic(UriParserSemanticException.MessageKeys.TEST);
// type filter for complex double on collection
testUri.runEx("FICRTCollCTTwoPrimParam(ParameterInt16=1,ParameterString='2')"
- + "/com.sap.odata.test1.CTBase/com.sap.odata.test1.CTBase").isExSemantic(0);
+ + "/com.sap.odata.test1.CTBase/com.sap.odata.test1.CTBase")
+ .isExSemantic(UriParserSemanticException.MessageKeys.TEST);
// type filter for complex double on non key pred
testUri.runEx("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/PropertyCompTwoPrim"
- + "/com.sap.odata.test1.CTBase/com.sap.odata.test1.CTBase").isExSemantic(0);
+ + "/com.sap.odata.test1.CTBase/com.sap.odata.test1.CTBase")
+ .isExSemantic(UriParserSemanticException.MessageKeys.TEST);
- testUri.runEx("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTESTwoKeyNav").isExSemantic(0);
+ testUri.runEx("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTESTwoKeyNav")
+ .isExSemantic(UriParserSemanticException.MessageKeys.TEST);
// $ref
- testUri.runEx("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/PropertyCompTwoPrim/$ref").isExSemantic(0);
- testUri.runEx("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/PropertyCompTwoPrim/$count").isExSemantic(0);
-
+ testUri.runEx("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/PropertyCompTwoPrim/$ref")
+ .isExSemantic(UriParserSemanticException.MessageKeys.TEST);
+ testUri.runEx("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/PropertyCompTwoPrim/$count")
+ .isExSemantic(UriParserSemanticException.MessageKeys.TEST);
}
@Test
@@ -5092,12 +5117,9 @@ public class TestFullResourcePath {
.isInAliasToValueMap("@A", "'2'")
.goUpUriValidator()
.isCustomParameter(0, "@A", "'2'");
-
}
public static String encode(final String decoded) throws UnsupportedEncodingException {
return Encoder.encode(decoded);
-
}
-
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9048d725/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestUriParserImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestUriParserImpl.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestUriParserImpl.java
index bd91666..e4f771b 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestUriParserImpl.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestUriParserImpl.java
@@ -18,6 +18,10 @@
*/
package org.apache.olingo.server.core.uri.antlr;
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.util.Arrays;
+
import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.server.api.uri.UriInfoKind;
@@ -25,6 +29,7 @@ import org.apache.olingo.server.api.uri.UriResourceKind;
import org.apache.olingo.server.api.uri.queryoption.expression.MethodKind;
import org.apache.olingo.server.core.edm.provider.EdmProviderImpl;
import org.apache.olingo.server.core.uri.parser.UriParserException;
+import org.apache.olingo.server.core.uri.parser.UriParserSemanticException;
import org.apache.olingo.server.core.uri.testutil.EdmTechTestProvider;
import org.apache.olingo.server.core.uri.testutil.FilterValidator;
import org.apache.olingo.server.core.uri.testutil.ResourceValidator;
@@ -35,10 +40,6 @@ import org.apache.olingo.server.tecsvc.provider.EntityTypeProvider;
import org.apache.olingo.server.tecsvc.provider.PropertyProvider;
import org.junit.Test;
-import java.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
-import java.util.Arrays;
-
public class TestUriParserImpl {
Edm edm = null;
private final String PropertyBoolean = "PropertyBoolean=true";
@@ -188,7 +189,7 @@ public class TestUriParserImpl {
.isAction("UARTETParam")
.isType(EntityTypeProvider.nameETTwoKeyTwoPrim, false);
- testUri.runEx("AIRTPrimParam/invalidElement").isExSemantic(0);
+ testUri.runEx("AIRTPrimParam/invalidElement").isExSemantic(UriParserSemanticException.MessageKeys.TEST);
}
@Test
@@ -316,7 +317,7 @@ public class TestUriParserImpl {
.isEntityType(EntityTypeProvider.nameETBase)
.isIdText("ESTwoPrim")
.isExpandText("*")
- .goExpand().first().isSegmentStar(0);
+ .goExpand().first().isSegmentStar();
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9048d725/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/ExpandValidator.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/ExpandValidator.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/ExpandValidator.java
index 82b5853..d79dfd3 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/ExpandValidator.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/ExpandValidator.java
@@ -24,16 +24,19 @@ import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.server.api.ODataApplicationException;
import org.apache.olingo.server.api.uri.UriInfoKind;
import org.apache.olingo.server.api.uri.queryoption.ExpandItem;
+import org.apache.olingo.server.api.uri.queryoption.FilterOption;
+import org.apache.olingo.server.api.uri.queryoption.QueryOption;
import org.apache.olingo.server.api.uri.queryoption.SelectItem;
+import org.apache.olingo.server.api.uri.queryoption.SelectOption;
import org.apache.olingo.server.api.uri.queryoption.expression.ExpressionVisitException;
import org.apache.olingo.server.core.uri.UriInfoImpl;
import org.apache.olingo.server.core.uri.queryoption.ExpandOptionImpl;
-import org.apache.olingo.server.core.uri.queryoption.FilterOptionImpl;
import org.apache.olingo.server.core.uri.queryoption.OrderByOptionImpl;
import org.apache.olingo.server.core.uri.queryoption.QueryOptionImpl;
import org.apache.olingo.server.core.uri.queryoption.SelectOptionImpl;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
public class ExpandValidator implements TestValidator {
@@ -127,19 +130,19 @@ public class ExpandValidator implements TestValidator {
try {
expandItem = expandOption.getExpandItems().get(expandItemIndex);
} catch (IndexOutOfBoundsException ex) {
- fail("not enought segments");
+ fail("not enough segments");
}
return this;
}
- public ExpandValidator isSegmentStar(final int index) {
- assertEquals(true, expandItem.isStar());
+ public ExpandValidator isSegmentStar() {
+ assertTrue(expandItem.isStar());
return this;
}
- public ExpandValidator isSegmentRef(final int index) {
- assertEquals(true, expandItem.isRef());
+ public ExpandValidator isSegmentRef() {
+ assertTrue(expandItem.isRef());
return this;
}
@@ -174,38 +177,36 @@ public class ExpandValidator implements TestValidator {
}
public ExpandValidator isSelectItemStar(final int index) {
- SelectOptionImpl select = (SelectOptionImpl) expandItem.getSelectOption();
-
+ SelectOption select = expandItem.getSelectOption();
SelectItem item = select.getSelectItems().get(index);
- assertEquals(true, item.isStar());
+ assertTrue(item.isStar());
return this;
}
public ExpandValidator isSelectItemAllOperations(final int index, final FullQualifiedName fqn) {
- SelectOptionImpl select = (SelectOptionImpl) expandItem.getSelectOption();
-
+ SelectOption select = expandItem.getSelectOption();
SelectItem item = select.getSelectItems().get(index);
assertEquals(fqn.toString(), item.getAllOperationsInSchemaNameSpace().toString());
return this;
}
public ExpandValidator isFilterOptionText(final String text) {
- QueryOptionImpl option = (QueryOptionImpl) expandItem.getFilterOption();
+ QueryOption option = expandItem.getFilterOption();
assertEquals(text, option.getText());
return this;
}
public ExpandValidator isFilterSerialized(final String serialized) {
- FilterOptionImpl filter = (FilterOptionImpl) expandItem.getFilterOption();
+ FilterOption filter = expandItem.getFilterOption();
try {
String tmp = FilterTreeToText.Serialize(filter);
assertEquals(serialized, tmp);
} catch (ExpressionVisitException e) {
- fail("Exception occured while converting the filterTree into text" + "\n"
+ fail("Exception occurred while converting the filterTree into text" + "\n"
+ " Exception: " + e.getMessage());
} catch (ODataApplicationException e) {
- fail("Exception occured while converting the filterTree into text" + "\n"
+ fail("Exception occurred while converting the filterTree into text" + "\n"
+ " Exception: " + e.getMessage());
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9048d725/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/FilterValidator.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/FilterValidator.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/FilterValidator.java
index ad8eeee..f20c7ea 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/FilterValidator.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/FilterValidator.java
@@ -491,13 +491,15 @@ public class FilterValidator implements TestValidator {
return this;
}
- public FilterValidator isExSyntax(final long errorID) {
+ public FilterValidator isExSyntax(final UriParserSyntaxException.MessageKeys messageKey) {
assertEquals(UriParserSyntaxException.class, exception.getClass());
+ assertEquals(messageKey, exception.getMessageKey());
return this;
}
- public FilterValidator isExSemantic(final long errorID) {
+ public FilterValidator isExSemantic(final UriParserSemanticException.MessageKeys messageKey) {
assertEquals(UriParserSemanticException.class, exception.getClass());
+ assertEquals(messageKey, exception.getMessageKey());
return this;
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9048d725/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/ResourceValidator.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/ResourceValidator.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/ResourceValidator.java
index 0332c73..9095d39 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/ResourceValidator.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/ResourceValidator.java
@@ -76,7 +76,7 @@ public class ResourceValidator implements TestValidator {
return this;
}
- public ResourceValidator setUriInfoImplPath(final UriInfoImpl uriInfoPath) {
+ public ResourceValidator setUriInfoImplPath(final UriInfo uriInfoPath) {
uriInfo = uriInfoPath;
last();
return this;
@@ -87,10 +87,10 @@ public class ResourceValidator implements TestValidator {
public ResourceValidator run(final String uri) {
ParserWithLogging testParser = new ParserWithLogging();
- UriInfoImpl uriInfoTmp = null;
+ UriInfo uriInfoTmp = null;
uriPathInfo = null;
try {
- uriInfoTmp = (UriInfoImpl) testParser.parseUri(uri, edm);
+ uriInfoTmp = testParser.parseUri(uri, edm);
UriValidator uriValidator = new UriValidator();
uriValidator.validate(uriInfoTmp, HttpMethod.GET);
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9048d725/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/TestUriValidator.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/TestUriValidator.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/TestUriValidator.java
index 300c8fc..f0407c1 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/TestUriValidator.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/TestUriValidator.java
@@ -18,11 +18,18 @@
*/
package org.apache.olingo.server.core.uri.testutil;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import java.util.List;
+
import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.edm.EdmEntityType;
import org.apache.olingo.commons.api.edm.EdmType;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.api.http.HttpMethod;
+import org.apache.olingo.server.api.ODataTranslatedException;
+import org.apache.olingo.server.api.uri.UriInfo;
import org.apache.olingo.server.api.uri.UriInfoKind;
import org.apache.olingo.server.api.uri.queryoption.CustomQueryOption;
import org.apache.olingo.server.api.uri.queryoption.SelectItem;
@@ -38,16 +45,11 @@ import org.apache.olingo.server.core.uri.queryoption.SelectOptionImpl;
import org.apache.olingo.server.core.uri.validator.UriValidationException;
import org.apache.olingo.server.core.uri.validator.UriValidator;
-import java.util.List;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
public class TestUriValidator implements TestValidator {
private Edm edm;
- private UriInfoImpl uriInfo;
- private Exception exception;
+ private UriInfo uriInfo;
+ private ODataTranslatedException exception;
// Setup
public TestUriValidator setEdm(final Edm edm) {
@@ -60,8 +62,7 @@ public class TestUriValidator implements TestValidator {
Parser parser = new Parser();
UriValidator validator = new UriValidator();
- uriInfo = null;
- uriInfo = (UriInfoImpl) parser.parseUri(uri, edm);
+ uriInfo = parser.parseUri(uri, edm);
validator.validate(uriInfo, HttpMethod.GET);
return this;
}
@@ -70,7 +71,7 @@ public class TestUriValidator implements TestValidator {
Parser parser = new Parser();
uriInfo = null;
try {
- uriInfo = (UriInfoImpl) parser.parseUri(uri, edm);
+ uriInfo = parser.parseUri(uri, edm);
new UriValidator().validate(uriInfo, HttpMethod.GET);
fail("Exception expected");
} catch (UriParserException e) {
@@ -87,8 +88,7 @@ public class TestUriValidator implements TestValidator {
parserTest.setLogLevel(1);
uriInfo = null;
try {
- // uriInfoTmp = new UriParserImpl(edm).ParseUri(uri);
- uriInfo = (UriInfoImpl) parserTest.parseUri(uri, edm);
+ uriInfo = parserTest.parseUri(uri, edm);
} catch (UriParserException e) {
fail("Exception occured while parsing the URI: " + uri + "\n"
+ " Exception: " + e.getMessage());
@@ -164,7 +164,7 @@ public class TestUriValidator implements TestValidator {
List<CustomQueryOption> list = uriInfo.getCustomQueryOptions();
if (list.size() <= index) {
- fail("not enought queryParameters");
+ fail("not enough queryParameters");
}
CustomQueryOptionImpl option = (CustomQueryOptionImpl) list.get(index);
@@ -186,13 +186,21 @@ public class TestUriValidator implements TestValidator {
}
- public TestUriValidator isExSyntax(final long errorID) {
+ public TestUriValidator isExSyntax(final UriParserSyntaxException.MessageKeys messageKey) {
assertEquals(UriParserSyntaxException.class, exception.getClass());
+ assertEquals(messageKey, exception.getMessageKey());
return this;
}
- public TestUriValidator isExSemantic(final long errorID) {
+ public TestUriValidator isExSemantic(final UriParserSemanticException.MessageKeys messageKey) {
assertEquals(UriParserSemanticException.class, exception.getClass());
+ assertEquals(messageKey, exception.getMessageKey());
+ return this;
+ }
+
+ public TestUriValidator isExValidation(final UriValidationException.MessageKeys messageKey) {
+ assertEquals(UriValidationException.class, exception.getClass());
+ assertEquals(messageKey, exception.getMessageKey());
return this;
}
@@ -254,10 +262,4 @@ public class TestUriValidator implements TestValidator {
assertEquals(fqn.toString(), item.getAllOperationsInSchemaNameSpace().toString());
return this;
}
-
- public TestUriValidator isExValidation(String string) {
- assertEquals(UriValidationException.class, exception.getClass());
- return this;
- }
-
}
[2/2] git commit: [OLINGO-356] Content negotiation change for custom
format
Posted by mi...@apache.org.
[OLINGO-356] Content negotiation change for custom format
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/266c7b4a
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/266c7b4a
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/266c7b4a
Branch: refs/heads/master
Commit: 266c7b4ae8e5ce75c14854fe70ac181e4819e02e
Parents: 9048d72
Author: Michael Bolz <mi...@sap.com>
Authored: Thu Aug 7 13:33:13 2014 +0200
Committer: Michael Bolz <mi...@sap.com>
Committed: Thu Aug 7 13:49:43 2014 +0200
----------------------------------------------------------------------
.../olingo/commons/api/format/AcceptType.java | 15 +--
.../olingo/commons/api/format/ContentType.java | 19 +--
.../CustomContentTypeSupportProcessor.java | 6 +-
.../api/processor/FormatContentTypeMapping.java | 57 --------
.../olingo/server/core/ContentNegotiator.java | 131 ++++++++----------
.../server/core/ContentNegotiatorTest.java | 133 +++++++++----------
.../olingo/server/core/ODataHandlerTest.java | 24 ++--
7 files changed, 141 insertions(+), 244 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/266c7b4a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/AcceptType.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/AcceptType.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/AcceptType.java
index 180583c..379eb95 100644
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/AcceptType.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/AcceptType.java
@@ -45,9 +45,6 @@ import java.util.TreeMap;
*/
public class AcceptType {
-// public static final AcceptType WILDCARD = new AcceptType(TypeUtil.MEDIA_TYPE_WILDCARD, TypeUtil.MEDIA_TYPE_WILDCARD,
-// createParameterMap(), 1.0F);
-
private final String type;
private final String subtype;
private final Map<String, String> parameters;
@@ -98,8 +95,8 @@ public class AcceptType {
}
}
- private static void
- parse(final String format, final List<String> typeSubtype, final Map<String, String> parameters) {
+ private static void parse(final String format, final List<String> typeSubtype,
+ final Map<String, String> parameters) {
final String[] typesAndParameters = format.split(TypeUtil.PARAMETER_SEPARATOR, 2);
final String types = typesAndParameters[0];
@@ -127,9 +124,9 @@ public class AcceptType {
}
/**
- * Create an {@link AcceptType} based on given input string (<code>format</code>).
- * @param format
- * @return a new <code>AcceptType</code> object
+ * Create a list of {@link AcceptType} objects based on given input string (<code>format</code>).
+ * @param format accept types, comma-separated, as specified for the HTTP header <code>Accept</code>
+ * @return a list of <code>AcceptType</code> objects
* @throws IllegalArgumentException if input string is not parseable
*/
public static List<AcceptType> create(final String format) {
@@ -216,7 +213,7 @@ public class AcceptType {
* as defined in RFC 7231, chapters 3.1.1.1, 5.3.1, and 5.3.2.
* @param toSort list which is sorted and hence re-arranged
*/
- private static void sort(final List<AcceptType> toSort) {
+ private static void sort(List<AcceptType> toSort) {
Collections.sort(toSort,
new Comparator<AcceptType>() {
@Override
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/266c7b4a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/ContentType.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/ContentType.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/ContentType.java
index 5fa44ce..20620fc 100644
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/ContentType.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/format/ContentType.java
@@ -302,22 +302,15 @@ public final class ContentType {
}
/**
- * {@link ContentType}s are <b>compatible</b>
- * <ul>
- * <li>if <code>type</code>, <code>subtype</code> have the same value.</li>
- * <li>if <code>type</code> and/or <code>subtype</code> is set to "*"</li>
- * </ul>
- * The set <code>parameters</code> are <b>always</b> ignored (for compare with parameters see {@link #equals(Object)}
- * ).
- *
+ * <p>{@link ContentType}s are <b>compatible</b>
+ * if <code>type</code> and <code>subtype</code> have the same value.</p>
+ * <p>The set <code>parameters</code> are <b>always</b> ignored
+ * (for compare with parameters see {@link #equals(Object)}).</p>
* @return <code>true</code> if both instances are equal (see definition above), otherwise <code>false</code>.
*/
public boolean isCompatible(final ContentType obj) {
- Boolean compatible = isEqualWithoutParameters(obj);
- if (compatible == null) {
- return true;
- }
- return compatible.booleanValue();
+ final Boolean compatible = isEqualWithoutParameters(obj);
+ return compatible == null || compatible.booleanValue();
}
/**
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/266c7b4a/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/CustomContentTypeSupportProcessor.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/CustomContentTypeSupportProcessor.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/CustomContentTypeSupportProcessor.java
index edcad72..0d94a52 100644
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/CustomContentTypeSupportProcessor.java
+++ b/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/CustomContentTypeSupportProcessor.java
@@ -20,6 +20,8 @@ package org.apache.olingo.server.api.processor;
import java.util.List;
+import org.apache.olingo.commons.api.format.ContentType;
+
/**
* A processor which supports custom content types can implement this interface. The processor can also remove default
* content types if the default serializer of Olingo are not used. By default this interface is not implemented and
@@ -35,7 +37,7 @@ public interface CustomContentTypeSupportProcessor {
* @return modified list of supported content types
*
*/
- public List<FormatContentTypeMapping> modifySupportedContentTypes(
- List<FormatContentTypeMapping> defaultContentTypes, Class<? extends Processor> processorClass);
+ public List<ContentType> modifySupportedContentTypes(
+ List<ContentType> defaultContentTypes, Class<? extends Processor> processorClass);
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/266c7b4a/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/FormatContentTypeMapping.java
----------------------------------------------------------------------
diff --git a/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/FormatContentTypeMapping.java b/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/FormatContentTypeMapping.java
deleted file mode 100644
index 38ce7d6..0000000
--- a/lib/server-api/src/main/java/org/apache/olingo/server/api/processor/FormatContentTypeMapping.java
+++ /dev/null
@@ -1,57 +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.api.processor;
-
-/**
- * Mapping between an uri $format option value and a content types. For instance the $format option "xml" maps to
- * content type "application/xml".
- */
-public class FormatContentTypeMapping {
-
- private String formatOptionValue;
- private String contentTypeValue;
-
- public FormatContentTypeMapping(final String formatOptionValue, final String contentTypeValue) {
- super();
- this.formatOptionValue = formatOptionValue;
- this.contentTypeValue = contentTypeValue;
- }
-
- public String getFormatAlias() {
- return formatOptionValue;
- }
-
- public String getContentType() {
- return contentTypeValue;
- }
-
- public void setFormatAlias(final String formatOptionValue) {
- this.formatOptionValue = formatOptionValue;
- }
-
- public void setContentType(final String contentTypeValue) {
- this.contentTypeValue = contentTypeValue;
- }
-
- @Override
- public String toString() {
- return "('" + formatOptionValue + "', '" + contentTypeValue + "')";
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/266c7b4a/lib/server-core/src/main/java/org/apache/olingo/server/core/ContentNegotiator.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/ContentNegotiator.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/ContentNegotiator.java
index e762464..1adabf7 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/ContentNegotiator.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/ContentNegotiator.java
@@ -28,7 +28,6 @@ import org.apache.olingo.commons.api.format.ODataFormat;
import org.apache.olingo.commons.api.http.HttpHeader;
import org.apache.olingo.server.api.ODataRequest;
import org.apache.olingo.server.api.processor.CustomContentTypeSupportProcessor;
-import org.apache.olingo.server.api.processor.FormatContentTypeMapping;
import org.apache.olingo.server.api.processor.MetadataProcessor;
import org.apache.olingo.server.api.processor.Processor;
import org.apache.olingo.server.api.uri.queryoption.FormatOption;
@@ -37,29 +36,28 @@ public class ContentNegotiator {
private ContentNegotiator() {}
- private static List<FormatContentTypeMapping>
+ private static List<ContentType>
getDefaultSupportedContentTypes(final Class<? extends Processor> processorClass) {
- List<FormatContentTypeMapping> defaults = new ArrayList<FormatContentTypeMapping>();
+ List<ContentType> defaults = new ArrayList<ContentType>();
if (processorClass == MetadataProcessor.class) {
- defaults.add(new FormatContentTypeMapping("xml", ContentType.APPLICATION_XML.toContentTypeString()));
+ defaults.add(ODataFormat.XML.getContentType(ODataServiceVersion.V40));
} else {
- defaults.add(new FormatContentTypeMapping("json",
- ODataFormat.JSON.getContentType(ODataServiceVersion.V40).toContentTypeString()));
+ defaults.add(ODataFormat.JSON.getContentType(ODataServiceVersion.V40));
+ defaults.add(ODataFormat.JSON_NO_METADATA.getContentType(ODataServiceVersion.V40));
}
return defaults;
}
- private static List<FormatContentTypeMapping> getSupportedContentTypes(final Processor processor,
+ private static List<ContentType> getSupportedContentTypes(final Processor processor,
final Class<? extends Processor> processorClass) {
- List<FormatContentTypeMapping> supportedContentTypes = getDefaultSupportedContentTypes(processorClass);
+ List<ContentType> supportedContentTypes = getDefaultSupportedContentTypes(processorClass);
if (processor instanceof CustomContentTypeSupportProcessor) {
- supportedContentTypes =
- ((CustomContentTypeSupportProcessor) processor).modifySupportedContentTypes(supportedContentTypes,
- processorClass);
+ supportedContentTypes = ((CustomContentTypeSupportProcessor) processor)
+ .modifySupportedContentTypes(supportedContentTypes, processorClass);
}
return supportedContentTypes;
@@ -67,98 +65,73 @@ public class ContentNegotiator {
public static ContentType doContentNegotiation(final FormatOption formatOption, final ODataRequest request,
final Processor processor, final Class<? extends Processor> processorClass) throws ContentNegotiatorException {
- ContentType requestedContentType = null;
-
- List<FormatContentTypeMapping> supportedContentTypes = getSupportedContentTypes(processor, processorClass);
-
- String acceptHeaderValue = request.getHeader(HttpHeader.ACCEPT);
-
- boolean supported = false;
-
- if (formatOption != null) {
- if ("json".equalsIgnoreCase(formatOption.getText().trim())) {
- requestedContentType = ODataFormat.JSON.getContentType(ODataServiceVersion.V40);
- for (FormatContentTypeMapping entry : supportedContentTypes) {
- if (requestedContentType.isCompatible(ContentType.create(entry.getContentType().trim()))) {
- supported = true;
- break;
- }
- }
- } else if ("xml".equalsIgnoreCase(formatOption.getText().trim())) {
- requestedContentType = ContentType.APPLICATION_XML;
- for (FormatContentTypeMapping entry : supportedContentTypes) {
- if (requestedContentType.isCompatible(ContentType.create(entry.getContentType().trim()))) {
- supported = true;
- break;
- }
- }
- } else {
- for (FormatContentTypeMapping entry : supportedContentTypes) {
- if (formatOption.getText().equalsIgnoreCase(entry.getFormatAlias().trim())) {
- requestedContentType = ContentType.create(entry.getContentType().trim());
- supported = true;
- break;
- }
- }
- }
- if (!supported) {
- throw new ContentNegotiatorException("Unsupported $format = " + formatOption.getText(),
- ContentNegotiatorException.MessageKeys.UNSUPPORTED_FORMAT_OPTION, formatOption.getText());
+ final List<ContentType> supportedContentTypes = getSupportedContentTypes(processor, processorClass);
+ final String acceptHeaderValue = request.getHeader(HttpHeader.ACCEPT);
+ ContentType result = null;
+
+ if (formatOption != null && formatOption.getFormat() != null) {
+ final String formatString = formatOption.getFormat().trim();
+ final ODataFormat format =
+ ODataFormat.JSON.name().equalsIgnoreCase(formatString) ? ODataFormat.JSON :
+ ODataFormat.XML.name().equalsIgnoreCase(formatString) ? ODataFormat.XML :
+ ODataFormat.ATOM.name().equalsIgnoreCase(formatString) ? ODataFormat.ATOM : null;
+ result = getSupportedContentType(format == null ?
+ ContentType.create(formatOption.getFormat()) : format.getContentType(ODataServiceVersion.V40),
+ supportedContentTypes);
+ if (result == null) {
+ throw new ContentNegotiatorException("Unsupported $format = " + formatString,
+ ContentNegotiatorException.MessageKeys.UNSUPPORTED_FORMAT_OPTION, formatString);
}
} else if (acceptHeaderValue != null) {
- List<AcceptType> acceptedContentTypes = AcceptType.create(acceptHeaderValue);
-
+ final List<AcceptType> acceptedContentTypes = AcceptType.create(acceptHeaderValue);
for (AcceptType acceptedType : acceptedContentTypes) {
- for (FormatContentTypeMapping supportedType : supportedContentTypes) {
-
- ContentType ct = ContentType.create(supportedType.getContentType());
+ for (final ContentType supportedContentType : supportedContentTypes) {
+ ContentType contentType = supportedContentType;
if (acceptedType.getParameters().containsKey("charset")) {
- String value = acceptedType.getParameters().get("charset");
+ final String value = acceptedType.getParameters().get("charset");
if ("utf8".equalsIgnoreCase(value) || "utf-8".equalsIgnoreCase(value)) {
- ct = ContentType.create(ct, ContentType.PARAMETER_CHARSET_UTF8);
+ contentType = ContentType.create(contentType, ContentType.PARAMETER_CHARSET_UTF8);
} else {
throw new ContentNegotiatorException("charset in accept header not supported: " + acceptHeaderValue,
ContentNegotiatorException.MessageKeys.WRONG_CHARSET_IN_HEADER, HttpHeader.ACCEPT, acceptHeaderValue);
}
}
-
- if (acceptedType.matches(ct)) {
- requestedContentType = ct;
- supported = true;
+ if (acceptedType.matches(contentType)) {
+ result = contentType;
break;
}
}
- if (supported) {
+ if (result != null) {
break;
}
}
-
- if (!supported) {
+ if (result == null) {
throw new ContentNegotiatorException(
"unsupported accept content type: " + acceptedContentTypes + " != " + supportedContentTypes,
ContentNegotiatorException.MessageKeys.UNSUPPORTED_CONTENT_TYPES, acceptedContentTypes.toString());
}
} else {
- if (processorClass == MetadataProcessor.class) {
- requestedContentType = ContentType.APPLICATION_XML;
- } else {
- requestedContentType = ODataFormat.JSON.getContentType(ODataServiceVersion.V40);
- }
-
- for (FormatContentTypeMapping entry : supportedContentTypes) {
- if (requestedContentType.isCompatible(ContentType.create(entry.getContentType().trim()))) {
- supported = true;
- break;
- }
+ final ContentType requestedContentType = processorClass == MetadataProcessor.class ?
+ ODataFormat.XML.getContentType(ODataServiceVersion.V40) :
+ ODataFormat.JSON.getContentType(ODataServiceVersion.V40);
+ result = getSupportedContentType(requestedContentType, supportedContentTypes);
+ if (result == null) {
+ throw new ContentNegotiatorException(
+ "unsupported accept content type: " + requestedContentType + " != " + supportedContentTypes,
+ ContentNegotiatorException.MessageKeys.UNSUPPORTED_CONTENT_TYPE,
+ requestedContentType.toContentTypeString());
}
}
+ return result;
+ }
- if (!supported) {
- throw new ContentNegotiatorException(
- "unsupported accept content type: " + requestedContentType + " != " + supportedContentTypes,
- ContentNegotiatorException.MessageKeys.UNSUPPORTED_CONTENT_TYPE, requestedContentType.toContentTypeString());
+ private static ContentType getSupportedContentType(final ContentType requestedContentType,
+ final List<ContentType> supportedContentTypes) {
+ for (final ContentType supportedContentType : supportedContentTypes) {
+ if (requestedContentType.isCompatible(supportedContentType)) {
+ return supportedContentType;
+ }
}
-
- return requestedContentType;
+ return null;
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/266c7b4a/lib/server-core/src/test/java/org/apache/olingo/server/core/ContentNegotiatorTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/ContentNegotiatorTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/ContentNegotiatorTest.java
index f858aa0..61d0bc8 100644
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/ContentNegotiatorTest.java
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/ContentNegotiatorTest.java
@@ -20,7 +20,6 @@ package org.apache.olingo.server.core;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -36,9 +35,8 @@ import org.apache.olingo.commons.api.http.HttpMethod;
import org.apache.olingo.server.api.OData;
import org.apache.olingo.server.api.ODataRequest;
import org.apache.olingo.server.api.ODataResponse;
-import org.apache.olingo.server.api.processor.EntityCollectionProcessor;
import org.apache.olingo.server.api.processor.CustomContentTypeSupportProcessor;
-import org.apache.olingo.server.api.processor.FormatContentTypeMapping;
+import org.apache.olingo.server.api.processor.EntityCollectionProcessor;
import org.apache.olingo.server.api.processor.MetadataProcessor;
import org.apache.olingo.server.api.processor.Processor;
import org.apache.olingo.server.api.processor.ServiceDocumentProcessor;
@@ -60,49 +58,49 @@ public class ContentNegotiatorTest {
//CHECKSTYLE:OFF (Maven checkstyle)
String[][] casesServiceDocument = {
- /* expected $format accept alias ct mapping */
- { ACCEPT_CASE_MIN, null, null, null ,null },
- { ACCEPT_CASE_MIN, "json", null, null ,null },
- { ACCEPT_CASE_MIN, "json", ACCEPT_CASE_JSONQ, null ,null },
- { "a/a", "a", null, "a" ,"a/a" },
- { ACCEPT_CASE_MIN, null, ACCEPT_CASE_JSONQ, null ,null },
- { ACCEPT_CASE_MIN, null, ACCEPT_CASE_WILDCARD1, null ,null },
- { ACCEPT_CASE_MIN, null, ACCEPT_CASE_WILDCARD2, null ,null },
- { "a/a", "a", null, "a, b" ,"a/a,b/b" },
- { "a/a", " a ", null, " a , b" ," a/a , b/b " },
- { "a/a;x=y", "a", ACCEPT_CASE_WILDCARD1, "a" ,"a/a;x=y" },
- { ACCEPT_CASE_MIN, "json", ACCEPT_CASE_MIN, null ,null },
- { ACCEPT_CASE_FULL, null, ACCEPT_CASE_FULL, "dummy" ,ACCEPT_CASE_FULL },
- { ACCEPT_CASE_MIN_UTF8, null, ACCEPT_CASE_MIN_UTF8, null ,null },
+ /* expected $format accept additional content types */
+ { ACCEPT_CASE_MIN, null, null, null },
+ { ACCEPT_CASE_MIN, "json", null, null },
+ { ACCEPT_CASE_MIN, "json", ACCEPT_CASE_JSONQ, null },
+ { "a/a", "a/a", null, "a/a" },
+ { ACCEPT_CASE_MIN, null, ACCEPT_CASE_JSONQ, null },
+ { ACCEPT_CASE_MIN, null, ACCEPT_CASE_WILDCARD1, null },
+ { ACCEPT_CASE_MIN, null, ACCEPT_CASE_WILDCARD2, null },
+ { "a/a", "a/a", null, "a/a,b/b" },
+ { "a/a", " a/a ", null, " a/a , b/b " },
+ { "a/a;x=y", "a/a", ACCEPT_CASE_WILDCARD1, "a/a;x=y" },
+ { ACCEPT_CASE_MIN, "json", ACCEPT_CASE_MIN, null },
+ { ACCEPT_CASE_FULL, null, ACCEPT_CASE_FULL, ACCEPT_CASE_FULL },
+ { ACCEPT_CASE_MIN_UTF8, null, ACCEPT_CASE_MIN_UTF8, null },
};
String[][] casesMetadata = {
- /* expected $format accept alias ct mapping */
- { "application/xml", null, null, null ,null },
- { "application/xml", "xml", null, null ,null },
- { "application/xml", "xml", ACCEPT_CASE_XML, null ,null },
- { "a/a", "a", null, "a" ,"a/a" },
- { "application/xml", null, ACCEPT_CASE_XML, null ,null },
- { "application/xml", null, ACCEPT_CASE_WILDCARD1, null ,null },
- { "application/xml", null, ACCEPT_CASE_WILDCARD2, null ,null },
- { "a/a", "a", null, "a, b" ,"a/a,b/b" },
- { "a/a", " a ", null, " a , b" ," a/a , b/b " },
- { "a/a;x=y", "a", ACCEPT_CASE_WILDCARD1, "a" ,"a/a;x=y" },
+ /* expected $format accept additional content types */
+ { ACCEPT_CASE_XML, null, null, null },
+ { ACCEPT_CASE_XML, "xml", null, null },
+ { ACCEPT_CASE_XML, "xml", ACCEPT_CASE_XML, null },
+ { "a/a", "a/a", null, "a/a" },
+ { ACCEPT_CASE_XML, null, ACCEPT_CASE_XML, null },
+ { ACCEPT_CASE_XML, null, ACCEPT_CASE_WILDCARD1, null },
+ { ACCEPT_CASE_XML, null, ACCEPT_CASE_WILDCARD2, null },
+ { "a/a", "a/a", null, "a/a,b/b" },
+ { "a/a", " a/a ", null, " a/a , b/b " },
+ { "a/a;x=y", "a/a", ACCEPT_CASE_WILDCARD1, "a/a;x=y" },
};
String[][] casesFail = {
- /* expected $format accept alias ct mapping */
- { "application/xml", "xxx", null, null ,null },
- { "a/a", "a", null, "b" ,"b/b" },
- { "application/xml", null, ACCEPT_CASE_JSONQ, null ,null },
- { "application/json", null, ACCEPT_CASE_FULL, null ,null }, // not jet supported
+ /* expected $format accept additional content types */
+ { ACCEPT_CASE_XML, "xxx/yyy", null, null },
+ { "a/a", "a/a", null, "b/b" },
+ { ACCEPT_CASE_XML, null, ACCEPT_CASE_JSONQ, null },
+ { "application/json", null, ACCEPT_CASE_FULL, null }, // not yet supported
};
//CHECKSTYLE:ON
//@formatter:on
@Test
public void testServiceDocumentSingleCase() throws Exception {
- String[] useCase = { ACCEPT_CASE_MIN_UTF8, null, ACCEPT_CASE_MIN_UTF8, null, null };
+ String[] useCase = { ACCEPT_CASE_MIN_UTF8, null, ACCEPT_CASE_MIN_UTF8, null };
testContentNegotiation(useCase, ServiceDocumentProcessor.class);
}
@@ -116,7 +114,7 @@ public class ContentNegotiatorTest {
@Test
public void testMetadataSingleCase() throws Exception {
- String[] useCase = { "application/xml", null, null, null, null };
+ String[] useCase = { ACCEPT_CASE_XML, null, null, null };
testContentNegotiation(useCase, MetadataProcessor.class);
}
@@ -129,86 +127,77 @@ public class ContentNegotiatorTest {
}
@Test
- public void testMetadataFail() {
+ public void testMetadataFail() throws Exception {
for (String[] useCase : casesFail) {
try {
testContentNegotiation(useCase, MetadataProcessor.class);
- fail("Exeption expected!");
- } catch (ContentNegotiatorException e) {
-
- }catch (Exception e) {
- e.printStackTrace();
- fail("Wrong Exception: " + e.getClass().getName());
- }
+ fail("Exception expected!");
+ } catch (final ContentNegotiatorException e) {}
}
}
- public void testContentNegotiation(final String[] useCase, final Class<? extends Processor> processorClass)
- throws Exception {
+ private void testContentNegotiation(final String[] useCase, final Class<? extends Processor> processorClass)
+ throws ContentNegotiatorException {
ODataRequest request = new ODataRequest();
request.setMethod(HttpMethod.GET);
request.setRawODataPath("/" + (useCase[1] == null ? "" : "?$format=" + useCase[1]));
- ProcessorStub p = new ProcessorStub(createCustomContentTypeMapping(useCase[3], useCase[4]));
+ ProcessorStub p = new ProcessorStub(createCustomContentTypes(useCase[3]));
FormatOption fo = null;
if (useCase[1] != null) {
fo = mock(FormatOption.class);
- when(fo.getText()).thenReturn(useCase[1].trim());
+ when(fo.getFormat()).thenReturn(useCase[1].trim());
}
if (useCase[2] != null) {
request.addHeader(HttpHeader.ACCEPT, Arrays.asList(useCase[2]));
}
- ContentType requestedContentType = ContentNegotiator.doContentNegotiation(fo, request, p, processorClass);
+ final ContentType requestedContentType = ContentNegotiator.doContentNegotiation(fo, request, p, processorClass);
assertNotNull(requestedContentType);
assertEquals(ContentType.create(useCase[0]), requestedContentType);
}
- private List<FormatContentTypeMapping> createCustomContentTypeMapping(final String formatString,
- final String contentTypeString) {
- List<FormatContentTypeMapping> map = null;
+ private List<ContentType> createCustomContentTypes(final String contentTypeString) {
- assertTrue(!(formatString == null ^ contentTypeString == null));
-
- if (formatString != null) {
- String[] formats = formatString.split(",");
- String[] contentTypes = contentTypeString.split(",");
+ if (contentTypeString == null) {
+ return null;
+ }
- assertEquals(formats.length, contentTypes.length);
+ String[] contentTypes = contentTypeString.split(",");
- map = new ArrayList<FormatContentTypeMapping>();
- for (int i = 0; i < formats.length; i++) {
- map.add(new FormatContentTypeMapping(formats[i], contentTypes[i]));
- }
+ List<ContentType> types = new ArrayList<ContentType>();
+ for (int i = 0; i < contentTypes.length; i++) {
+ types.add(ContentType.create(contentTypes[i].trim()));
}
- return map;
+ return types;
}
private class ProcessorStub implements ServiceDocumentProcessor, MetadataProcessor,
- EntityCollectionProcessor,
- CustomContentTypeSupportProcessor {
+ EntityCollectionProcessor, CustomContentTypeSupportProcessor {
- List<FormatContentTypeMapping> customMapping;
+ List<ContentType> customTypes;
- ProcessorStub(final List<FormatContentTypeMapping> mapping) {
- customMapping = mapping;
+ ProcessorStub(final List<ContentType> types) {
+ customTypes = types;
}
@Override
public void init(final OData odata, final Edm edm) {}
@Override
- public List<FormatContentTypeMapping> modifySupportedContentTypes(
- final List<FormatContentTypeMapping> supportedContentTypes,
+ public List<ContentType> modifySupportedContentTypes(final List<ContentType> supportedContentTypes,
final Class<? extends Processor> processorClass) {
- if (customMapping != null) {
- supportedContentTypes.addAll(customMapping);
+ if (customTypes == null) {
+ return supportedContentTypes;
+ } else {
+ List<ContentType> modifiedTypes = new ArrayList<ContentType>(supportedContentTypes);
+ modifiedTypes.addAll(customTypes);
+ return modifiedTypes;
}
- return supportedContentTypes;
}
@Override
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/266c7b4a/lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerTest.java
index 7e55ab8..3ac7208 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerTest.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerTest.java
@@ -78,7 +78,7 @@ public class ODataHandlerTest {
ODataResponse response = handler.process(request);
assertNotNull(response);
- assertEquals(500, response.getStatusCode());
+ assertEquals(HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode());
}
@Test
@@ -92,7 +92,7 @@ public class ODataHandlerTest {
ODataResponse response = handler.process(request);
assertNotNull(response);
- assertEquals(200, response.getStatusCode());
+ assertEquals(HttpStatusCode.OK.getStatusCode(), response.getStatusCode());
String ct = response.getHeaders().get(HttpHeader.CONTENT_TYPE);
assertTrue(ct.contains("application/json"));
@@ -134,7 +134,7 @@ public class ODataHandlerTest {
ODataResponse response = handler.process(request);
assertNotNull(response);
- assertEquals(500, response.getStatusCode());
+ assertEquals(HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode());
}
@Test
@@ -147,7 +147,7 @@ public class ODataHandlerTest {
ODataResponse response = handler.process(request);
assertNotNull(response);
- assertEquals(200, response.getStatusCode());
+ assertEquals(HttpStatusCode.OK.getStatusCode(), response.getStatusCode());
assertEquals(HttpContentType.APPLICATION_XML, response.getHeaders().get(HttpHeader.CONTENT_TYPE));
assertNotNull(response.getContent());
@@ -195,7 +195,7 @@ public class ODataHandlerTest {
assertNotNull(response);
assertEquals(ODataServiceVersion.V40.toString(), response.getHeaders().get(HttpHeader.ODATA_VERSION));
- assertEquals(400, response.getStatusCode());
+ assertEquals(HttpStatusCode.BAD_REQUEST.getStatusCode(), response.getStatusCode());
}
@Test
@@ -208,7 +208,7 @@ public class ODataHandlerTest {
ODataResponse response = handler.process(request);
assertNotNull(response);
- assertEquals(200, response.getStatusCode());
+ assertEquals(HttpStatusCode.OK.getStatusCode(), response.getStatusCode());
}
@Test
@@ -217,11 +217,11 @@ public class ODataHandlerTest {
request.setMethod(HttpMethod.GET);
request.setRawODataPath("$metadata");
- request.setRawQueryPath("$format=notSupported");
+ request.setRawQueryPath("$format=not/Supported");
ODataResponse response = handler.process(request);
assertNotNull(response);
- assertEquals(406, response.getStatusCode());
+ assertEquals(HttpStatusCode.NOT_ACCEPTABLE.getStatusCode(), response.getStatusCode());
}
@Test
@@ -233,7 +233,7 @@ public class ODataHandlerTest {
ODataResponse response = handler.process(request);
assertNotNull(response);
- assertEquals(501, response.getStatusCode());
+ assertEquals(HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), response.getStatusCode());
}
@Test
@@ -265,7 +265,7 @@ public class ODataHandlerTest {
ODataResponse response = handler.process(request);
assertNotNull(response);
- assertEquals(404, response.getStatusCode());
+ assertEquals(HttpStatusCode.NOT_FOUND.getStatusCode(), response.getStatusCode());
}
//TODO: Use this test
@@ -279,7 +279,7 @@ public class ODataHandlerTest {
ODataResponse response = handler.process(request);
assertNotNull(response);
- assertEquals(404, response.getStatusCode());
+ assertEquals(HttpStatusCode.NOT_FOUND.getStatusCode(), response.getStatusCode());
}
@Test
@@ -301,7 +301,7 @@ public class ODataHandlerTest {
ODataResponse response = localHandler.process(request);
assertNotNull(response);
- assertEquals(500, response.getStatusCode());
+ assertEquals(HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode());
// TODO: Check for message in case of EdmException
// System.out.println(IOUtils.toString(response.getContent()));
}