This is an automated email from the ASF dual-hosted git repository. ramyav pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/olingo-odata2.git
The following commit(s) were added to refs/heads/master by this push: new dc35f3e [OLINGO-1482]Fix buildUri when matrix parameter does not value value dc35f3e is described below commit dc35f3e31d5160c1dfb14777ac6e3ea416c8cd4c Author: ramya vasanth <ramya.vasa...@sap.com> AuthorDate: Thu Sep 24 12:40:11 2020 +0530 [OLINGO-1482]Fix buildUri when matrix parameter does not value value --- .../apache/olingo/odata2/core/servlet/RestUtil.java | 7 ++++--- .../olingo/odata2/core/servlet/RestUtilTest.java | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/RestUtil.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/RestUtil.java index ad76658..8931faa 100644 --- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/RestUtil.java +++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/servlet/RestUtil.java @@ -239,11 +239,12 @@ public class RestUtil { if (!"".equals(ps.getPath()) && ps.getPath().length() > 0) { stringBuilder.append("/").append(ps.getPath()); } - for (final String key : ps.getMatrixParameters().keySet()) { - List<String> matrixParameters = ps.getMatrixParameters().get(key); + Map<String, List<String>> matrixParams = ps.getMatrixParameters(); + for (final String key : matrixParams.keySet()) { + List<String> matrixParameters = matrixParams.get(key); String matrixParameterString = ";" + key + "="; for (String matrixParam : matrixParameters) { - matrixParameterString += Decoder.decode(matrixParam) + ","; + matrixParameterString += (matrixParam.length() > 0) ? (Decoder.decode(matrixParam) + ",") : ""; } stringBuilder.append(matrixParameterString.substring(0, matrixParameterString.length() - 1)); } diff --git a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/servlet/RestUtilTest.java b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/servlet/RestUtilTest.java index 1086c46..b23c6e6 100644 --- a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/servlet/RestUtilTest.java +++ b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/servlet/RestUtilTest.java @@ -19,11 +19,17 @@ package org.apache.olingo.odata2.core.servlet; import junit.framework.Assert; + +import org.apache.olingo.odata2.api.exception.ODataException; +import org.apache.olingo.odata2.api.uri.PathInfo; import org.junit.Test; +import org.mockito.Mockito; import java.util.List; import java.util.Map; +import javax.servlet.http.HttpServletRequest; + public class RestUtilTest { @Test @@ -81,4 +87,16 @@ public class RestUtilTest { Assert.assertEquals("image/webp", result.get(3)); Assert.assertEquals("*/*", result.get(4)); } + + @Test + public void testBuildODataPathInfo() throws ODataException { + HttpServletRequest req = Mockito.mock(HttpServletRequest.class); + Mockito.when(req.getRequestURI()).thenReturn("http://localhost:80/odata/" + + "catalogSrv/odata.svc;v=1;mo/BookCollection?$top=10"); + Mockito.when(req.getServletPath()).thenReturn("/odata"); + Mockito.when(req.getContextPath()).thenReturn(""); + PathInfo pathInfo = RestUtil.buildODataPathInfo(req, 2); + Assert.assertEquals(1, pathInfo.getODataSegments().size()); + Assert.assertEquals(2, pathInfo.getPrecedingSegments().size()); + } } \ No newline at end of file