olingo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From m...@apache.org
Subject [4/4] olingo-odata4 git commit: [OLINGO-573] Start replacement of Jetty with Tomcat
Date Thu, 02 Apr 2015 13:32:17 GMT
[OLINGO-573] Start replacement of Jetty with Tomcat


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

Branch: refs/heads/OLINGO-573
Commit: 8c6be6654fd4da9a1c40d445278dc8eddf235096
Parents: 61b0daa
Author: Michael Bolz <michael.bolz@sap.com>
Authored: Thu Apr 2 15:09:02 2015 +0200
Committer: Michael Bolz <michael.bolz@sap.com>
Committed: Thu Apr 2 15:09:02 2015 +0200

----------------------------------------------------------------------
 lib/pom.xml                                     |    2 -
 lib/server-core-ext/pom.xml                     |   57 +-
 .../server/core/ServiceDispatcherTest.java      |  749 +++++----
 .../server/example/TripPinServiceTest.java      | 1417 +++++++++---------
 pom.xml                                         |    7 +-
 5 files changed, 1114 insertions(+), 1118 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8c6be665/lib/pom.xml
----------------------------------------------------------------------
diff --git a/lib/pom.xml b/lib/pom.xml
index 44d6d7c..d1e8864 100644
--- a/lib/pom.xml
+++ b/lib/pom.xml
@@ -42,9 +42,7 @@
     <module>client-core</module>
     <module>server-api</module>
     <module>server-core</module>
-    <!-- Temporary disable build of core-ext module
     <module>server-core-ext</module>
-    -->
     <module>server-tecsvc</module>
     <module>server-test</module>
   </modules>

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8c6be665/lib/server-core-ext/pom.xml
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/pom.xml b/lib/server-core-ext/pom.xml
index a5730c0..5249ed4 100644
--- a/lib/server-core-ext/pom.xml
+++ b/lib/server-core-ext/pom.xml
@@ -59,6 +59,7 @@
     <dependency>
       <groupId>javax.servlet</groupId>
       <artifactId>javax.servlet-api</artifactId>
+      <version>3.0.1</version>
       <scope>provided</scope>
     </dependency>
     <dependency>
@@ -82,36 +83,32 @@
       <artifactId>commons-io</artifactId>
       <scope>test</scope>
     </dependency>
-        <dependency>
-            <groupId>org.eclipse.jetty</groupId>
-            <artifactId>jetty-server</artifactId>
-            <scope>test</scope>
-            <version>${jetty-version}</version>
-        </dependency>
-        <dependency>
-            <groupId>org.eclipse.jetty</groupId>
-            <artifactId>jetty-servlet</artifactId>
-            <version>${jetty-version}</version>
-            <scope>test</scope>
-            <exclusions>
-              <exclusion>
-                <groupId>javax.servlet</groupId>
-                <artifactId>javax.servlet-api</artifactId>
-              </exclusion>
-            </exclusions>
-        </dependency>
-        <dependency>
-            <groupId>org.eclipse.jetty</groupId>
-            <artifactId>jetty-http</artifactId>
-            <version>${jetty-version}</version>
-            <scope>test</scope>
-        </dependency>    
-        <dependency>
-            <groupId>org.eclipse.jetty</groupId>
-            <artifactId>jetty-client</artifactId>
-            <scope>test</scope>
-            <version>${jetty-version}</version>
-        </dependency>        
+    <dependency>
+      <groupId>org.apache.tomcat.embed</groupId>
+      <artifactId>tomcat-embed-core</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.tomcat.embed</groupId>
+      <artifactId>tomcat-embed-logging-log4j</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.tomcat</groupId>
+      <artifactId>tomcat-jasper</artifactId>
+      <scope>test</scope>
+      <exclusions>
+        <exclusion>
+          <groupId>javax.servlet</groupId>
+          <artifactId>javax.servlet-api</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.httpcomponents</groupId>
+      <artifactId>httpclient</artifactId>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 
 </project>

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8c6be665/lib/server-core-ext/src/test/java/org/apache/olingo/server/core/ServiceDispatcherTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core-ext/src/test/java/org/apache/olingo/server/core/ServiceDispatcherTest.java
b/lib/server-core-ext/src/test/java/org/apache/olingo/server/core/ServiceDispatcherTest.java
index 16caa1a..c918134 100644
--- a/lib/server-core-ext/src/test/java/org/apache/olingo/server/core/ServiceDispatcherTest.java
+++ b/lib/server-core-ext/src/test/java/org/apache/olingo/server/core/ServiceDispatcherTest.java
@@ -18,400 +18,359 @@
  */
 package org.apache.olingo.server.core;
 
