[OLINGO-573] Start replacement of Jetty with Tomcat
This commit is contained in:
parent
29e2833541
commit
b6da769ac8
|
@ -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>
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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());
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
7
pom.xml
7
pom.xml
|
@ -95,7 +95,9 @@
|
|||
<tomcat.servlet.port>9080</tomcat.servlet.port>
|
||||
<tomcat.version>7.0.55</tomcat.version>
|
||||
|
||||
<!-- Project build settings -->
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.build.source>1.6</project.build.source>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
|
@ -291,7 +293,6 @@
|
|||
</dependencyManagement>
|
||||
|
||||
<build>
|
||||
|
||||
<finalName>${project.name}-${project.version}</finalName>
|
||||
|
||||
<pluginManagement>
|
||||
|
@ -463,8 +464,8 @@
|
|||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>1.6</source>
|
||||
<target>1.6</target>
|
||||
<source>${project.build.source}</source>
|
||||
<target>${project.build.source}</target>
|
||||
<showWarnings>true</showWarnings>
|
||||
<showDeprecation>true</showDeprecation>
|
||||
<compilerArgument>-Xlint:unchecked</compilerArgument>
|
||||
|
|
Loading…
Reference in New Issue