[OLINGO-266] OData handler + service document test
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/181bd264 Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/181bd264 Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/181bd264 Branch: refs/heads/master Commit: 181bd2645466484c37cd742b0dd143b50f8d9717 Parents: 92ad342 Author: Stephan Klevenz <[email protected]> Authored: Thu May 15 13:05:03 2014 +0200 Committer: Stephan Klevenz <[email protected]> Committed: Mon May 19 14:27:04 2014 +0200 ---------------------------------------------------------------------- .../apache/olingo/server/core/ODataHandler.java | 6 +- .../apache/olingo/server/core/ODataRequest.java | 12 +--- .../olingo/server/core/ODataHandlerTest.java | 67 ++++++++++++++++++++ 3 files changed, 72 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/181bd264/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 1f7e3c4..da6baf7 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 @@ -27,8 +27,8 @@ import org.apache.olingo.server.api.serializer.ODataSerializer; public class ODataHandler { - private ODataServer server; - private Edm edm; + private final ODataServer server; + private final Edm edm; public ODataHandler(final ODataServer server, final Edm edm) { this.server = server; @@ -39,7 +39,7 @@ public class ODataHandler { ODataResponse response = new ODataResponse(); ODataSerializer serializer = server.createSerializer(ODataFormat.JSON); - InputStream responseEntity = serializer.serviceDocument(edm, "http//:root"); + InputStream responseEntity = serializer.serviceDocument(edm, "http://root"); response.setStatusCode(200); response.setHeader("Content-Type", "application/json"); http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/181bd264/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataRequest.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataRequest.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataRequest.java index 5d992a0..5499a79 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataRequest.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataRequest.java @@ -19,6 +19,7 @@ package org.apache.olingo.server.core; import java.io.InputStream; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -30,7 +31,6 @@ public class ODataRequest { private Map<String, List<String>> headers = new HashMap<String, List<String>>(); private InputStream body; private Map<String, String> queryParameters; - private String contentType; public HttpMethod getMethod() { return method; @@ -41,7 +41,7 @@ public class ODataRequest { } public Map<String, List<String>> getHeaders() { - return headers; + return Collections.unmodifiableMap(headers); } public void setHeaders(final Map<String, List<String>> headers) { @@ -63,12 +63,4 @@ public class ODataRequest { public void setQueryParameters(final Map<String, String> queryParameters) { this.queryParameters = queryParameters; } - - public String getContentType() { - return contentType; - } - - public void setContentType(final String contentType) { - this.contentType = contentType; - } } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/181bd264/lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerTest.java ---------------------------------------------------------------------- diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerTest.java new file mode 100644 index 0000000..aa472c4 --- /dev/null +++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerTest.java @@ -0,0 +1,67 @@ +/* + * 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; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import org.apache.commons.io.IOUtils; +import org.apache.olingo.commons.api.edm.Edm; +import org.apache.olingo.commons.api.http.HttpMethod; +import org.apache.olingo.server.api.ODataServer; +import org.apache.olingo.server.tecsvc.provider.EdmTechProvider; +import org.junit.Before; +import org.junit.Test; + +public class ODataHandlerTest { + + private ODataHandler handler; + + @Before + public void before() { + ODataServer server = ODataServer.newInstance(); + Edm edm = server.createEdm(new EdmTechProvider()); + + handler = new ODataHandler(server, edm); + } + + @Test + public void testServiceDocumentDefault() throws Exception { + ODataRequest request = new ODataRequest(); + + request.setMethod(HttpMethod.GET); + + ODataResponse response = handler.process(request); + + assertNotNull(response); + assertEquals(200, response.getStatusCode()); + assertEquals("application/json", response.getHeaders().get("Content-Type")); + + + assertNotNull(response.getContent()); + String doc = IOUtils.toString(response.getContent()); + + assertTrue(doc.contains("\"@odata.context\" : \"http://root/$metadata\"")); + assertTrue(doc.contains("\"value\" :")); + + // TODO + } + +}
