[OLINGO-636] Small refactoring URIParser
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata2/repo Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata2/commit/0c12f272 Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata2/tree/0c12f272 Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata2/diff/0c12f272 Branch: refs/heads/master Commit: 0c12f272ec4c7e2ef83ba97fb9152fa03b187f25 Parents: 39e774b Author: Christian Holzer <[email protected]> Authored: Tue Apr 21 13:13:21 2015 +0200 Committer: Christian Holzer <[email protected]> Committed: Tue Apr 21 13:27:12 2015 +0200 ---------------------------------------------------------------------- .../apache/olingo/odata2/core/uri/UriParserImpl.java | 6 +++--- .../apache/olingo/odata2/core/uri/UriParserTest.java | 14 +++++++++++++- .../olingo/odata2/fit/ref/EntryJsonReadOnlyTest.java | 14 ++++++++++++++ 3 files changed, 30 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/0c12f272/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/UriParserImpl.java ---------------------------------------------------------------------- diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/UriParserImpl.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/UriParserImpl.java index d9ae0a5..162ca8d 100644 --- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/UriParserImpl.java +++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/UriParserImpl.java @@ -167,13 +167,13 @@ public class UriParserImpl extends UriParser { } else { currentPathSegment = pathSegments.remove(0); - final String encodedPath = percentDecode(currentPathSegment); + final String decodedPath = percentDecode(currentPathSegment); - if ("$metadata".equals(encodedPath)) { + if ("$metadata".equals(decodedPath)) { ensureLastSegment(); uriResult.setUriType(UriType.URI8); - } else if ("$batch".equals(encodedPath)) { + } else if ("$batch".equals(decodedPath)) { ensureLastSegment(); uriResult.setUriType(UriType.URI9); http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/0c12f272/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/uri/UriParserTest.java ---------------------------------------------------------------------- diff --git a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/uri/UriParserTest.java b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/uri/UriParserTest.java index d2b57d2..64b88bd 100644 --- a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/uri/UriParserTest.java +++ b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/uri/UriParserTest.java @@ -134,7 +134,7 @@ public class UriParserTest extends BaseTest { @Test public void copyPathSegmentsTestEncoded() throws Exception { List<PathSegment> pathSegments = new ArrayList<PathSegment>(); - pathSegments.add(new ODataPathSegmentImpl("$metadata", null)); + pathSegments.add(new ODataPathSegmentImpl("%24metadata", null)); UriInfoImpl result = (UriInfoImpl) new UriParserImpl(edm).parse(pathSegments, Collections.<String, String> emptyMap()); assertNotNull(result); @@ -254,6 +254,18 @@ public class UriParserTest extends BaseTest { } @Test + public void parseEmployeesEntityWithKeyEncoded() throws Exception { + UriInfoImpl result = parse("/%45mployees('1')"); + assertNull(result.getEntityContainer().getName()); + assertEquals("Employees", result.getTargetEntitySet().getName()); + assertEquals(UriType.URI2, result.getUriType()); + + assertEquals(1, result.getKeyPredicates().size()); + assertEquals("1", result.getKeyPredicates().get(0).getLiteral()); + assertEquals("EmployeeId", result.getKeyPredicates().get(0).getProperty().getName()); + } + + @Test public void parseEmployeesEntity() throws Exception { UriInfoImpl result = parse("/Employees('1')"); assertNull(result.getEntityContainer().getName()); http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/0c12f272/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/EntryJsonReadOnlyTest.java ---------------------------------------------------------------------- diff --git a/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/EntryJsonReadOnlyTest.java b/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/EntryJsonReadOnlyTest.java index e7895cc..0f42b97 100644 --- a/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/EntryJsonReadOnlyTest.java +++ b/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/EntryJsonReadOnlyTest.java @@ -61,7 +61,21 @@ public class EntryJsonReadOnlyTest extends AbstractRefTest { + "\"ne_Team\":{\"__deferred\":{\"uri\":\"" + getEndpoint() + "Employees('3')/ne_Team\"}}}}", getBody(response)); } + + @Test + public void mediaLinkEntryWithEncodedSystemQueryParameters() throws Exception { + final HttpResponse response = callUri("Employees('3')?%24select=Age,EntryDate,ne_Team&%24format=json"); + checkMediaType(response, HttpContentType.APPLICATION_JSON); + assertEquals("{\"d\":{\"__metadata\":{\"id\":\"" + getEndpoint() + "Employees('3')\"," + + "\"uri\":\"" + getEndpoint() + "Employees('3')\",\"type\":\"RefScenario.Employee\"," + + "\"content_type\":\"image/jpeg\",\"media_src\":\"Employees('3')/$value\"," + + "\"edit_media\":\"" + getEndpoint() + "Employees('3')/$value\"}," + + "\"Age\":56,\"EntryDate\":null," + + "\"ne_Team\":{\"__deferred\":{\"uri\":\"" + getEndpoint() + "Employees('3')/ne_Team\"}}}}", + getBody(response)); + } + @Test public void entryFromNonDefaultContainer() throws Exception { final HttpResponse response = callUri("Container2.Photos(Id=1,Type='image%2Fpng')?$format=json");