-import static org.junit.Assert.assertEquals;
-
-import java.io.FileReader;
-import java.io.IOException;
-import java.net.URI;
-import java.util.Collections;
-import java.util.List;
-
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.olingo.commons.api.edm.provider.EdmProvider;
-import org.apache.olingo.commons.api.http.HttpMethod;
-import org.apache.olingo.server.api.OData;
-import org.apache.olingo.server.api.ODataHttpHandler;
-import org.apache.olingo.server.api.ServiceMetadata;
-import org.apache.olingo.server.core.requests.ActionRequest;
-import org.apache.olingo.server.core.requests.DataRequest;
-import org.apache.olingo.server.core.requests.FunctionRequest;
-import org.apache.olingo.server.core.requests.MediaRequest;
-import org.apache.olingo.server.core.requests.MetadataRequest;
-import org.apache.olingo.server.core.responses.CountResponse;
-import org.apache.olingo.server.core.responses.EntityResponse;
-import org.apache.olingo.server.core.responses.EntitySetResponse;
-import org.apache.olingo.server.core.responses.MetadataResponse;
-import org.apache.olingo.server.core.responses.NoContentResponse;
-import org.apache.olingo.server.core.responses.PrimitiveValueResponse;
-import org.apache.olingo.server.core.responses.PropertyResponse;
-import org.apache.olingo.server.core.responses.StreamResponse;
-import org.apache.olingo.server.example.TripPinServiceTest;
-import org.eclipse.jetty.client.HttpClient;
-import org.eclipse.jetty.server.Connector;
-import org.eclipse.jetty.server.Server;
-import org.eclipse.jetty.server.ServerConnector;
-import org.eclipse.jetty.servlet.ServletContextHandler;
-import org.eclipse.jetty.servlet.ServletHolder;
-import org.junit.Test;
-import org.mockito.ArgumentCaptor;
-import org.mockito.Mockito;
-
 public class ServiceDispatcherTest {
-  private Server server;
-
-  public class SampleODataServlet extends HttpServlet {
-    private final ServiceHandler handler; // must be stateless
-    private final EdmProvider provider; // must be stateless
-
-    public SampleODataServlet(ServiceHandler handler, EdmProvider provider) {
-      this.handler = handler;
-      this.provider = provider;
-    }
-
-    @Override
-    public void service(HttpServletRequest request, HttpServletResponse response)
-        throws IOException {
-      OData odata = OData4Impl.newInstance();
-      ServiceMetadata metadata = odata.createServiceMetadata(this.provider, Collections.EMPTY_LIST);
-
-      ODataHttpHandler handler = odata.createHandler(metadata);
-
-      handler.register(this.handler);
-      handler.process(request, response);
-    }
-  }
-
-  public int beforeTest(ServiceHandler serviceHandler) throws Exception {
-    MetadataParser parser = new MetadataParser();
-    EdmProvider edmProvider = parser.buildEdmProvider(new FileReader(
-        "src/test/resources/trippin.xml"));
-
-    this.server = new Server();
-
-    ServerConnector connector = new ServerConnector(this.server);
-    this.server.setConnectors(new Connector[] { connector });
-
-    ServletContextHandler context = new ServletContextHandler();
-    context.setContextPath("/trippin");
-    context
-        .addServlet(new ServletHolder(new SampleODataServlet(serviceHandler, edmProvider)),
"/*");
-    this.server.setHandler(context);
-    this.server.start();
-
-    return connector.getLocalPort();
-  }
-
-  public void afterTest() throws Exception {
-    this.server.stop();
-  }
-
-  interface TestResult {
-    void validate() throws Exception;
-  }
-
-  private void helpGETTest(ServiceHandler handler, String path, TestResult validator)
-      throws Exception {
-    int port = beforeTest(handler);
-    HttpClient http = new HttpClient();
-    http.start();
-    http.GET("http://localhost:" + port + "/" + path);
-    validator.validate();
-    afterTest();
-  }
-
-  private void helpTest(ServiceHandler handler, String path, String method, String payload,
-      TestResult validator) throws Exception {
-    int port = beforeTest(handler);
-    HttpClient http = new HttpClient();
-    http.start();
-    String editUrl = "http://localhost:" + port + "/" + path;
-    http.newRequest(editUrl).method(method)
-        .header("Content-Type", "application/json;odata.metadata=minimal")
-        .content(TripPinServiceTest.content(payload)).send();
-    validator.validate();
-    afterTest();
-  }
-
-  @Test
-  public void testMetadata() throws Exception {
-    final ServiceHandler handler = Mockito.mock(ServiceHandler.class);
-    helpGETTest(handler, "trippin/$metadata", new TestResult() {
-      @Override
-      public void validate() throws Exception {
-        ArgumentCaptor<MetadataRequest> arg1 = ArgumentCaptor.forClass(MetadataRequest.class);
-        ArgumentCaptor<MetadataResponse> arg2 = ArgumentCaptor.forClass(MetadataResponse.class);
-        Mockito.verify(handler).readMetadata(arg1.capture(), arg2.capture());
-      }
-    });
-  }
-
-  @Test
-  public void testEntitySet() throws Exception {
-    final ServiceHandler handler = Mockito.mock(ServiceHandler.class);
-    helpGETTest(handler, "trippin/Airports", new TestResult() {
-      @Override
-      public void validate() throws Exception {
-        ArgumentCaptor<DataRequest> arg1 = ArgumentCaptor.forClass(DataRequest.class);
-        ArgumentCaptor<EntityResponse> arg2 = ArgumentCaptor.forClass(EntityResponse.class);
-        Mockito.verify(handler).read(arg1.capture(), arg2.capture());
-
-        DataRequest request = arg1.getValue();
-        // Need toString on ContextURL class
-        // assertEquals("",
-        // request.getContextURL(request.getOdata()).toString());
-        assertEquals("application/json;odata.metadata=minimal", request.getResponseContentType()
-            .toContentTypeString());
-      }
-    });
-  }
-
-  @Test
-  public void testEntitySetCount() throws Exception {
-    final ServiceHandler handler = Mockito.mock(ServiceHandler.class);
-    helpGETTest(handler, "trippin/Airports/$count", new TestResult() {
-      @Override
-      public void validate() throws Exception {
-        ArgumentCaptor<DataRequest> arg1 = ArgumentCaptor.forClass(DataRequest.class);
-        ArgumentCaptor<CountResponse> arg2 = ArgumentCaptor.forClass(CountResponse.class);
-        Mockito.verify(handler).read(arg1.capture(), arg2.capture());
-
-        DataRequest request = arg1.getValue();
-        // Need toString on ContextURL class
-        // assertEquals("",
-        // request.getContextURL(request.getOdata()).toString());
-        assertEquals("text/plain", request.getResponseContentType().toContentTypeString());
-      }
-    });
-  }
-
-  @Test
-  public void testEntity() throws Exception {
-    final ServiceHandler handler = Mockito.mock(ServiceHandler.class);
-    helpGETTest(handler, "trippin/Airports('0')", new TestResult() {
-      @Override
-      public void validate() throws Exception {
-        ArgumentCaptor<DataRequest> arg1 = ArgumentCaptor.forClass(DataRequest.class);
-        ArgumentCaptor<EntityResponse> arg2 = ArgumentCaptor.forClass(EntityResponse.class);
-        Mockito.verify(handler).read(arg1.capture(), arg2.capture());
-
-        DataRequest request = arg1.getValue();
-        assertEquals(1, request.getUriResourceEntitySet().getKeyPredicates().size());
-        assertEquals("application/json;odata.metadata=minimal", request.getResponseContentType()
-            .toContentTypeString());
-      }
-    });
-  }
-
-  @Test
-  public void testReadProperty() throws Exception {
-    final ServiceHandler handler = Mockito.mock(ServiceHandler.class);
-    helpGETTest(handler, "trippin/Airports('0')/IataCode", new TestResult() {
-      @Override
-      public void validate() throws Exception {
-        ArgumentCaptor<DataRequest> arg1 = ArgumentCaptor.forClass(DataRequest.class);
-        ArgumentCaptor<PropertyResponse> arg2 = ArgumentCaptor.forClass(PropertyResponse.class);
-        Mockito.verify(handler).read(arg1.capture(), arg2.capture());
-
-        DataRequest request = arg1.getValue();
-        assertEquals(true, request.isPropertyRequest());
-        assertEquals(false, request.isPropertyComplex());
-        assertEquals(1, request.getUriResourceEntitySet().getKeyPredicates().size());
-        assertEquals("application/json;odata.metadata=minimal", request.getResponseContentType()
-            .toContentTypeString());
-      }
-    });
-  }
-
-  @Test
-  public void testReadComplexProperty() throws Exception {
-    final ServiceHandler handler = Mockito.mock(ServiceHandler.class);
-    helpGETTest(handler, "trippin/Airports('0')/Location", new TestResult() {
-      @Override
-      public void validate() throws Exception {
-        ArgumentCaptor<DataRequest> arg1 = ArgumentCaptor.forClass(DataRequest.class);
-        ArgumentCaptor<PropertyResponse> arg2 = ArgumentCaptor.forClass(PropertyResponse.class);
-        Mockito.verify(handler).read(arg1.capture(), arg2.capture());
-
-        DataRequest request = arg1.getValue();
-        assertEquals(true, request.isPropertyRequest());
-        assertEquals(true, request.isPropertyComplex());
-        assertEquals(1, request.getUriResourceEntitySet().getKeyPredicates().size());
-        assertEquals("application/json;odata.metadata=minimal", request.getResponseContentType()
-            .toContentTypeString());
-      }
-    });
-  }
-
-  @Test
-  public void testReadProperty$Value() throws Exception {
-    final ServiceHandler handler = Mockito.mock(ServiceHandler.class);
-    helpGETTest(handler, "trippin/Airports('0')/IataCode/$value", new TestResult() {
-      @Override
-      public void validate() throws Exception {
-        ArgumentCaptor<DataRequest> arg1 = ArgumentCaptor.forClass(DataRequest.class);
-        ArgumentCaptor<PrimitiveValueResponse> arg2 = ArgumentCaptor
-            .forClass(PrimitiveValueResponse.class);
-        Mockito.verify(handler).read(arg1.capture(), arg2.capture());
-
-        DataRequest request = arg1.getValue();
-        assertEquals(true, request.isPropertyRequest());
-        assertEquals(false, request.isPropertyComplex());
-        assertEquals(1, request.getUriResourceEntitySet().getKeyPredicates().size());
-        assertEquals("text/plain", request.getResponseContentType().toContentTypeString());
-      }
-    });
-  }
-
-  @Test
-  public void testReadPropertyRef() throws Exception {
-    final ServiceHandler handler = Mockito.mock(ServiceHandler.class);
-    helpGETTest(handler, "trippin/Airports('0')/IataCode/$value", new TestResult() {
-      @Override
-      public void validate() throws Exception {
-        ArgumentCaptor<DataRequest> arg1 = ArgumentCaptor.forClass(DataRequest.class);
-        ArgumentCaptor<PrimitiveValueResponse> arg2 = ArgumentCaptor
-            .forClass(PrimitiveValueResponse.class);
-        Mockito.verify(handler).read(arg1.capture(), arg2.capture());
-
-        DataRequest request = arg1.getValue();
-        assertEquals(true, request.isPropertyRequest());
-        assertEquals(false, request.isPropertyComplex());
-        assertEquals(1, request.getUriResourceEntitySet().getKeyPredicates().size());
-        assertEquals("text/plain", request.getResponseContentType().toContentTypeString());
-      }
-    });
-  }
-
-  @Test
-  public void testFunctionImport() throws Exception {
-    final ServiceHandler handler = Mockito.mock(ServiceHandler.class);
-    helpGETTest(handler, "trippin/GetNearestAirport(lat=12.11,lon=34.23)", new TestResult()
{
-      @Override
-      public void validate() throws Exception {
-        ArgumentCaptor<FunctionRequest> arg1 = ArgumentCaptor.forClass(FunctionRequest.class);
-        ArgumentCaptor<PropertyResponse> arg3 = ArgumentCaptor.forClass(PropertyResponse.class);
-        ArgumentCaptor<HttpMethod> arg2 = ArgumentCaptor.forClass(HttpMethod.class);
-        Mockito.verify(handler).invoke(arg1.capture(), arg2.capture(), arg3.capture());
-
-        FunctionRequest request = arg1.getValue();
-      }
-    });
-  }
-
-  @Test
-  public void testActionImport() throws Exception {
-    final ServiceHandler handler = Mockito.mock(ServiceHandler.class);
-    helpTest(handler, "trippin/ResetDataSource", "POST", "", new TestResult() {
-      @Override
-      public void validate() throws Exception {
-        ArgumentCaptor<ActionRequest> arg1 = ArgumentCaptor.forClass(ActionRequest.class);
-        ArgumentCaptor<NoContentResponse> arg2 = ArgumentCaptor.forClass(NoContentResponse.class);
-        Mockito.verify(handler).invoke(arg1.capture(), Mockito.anyString(), arg2.capture());
-
-        ActionRequest request = arg1.getValue();
-      }
-    });
-  }
-
-  @Test
-  public void testReadMedia() throws Exception {
-    final ServiceHandler handler = Mockito.mock(ServiceHandler.class);
-    helpGETTest(handler, "trippin/Photos(1)/$value", new TestResult() {
-      @Override
-      public void validate() throws Exception {
-        ArgumentCaptor<MediaRequest> arg1 = ArgumentCaptor.forClass(MediaRequest.class);
-        ArgumentCaptor<StreamResponse> arg2 = ArgumentCaptor.forClass(StreamResponse.class);
-        Mockito.verify(handler).readMediaStream(arg1.capture(), arg2.capture());
-
-        MediaRequest request = arg1.getValue();
-        assertEquals("application/octet-stream", request.getResponseContentType()
-            .toContentTypeString());
-      }
-    });
-  }
-
-  @Test
-  public void testReadNavigation() throws Exception {
-    final ServiceHandler handler = Mockito.mock(ServiceHandler.class);
-    helpGETTest(handler, "trippin/People('russelwhyte')/Friends", new TestResult() {
-      @Override
-      public void validate() throws Exception {
-        ArgumentCaptor<DataRequest> arg1 = ArgumentCaptor.forClass(DataRequest.class);
-        ArgumentCaptor<EntitySetResponse> arg2 = ArgumentCaptor.forClass(EntitySetResponse.class);
-        Mockito.verify(handler).read(arg1.capture(), arg2.capture());
-
-        DataRequest request = arg1.getValue();
-        assertEquals("application/json;odata.metadata=minimal", request.getResponseContentType()
-            .toContentTypeString());
-      }
-    });
-  }
-
-  @Test
-  public void testReadReference() throws Exception {
-    final ServiceHandler handler = Mockito.mock(ServiceHandler.class);
-    helpGETTest(handler, "trippin/People('russelwhyte')/Friends/$ref", new TestResult() {
-      @Override
-      public void validate() throws Exception {
-        ArgumentCaptor<DataRequest> arg1 = ArgumentCaptor.forClass(DataRequest.class);
-        ArgumentCaptor<EntitySetResponse> arg2 = ArgumentCaptor.forClass(EntitySetResponse.class);
-        Mockito.verify(handler).read(arg1.capture(), arg2.capture());
-
-        DataRequest request = arg1.getValue();
-        assertEquals("application/json;odata.metadata=minimal", request.getResponseContentType()
-            .toContentTypeString());
-      }
-    });
-  }
-
-  @Test
-  public void testWriteReferenceCollection() throws Exception {
-    String payload = "{\n" + "\"@odata.id\": \"/Photos(11)\"\n" + "}";
-
-    final ServiceHandler handler = Mockito.mock(ServiceHandler.class);
-    helpTest(handler, "trippin/People('russelwhyte')/Friends/$ref", "POST", payload,
-        new TestResult() {
-          @Override
-          public void validate() throws Exception {
-            ArgumentCaptor<DataRequest> arg1 = ArgumentCaptor.forClass(DataRequest.class);
-            ArgumentCaptor<String> arg2 = ArgumentCaptor.forClass(String.class);
-            ArgumentCaptor<List> arg3 = ArgumentCaptor.forClass(List.class);
-            ArgumentCaptor<NoContentResponse> arg4 = ArgumentCaptor
-                .forClass(NoContentResponse.class);
-            Mockito.verify(handler).addReference(arg1.capture(), arg2.capture(), arg3.capture(),
-                arg4.capture());
-
-            DataRequest request = arg1.getValue();
-            assertEquals("application/json;odata.metadata=minimal", request
-                .getResponseContentType().toContentTypeString());
-          }
-        });
-  }
-
-  @Test
-  public void testWriteReference() throws Exception {
-    String payload = "{\n" + "\"@odata.id\": \"/Photos(11)\"\n" + "}";
-
-    final ServiceHandler handler = Mockito.mock(ServiceHandler.class);
-    helpTest(handler, "trippin/People('russelwhyte')/Friends('someone')/Photo/$ref", "PUT",
payload,
-        new TestResult() {
-          @Override
-          public void validate() throws Exception {
-            ArgumentCaptor<DataRequest> arg1 = ArgumentCaptor.forClass(DataRequest.class);
-            ArgumentCaptor<String> arg2 = ArgumentCaptor.forClass(String.class);
-            ArgumentCaptor<URI> arg3 = ArgumentCaptor.forClass(URI.class);
-            ArgumentCaptor<NoContentResponse> arg4 = ArgumentCaptor
-                .forClass(NoContentResponse.class);
-            Mockito.verify(handler).updateReference(arg1.capture(), arg2.capture(), arg3.capture(),
-                arg4.capture());
-
-            DataRequest request = arg1.getValue();
-            assertEquals("application/json;odata.metadata=minimal", request
-                .getResponseContentType().toContentTypeString());
-          }
-        });
-  }
+//  private Server server;
+//
+//  public class SampleODataServlet extends HttpServlet {
+//    private final ServiceHandler handler; // must be stateless
+//    private final EdmProvider provider; // must be stateless
+//
+//    public SampleODataServlet(ServiceHandler handler, EdmProvider provider) {
+//      this.handler = handler;
+//      this.provider = provider;
+//    }
+//
+//    @Override
+//    public void service(HttpServletRequest request, HttpServletResponse response)
+//        throws IOException {
+//      OData odata = OData4Impl.newInstance();
+//      ServiceMetadata metadata = odata.createServiceMetadata(this.provider, Collections.EMPTY_LIST);
+//
+//      ODataHttpHandler handler = odata.createHandler(metadata);
+//
+//      handler.register(this.handler);
+//      handler.process(request, response);
+//    }
+//  }
+//
+//  public int beforeTest(ServiceHandler serviceHandler) throws Exception {
+//    MetadataParser parser = new MetadataParser();
+//    EdmProvider edmProvider = parser.buildEdmProvider(new FileReader(
+//        "src/test/resources/trippin.xml"));
+//
+//    this.server = new Server();
+//
+//    ServerConnector connector = new ServerConnector(this.server);
+//    this.server.setConnectors(new Connector[] { connector });
+//
+//    ServletContextHandler context = new ServletContextHandler();
+//    context.setContextPath("/trippin");
+//    context
+//        .addServlet(new ServletHolder(new SampleODataServlet(serviceHandler, edmProvider)),
"/*");
+//    this.server.setHandler(context);
+//    this.server.start();
+//
+//    return connector.getLocalPort();
+//  }
+//
+//  public void afterTest() throws Exception {
+//    this.server.stop();
+//  }
+//
+//  interface TestResult {
+//    void validate() throws Exception;
+//  }
+//
+//  private void helpGETTest(ServiceHandler handler, String path, TestResult validator)
+//      throws Exception {
+//    int port = beforeTest(handler);
+//    HttpClient http = new HttpClient();
+//    http.start();
+//    http.GET("http://localhost:" + port + "/" + path);
+//    validator.validate();
+//    afterTest();
+//  }
+//
+//  private void helpTest(ServiceHandler handler, String path, String method, String payload,
+//      TestResult validator) throws Exception {
+//    int port = beforeTest(handler);
+//    HttpClient http = new HttpClient();
+//    http.start();
+//    String editUrl = "http://localhost:" + port + "/" + path;
+//    http.newRequest(editUrl).method(method)
+//        .header("Content-Type", "application/json;odata.metadata=minimal")
+//        .content(TripPinServiceTest.content(payload)).send();
+//    validator.validate();
+//    afterTest();
+//  }
+//
+//  @Test
+//  public void testMetadata() throws Exception {
+//    final ServiceHandler handler = Mockito.mock(ServiceHandler.class);
+//    helpGETTest(handler, "trippin/$metadata", new TestResult() {
+//      @Override
+//      public void validate() throws Exception {
+//        ArgumentCaptor<MetadataRequest> arg1 = ArgumentCaptor.forClass(MetadataRequest.class);
+//        ArgumentCaptor<MetadataResponse> arg2 = ArgumentCaptor.forClass(MetadataResponse.class);
+//        Mockito.verify(handler).readMetadata(arg1.capture(), arg2.capture());
+//      }
+//    });
+//  }
+//
+//  @Test
+//  public void testEntitySet() throws Exception {
+//    final ServiceHandler handler = Mockito.mock(ServiceHandler.class);
+//    helpGETTest(handler, "trippin/Airports", new TestResult() {
+//      @Override
+//      public void validate() throws Exception {
+//        ArgumentCaptor<DataRequest> arg1 = ArgumentCaptor.forClass(DataRequest.class);
+//        ArgumentCaptor<EntityResponse> arg2 = ArgumentCaptor.forClass(EntityResponse.class);
+//        Mockito.verify(handler).read(arg1.capture(), arg2.capture());
+//
+//        DataRequest request = arg1.getValue();
+//        // Need toString on ContextURL class
+//        // assertEquals("",
+//        // request.getContextURL(request.getOdata()).toString());
+//        assertEquals("application/json;odata.metadata=minimal", request.getResponseContentType()
+//            .toContentTypeString());
+//      }
+//    });
+//  }
+//
+//  @Test
+//  public void testEntitySetCount() throws Exception {
+//    final ServiceHandler handler = Mockito.mock(ServiceHandler.class);
+//    helpGETTest(handler, "trippin/Airports/$count", new TestResult() {
+//      @Override
+//      public void validate() throws Exception {
+//        ArgumentCaptor<DataRequest> arg1 = ArgumentCaptor.forClass(DataRequest.class);
+//        ArgumentCaptor<CountResponse> arg2 = ArgumentCaptor.forClass(CountResponse.class);
+//        Mockito.verify(handler).read(arg1.capture(), arg2.capture());
+//
+//        DataRequest request = arg1.getValue();
+//        // Need toString on ContextURL class
+//        // assertEquals("",
+//        // request.getContextURL(request.getOdata()).toString());
+//        assertEquals("text/plain", request.getResponseContentType().toContentTypeString());
+//      }
+//    });
+//  }
+//
+//  @Test
+//  public void testEntity() throws Exception {
+//    final ServiceHandler handler = Mockito.mock(ServiceHandler.class);
+//    helpGETTest(handler, "trippin/Airports('0')", new TestResult() {
+//      @Override
+//      public void validate() throws Exception {
+//        ArgumentCaptor<DataRequest> arg1 = ArgumentCaptor.forClass(DataRequest.class);
+//        ArgumentCaptor<EntityResponse> arg2 = ArgumentCaptor.forClass(EntityResponse.class);
+//        Mockito.verify(handler).read(arg1.capture(), arg2.capture());
+//
+//        DataRequest request = arg1.getValue();
+//        assertEquals(1, request.getUriResourceEntitySet().getKeyPredicates().size());
+//        assertEquals("application/json;odata.metadata=minimal", request.getResponseContentType()
+//            .toContentTypeString());
+//      }
+//    });
+//  }
+//
+//  @Test
+//  public void testReadProperty() throws Exception {
+//    final ServiceHandler handler = Mockito.mock(ServiceHandler.class);
+//    helpGETTest(handler, "trippin/Airports('0')/IataCode", new TestResult() {
+//      @Override
+//      public void validate() throws Exception {
+//        ArgumentCaptor<DataRequest> arg1 = ArgumentCaptor.forClass(DataRequest.class);
+//        ArgumentCaptor<PropertyResponse> arg2 = ArgumentCaptor.forClass(PropertyResponse.class);
+//        Mockito.verify(handler).read(arg1.capture(), arg2.capture());
+//
+//        DataRequest request = arg1.getValue();
+//        assertEquals(true, request.isPropertyRequest());
+//        assertEquals(false, request.isPropertyComplex());
+//        assertEquals(1, request.getUriResourceEntitySet().getKeyPredicates().size());
+//        assertEquals("application/json;odata.metadata=minimal", request.getResponseContentType()
+//            .toContentTypeString());
+//      }
+//    });
+//  }
+//
+//  @Test
+//  public void testReadComplexProperty() throws Exception {
+//    final ServiceHandler handler = Mockito.mock(ServiceHandler.class);
+//    helpGETTest(handler, "trippin/Airports('0')/Location", new TestResult() {
+//      @Override
+//      public void validate() throws Exception {
+//        ArgumentCaptor<DataRequest> arg1 = ArgumentCaptor.forClass(DataRequest.class);
+//        ArgumentCaptor<PropertyResponse> arg2 = ArgumentCaptor.forClass(PropertyResponse.class);
+//        Mockito.verify(handler).read(arg1.capture(), arg2.capture());
+//
+//        DataRequest request = arg1.getValue();
+//        assertEquals(true, request.isPropertyRequest());
+//        assertEquals(true, request.isPropertyComplex());
+//        assertEquals(1, request.getUriResourceEntitySet().getKeyPredicates().size());
+//        assertEquals("application/json;odata.metadata=minimal", request.getResponseContentType()
+//            .toContentTypeString());
+//      }
+//    });
+//  }
+//
+//  @Test
+//  public void testReadProperty$Value() throws Exception {
+//    final ServiceHandler handler = Mockito.mock(ServiceHandler.class);
+//    helpGETTest(handler, "trippin/Airports('0')/IataCode/$value", new TestResult() {
+//      @Override
+//      public void validate() throws Exception {
+//        ArgumentCaptor<DataRequest> arg1 = ArgumentCaptor.forClass(DataRequest.class);
+//        ArgumentCaptor<PrimitiveValueResponse> arg2 = ArgumentCaptor
+//            .forClass(PrimitiveValueResponse.class);
+//        Mockito.verify(handler).read(arg1.capture(), arg2.capture());
+//
+//        DataRequest request = arg1.getValue();
+//        assertEquals(true, request.isPropertyRequest());
+//        assertEquals(false, request.isPropertyComplex());
+//        assertEquals(1, request.getUriResourceEntitySet().getKeyPredicates().size());
+//        assertEquals("text/plain", request.getResponseContentType().toContentTypeString());
+//      }
+//    });
+//  }
+//
+//  @Test
+//  public void testReadPropertyRef() throws Exception {
+//    final ServiceHandler handler = Mockito.mock(ServiceHandler.class);
+//    helpGETTest(handler, "trippin/Airports('0')/IataCode/$value", new TestResult() {
+//      @Override
+//      public void validate() throws Exception {
+//        ArgumentCaptor<DataRequest> arg1 = ArgumentCaptor.forClass(DataRequest.class);
+//        ArgumentCaptor<PrimitiveValueResponse> arg2 = ArgumentCaptor
+//            .forClass(PrimitiveValueResponse.class);
+//        Mockito.verify(handler).read(arg1.capture(), arg2.capture());
+//
+//        DataRequest request = arg1.getValue();
+//        assertEquals(true, request.isPropertyRequest());
+//        assertEquals(false, request.isPropertyComplex());
+//        assertEquals(1, request.getUriResourceEntitySet().getKeyPredicates().size());
+//        assertEquals("text/plain", request.getResponseContentType().toContentTypeString());
+//      }
+//    });
+//  }
+//
+//  @Test
+//  public void testFunctionImport() throws Exception {
+//    final ServiceHandler handler = Mockito.mock(ServiceHandler.class);
+//    helpGETTest(handler, "trippin/GetNearestAirport(lat=12.11,lon=34.23)", new TestResult()
{
+//      @Override
+//      public void validate() throws Exception {
+//        ArgumentCaptor<FunctionRequest> arg1 = ArgumentCaptor.forClass(FunctionRequest.class);
+//        ArgumentCaptor<PropertyResponse> arg3 = ArgumentCaptor.forClass(PropertyResponse.class);
+//        ArgumentCaptor<HttpMethod> arg2 = ArgumentCaptor.forClass(HttpMethod.class);
+//        Mockito.verify(handler).invoke(arg1.capture(), arg2.capture(), arg3.capture());
+//
+//        FunctionRequest request = arg1.getValue();
+//      }
+//    });
+//  }
+//
+//  @Test
+//  public void testActionImport() throws Exception {
+//    final ServiceHandler handler = Mockito.mock(ServiceHandler.class);
+//    helpTest(handler, "trippin/ResetDataSource", "POST", "", new TestResult() {
+//      @Override
+//      public void validate() throws Exception {
+//        ArgumentCaptor<ActionRequest> arg1 = ArgumentCaptor.forClass(ActionRequest.class);
+//        ArgumentCaptor<NoContentResponse> arg2 = ArgumentCaptor.forClass(NoContentResponse.class);
+//        Mockito.verify(handler).invoke(arg1.capture(), Mockito.anyString(), arg2.capture());
+//
+//        ActionRequest request = arg1.getValue();
+//      }
+//    });
+//  }
+//
+//  @Test
+//  public void testReadMedia() throws Exception {
+//    final ServiceHandler handler = Mockito.mock(ServiceHandler.class);
+//    helpGETTest(handler, "trippin/Photos(1)/$value", new TestResult() {
+//      @Override
+//      public void validate() throws Exception {
+//        ArgumentCaptor<MediaRequest> arg1 = ArgumentCaptor.forClass(MediaRequest.class);
+//        ArgumentCaptor<StreamResponse> arg2 = ArgumentCaptor.forClass(StreamResponse.class);
+//        Mockito.verify(handler).readMediaStream(arg1.capture(), arg2.capture());
+//
+//        MediaRequest request = arg1.getValue();
+//        assertEquals("application/octet-stream", request.getResponseContentType()
+//            .toContentTypeString());
+//      }
+//    });
+//  }
+//
+//  @Test
+//  public void testReadNavigation() throws Exception {
+//    final ServiceHandler handler = Mockito.mock(ServiceHandler.class);
+//    helpGETTest(handler, "trippin/People('russelwhyte')/Friends", new TestResult() {
+//      @Override
+//      public void validate() throws Exception {
+//        ArgumentCaptor<DataRequest> arg1 = ArgumentCaptor.forClass(DataRequest.class);
+//        ArgumentCaptor<EntitySetResponse> arg2 = ArgumentCaptor.forClass(EntitySetResponse.class);
+//        Mockito.verify(handler).read(arg1.capture(), arg2.capture());
+//
+//        DataRequest request = arg1.getValue();
+//        assertEquals("application/json;odata.metadata=minimal", request.getResponseContentType()
+//            .toContentTypeString());
+//      }
+//    });
+//  }
+//
+//  @Test
+//  public void testReadReference() throws Exception {
+//    final ServiceHandler handler = Mockito.mock(ServiceHandler.class);
+//    helpGETTest(handler, "trippin/People('russelwhyte')/Friends/$ref", new TestResult()
{
+//      @Override
+//      public void validate() throws Exception {
+//        ArgumentCaptor<DataRequest> arg1 = ArgumentCaptor.forClass(DataRequest.class);
+//        ArgumentCaptor<EntitySetResponse> arg2 = ArgumentCaptor.forClass(EntitySetResponse.class);
+//        Mockito.verify(handler).read(arg1.capture(), arg2.capture());
+//
+//        DataRequest request = arg1.getValue();
+//        assertEquals("application/json;odata.metadata=minimal", request.getResponseContentType()
+//            .toContentTypeString());
+//      }
+//    });
+//  }
+//
+//  @Test
+//  public void testWriteReferenceCollection() throws Exception {
+//    String payload = "{\n" + "\"@odata.id\": \"/Photos(11)\"\n" + "}";
+//
+//    final ServiceHandler handler = Mockito.mock(ServiceHandler.class);
+//    helpTest(handler, "trippin/People('russelwhyte')/Friends/$ref", "POST", payload,
+//        new TestResult() {
+//          @Override
+//          public void validate() throws Exception {
+//            ArgumentCaptor<DataRequest> arg1 = ArgumentCaptor.forClass(DataRequest.class);
+//            ArgumentCaptor<String> arg2 = ArgumentCaptor.forClass(String.class);
+//            ArgumentCaptor<List> arg3 = ArgumentCaptor.forClass(List.class);
+//            ArgumentCaptor<NoContentResponse> arg4 = ArgumentCaptor
+//                .forClass(NoContentResponse.class);
+//            Mockito.verify(handler).addReference(arg1.capture(), arg2.capture(), arg3.capture(),
+//                arg4.capture());
+//
+//            DataRequest request = arg1.getValue();
+//            assertEquals("application/json;odata.metadata=minimal", request
+//                .getResponseContentType().toContentTypeString());
+//          }
+//        });
+//  }
+//
+//  @Test
+//  public void testWriteReference() throws Exception {
+//    String payload = "{\n" + "\"@odata.id\": \"/Photos(11)\"\n" + "}";
+//
+//    final ServiceHandler handler = Mockito.mock(ServiceHandler.class);
+//    helpTest(handler, "trippin/People('russelwhyte')/Friends('someone')/Photo/$ref", "PUT",
payload,
+//        new TestResult() {
+//          @Override
+//          public void validate() throws Exception {
+//            ArgumentCaptor<DataRequest> arg1 = ArgumentCaptor.forClass(DataRequest.class);
+//            ArgumentCaptor<String> arg2 = ArgumentCaptor.forClass(String.class);
+//            ArgumentCaptor<URI> arg3 = ArgumentCaptor.forClass(URI.class);
+//            ArgumentCaptor<NoContentResponse> arg4 = ArgumentCaptor
+//                .forClass(NoContentResponse.class);
+//            Mockito.verify(handler).updateReference(arg1.capture(), arg2.capture(), arg3.capture(),
+//                arg4.capture());
+//
+//            DataRequest request = arg1.getValue();
+//            assertEquals("application/json;odata.metadata=minimal", request
+//                .getResponseContentType().toContentTypeString());
+//          }
+//        });
+//  }
 }


Mime
View raw message