Repository: olingo-odata4 Updated Branches: refs/heads/master a42641f70 -> 4f15c7c72
[OLINGO-596] Fix: The client URIBuilder uses semicolons instead of commas to split system query options in expand options Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/b9827515 Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/b9827515 Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/b9827515 Branch: refs/heads/master Commit: b98275153a9895d1ca69fd0fd76c236037f6e444 Parents: a42641f Author: Christian Holzer <[email protected]> Authored: Wed Mar 18 17:00:29 2015 +0100 Committer: Christian Holzer <[email protected]> Committed: Thu Mar 19 15:55:01 2015 +0100 ---------------------------------------------------------------------- .../olingo/client/core/uri/URIBuilderImpl.java | 9 ++- .../client/core/uri/v4/URIBuilderTest.java | 83 ++++++++++---------- 2 files changed, 47 insertions(+), 45 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/b9827515/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/URIBuilderImpl.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/URIBuilderImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/URIBuilderImpl.java index 2815a61..452596c 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/URIBuilderImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/uri/URIBuilderImpl.java @@ -143,7 +143,7 @@ public class URIBuilderImpl implements URIBuilder { @Override public URIBuilder appendKeySegment(final Map<String, Object> segmentValues) { if (!configuration.isKeyAsSegment()) { - final String key = buildMultiKeySegment(segmentValues, true); + final String key = buildMultiKeySegment(segmentValues, true, ','); if (StringUtils.isEmpty(key)) { segments.add(new Segment(SegmentType.KEY, noKeysWrapper())); } else { @@ -330,7 +330,8 @@ public class URIBuilderImpl implements URIBuilder { return build().toASCIIString(); } - protected String buildMultiKeySegment(final Map<String, Object> segmentValues, final boolean escape) { + protected String buildMultiKeySegment(final Map<String, Object> segmentValues, final boolean escape, + final char sperator) { if (segmentValues == null || segmentValues.isEmpty()) { return StringUtils.EMPTY; } else { @@ -338,7 +339,7 @@ public class URIBuilderImpl implements URIBuilder { for (Map.Entry<String, Object> entry : segmentValues.entrySet()) { keyBuilder.append(entry.getKey()).append('=').append( escape ? URIUtils.escape(entry.getValue()) : entry.getValue()); - keyBuilder.append(','); + keyBuilder.append(sperator); } keyBuilder.deleteCharAt(keyBuilder.length() - 1).append(')'); @@ -434,7 +435,7 @@ public class URIBuilderImpl implements URIBuilder { for (Map.Entry<QueryOption, Object> entry : options.entrySet()) { _options.put("$" + entry.getKey().toString(), entry.getValue()); } - return expand(expandItem + buildMultiKeySegment(_options, false)); + return expand(expandItem + buildMultiKeySegment(_options, false, ';')); } @Override http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/b9827515/lib/client-core/src/test/java/org/apache/olingo/client/core/uri/v4/URIBuilderTest.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/uri/v4/URIBuilderTest.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/uri/v4/URIBuilderTest.java index 731bf1d..15465dc 100644 --- a/lib/client-core/src/test/java/org/apache/olingo/client/core/uri/v4/URIBuilderTest.java +++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/uri/v4/URIBuilderTest.java @@ -1,18 +1,18 @@ /* * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file + * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file + * 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 - * + * 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 + * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ @@ -27,7 +27,9 @@ import org.junit.Test; import java.net.URI; import java.net.URISyntaxException; import java.util.Collections; +import java.util.HashMap; import java.util.LinkedHashMap; +import java.util.Map; import static org.junit.Assert.assertEquals; @@ -43,27 +45,26 @@ public class URIBuilderTest extends AbstractTest { @Test public void expandWithOptions() throws URISyntaxException { final URI uri = getClient().newURIBuilder(SERVICE_ROOT).appendEntitySetSegment("Products").appendKeySegment(5). - expandWithOptions("ProductDetails", new LinkedHashMap<QueryOption, Object>() { - private static final long serialVersionUID = 3109256773218160485L; + expandWithOptions("ProductDetails", new LinkedHashMap<QueryOption, Object>() { + private static final long serialVersionUID = 3109256773218160485L; - { - put(QueryOption.EXPAND, "ProductInfo"); - put(QueryOption.SELECT, "Price"); - } - }).expand("Orders", "Customers").build(); + { + put(QueryOption.EXPAND, "ProductInfo"); + put(QueryOption.SELECT, "Price"); + } + }).expand("Orders", "Customers").build(); assertEquals(new org.apache.http.client.utils.URIBuilder(SERVICE_ROOT + "/Products(5)"). - addParameter("$expand", "ProductDetails($expand=ProductInfo,$select=Price),Orders,Customers").build(), uri); + addParameter("$expand", "ProductDetails($expand=ProductInfo;$select=Price),Orders,Customers").build(), uri); } - @Test public void expandWithLevels() throws URISyntaxException { final URI uri = getClient().newURIBuilder(SERVICE_ROOT).appendEntitySetSegment("Products").appendKeySegment(1). - expandWithOptions("Customer", Collections.<QueryOption, Object>singletonMap(QueryOption.LEVELS, 4)). - build(); + expandWithOptions("Customer", Collections.<QueryOption, Object> singletonMap(QueryOption.LEVELS, 4)). + build(); assertEquals(new org.apache.http.client.utils.URIBuilder(SERVICE_ROOT + "/Products(1)"). - addParameter("$expand", "Customer($levels=4)").build(), uri); + addParameter("$expand", "Customer($levels=4)").build(), uri); } @Test @@ -75,72 +76,72 @@ public class URIBuilderTest extends AbstractTest { uri = getClient().newURIBuilder(SERVICE_ROOT).appendEntitySetSegment("Products").count(true).build(); assertEquals(new org.apache.http.client.utils.URIBuilder(SERVICE_ROOT + "/Products"). - addParameter("$count", "true").build(), uri); + addParameter("$count", "true").build(), uri); } @Test public void singleton() throws URISyntaxException { final URIBuilder uriBuilder = getClient().newURIBuilder(SERVICE_ROOT). - appendSingletonSegment("BestProductEverCreated"); + appendSingletonSegment("BestProductEverCreated"); assertEquals(new org.apache.http.client.utils.URIBuilder( - SERVICE_ROOT + "/BestProductEverCreated").build(), uriBuilder.build()); + SERVICE_ROOT + "/BestProductEverCreated").build(), uriBuilder.build()); } @Test public void entityId() throws URISyntaxException { final URIBuilder uriBuilder = getClient().newURIBuilder(SERVICE_ROOT). - appendEntityIdSegment("Products(0)"); + appendEntityIdSegment("Products(0)"); assertEquals(new org.apache.http.client.utils.URIBuilder( - SERVICE_ROOT + "/$entity").addParameter("$id", "Products(0)").build(), uriBuilder.build()); + SERVICE_ROOT + "/$entity").addParameter("$id", "Products(0)").build(), uriBuilder.build()); } @Test public void boundAction() throws URISyntaxException { final URIBuilder uriBuilder = getClient().newURIBuilder(SERVICE_ROOT). - appendEntitySetSegment("Categories").appendKeySegment(1). - appendNavigationSegment("Products").appendNavigationSegment("Model"). - appendOperationCallSegment("AllOrders"); + appendEntitySetSegment("Categories").appendKeySegment(1). + appendNavigationSegment("Products").appendNavigationSegment("Model"). + appendOperationCallSegment("AllOrders"); assertEquals(new org.apache.http.client.utils.URIBuilder( - SERVICE_ROOT + "/Categories(1)/Products/Model.AllOrders()").build(), uriBuilder.build()); + SERVICE_ROOT + "/Categories(1)/Products/Model.AllOrders()").build(), uriBuilder.build()); } @Test public void ref() throws URISyntaxException { URIBuilder uriBuilder = getClient().newURIBuilder(SERVICE_ROOT). - appendEntitySetSegment("Categories").appendKeySegment(1). - appendNavigationSegment("Products").appendRefSegment(); + appendEntitySetSegment("Categories").appendKeySegment(1). + appendNavigationSegment("Products").appendRefSegment(); assertEquals(new org.apache.http.client.utils.URIBuilder( - SERVICE_ROOT + "/Categories(1)/Products/$ref").build(), uriBuilder.build()); + SERVICE_ROOT + "/Categories(1)/Products/$ref").build(), uriBuilder.build()); uriBuilder = getClient().newURIBuilder(SERVICE_ROOT). - appendEntitySetSegment("Categories").appendKeySegment(1). - appendNavigationSegment("Products").appendRefSegment().id("../../Products(0)"); + appendEntitySetSegment("Categories").appendKeySegment(1). + appendNavigationSegment("Products").appendRefSegment().id("../../Products(0)"); assertEquals(new org.apache.http.client.utils.URIBuilder( - SERVICE_ROOT + "/Categories(1)/Products/$ref").addParameter("$id", "../../Products(0)").build(), - uriBuilder.build()); + SERVICE_ROOT + "/Categories(1)/Products/$ref").addParameter("$id", "../../Products(0)").build(), + uriBuilder.build()); } @Test public void derived() throws URISyntaxException { final URIBuilder uriBuilder = getClient().newURIBuilder(SERVICE_ROOT). - appendEntitySetSegment("Customers").appendDerivedEntityTypeSegment("Model.VipCustomer").appendKeySegment(1); + appendEntitySetSegment("Customers").appendDerivedEntityTypeSegment("Model.VipCustomer").appendKeySegment(1); assertEquals(new org.apache.http.client.utils.URIBuilder( - SERVICE_ROOT + "/Customers/Model.VipCustomer(1)").build(), uriBuilder.build()); + SERVICE_ROOT + "/Customers/Model.VipCustomer(1)").build(), uriBuilder.build()); } @Test public void crossjoin() throws URISyntaxException { final URIBuilder uriBuilder = getClient().newURIBuilder(SERVICE_ROOT). - appendCrossjoinSegment("Products", "Sales"); + appendCrossjoinSegment("Products", "Sales"); assertEquals(new org.apache.http.client.utils.URIBuilder( - SERVICE_ROOT + "/$crossjoin(Products,Sales)").build(), uriBuilder.build()); + SERVICE_ROOT + "/$crossjoin(Products,Sales)").build(), uriBuilder.build()); } @Test @@ -148,13 +149,13 @@ public class URIBuilderTest extends AbstractTest { final URIBuilder uriBuilder = getClient().newURIBuilder(SERVICE_ROOT).appendAllSegment(); assertEquals(new org.apache.http.client.utils.URIBuilder( - SERVICE_ROOT + "/$all").build(), uriBuilder.build()); + SERVICE_ROOT + "/$all").build(), uriBuilder.build()); } @Test public void search() throws URISyntaxException { final URIBuilder uriBuilder = getClient().newURIBuilder(SERVICE_ROOT). - appendEntitySetSegment("Products").search("blue OR green"); + appendEntitySetSegment("Products").search("blue OR green"); assertEquals(new URI("http://host/service/Products?%24search=blue%20OR%20green"), uriBuilder.build()); }
