Repository: olingo-odata2
Updated Branches:
  refs/heads/master fcf813717 -> 6c321d04b


[OLINGO-637] Added 'createPathSegment' to 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/c9524569
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata2/tree/c9524569
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata2/diff/c9524569

Branch: refs/heads/master
Commit: c9524569ea269c7b84e650e25dbf7b8ce1626700
Parents: fcf8137
Author: Michael Bolz <[email protected]>
Authored: Thu Apr 23 10:08:34 2015 +0200
Committer: Michael Bolz <[email protected]>
Committed: Thu Apr 30 15:33:07 2015 +0200

----------------------------------------------------------------------
 .../apache/olingo/odata2/api/uri/UriParser.java | 19 ++++++++++
 .../olingo/odata2/core/uri/UriParserImpl.java   |  6 ++++
 .../olingo/odata2/core/uri/UriParserTest.java   | 38 ++++++++++++++------
 3 files changed, 52 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/c9524569/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/uri/UriParser.java
----------------------------------------------------------------------
diff --git 
a/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/uri/UriParser.java
 
b/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/uri/UriParser.java
index 4032306..5447bc4 100644
--- 
a/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/uri/UriParser.java
+++ 
b/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/uri/UriParser.java
@@ -206,6 +206,25 @@ public abstract class UriParser {
       List<ArrayList<NavigationPropertySegment>> expand) throws EdmException;
 
   /**
+   * Creates an path segment object.
+   * @param path path of created path segment
+   * @param matrixParameters Map of Lists of matrix parameters for this path 
segemt
+   * @return create path segment
+   */
+  protected abstract PathSegment buildPathSegment(String path, Map<String, 
List<String>> matrixParameters);
+
+
+  /**
+   * Creates an path segment object.
+   * @param path path of created path segment
+   * @param matrixParameters Map of Lists of matrix parameters for this path 
segemt
+   * @return create path segment
+   */
+  public static PathSegment createPathSegment(String path, Map<String, 
List<String>> matrixParameters) {
+    return RuntimeDelegate.getUriParser(null).buildPathSegment(path, 
matrixParameters);
+  }
+
+  /**
    * <p>Retrieves the key predicates from a canonical link to an entity.</p>
    * <p>A canonical link to an entity must follow the pattern
    * <code>[&lt;service 
root&gt;][&lt;entityContainer&gt;.]&lt;entitySet&gt;(&lt;key&gt;)</code>, i.e.,

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/c9524569/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 162ca8d..61f73dc 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
@@ -62,6 +62,7 @@ import org.apache.olingo.odata2.api.uri.UriSyntaxException;
 import org.apache.olingo.odata2.api.uri.expression.ExpressionParserException;
 import org.apache.olingo.odata2.api.uri.expression.FilterExpression;
 import org.apache.olingo.odata2.api.uri.expression.OrderByExpression;
+import org.apache.olingo.odata2.core.ODataPathSegmentImpl;
 import org.apache.olingo.odata2.core.commons.Decoder;
 import org.apache.olingo.odata2.core.edm.EdmSimpleTypeFacadeImpl;
 import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
@@ -894,6 +895,11 @@ public class UriParserImpl extends UriParser {
   }
 
   @Override
+  protected PathSegment buildPathSegment(String path, Map<String, 
List<String>> matrixParameters) {
+    return new ODataPathSegmentImpl(path, matrixParameters);
+  }
+
+  @Override
   public List<KeyPredicate> getKeyFromEntityLink(final EdmEntitySet entitySet, 
final String entityLink,
       final URI serviceRoot) throws ODataException {
     final String relativeLink = serviceRoot == null ? entityLink :

http://git-wip-us.apache.org/repos/asf/olingo-odata2/blob/c9524569/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 64b88bd..e628fc3 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
@@ -48,8 +48,8 @@ import org.apache.olingo.odata2.api.uri.KeyPredicate;
 import org.apache.olingo.odata2.api.uri.PathSegment;
 import org.apache.olingo.odata2.api.uri.UriInfo;
 import org.apache.olingo.odata2.api.uri.UriNotMatchingException;
+import org.apache.olingo.odata2.api.uri.UriParser;
 import org.apache.olingo.odata2.api.uri.UriSyntaxException;
-import org.apache.olingo.odata2.core.ODataPathSegmentImpl;
 import org.apache.olingo.odata2.testutil.fit.BaseTest;
 import org.apache.olingo.odata2.testutil.mock.MockFacade;
 import org.junit.Before;
@@ -64,7 +64,7 @@ public class UriParserTest extends BaseTest {
   private Edm edm;
 
   @Before
-  public void getEdm() throws ODataException, EdmException {
+  public void getEdm() throws ODataException {
     edm = MockFacade.getMockEdm();
   }
 
@@ -124,7 +124,7 @@ public class UriParserTest extends BaseTest {
   @Test
   public void copyPathSegmentsTest() throws Exception {
     List<PathSegment> pathSegments = new ArrayList<PathSegment>();
-    pathSegments.add(new ODataPathSegmentImpl("$metadata", null));
+    pathSegments.add(UriParser.createPathSegment("$metadata", null));
     UriInfo result = new UriParserImpl(edm).parse(pathSegments, 
Collections.<String, String> emptyMap());
     assertNotNull(result);
     assertEquals(1, pathSegments.size());
@@ -134,8 +134,8 @@ public class UriParserTest extends BaseTest {
   @Test
   public void copyPathSegmentsTestEncoded() throws Exception {
     List<PathSegment> pathSegments = new ArrayList<PathSegment>();
-    pathSegments.add(new ODataPathSegmentImpl("%24metadata", null));
-    UriInfoImpl result = (UriInfoImpl) new 
UriParserImpl(edm).parse(pathSegments, 
+    pathSegments.add(UriParser.createPathSegment("%24metadata", null));
+    UriInfoImpl result = (UriInfoImpl) new 
UriParserImpl(edm).parse(pathSegments,
         Collections.<String, String> emptyMap());
     assertNotNull(result);
     assertEquals(UriType.URI8, result.getUriType());
@@ -951,8 +951,8 @@ public class UriParserTest extends BaseTest {
     assertEquals("EmployeeName", 
result.getSelect().get(0).getProperty().getName());
     assertEquals("Location", 
result.getSelect().get(1).getProperty().getName());
     assertEquals(1, 
result.getSelect().get(0).getNavigationPropertySegments().size());
-    assertEquals("Employees", 
result.getSelect().get(0).getNavigationPropertySegments().get(0).getTargetEntitySet()
-        .getName());
+    assertEquals("Employees",
+        
result.getSelect().get(0).getNavigationPropertySegments().get(0).getTargetEntitySet().getName());
   }
 
   @Test
@@ -980,8 +980,8 @@ public class UriParserTest extends BaseTest {
     assertEquals(1, result.getExpand().size());
     assertEquals(1, result.getExpand().get(0).size());
     assertEquals("Employees", 
result.getExpand().get(0).get(0).getTargetEntitySet().getName());
-    
assertEquals(result.getTargetEntitySet().getEntityType().getProperty("nm_Employees"),
 result.getExpand().get(0)
-        .get(0).getNavigationProperty());
+    
assertEquals(result.getTargetEntitySet().getEntityType().getProperty("nm_Employees"),
+        result.getExpand().get(0).get(0).getNavigationProperty());
     
     result = parse("Managers('1')?%24expand=nm_Employees");
     assertEquals("Managers", result.getTargetEntitySet().getName());
@@ -989,8 +989,8 @@ public class UriParserTest extends BaseTest {
     assertEquals(1, result.getExpand().size());
     assertEquals(1, result.getExpand().get(0).size());
     assertEquals("Employees", 
result.getExpand().get(0).get(0).getTargetEntitySet().getName());
-    
assertEquals(result.getTargetEntitySet().getEntityType().getProperty("nm_Employees"),
 result.getExpand().get(0)
-        .get(0).getNavigationProperty());
+    
assertEquals(result.getTargetEntitySet().getEntityType().getProperty("nm_Employees"),
+        result.getExpand().get(0).get(0).getNavigationProperty());
   }
 
   @Test
@@ -1057,4 +1057,20 @@ public class UriParserTest extends BaseTest {
     wrongGetKey(entitySet2, "anotherContainer.Photos(Id=12,Type='test')", null,
         UriNotMatchingException.CONTAINERNOTFOUND);
   }
+
+  @Test
+  public void createPathSegment() {
+    PathSegment segment = UriParser.createPathSegment("simple", null);
+    assertEquals("simple", segment.getPath());
+    assertTrue(segment.getMatrixParameters().isEmpty());
+
+    Map<String, List<String>> matrixParameter = new HashMap<String, 
List<String>>();
+    matrixParameter.put("parameter1", Arrays.asList("one", "two"));
+    PathSegment segmentWithMatrix = UriParser.createPathSegment("matrix", 
matrixParameter);
+    assertEquals("matrix", segmentWithMatrix.getPath());
+    assertEquals(1, segmentWithMatrix.getMatrixParameters().size());
+    assertEquals(2, 
segmentWithMatrix.getMatrixParameters().get("parameter1").size());
+    
assertTrue(segmentWithMatrix.getMatrixParameters().get("parameter1").contains("one"));
+    
assertTrue(segmentWithMatrix.getMatrixParameters().get("parameter1").contains("two"));
+  }
 }

Reply via email to