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 2015/08/07 10:53:09 UTC

olingo-odata4 git commit: [OLINGO-659] Several fixes for issues from static code check

Repository: olingo-odata4
Updated Branches:
  refs/heads/master 15a06522e -> 24668aa2d


[OLINGO-659] Several fixes for issues from static code check


Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/24668aa2
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/24668aa2
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/24668aa2

Branch: refs/heads/master
Commit: 24668aa2db8ede026d6e7af44efca7ab1cd2b773
Parents: 15a0652
Author: Michael Bolz <mi...@sap.com>
Authored: Fri Aug 7 10:48:51 2015 +0200
Committer: Michael Bolz <mi...@sap.com>
Committed: Fri Aug 7 10:48:51 2015 +0200

----------------------------------------------------------------------
 .../server/core/batchhandler/BatchHandler.java  |   2 +-
 .../core/deserializer/batch/BatchBodyPart.java  |   2 +-
 .../deserializer/batch/BatchParserCommon.java   |  15 +-
 .../batch/BatchTransformatorCommon.java         |   5 +-
 .../olingo/server/core/uri/UriInfoImpl.java     |   6 +-
 .../olingo/server/core/uri/parser/Parser.java   |  15 +-
 .../server/core/uri/parser/UriDecoder.java      |  66 ++++++--
 .../core/uri/parser/UriParseTreeVisitor.java    |   8 +-
 .../core/uri/queryoption/ExpandItemImpl.java    |  18 +-
 .../server/core/uri/validator/UriValidator.java |  17 +-
 .../olingo/server/core/uri/RawUriTest.java      | 151 -----------------
 .../server/core/uri/parser/RawUriTest.java      | 166 +++++++++++++++++++
 12 files changed, 266 insertions(+), 205 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/24668aa2/lib/server-core/src/main/java/org/apache/olingo/server/core/batchhandler/BatchHandler.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/batchhandler/BatchHandler.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/batchhandler/BatchHandler.java
