You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by ch...@apache.org on 2015/07/29 11:55:26 UTC

olingo-odata4 git commit: [OLINGO-731] Added tests

Repository: olingo-odata4
Updated Branches:
  refs/heads/master b146a403b -> 57a11aff6


[OLINGO-731] Added tests


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

Branch: refs/heads/master
Commit: 57a11aff6b1658e66424290423a4cadb104661f5
Parents: b146a40
Author: Christian Amend <ch...@sap.com>
Authored: Tue Jul 28 15:35:50 2015 +0200
Committer: Christian Amend <ch...@sap.com>
Committed: Tue Jul 28 15:47:23 2015 +0200

----------------------------------------------------------------------
 .../apache/olingo/server/core/ODataHandler.java |  16 +-
 .../core/debug/DebugResponseHelperImpl.java     |  15 +-
 .../olingo/server/core/debug/DebugTabBody.java  |  19 ++-
 .../server/core/debug/DebugTabRequest.java      |  99 +++++++-----
 .../server/core/debug/DebugTabResponse.java     |  20 ++-
 .../server/core/debug/DebugTabServer.java       |  10 +-
 .../server/core/debug/ServerCoreDebugger.java   |   7 +-
 .../serializer/BatchResponseSerializer.java     |   1 -
 .../server/core/debug/AbstractDebugTabTest.java |  58 +++++++
 .../server/core/debug/DebugTabBodyTest.java     |  37 +++++
 .../server/core/debug/DebugTabRequestTest.java  | 155 +++++++++++++++++++
 .../server/core/debug/DebugTabResponseTest.java |  79 ++++++++++
 .../server/core/debug/DebugTabServerTest.java   |  84 ++++++++++
 .../core/debug/ServerCoreDebuggerTest.java      | 121 +++++++++++++++
 14 files changed, 651 insertions(+), 70 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/57a11aff/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandler.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandler.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandler.java
index 1d1b270..bfbc5ac 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandler.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataHandler.java
@@ -74,10 +74,9 @@ public class ODataHandler {
 
   public ODataResponse process(final ODataRequest request) {
     ODataResponse response = new ODataResponse();
+    int measurementHandel = debugger.startRuntimeMeasurement("ODataHandler", "processInternal");
     try {
-
       processInternal(request, response);
-
     } catch (final UriValidationException e) {
       ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e, null);
       handleException(request, response, serverError, e);
@@ -112,6 +111,7 @@ public class ODataHandler {
       ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e);
       handleException(request, response, serverError, e);
     }
+    debugger.stopRuntimeMeasurement(measurementHandel);
     return response;
   }
 