index d842c51..18cc69b 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/batchhandler/BatchHandler.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/batchhandler/BatchHandler.java
@@ -57,7 +57,7 @@ public class BatchHandler {
 
   private void validateContentType(final ODataRequest request) throws BatchDeserializerException {
     // This method does validation.
-    BatchParserCommon.getContentType(request.getHeader(HttpHeader.CONTENT_TYPE), ContentType.MULTIPART_MIXED, 0);
+    BatchParserCommon.parseContentType(request.getHeader(HttpHeader.CONTENT_TYPE), ContentType.MULTIPART_MIXED, 0);
   }
 
   private void validateHttpMethod(final ODataRequest request) throws BatchDeserializerException {

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/24668aa2/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchBodyPart.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchBodyPart.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchBodyPart.java
index cf7257a..3642f9a 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchBodyPart.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchBodyPart.java
@@ -113,7 +113,7 @@ public class BatchBodyPart implements BatchPart {
 
   private boolean isContentTypeMultiPartMixed(final String contentType) {
     try {
-      BatchParserCommon.getContentType(contentType, ContentType.MULTIPART_MIXED, 0);
+      BatchParserCommon.parseContentType(contentType, ContentType.MULTIPART_MIXED, 0);
       return true;
     } catch (final BatchDeserializerException e) {
       return false;

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/24668aa2/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchParserCommon.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchParserCommon.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchParserCommon.java
index ce8eb35..c826bd3 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchParserCommon.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchParserCommon.java
@@ -44,7 +44,7 @@ public class BatchParserCommon {
   public static final String BINARY_ENCODING = "binary";
 
   public static String getBoundary(final String contentType, final int line) throws BatchDeserializerException {
-    final ContentType type = getContentType(contentType, ContentType.MULTIPART_MIXED, line);
+    final ContentType type = parseContentType(contentType, ContentType.MULTIPART_MIXED, line);
     final Map<String, String> parameters = type.getParameters();
     for (final Map.Entry<String, String> entries : parameters.entrySet()) {
       if (BOUNDARY.equalsIgnoreCase(entries.getKey())) {
@@ -61,7 +61,18 @@ public class BatchParserCommon {
         BatchDeserializerException.MessageKeys.MISSING_BOUNDARY_DELIMITER, Integer.toString(line));
   }
 
-  public static ContentType getContentType(final String contentType, final ContentType expected, final int line)
+  /**
+   * Get the content type based on <code>contentType</code> parameter.
+   * If this content type is not compatible to the expected ContentType a
+   * BatchDeserializerException is thrown.
+   *
+   * @param contentType content type string which is parsed
+   * @param expected content type to which the parsed must be compatible
+   * @param line parsed line
+   * @return the parsed content type or if not compatible or parseable an exception is thrown (never returns null)
+   * @throws BatchDeserializerException
+   */
+  public static ContentType parseContentType(final String contentType, final ContentType expected, final int line)
       throws BatchDeserializerException {
     ContentType type;
     try {

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/24668aa2/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchTransformatorCommon.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchTransformatorCommon.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchTransformatorCommon.java
index 5c379e0..5757643 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchTransformatorCommon.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/batch/BatchTransformatorCommon.java
@@ -35,10 +35,7 @@ public class BatchTransformatorCommon {
       throw new BatchDeserializerException("Missing content type", MessageKeys.MISSING_CONTENT_TYPE,
           Integer.toString(headers.getLineNumber()));
     }
-    if (BatchParserCommon.getContentType(contentTypes.get(0), expected, headers.getLineNumber()) == null) {
-      throw new BatchDeserializerException("Invalid content type", MessageKeys.INVALID_CONTENT_TYPE,
-          expected.toContentTypeString());
-    }
+    BatchParserCommon.parseContentType(contentTypes.get(0), expected, headers.getLineNumber());
   }
 
   public static void validateContentTransferEncoding(final Header headers) throws BatchDeserializerException {

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/24668aa2/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriInfoImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriInfoImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriInfoImpl.java
index ae46328..525da75 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriInfoImpl.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/UriInfoImpl.java
@@ -227,14 +227,14 @@ public class UriInfoImpl implements UriInfo {
       if (item instanceof SystemQueryOptionImpl) {
         setSystemQueryOption((SystemQueryOptionImpl) item);
       } else if (item instanceof CustomQueryOptionImpl) {
-        addCustomQueryOption(item);
+        addCustomQueryOption((CustomQueryOptionImpl) item);
       }
     }
     return this;
   }
 
-  public void addCustomQueryOption(final QueryOptionImpl item) {
-    customQueryOptions.add((CustomQueryOptionImpl) item);
+  public void addCustomQueryOption(final CustomQueryOptionImpl item) {
+    customQueryOptions.add(item);
     if (item.getName().startsWith("@")) {
       aliasToValue.put(item.getName(), item.getText());
     }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/24668aa2/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/Parser.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/Parser.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/Parser.java
index f764c53..135ba56 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/Parser.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/Parser.java
@@ -465,22 +465,23 @@ public class Parser {
     boolean first = true;
     System.out.println("input: " + input);
     String nL = "\n";
-    String out = "[" + nL;
+    StringBuilder out = new StringBuilder("[").append(nL);
     for (Token token : list) {
       if (!first) {
-        out += ",";
+        out.append(",");
         first = false;
       }
       int index = token.getType();
+      out.append("\"").append(token.getText()).append("\"").append("     ");
       if (index != -1) {
-        out += "\"" + token.getText() + "\"" + "     " + UriLexer.tokenNames[index] + nL;
+        out.append(UriLexer.tokenNames[index]);
       } else {
-        out += "\"" + token.getText() + "\"" + "     " + index + nL;
+        out.append(index);
       }
+        out.append(nL);
     }
-    out += ']';
-    System.out.println("tokens: " + out);
-    return;
+    out.append(']');
+    System.out.println("tokens: " + out.toString());
   }
 
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/24668aa2/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriDecoder.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriDecoder.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriDecoder.java
index 5918b6f..c49b98f 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriDecoder.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriDecoder.java
@@ -59,15 +59,13 @@ public class UriDecoder {
 
   private static List<RawUri.QueryOption> splitOptions(final String queryOptionString) {
     if (queryOptionString == null) {
-      return Collections.<RawUri.QueryOption> emptyList();
+      return Collections.emptyList();
     }
 
     List<RawUri.QueryOption> queryOptionList = new ArrayList<RawUri.QueryOption>();
-    for (String option : split(queryOptionString, '&')) {
-      if (option.length() != 0) {
-        final List<String> pair = splitFirst(option, '=');
-        queryOptionList.add(new RawUri.QueryOption(pair.get(0), pair.get(1)));
-      }
+    for (String option : splitSkipEmpty(queryOptionString, '&')) {
+      final List<String> pair = splitFirst(option, '=');
+      queryOptionList.add(new RawUri.QueryOption(pair.get(0), pair.get(1)));
     }
     return queryOptionList;
   }
@@ -82,29 +80,67 @@ public class UriDecoder {
   }
 
   private static List<String> splitPath(final String path, final int skipSegments) {
-    List<String> list = split(path, '/');
+    List<String> list = splitSkipEmpty(path, '/');
+
+    return skipSegments > 0 ? list.subList(skipSegments, list.size()) : list;
+  }
+
+  static List<String> split(final String input, final char c) {
+    return split(input, c, false);
+  }
 
-    // Empty path segments of the resource path are removed.
-    while (list.remove("")) {
-      // this place intentionally left blank
+  static List<String> splitSkipEmpty(final String input, final char c) {
+    if(input.isEmpty() || input.length() == 1 && input.charAt(0) == c) {
+      return Collections.emptyList();
     }
 
-    return skipSegments > 0 ? list.subList(skipSegments, list.size()) : list;
+    List<String> list = new LinkedList<String>();
+
+    int start = 0;
+    int end;
+
+    while ((end = input.indexOf(c, start)) >= 0) {
+      if(start != end) {
+        list.add(input.substring(start, end));
+      }
+      start = end + 1;
+    }
+
+    if(input.charAt(input.length()-1) != c) {
+      list.add(input.substring(start));
+    }
+
+    return list;
   }
 
-  public static List<String> split(final String input, final char c) {
+  static List<String> split(final String input, final char c, boolean skipEmpty) {
+    if(skipEmpty && (input.isEmpty() || input.length() == 1 && input.charAt(0) == c)) {
+      return Collections.emptyList();
+    }
 
     List<String> list = new LinkedList<String>();
 
     int start = 0;
-    int end = -1;
+    int end;
 
     while ((end = input.indexOf(c, start)) >= 0) {
-      list.add(input.substring(start, end));
+      if(skipEmpty) {
+        if(start != end) {
+          list.add(input.substring(start, end));
+        }
+      } else {
+        list.add(input.substring(start, end));
+      }
       start = end + 1;
     }
 
-    list.add(input.substring(start));
+    if(skipEmpty) {
+      if(input.charAt(input.length()-1) != c) {
+        list.add(input.substring(start));
+      }
+    } else {
+      list.add(input.substring(start));
+    }
 
     return list;
   }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/24668aa2/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParseTreeVisitor.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParseTreeVisitor.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParseTreeVisitor.java
index dcccf7c..2ed6d19 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParseTreeVisitor.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParseTreeVisitor.java
@@ -360,13 +360,13 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
         // get function from function import
         EdmFunction function = edmFunctionImport.getUnboundFunction(names);
         if (function == null) {
-          String tmp = "";
+          StringBuilder tmp = new StringBuilder();
           for (String name : names) {
-            tmp += (tmp.length() != 0 ? "," : "") + name;
+            tmp.append((tmp.length() != 0 ? "," : "")).append(name);
           }
           throw wrap(new UriParserSemanticException("Function of functionimport '" + edmFunctionImport.getName()
-              + "' with parameters [" + tmp + "] not found",
-              UriParserSemanticException.MessageKeys.FUNCTION_NOT_FOUND, edmFunctionImport.getName(), tmp));
+              + "' with parameters [" + tmp.toString() + "] not found",
+              UriParserSemanticException.MessageKeys.FUNCTION_NOT_FOUND, edmFunctionImport.getName(), tmp.toString()));
         }
 
         uriResource.setFunction(edmFunctionImport.getUnboundFunction(names));

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/24668aa2/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/queryoption/ExpandItemImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/queryoption/ExpandItemImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/queryoption/ExpandItemImpl.java
index 12985ee..aa20845 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/queryoption/ExpandItemImpl.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/queryoption/ExpandItemImpl.java
@@ -54,23 +54,23 @@ public class ExpandItemImpl implements ExpandItem {
 
   public ExpandItemImpl setSystemQueryOption(final SystemQueryOptionImpl sysItem) {
 
-    if (sysItem.getKind() == SystemQueryOptionKind.EXPAND) {
+    if (sysItem instanceof ExpandOptionImpl) {
       expandOption = (ExpandOptionImpl) sysItem;
-    } else if (sysItem.getKind() == SystemQueryOptionKind.FILTER) {
+    } else if (sysItem instanceof FilterOptionImpl) {
       filterOption = (FilterOptionImpl) sysItem;
-    } else if (sysItem.getKind() == SystemQueryOptionKind.COUNT) {
+    } else if (sysItem instanceof CountOptionImpl) {
       inlineCountOption = (CountOptionImpl) sysItem;
-    } else if (sysItem.getKind() == SystemQueryOptionKind.ORDERBY) {
+    } else if (sysItem instanceof OrderByOptionImpl) {
       orderByOption = (OrderByOptionImpl) sysItem;
-    } else if (sysItem.getKind() == SystemQueryOptionKind.SEARCH) {
+    } else if (sysItem instanceof SearchOptionImpl) {
       searchOption = (SearchOptionImpl) sysItem;
-    } else if (sysItem.getKind() == SystemQueryOptionKind.SELECT) {
+    } else if (sysItem instanceof SelectOptionImpl) {
       selectOption = (SelectOptionImpl) sysItem;
-    } else if (sysItem.getKind() == SystemQueryOptionKind.SKIP) {
+    } else if (sysItem instanceof SkipOptionImpl) {
       skipOption = (SkipOptionImpl) sysItem;
-    } else if (sysItem.getKind() == SystemQueryOptionKind.TOP) {
+    } else if (sysItem instanceof TopOptionImpl) {
       topOption = (TopOptionImpl) sysItem;
-    } else if (sysItem.getKind() == SystemQueryOptionKind.LEVELS) {
+    } else if (sysItem instanceof LevelsExpandOption) {
       levelsExpandOption = (LevelsExpandOption) sysItem;
     }
     return this;

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/24668aa2/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 fbd010a..e1d9638 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
@@ -502,22 +502,22 @@ public class UriValidator {
   private void validateNoQueryOptionsForHttpMethod(final UriInfo uriInfo, final HttpMethod httpMethod)
       throws UriValidationException {
     if (!uriInfo.getSystemQueryOptions().isEmpty()) {
-      String options = "";
+      StringBuilder options = new StringBuilder();
       for (SystemQueryOption option : uriInfo.getSystemQueryOptions()) {
-        options = options + option.getName() + " ";
+        options.append(option.getName()).append(" ");
       }
-      throw new UriValidationException("System query option " + options + " not allowed for method "
+      throw new UriValidationException("System query option " + options.toString() + " not allowed for method "
           + httpMethod, UriValidationException.MessageKeys.SYSTEM_QUERY_OPTION_NOT_ALLOWED_FOR_HTTP_METHOD,
-          options, httpMethod.toString());
+          options.toString(), httpMethod.toString());
     }
   }
 
   private boolean isAction(final UriInfo uriInfo) {
     List<UriResource> uriResourceParts = uriInfo.getUriResourceParts();
-    if (!uriResourceParts.isEmpty()) {
-      return UriResourceKind.action == uriResourceParts.get(uriResourceParts.size() - 1).getKind();
+    if (uriResourceParts.isEmpty()) {
+      return false;
     }
-    return false;
+    return UriResourceKind.action == uriResourceParts.get(uriResourceParts.size() - 1).getKind();
   }
 
   private void validateKeyPredicates(final UriInfo uriInfo) throws UriValidationException {
@@ -586,7 +586,8 @@ public class UriValidator {
     if (last != null
         && (last.getKind() == UriResourceKind.primitiveProperty
             || last.getKind() == UriResourceKind.complexProperty
-            || last.getKind() == UriResourceKind.value && previous.getKind() == UriResourceKind.primitiveProperty)) {
+            || (last.getKind() == UriResourceKind.value
+                          && previous != null && previous.getKind() == UriResourceKind.primitiveProperty))) {
       final EdmProperty property = ((UriResourceProperty)
           (last.getKind() == UriResourceKind.value ? previous : last)).getProperty();
       if (method == HttpMethod.PATCH && property.isCollection()) {

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/24668aa2/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/RawUriTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/RawUriTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/RawUriTest.java
deleted file mode 100644
index 8945376..0000000
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/RawUriTest.java
+++ /dev/null
@@ -1,151 +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.core.uri;
-
-import static org.junit.Assert.assertEquals;
-
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-
-import org.apache.olingo.server.core.uri.parser.RawUri;
-import org.apache.olingo.server.core.uri.parser.UriDecoder;
-import org.apache.olingo.server.core.uri.parser.UriParserSyntaxException;
-import org.junit.Test;
-
-public class RawUriTest {
-
-  private RawUri runRawParser(final String path, final String query, final int skipSegments)
-      throws UriParserSyntaxException {
-    return UriDecoder.decodeUri(path, query, null, skipSegments);
-  }
-
-  @Test
-  public void testOption() throws Exception {
-    RawUri rawUri;
-    rawUri = runRawParser("", "", 0);
-    checkOptionCount(rawUri, 0);
-
-    rawUri = runRawParser("", "a", 0);
-    checkOption(rawUri, 0, "a", "");
-
-    rawUri = runRawParser("", "a=b", 0);
-    checkOption(rawUri, 0, "a", "b");
-
-    rawUri = runRawParser("", "=", 0);
-    checkOption(rawUri, 0, "", "");
-
-    rawUri = runRawParser("", "=b", 0);
-    checkOption(rawUri, 0, "", "b");
-
-    rawUri = runRawParser("", "a&c", 0);
-    checkOption(rawUri, 0, "a", "");
-    checkOption(rawUri, 1, "c", "");
-
-    rawUri = runRawParser("", "a=b&c", 0);
-    checkOption(rawUri, 0, "a", "b");
-    checkOption(rawUri, 1, "c", "");
-
-    rawUri = runRawParser("", "a=b&c=d", 0);
-    checkOption(rawUri, 0, "a", "b");
-    checkOption(rawUri, 1, "c", "d");
-
-    rawUri = runRawParser("", "=&=", 0);
-    checkOption(rawUri, 0, "", "");
-    checkOption(rawUri, 1, "", "");
-
-    rawUri = runRawParser("", "=&c=d", 0);
-    checkOption(rawUri, 0, "", "");
-    checkOption(rawUri, 1, "c", "d");
-  }
-
-  private void checkOption(final RawUri rawUri, final int index, final String name, final String value) {
-    RawUri.QueryOption option = rawUri.queryOptionListDecoded.get(index);
-
-    assertEquals(name, option.name);
-    assertEquals(value, option.value);
-  }
-
-  private void checkOptionCount(final RawUri rawUri, final int count) {
-    assertEquals(count, rawUri.queryOptionListDecoded.size());
-  }
-
-  @Test
-  public void testPath() throws Exception {
-    RawUri rawUri;
-
-    rawUri = runRawParser("", null, 0);
-    checkPath(rawUri, "", Collections.<String> emptyList());
-
-    rawUri = runRawParser("/", null, 0);
-    checkPath(rawUri, "/", Collections.<String> emptyList());
-
-    rawUri = runRawParser("/entitySet", null, 0);
-    checkPath(rawUri, "/entitySet", Arrays.asList("entitySet"));
-
-    rawUri = runRawParser("//entitySet", null, 0);
-    checkPath(rawUri, "//entitySet", Arrays.asList("entitySet"));
-
-    rawUri = runRawParser("entitySet", null, 0);
-    checkPath(rawUri, "entitySet", Arrays.asList("entitySet"));
-
-    rawUri = runRawParser("/nonServiceSegment/entitySet", null, 0);
-    checkPath(rawUri, "/nonServiceSegment/entitySet", Arrays.asList("nonServiceSegment", "entitySet"));
-
-    rawUri = runRawParser("/nonServiceSegment/entitySet", null, 1);
-    checkPath(rawUri, "/nonServiceSegment/entitySet", Arrays.asList("entitySet"));
-
-    rawUri = runRawParser("nonServiceSegment/entitySet", null, 0);
-    checkPath(rawUri, "nonServiceSegment/entitySet", Arrays.asList("nonServiceSegment", "entitySet"));
-
-    rawUri = runRawParser("nonServiceSegment/entitySet", null, 1);
-    checkPath(rawUri, "nonServiceSegment/entitySet", Arrays.asList("entitySet"));
-
-    rawUri = runRawParser("non//Service/Segment///entitySet/", null, 3);
-    checkPath(rawUri, "non//Service/Segment///entitySet/", Arrays.asList("entitySet"));
-
-    rawUri = runRawParser("/a", "abc=xx+yz", 0);
-    checkPath(rawUri, "/a", Arrays.asList("a"));
-  }
-
-  @Test
-  public void testSplit() {
-    UriDecoder.split("", '/');
-    UriDecoder.split("/", '/');
-    UriDecoder.split("a", '/');
-    UriDecoder.split("a/", '/');
-    UriDecoder.split("/a", '/');
-    UriDecoder.split("a/a", '/');
-  }
-
-  private void checkPath(final RawUri rawUri, final String path, final List<String> list) {
-    assertEquals(path, rawUri.path);
-
-    assertEquals(list.size(), rawUri.pathSegmentListDecoded.size());
-
-    for (int i = 0; i < list.size(); i++) {
-      assertEquals(list.get(i), rawUri.pathSegmentListDecoded.get(i));
-    }
-  }
-
-  @Test(expected = UriParserSyntaxException.class)
-  public void wrongPercentEncoding() throws Exception {
-    runRawParser("%wrong", null, 0);
-  }
-}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/24668aa2/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/parser/RawUriTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/parser/RawUriTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/parser/RawUriTest.java
new file mode 100644
index 0000000..927a37a
--- /dev/null
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/parser/RawUriTest.java
@@ -0,0 +1,166 @@
+/*
+ * 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.core.uri.parser;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import org.junit.Test;
+
+public class RawUriTest {
+
+  private RawUri runRawParser(final String path, final String query, final int skipSegments)
+      throws UriParserSyntaxException {
+    return UriDecoder.decodeUri(path, query, null, skipSegments);
+  }
+
+  @Test
+  public void testOption() throws Exception {
+    RawUri rawUri;
+    rawUri = runRawParser("", "", 0);
+    checkOptionCount(rawUri, 0);
+
+    rawUri = runRawParser("", "a", 0);
+    checkOption(rawUri, 0, "a", "");
+
+    rawUri = runRawParser("", "a=b", 0);
+    checkOption(rawUri, 0, "a", "b");
+
+    rawUri = runRawParser("", "=", 0);
+    checkOption(rawUri, 0, "", "");
+
+    rawUri = runRawParser("", "=b", 0);
+    checkOption(rawUri, 0, "", "b");
+
+    rawUri = runRawParser("", "a&c", 0);
+    checkOption(rawUri, 0, "a", "");
+    checkOption(rawUri, 1, "c", "");
+
+    rawUri = runRawParser("", "a=b&c", 0);
+    checkOption(rawUri, 0, "a", "b");
+    checkOption(rawUri, 1, "c", "");
+
+    rawUri = runRawParser("", "a=b&c=d", 0);
+    checkOption(rawUri, 0, "a", "b");
+    checkOption(rawUri, 1, "c", "d");
+
+    rawUri = runRawParser("", "=&=", 0);
+    checkOption(rawUri, 0, "", "");
+    checkOption(rawUri, 1, "", "");
+
+    rawUri = runRawParser("", "=&c=d", 0);
+    checkOption(rawUri, 0, "", "");
+    checkOption(rawUri, 1, "c", "d");
+  }
+
+  private void checkOption(final RawUri rawUri, final int index, final String name, final String value) {
+    RawUri.QueryOption option = rawUri.queryOptionListDecoded.get(index);
+
+    assertEquals(name, option.name);
+    assertEquals(value, option.value);
+  }
+
+  private void checkOptionCount(final RawUri rawUri, final int count) {
+    assertEquals(count, rawUri.queryOptionListDecoded.size());
+  }
+
+  @Test
+  public void testPath() throws Exception {
+    RawUri rawUri;
+
+    rawUri = runRawParser("", null, 0);
+    checkPath(rawUri, "", Collections.<String> emptyList());
+
+    rawUri = runRawParser("/", null, 0);
+    checkPath(rawUri, "/", Collections.<String> emptyList());
+
+    rawUri = runRawParser("/entitySet", null, 0);
+    checkPath(rawUri, "/entitySet", Arrays.asList("entitySet"));
+
+    rawUri = runRawParser("//entitySet", null, 0);
+    checkPath(rawUri, "//entitySet", Arrays.asList("entitySet"));
+
+    rawUri = runRawParser("entitySet", null, 0);
+    checkPath(rawUri, "entitySet", Arrays.asList("entitySet"));
+
+    rawUri = runRawParser("/nonServiceSegment/entitySet", null, 0);
+    checkPath(rawUri, "/nonServiceSegment/entitySet", Arrays.asList("nonServiceSegment", "entitySet"));
+
+    rawUri = runRawParser("/nonServiceSegment/entitySet", null, 1);
+    checkPath(rawUri, "/nonServiceSegment/entitySet", Arrays.asList("entitySet"));
+
+    rawUri = runRawParser("nonServiceSegment/entitySet", null, 0);
+    checkPath(rawUri, "nonServiceSegment/entitySet", Arrays.asList("nonServiceSegment", "entitySet"));
+
+    rawUri = runRawParser("nonServiceSegment/entitySet", null, 1);
+    checkPath(rawUri, "nonServiceSegment/entitySet", Arrays.asList("entitySet"));
+
+    rawUri = runRawParser("non//Service/Segment///entitySet/", null, 3);
+    checkPath(rawUri, "non//Service/Segment///entitySet/", Arrays.asList("entitySet"));
+
+    rawUri = runRawParser("/a", "abc=xx+yz", 0);
+    checkPath(rawUri, "/a", Arrays.asList("a"));
+  }
+
+  @Test
+  public void testSplit() {
+    assertEquals(Arrays.asList(""), UriDecoder.split("", '/'));
+    assertEquals(Arrays.asList("", ""), UriDecoder.split("/", '/'));
+    assertEquals(Arrays.asList("a"), UriDecoder.split("a", '/'));
+    assertEquals(Arrays.asList("a", ""), UriDecoder.split("a/", '/'));
+    assertEquals(Arrays.asList("", "a"), UriDecoder.split("/a", '/'));
+    assertEquals(Arrays.asList("a", "a"), UriDecoder.split("a/a", '/'));
+    assertEquals(Arrays.asList("", "a", "a"), UriDecoder.split("/a/a", '/'));
+    // with skip
+    assertTrue(UriDecoder.split("", '/', true).isEmpty());
+    assertTrue(UriDecoder.split("/", '/', true).isEmpty());
+    assertEquals(Arrays.asList("a"), UriDecoder.split("a", '/', true));
+    assertEquals(Arrays.asList("a"), UriDecoder.split("a/", '/', true));
+    assertEquals(Arrays.asList("a"), UriDecoder.split("/a", '/', true));
+    assertEquals(Arrays.asList("a", "a"), UriDecoder.split("a/a", '/', true));
+    assertEquals(Arrays.asList("a", "a"), UriDecoder.split("/a/a", '/', true));
+    // with skip
+    assertTrue(UriDecoder.splitSkipEmpty("", '/').isEmpty());
+    assertTrue(UriDecoder.splitSkipEmpty("/", '/').isEmpty());
+    assertEquals(Arrays.asList("a"), UriDecoder.splitSkipEmpty("a", '/'));
+    assertEquals(Arrays.asList("a"), UriDecoder.splitSkipEmpty("a/", '/'));
+    assertEquals(Arrays.asList("a"), UriDecoder.splitSkipEmpty("/a", '/'));
+    assertEquals(Arrays.asList("a", "a"), UriDecoder.splitSkipEmpty("a/a", '/'));
+    assertEquals(Arrays.asList("a", "a"), UriDecoder.splitSkipEmpty("/a/a", '/'));
+  }
+
+  private void checkPath(final RawUri rawUri, final String path, final List<String> list) {
+    assertEquals(path, rawUri.path);
+
+    assertEquals(list.size(), rawUri.pathSegmentListDecoded.size());
+
+    for (int i = 0; i < list.size(); i++) {
+      assertEquals(list.get(i), rawUri.pathSegmentListDecoded.get(i));
+    }
+  }
+
+  @Test(expected = UriParserSyntaxException.class)
+  public void wrongPercentEncoding() throws Exception {
+    runRawParser("%wrong", null, 0);
+  }
+}