@@ -119,13 +119,19 @@ public class ODataHandler {
       throws ODataApplicationException, ODataLibraryException {
     validateODataVersion(request, response);
 
+    int measurementUriParser = debugger.startRuntimeMeasurement("UriParser", "parseUri");
     uriInfo = new Parser().parseUri(request.getRawODataPath(), request.getRawQueryPath(), null,
         serviceMetadata.getEdm());
+    debugger.stopRuntimeMeasurement(measurementUriParser);
 
+    int measurementUriValidator = debugger.startRuntimeMeasurement("UriValidator", "validate");
     final HttpMethod method = request.getMethod();
     new UriValidator().validate(uriInfo, method);
+    debugger.stopRuntimeMeasurement(measurementUriValidator);
 
+    int measurementDispatcher = debugger.startRuntimeMeasurement("Dispatcher", "dispatch");
     new ODataDispatcher(method, uriInfo, this).dispatch(request, response);
+    debugger.stopRuntimeMeasurement(measurementDispatcher);
   }
 
   public void handleException(final ODataRequest request, final ODataResponse response,
@@ -146,7 +152,9 @@ public class ODataHandler {
     } catch (final ContentNegotiatorException e) {
       requestedContentType = ContentType.JSON;
     }
+    int measurementHandle = debugger.startRuntimeMeasurement("ErrorProcessor", "processError");
     exceptionProcessor.processError(request, response, serverError, requestedContentType);
+    debugger.stopRuntimeMeasurement(measurementHandle);
   }
 
   private void validateODataVersion(final ODataRequest request, final ODataResponse response)
@@ -196,8 +204,8 @@ public class ODataHandler {
   public Exception getLastThrownException() {
     return lastThrownException;
   }
-  
-  public UriInfo getUriInfo(){
+
+  public UriInfo getUriInfo() {
     return uriInfo;
   }
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/57a11aff/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugResponseHelperImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugResponseHelperImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugResponseHelperImpl.java
index d99dd4c..94ab544 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugResponseHelperImpl.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugResponseHelperImpl.java
@@ -76,7 +76,7 @@ public class DebugResponseHelperImpl implements DebugResponseHelper {
             + new Date().toString().replace(' ', '_').replace(':', '.') + ".html");
         // Download is the same as html except for the above header
       case HTML:
-        String title = debugInfo.getRequest() == null ? 
+        String title = debugInfo.getRequest() == null ?
             "V4 Service" : "V4 Service: " + debugInfo.getRequest().getRawODataPath();
         body = wrapInHtml(parts, title);
         contentTypeString = ContentType.TEXT_HTML.toContentTypeString();
@@ -164,7 +164,7 @@ public class DebugResponseHelperImpl implements DebugResponseHelper {
 
     gen.writeEndObject();
     gen.close();
-    csb.close();
+    csb.closeWrite();
 
     return csb.getInputStream();
   }
@@ -258,14 +258,15 @@ public class DebugResponseHelperImpl implements DebugResponseHelper {
         .append("</thead>\n<tbody>\n");
     for (final String name : entries.keySet()) {
       final String value = entries.get(name);
+      writer.append("<tr><td class=\"name\">").append(name).append("</td>")
+      .append("<td class=\"value\">");
       if (value != null) {
-        writer.append("<tr><td class=\"name\">").append(name).append("</td>")
-            .append("<td class=\"value\">")
-            .append(escapeHtml(value))
-            .append("</td></tr>\n");
+        writer.append(escapeHtml(value));
+      }else{
+        writer.append("null");
       }
+      writer.append("</td></tr>\n");
     }
     writer.append("</tbody>\n</table>\n");
   }
-
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/57a11aff/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugTabBody.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugTabBody.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugTabBody.java
index 43e9ba6..5608d58 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugTabBody.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugTabBody.java
@@ -50,11 +50,15 @@ public class DebugTabBody implements DebugTab {
 
   public DebugTabBody(final ODataResponse response, final String serviceRoot) {
     this.response = response;
-    this.serviceRoot = serviceRoot;
-    final String contentType = response.getHeaders().get(HttpHeader.CONTENT_TYPE);
-    // TODO: Differentiate better
-    if (contentType != null) {
-      responseContent = ResponseContent.JSON;
+    this.serviceRoot = serviceRoot == null ? "/" : serviceRoot;
+    if (response != null) {
+      final String contentType = response.getHeaders().get(HttpHeader.CONTENT_TYPE);
+      // TODO: Differentiate better
+      if (contentType != null) {
+        responseContent = ResponseContent.JSON;
+      } else {
+        responseContent = ResponseContent.TEXT;
+      }
     } else {
       responseContent = ResponseContent.TEXT;
     }
@@ -74,7 +78,7 @@ public class DebugTabBody implements DebugTab {
 //
   @Override
   public void appendJson(final JsonGenerator gen) throws IOException {
-    if (response.getContent() == null) {
+    if (response == null || response.getContent() == null) {
       gen.writeNull();
     } else {
       gen.writeString(getContentString());
@@ -106,7 +110,8 @@ public class DebugTabBody implements DebugTab {
   @Override
   public void appendHtml(final Writer writer) throws IOException {
 
-    final String body = response.getContent() == null ? "ODataLibrary: null body." : getContentString();
+    final String body =
+        response == null || response.getContent() == null ? "ODataLibrary: No body." : getContentString();
     switch (responseContent) {
     case XML:
       writer.append("<pre class=\"code").append("xml").append("\">\n");

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/57a11aff/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugTabRequest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugTabRequest.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugTabRequest.java
index 8eba537..be38f68 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugTabRequest.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugTabRequest.java
@@ -20,7 +20,7 @@ package org.apache.olingo.server.core.debug;
 
 import java.io.IOException;
 import java.io.Writer;
-import java.util.LinkedHashMap;
+import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 
@@ -36,33 +36,20 @@ public class DebugTabRequest implements DebugTab {
   private final String method;
   private final String uri;
   private final String protocol;
-  private final Map<String, String> headers;
+  private final Map<String, List<String>> headers;
 
   public DebugTabRequest(ODataRequest request) {
-    method = request.getMethod() == null ? "unkown" : request.getMethod().toString();
-    uri = request.getRawRequestUri() == null ? "unkown" : request.getRawRequestUri();
-    protocol = request.getProtocol() == null ? "unkown" : request.getProtocol();
-    // TODO: Should we really wrap the headers here or keep the original structure?
-    headers = wrapHeaders(request.getAllHeaders());
-  }
-
-  private Map<String, String> wrapHeaders(Map<String, List<String>> allHeaders) {
-    Map<String, String> localHeaders = new LinkedHashMap<String, String>();
-    for (Map.Entry<String, List<String>> entry : allHeaders.entrySet()) {
-      String value = null;
-      if (entry.getValue() != null) {
-        value = "";
-        boolean first = true;
-        for (String valuePart : entry.getValue()) {
-          if (!first) {
-            value = value + ", ";
-          }
-          value = value + valuePart;
-        }
-      }
-      localHeaders.put(entry.getKey(), value);
+    if (request != null) {
+      method = request.getMethod() == null ? "unkown" : request.getMethod().toString();
+      uri = request.getRawRequestUri() == null ? "unkown" : request.getRawRequestUri();
+      protocol = request.getProtocol() == null ? "unkown" : request.getProtocol();
+      headers = request.getAllHeaders();
+    } else {
+      method = "unkown";
+      uri = "unkown";
+      protocol = "unkown";
+      headers = Collections.emptyMap();
     }
-    return localHeaders;
   }
 
   @Override
@@ -70,25 +57,26 @@ public class DebugTabRequest implements DebugTab {
     writer.append("<h2>Request Method</h2>\n")
         .append("<p>").append(method).append("</p>\n")
         .append("<h2>Request URI</h2>\n")
-        .append("<p>").append(DebugResponseHelperImpl.escapeHtml(uri.toString())).append("</p>\n")
+        .append("<p>").append(DebugResponseHelperImpl.escapeHtml(uri)).append("</p>\n")
         .append("<h2>Request Protocol</h2>\n")
-        .append("<p>").append(protocol).append("</p>\n");
+        .append("<p>").append(DebugResponseHelperImpl.escapeHtml(protocol)).append("</p>\n");
     writer.append("<h2>Request Headers</h2>\n");
-    DebugResponseHelperImpl.appendHtmlTable(writer, headers);
-
-//        .append("<table>\n<thead>\n")
-//        .append("<tr><th class=\"name\">Name</th><th class=\"value\">Value</th></tr>\n")
-//        .append("</thead>\n<tbody>\n");
-//    for (final String name : headers.keySet()) {
-//      for (final String value : headers.get(name)) {
-//        if (value != null) {
-//          writer.append("<tr><td class=\"name\">").append(name).append("</td>")
-//              .append("<td class=\"value\">").append(DebugResponseHelperImpl.escapeHtml(value))
-//              .append("</td></tr>\n");
-//        }
-//      }
-//    }
-//    writer.append("</tbody>\n</table>\n");
+
+    writer.append("<table>\n<thead>\n")
+        .append("<tr><th class=\"name\">Name</th><th class=\"value\">Value</th></tr>\n")
+        .append("</thead>\n<tbody>\n");
+    for (final Map.Entry<String, List<String>> entry : headers.entrySet()) {
+      List<String> headersList = entry.getValue();
+      if (headersList != null && !headersList.isEmpty()) {
+        for (String headerValue : headersList) {
+          writer.append("<tr><td class=\"name\">").append(entry.getKey()).append("</td>")
+              .append("<td class=\"value\">")
+              .append(DebugResponseHelperImpl.escapeHtml(headerValue))
+              .append("</td></tr>\n");
+        }
+      }
+    }
+    writer.append("</tbody>\n</table>\n");
   }
 
   @Override
@@ -107,7 +95,32 @@ public class DebugTabRequest implements DebugTab {
 
     if (!headers.isEmpty()) {
       gen.writeFieldName("headers");
-      DebugResponseHelperImpl.appendJsonTable(gen, headers);
+
+      gen.writeStartObject();
+
+      for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
+        List<String> headersList = entry.getValue();
+        if (headersList != null && !headersList.isEmpty()) {
+          if (headersList.size() == 1) {
+            gen.writeStringField(entry.getKey(), headersList.get(0));
+          } else {
+            gen.writeFieldName(entry.getKey());
+            gen.writeStartArray();
+            for (String headerValue : headersList) {
+              if (headerValue != null) {
+                gen.writeString(headerValue);
+              } else {
+                gen.writeNull();
+              }
+            }
+            gen.writeEndArray();
+          }
+        } else {
+          gen.writeNullField(entry.getKey());
+        }
+      }
+
+      gen.writeEndObject();
     }
 
     gen.writeEndObject();

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/57a11aff/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugTabResponse.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugTabResponse.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugTabResponse.java
index 5cb153c..528cf61 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugTabResponse.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugTabResponse.java
@@ -20,6 +20,7 @@ package org.apache.olingo.server.core.debug;
 
 import java.io.IOException;
 import java.io.Writer;
+import java.util.Collections;
 import java.util.Map;
 
 import org.apache.olingo.commons.api.http.HttpStatusCode;
@@ -39,9 +40,14 @@ public class DebugTabResponse implements DebugTab {
 
   public DebugTabResponse(final ODataResponse applicationResponse, final String serviceRoot) {
     this.response = applicationResponse;
-    this.serviceRoot = serviceRoot;
-    status = HttpStatusCode.fromStatusCode(response.getStatusCode());
-    headers = response.getHeaders();
+    if (response != null) {
+      status = HttpStatusCode.fromStatusCode(response.getStatusCode());
+      headers = response.getHeaders();
+    } else {
+      status = HttpStatusCode.INTERNAL_SERVER_ERROR;
+      headers = Collections.emptyMap();
+    }
+    this.serviceRoot = serviceRoot == null ? "/" : serviceRoot;
   }
 
   @Override
@@ -67,7 +73,11 @@ public class DebugTabResponse implements DebugTab {
     }
 
     gen.writeFieldName("body");
-    new DebugTabBody(response, serviceRoot).appendJson(gen);
+    if (response != null && response.getContent() != null) {
+      new DebugTabBody(response, serviceRoot).appendJson(gen);
+    } else {
+      gen.writeNull();
+    }
 
     gen.writeEndObject();
   }
@@ -80,7 +90,7 @@ public class DebugTabResponse implements DebugTab {
         .append("<h2>Response Headers</h2>\n");
     DebugResponseHelperImpl.appendHtmlTable(writer, headers);
     writer.append("<h2>Response Body</h2>\n");
-    if (response.getContent() != null) {
+    if (response != null && response.getContent() != null) {
       new DebugTabBody(response, serviceRoot).appendHtml(writer);
     } else {
       writer.append("<p>ODataLibrary: no response body</p>");

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/57a11aff/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugTabServer.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugTabServer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugTabServer.java
index 4eb95ba..2faae3e 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugTabServer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/DebugTabServer.java
@@ -42,7 +42,11 @@ public class DebugTabServer implements DebugTab {
 
   @Override
   public void appendJson(JsonGenerator gen) throws IOException {
-    DebugResponseHelperImpl.appendJsonTable(gen, serverEnvironmentVaribles);
+    if (serverEnvironmentVaribles != null && !serverEnvironmentVaribles.isEmpty()) {
+      DebugResponseHelperImpl.appendJsonTable(gen, serverEnvironmentVaribles);
+    } else {
+      gen.writeNull();
+    }
   }
 
   @Override
@@ -52,6 +56,8 @@ public class DebugTabServer implements DebugTab {
         .append("<p>").append(pack.getImplementationTitle())
         .append(" Version ").append(pack.getImplementationVersion()).append("</p>\n")
         .append("<h2>Server Environment</h2>\n");
-    DebugResponseHelperImpl.appendHtmlTable(writer, serverEnvironmentVaribles);
+    if (serverEnvironmentVaribles != null && !serverEnvironmentVaribles.isEmpty()) {
+      DebugResponseHelperImpl.appendHtmlTable(writer, serverEnvironmentVaribles);
+    }
   }
 }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/57a11aff/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/ServerCoreDebugger.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/ServerCoreDebugger.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/ServerCoreDebugger.java
index fcf611d..8bdbe39 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/ServerCoreDebugger.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/debug/ServerCoreDebugger.java
@@ -64,6 +64,11 @@ public class ServerCoreDebugger {
   public ODataResponse createDebugResponse(final HttpServletRequest request, final Exception exception,
       final ODataRequest odRequest, final ODataResponse odResponse, UriInfo uriInfo,
       Map<String, String> serverEnvironmentVaribles) {
+    //Failsafe so we do not generate unauthorized debug messages
+    if(!isDebugMode){
+      return odResponse;
+    }
+    
     try {
       DebugInformation debugInfo =
           createDebugInformation(request, exception, odRequest, odResponse, uriInfo, serverEnvironmentVaribles);
@@ -80,7 +85,7 @@ public class ServerCoreDebugger {
     odResponse.setHeader(HttpHeader.CONTENT_TYPE, ContentType.TEXT_PLAIN.toContentTypeString());
     InputStream content = new ByteArrayInputStream("ODataLibrary: Could not assemble debug response.".getBytes());
     odResponse.setContent(content);
-    return null;
+    return odResponse;
   }
 
   private DebugInformation createDebugInformation(final HttpServletRequest request, final Exception exception,

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/57a11aff/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/BatchResponseSerializer.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/BatchResponseSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/BatchResponseSerializer.java
index 377c5e1..c907b8f 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/BatchResponseSerializer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/BatchResponseSerializer.java
@@ -22,7 +22,6 @@ import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.OutputStream;
 import java.nio.ByteBuffer;
 import java.nio.channels.Channels;
 import java.nio.channels.ReadableByteChannel;

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/57a11aff/lib/server-core/src/test/java/org/apache/olingo/server/core/debug/AbstractDebugTabTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/debug/AbstractDebugTabTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/debug/AbstractDebugTabTest.java
new file mode 100644
index 0000000..43b1aaa
--- /dev/null
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/debug/AbstractDebugTabTest.java
@@ -0,0 +1,58 @@
+/*
+ * 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.debug;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.StringWriter;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.olingo.server.core.serializer.utils.CircleStreamBuffer;
+
+import com.fasterxml.jackson.core.JsonEncoding;
+import com.fasterxml.jackson.core.JsonFactory;
+import com.fasterxml.jackson.core.JsonGenerator;
+
+public abstract class AbstractDebugTabTest {
+
+  protected String createHtml(DebugTab tab) throws Exception {
+    StringWriter writer = new StringWriter();
+    tab.appendHtml(writer);
+    writer.flush();
+    byte[] bytes = writer.toString().getBytes("UTF-8");
+    return IOUtils.toString(new ByteArrayInputStream(bytes));
+  }
+
+  protected String createJson(DebugTab requestTab) throws IOException {
+    CircleStreamBuffer csb = new CircleStreamBuffer();
+    JsonGenerator gen = new JsonFactory().createGenerator(csb.getOutputStream(), JsonEncoding.UTF8);
+    requestTab.appendJson(gen);
+    gen.flush();
+    gen.close();
+    csb.closeWrite();
+    return IOUtils.toString(csb.getInputStream());
+  }
+  
+  protected void print(DebugTab tab) throws Exception{
+    System.out.println(createJson(tab));
+    System.out.println("---------------------------------------------------------");
+    System.out.println(createHtml(tab));
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/57a11aff/lib/server-core/src/test/java/org/apache/olingo/server/core/debug/DebugTabBodyTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/debug/DebugTabBodyTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/debug/DebugTabBodyTest.java
new file mode 100644
index 0000000..7d3a58e
--- /dev/null
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/debug/DebugTabBodyTest.java
@@ -0,0 +1,37 @@
+/*
+ * 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.debug;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+public class DebugTabBodyTest extends AbstractDebugTabTest {
+
+  @Test
+  public void nullResponseMustNotLeadToException() throws Exception {
+    DebugTabBody tab = new DebugTabBody(null, null);
+
+    String expectedHtml = "<pre class=\"code\">\n"
+        + "ODataLibrary: No body.</pre>\n";
+
+    assertEquals("null", createJson(tab));
+    assertEquals(expectedHtml, createHtml(tab));
+  }
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/57a11aff/lib/server-core/src/test/java/org/apache/olingo/server/core/debug/DebugTabRequestTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/debug/DebugTabRequestTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/debug/DebugTabRequestTest.java
new file mode 100644
index 0000000..3689301
--- /dev/null
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/debug/DebugTabRequestTest.java
@@ -0,0 +1,155 @@
+/*
+ * 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.debug;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.olingo.commons.api.http.HttpMethod;
+import org.apache.olingo.server.api.ODataRequest;
+import org.junit.Test;
+
+public class DebugTabRequestTest extends AbstractDebugTabTest {
+
+  @Test
+  public void initialRequestMustNotleadToException() throws Exception {
+    String expectedJson = "{\"method\":\"unkown\",\"uri\":\"unkown\",\"protocol\":\"unkown\"}";
+    String expectedHtml = "<h2>Request Method</h2>\n"
+        + "<p>unkown</p>\n"
+        + "<h2>Request URI</h2>\n"
+        + "<p>unkown</p>\n"
+        + "<h2>Request Protocol</h2>\n"
+        + "<p>unkown</p>\n"
+        + "<h2>Request Headers</h2>\n"
+        + "<table>\n"
+        + "<thead>\n"
+        + "<tr><th class=\"name\">Name</th><th class=\"value\">Value</th></tr>\n"
+        + "</thead>\n"
+        + "<tbody>\n"
+        + "</tbody>\n"
+        + "</table>\n";
+
+    DebugTabRequest requestTab = new DebugTabRequest(null);
+    assertEquals(expectedJson, createJson(requestTab));
+    assertEquals(expectedHtml, createHtml(requestTab));
+
+    requestTab = new DebugTabRequest(new ODataRequest());
+    assertEquals(expectedJson, createJson(requestTab));
+    assertEquals(expectedHtml, createHtml(requestTab));
+  }
+
+  @Test
+  public void onlyProtocolNotSet() throws Exception {
+    String expectedJson = "{\"method\":\"GET\",\"uri\":\"def&\",\"protocol\":\"unkown\"}";
+    String expectedHtml = "<h2>Request Method</h2>\n"
+        + "<p>GET</p>\n"
+        + "<h2>Request URI</h2>\n"
+        + "<p>def&amp;</p>\n"
+        + "<h2>Request Protocol</h2>\n"
+        + "<p>unkown</p>\n"
+        + "<h2>Request Headers</h2>\n"
+        + "<table>\n"
+        + "<thead>\n"
+        + "<tr><th class=\"name\">Name</th><th class=\"value\">Value</th></tr>\n"
+        + "</thead>\n"
+        + "<tbody>\n"
+        + "</tbody>\n"
+        + "</table>\n";
+
+    ODataRequest oDataRequest = new ODataRequest();
+    oDataRequest.setMethod(HttpMethod.GET);
+    oDataRequest.setRawRequestUri("def&");
+
+    DebugTabRequest requestTab = new DebugTabRequest(oDataRequest);
+    assertEquals(expectedJson, createJson(requestTab));
+    assertEquals(expectedHtml, createHtml(requestTab));
+  }
+
+  @Test
+  public void singleHeaderValue() throws Exception {
+    String expectedJson =
+        "{\"method\":\"GET\",\"uri\":\"def&\",\"protocol\":\"def&\",\"headers\":{\"HEADERNAME\":\"Value1\"}}";
+    String expectedHtml = "<h2>Request Method</h2>\n"
+        + "<p>GET</p>\n"
+        + "<h2>Request URI</h2>\n"
+        + "<p>def&amp;</p>\n"
+        + "<h2>Request Protocol</h2>\n"
+        + "<p>def&amp;</p>\n"
+        + "<h2>Request Headers</h2>\n"
+        + "<table>\n"
+        + "<thead>\n"
+        + "<tr><th class=\"name\">Name</th><th class=\"value\">Value</th></tr>\n"
+        + "</thead>\n"
+        + "<tbody>\n"
+        + "<tr><td class=\"name\">HEADERNAME</td><td class=\"value\">Value1</td></tr>\n"
+        + "</tbody>\n"
+        + "</table>\n";
+
+    ODataRequest oDataRequest = new ODataRequest();
+    oDataRequest.setMethod(HttpMethod.GET);
+    oDataRequest.setRawRequestUri("def&");
+    oDataRequest.setProtocol("def&");
+    List<String> headerValues = new ArrayList<String>();
+    headerValues.add("Value1");
+    oDataRequest.addHeader("HeaderName", headerValues);
+
+    DebugTabRequest requestTab = new DebugTabRequest(oDataRequest);
+    System.out.println(createHtml(requestTab));
+    assertEquals(expectedJson, createJson(requestTab));
+    assertEquals(expectedHtml, createHtml(requestTab));
+  }
+
+  @Test
+  public void multiHeaderValueResultsInMap() throws Exception {
+    String expectedJson = "{\"method\":\"GET\",\"uri\":\"def&\",\"protocol\":\"def&\","
+        + "\"headers\":{\"HEADERNAME\":[\"Value1\",\"Value2\"]}}";
+    String expectedHtml = "<h2>Request Method</h2>\n"
+        + "<p>GET</p>\n"
+        + "<h2>Request URI</h2>\n"
+        + "<p>def&amp;</p>\n"
+        + "<h2>Request Protocol</h2>\n"
+        + "<p>def&amp;</p>\n"
+        + "<h2>Request Headers</h2>\n"
+        + "<table>\n"
+        + "<thead>\n"
+        + "<tr><th class=\"name\">Name</th><th class=\"value\">Value</th></tr>\n"
+        + "</thead>\n"
+        + "<tbody>\n"
+        + "<tr><td class=\"name\">HEADERNAME</td><td class=\"value\">Value1</td></tr>\n"
+        + "<tr><td class=\"name\">HEADERNAME</td><td class=\"value\">Value2</td></tr>\n"
+        + "</tbody>\n"
+        + "</table>\n";
+
+    ODataRequest oDataRequest = new ODataRequest();
+    oDataRequest.setMethod(HttpMethod.GET);
+    oDataRequest.setRawRequestUri("def&");
+    oDataRequest.setProtocol("def&");
+    List<String> headerValues = new ArrayList<String>();
+    headerValues.add("Value1");
+    headerValues.add("Value2");
+    oDataRequest.addHeader("HeaderName", headerValues);
+
+    DebugTabRequest requestTab = new DebugTabRequest(oDataRequest);
+    assertEquals(expectedJson, createJson(requestTab));
+    assertEquals(expectedHtml, createHtml(requestTab));
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/57a11aff/lib/server-core/src/test/java/org/apache/olingo/server/core/debug/DebugTabResponseTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/debug/DebugTabResponseTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/debug/DebugTabResponseTest.java
new file mode 100644
index 0000000..af55a40
--- /dev/null
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/debug/DebugTabResponseTest.java
@@ -0,0 +1,79 @@
+/*
+ * 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.debug;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.olingo.commons.api.http.HttpStatusCode;
+import org.apache.olingo.server.api.ODataResponse;
+import org.junit.Test;
+
+public class DebugTabResponseTest extends AbstractDebugTabTest {
+
+  @Test
+  public void nullResponseMustNotLeadToException() throws Exception {
+    DebugTabResponse tab = new DebugTabResponse(null, null);
+
+    String expectedJson = "{\"status\":{\"code\":\"500\",\"info\":\"Internal Server Error\"},\"body\":null}";
+    String expectedHtml = "<h2>Status Code</h2>\n"
+        + "<p>500 Internal Server Error</p>\n"
+        + "<h2>Response Headers</h2>\n"
+        + "<table>\n"
+        + "<thead>\n"
+        + "<tr><th class=\"name\">Name</th><th class=\"value\">Value</th></tr>\n"
+        + "</thead>\n"
+        + "<tbody>\n"
+        + "</tbody>\n"
+        + "</table>\n"
+        + "<h2>Response Body</h2>\n"
+        + "<p>ODataLibrary: no response body</p>";
+
+    assertEquals(expectedJson, createJson(tab));
+    assertEquals(expectedHtml, createHtml(tab));
+  }
+
+  @Test
+  public void withInformationNoBody() throws Exception {
+    ODataResponse response = new ODataResponse();
+    response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode());
+    response.setHeader("headername", "headervalue");
+    response.setHeader("headername2", "headervalue2");
+    DebugTabResponse tab = new DebugTabResponse(response, null);
+
+    String expectedJson = "{\"status\":{\"code\":\"204\",\"info\":\"No Content\"},"
+        + "\"headers\":{\"headername\":\"headervalue\",\"headername2\":\"headervalue2\"},\"body\":null}";
+    String expectedHtml = "<h2>Status Code</h2>\n"
+        + "<p>204 No Content</p>\n"
+        + "<h2>Response Headers</h2>\n"
+        + "<table>\n"
+        + "<thead>\n"
+        + "<tr><th class=\"name\">Name</th><th class=\"value\">Value</th></tr>\n"
+        + "</thead>\n"
+        + "<tbody>\n"
+        + "<tr><td class=\"name\">headername</td><td class=\"value\">headervalue</td></tr>\n"
+        + "<tr><td class=\"name\">headername2</td><td class=\"value\">headervalue2</td></tr>\n"
+        + "</tbody>\n"
+        + "</table>\n"
+        + "<h2>Response Body</h2>\n"
+        + "<p>ODataLibrary: no response body</p>";
+    assertEquals(expectedJson, createJson(tab));
+    assertEquals(expectedHtml, createHtml(tab));
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/57a11aff/lib/server-core/src/test/java/org/apache/olingo/server/core/debug/DebugTabServerTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/debug/DebugTabServerTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/debug/DebugTabServerTest.java
new file mode 100644
index 0000000..dc4748d
--- /dev/null
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/debug/DebugTabServerTest.java
@@ -0,0 +1,84 @@
+/*
+ * 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.debug;
+
+import static org.junit.Assert.*;
+
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import org.junit.Test;
+
+public class DebugTabServerTest extends AbstractDebugTabTest {
+
+  @Test
+  public void nullServerInformationMustNotleadToException() throws Exception {
+    DebugTabServer serverTab = new DebugTabServer(null);
+
+    assertEquals("null", createJson(serverTab));
+    String html = createHtml(serverTab);
+    assertTrue(html.startsWith("<h2>Library Version</h2>"));
+    assertTrue(html.endsWith("<h2>Server Environment</h2>\n"));
+  }
+
+  @Test
+  public void initialServerInformationMustNotleadToException() throws Exception {
+    Map<String, String> env = Collections.emptyMap();
+    DebugTabServer serverTab = new DebugTabServer(env);
+
+    assertEquals("null", createJson(serverTab));
+    String html = createHtml(serverTab);
+    assertTrue(html.startsWith("<h2>Library Version</h2>"));
+    assertTrue(html.endsWith("<h2>Server Environment</h2>\n"));
+  }
+
+  @Test
+  public void twoParametersNoNull() throws Exception {
+    Map<String, String> env = new LinkedHashMap<String, String>();
+    env.put("key1", "value1");
+    env.put("key2", "value2");
+    DebugTabServer serverTab = new DebugTabServer(env);
+
+    String expectedJson = "{\"key1\":\"value1\",\"key2\":\"value2\"}";
+
+    assertEquals(expectedJson, createJson(serverTab));
+    String html = createHtml(serverTab);
+    assertTrue(html.contains("<tr><td class=\"name\">key1</td><td class=\"value\">value1</td></tr>"));
+    assertTrue(html.contains("<tr><td class=\"name\">key2</td><td class=\"value\">value2</td></tr>"));
+    assertTrue(html.endsWith("</table>\n"));
+  }
+  
+  @Test
+  public void twoParametersWithNull() throws Exception {
+    Map<String, String> env = new LinkedHashMap<String, String>();
+    env.put("key1", null);
+    env.put("key2", null);
+    DebugTabServer serverTab = new DebugTabServer(env);
+
+    String expectedJson = "{\"key1\":null,\"key2\":null}";
+
+    assertEquals(expectedJson, createJson(serverTab));
+    String html = createHtml(serverTab);
+    assertTrue(html.contains("<tr><td class=\"name\">key1</td><td class=\"value\">null</td></tr>"));
+    assertTrue(html.contains("<tr><td class=\"name\">key2</td><td class=\"value\">null</td></tr>"));
+    assertTrue(html.endsWith("</table>\n"));
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/57a11aff/lib/server-core/src/test/java/org/apache/olingo/server/core/debug/ServerCoreDebuggerTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/debug/ServerCoreDebuggerTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/debug/ServerCoreDebuggerTest.java
new file mode 100644
index 0000000..32ec195
--- /dev/null
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/debug/ServerCoreDebuggerTest.java
@@ -0,0 +1,121 @@
+/*
+ * 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.debug;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.olingo.commons.api.ODataRuntimeException;
+import org.apache.olingo.server.api.OData;
+import org.apache.olingo.server.api.ODataResponse;
+import org.apache.olingo.server.api.debug.DebugInformation;
+import org.apache.olingo.server.api.debug.DebugSupport;
+import org.junit.Before;
+import org.junit.Test;
+
+public class ServerCoreDebuggerTest {
+
+  private ServerCoreDebugger debugger;
+
+  @Before
+  public void setupDebugger() {
+    debugger = new ServerCoreDebugger(OData.newInstance());
+    debugger.setDebugSupportProcessor(new LocalDebugProcessor());
+  }
+
+  @Test
+  public void standardIsDebugModeIsFlase() {
+    assertFalse(debugger.isDebugMode());
+  }
+
+  @Test
+  public void resolveDebugModeNoDebugSupportProcessor() {
+    HttpServletRequest request = mock(HttpServletRequest.class);
+    when(request.getParameter(DebugSupport.ODATA_DEBUG_QUERY_PARAMETER)).thenReturn(DebugSupport.ODATA_DEBUG_JSON);
+
+    ServerCoreDebugger localDebugger = new ServerCoreDebugger(OData.newInstance());
+    localDebugger.resolveDebugMode(request);
+    assertFalse(debugger.isDebugMode());
+  }
+
+  @Test
+  public void resolveDebugModeNullParameter() {
+    HttpServletRequest request = mock(HttpServletRequest.class);
+    when(request.getParameter(DebugSupport.ODATA_DEBUG_QUERY_PARAMETER)).thenReturn(null);
+    debugger.resolveDebugMode(request);
+    assertFalse(debugger.isDebugMode());
+  }
+
+  @Test
+  public void resolveDebugModeJsonNotAuthorized() {
+    HttpServletRequest request = mock(HttpServletRequest.class);
+    when(request.getParameter(DebugSupport.ODATA_DEBUG_QUERY_PARAMETER)).thenReturn(DebugSupport.ODATA_DEBUG_JSON);
+
+    DebugSupport debugSupportMock = mock(DebugSupport.class);
+    when(debugSupportMock.isUserAuthorized()).thenReturn(false);
+
+    ServerCoreDebugger localDebugger = new ServerCoreDebugger(OData.newInstance());
+    localDebugger.setDebugSupportProcessor(debugSupportMock);
+
+    localDebugger.resolveDebugMode(request);
+    assertFalse(debugger.isDebugMode());
+  }
+
+  @Test
+  public void testFailResponse() throws IOException {
+    HttpServletRequest request = mock(HttpServletRequest.class);
+    when(request.getParameter(DebugSupport.ODATA_DEBUG_QUERY_PARAMETER)).thenReturn(DebugSupport.ODATA_DEBUG_JSON);
+    debugger.resolveDebugMode(request);
+    ODataResponse debugResponse = debugger.createDebugResponse(null, null, null, null, null, null);
+    assertEquals(500, debugResponse.getStatusCode());
+    assertEquals("ODataLibrary: Could not assemble debug response.", IOUtils.toString(debugResponse.getContent()));
+  }
+
+  @Test
+  public void noDebugModeCreateDebugResponseCallMustDoNothing() {
+    ODataResponse odResponse = new ODataResponse();
+    ODataResponse debugResponse = debugger.createDebugResponse(null, null, null, odResponse, null, null);
+
+    assertTrue(odResponse == debugResponse);
+  }
+
+  public class LocalDebugProcessor implements DebugSupport {
+
+    @Override
+    public void init(OData odata) {}
+
+    @Override
+    public boolean isUserAuthorized() {
+      return true;
+    }
+
+    @Override
+    public ODataResponse createDebugResponse(String debugFormat, DebugInformation debugInfo) {
+      throw new ODataRuntimeException("Test");
+    }
+  }
+}