You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by tb...@apache.org on 2014/01/02 13:46:53 UTC
[06/47] git commit: [OLINGO-87] Create base test classes and service
document test
[OLINGO-87] Create base test classes and service document test
Project: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/commit/78da059d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/78da059d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/78da059d
Branch: refs/heads/ODataServlet
Commit: 78da059d588a2d7fdae9b280ed5a6a7f1f324b0a
Parents: d9a7f2d
Author: Michael Bolz <mi...@apache.org>
Authored: Mon Dec 23 11:01:58 2013 +0100
Committer: Michael Bolz <mi...@apache.org>
Committed: Mon Dec 23 13:28:15 2013 +0100
----------------------------------------------------------------------
.../annotation-processor-webref/pom.xml | 6 +
.../processor/ref/AbstractRefTest.java | 195 +++++++++++++++++++
.../processor/ref/AbstractRefXmlTest.java | 89 +++++++++
.../processor/ref/ServiceJsonTest.java | 71 +++++++
.../processor/ref/ServiceXmlTest.java | 123 ++++++++++++
5 files changed, 484 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/78da059d/odata2-annotation-processor/annotation-processor-webref/pom.xml
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-webref/pom.xml b/odata2-annotation-processor/annotation-processor-webref/pom.xml
index 9f31106..a6cc569 100644
--- a/odata2-annotation-processor/annotation-processor-webref/pom.xml
+++ b/odata2-annotation-processor/annotation-processor-webref/pom.xml
@@ -98,6 +98,12 @@ the License. -->
<artifactId>slf4j-log4j12</artifactId>
<version>${version.slf4j}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>olingo-odata2-testutil-incubating</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<profiles>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/78da059d/odata2-annotation-processor/annotation-processor-webref/src/test/java/org/apache/olingo/odata2/annotation/processor/ref/AbstractRefTest.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-webref/src/test/java/org/apache/olingo/odata2/annotation/processor/ref/AbstractRefTest.java b/odata2-annotation-processor/annotation-processor-webref/src/test/java/org/apache/olingo/odata2/annotation/processor/ref/AbstractRefTest.java
new file mode 100644
index 0000000..6ddbff4
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-webref/src/test/java/org/apache/olingo/odata2/annotation/processor/ref/AbstractRefTest.java
@@ -0,0 +1,195 @@
+/*******************************************************************************
+ * 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.odata2.annotation.processor.ref;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.net.URI;
+
+import org.apache.http.HttpEntityEnclosingRequest;
+import org.apache.http.HttpHeaders;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.methods.HttpDelete;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPatch;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.methods.HttpPut;
+import org.apache.http.client.methods.HttpRequestBase;
+import org.apache.http.entity.StringEntity;
+import org.apache.olingo.odata2.annotation.processor.api.AnnotationServiceFactory;
+import org.apache.olingo.odata2.api.ODataService;
+import org.apache.olingo.odata2.api.commons.HttpStatusCodes;
+import org.apache.olingo.odata2.api.commons.ODataHttpMethod;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.testutil.fit.AbstractFitTest;
+import org.apache.olingo.odata2.testutil.helper.StringHelper;
+
+/**
+ * Abstract base class for tests employing the reference scenario.
+ *
+ */
+public class AbstractRefTest extends AbstractFitTest {
+
+ protected static final String IMAGE_JPEG = "image/jpeg";
+ protected static final String IMAGE_GIF = "image/gif";
+
+ final static String MODEL_PACKAGE = "org.apache.olingo.odata2.annotation.processor.ref.model";
+
+ @Override
+ protected ODataService createService() throws ODataException {
+ return AnnotationServiceFactory.createAnnotationService(MODEL_PACKAGE);
+ }
+
+ protected HttpResponse callUri(
+ final ODataHttpMethod httpMethod, final String uri,
+ final String additionalHeader, final String additionalHeaderValue,
+ final String requestBody, final String requestContentType,
+ final HttpStatusCodes expectedStatusCode) throws Exception {
+
+ HttpRequestBase request =
+ httpMethod == ODataHttpMethod.GET ? new HttpGet() :
+ httpMethod == ODataHttpMethod.DELETE ? new HttpDelete() :
+ httpMethod == ODataHttpMethod.POST ? new HttpPost() :
+ httpMethod == ODataHttpMethod.PUT ? new HttpPut() : new HttpPatch();
+ request.setURI(URI.create(getEndpoint() + uri));
+ if (additionalHeader != null) {
+ request.addHeader(additionalHeader, additionalHeaderValue);
+ }
+ if (requestBody != null) {
+ ((HttpEntityEnclosingRequest) request).setEntity(new StringEntity(requestBody));
+ request.setHeader(HttpHeaders.CONTENT_TYPE, requestContentType);
+ }
+
+ final HttpResponse response = getHttpClient().execute(request);
+
+ assertNotNull(response);
+ assertEquals(expectedStatusCode.getStatusCode(), response.getStatusLine().getStatusCode());
+
+ if (expectedStatusCode == HttpStatusCodes.OK) {
+ assertNotNull(response.getEntity());
+ assertNotNull(response.getEntity().getContent());
+ } else if (expectedStatusCode == HttpStatusCodes.CREATED) {
+ assertNotNull(response.getEntity());
+ assertNotNull(response.getEntity().getContent());
+ assertNotNull(response.getFirstHeader(HttpHeaders.LOCATION));
+ } else if (expectedStatusCode == HttpStatusCodes.NO_CONTENT) {
+ assertTrue(response.getEntity() == null || response.getEntity().getContent() == null);
+ }
+
+ return response;
+ }
+
+ protected HttpResponse callUri(final String uri, final String additionalHeader, final String additionalHeaderValue,
+ final HttpStatusCodes expectedStatusCode) throws Exception {
+ return callUri(ODataHttpMethod.GET, uri, additionalHeader, additionalHeaderValue, null, null, expectedStatusCode);
+ }
+
+ protected HttpResponse callUri(final String uri, final String additionalHeader, final String additionalHeaderValue)
+ throws Exception {
+ return callUri(ODataHttpMethod.GET, uri, additionalHeader, additionalHeaderValue, null, null, HttpStatusCodes.OK);
+ }
+
+ protected HttpResponse callUri(final String uri, final HttpStatusCodes expectedStatusCode) throws Exception {
+ return callUri(uri, null, null, expectedStatusCode);
+ }
+
+ protected HttpResponse callUri(final String uri) throws Exception {
+ return callUri(uri, HttpStatusCodes.OK);
+ }
+
+ protected void checkUri(final String uri) throws Exception {
+ assertNotNull(getBody(callUri(uri)));
+ }
+
+ protected void badRequest(final String uri) throws Exception {
+ final HttpResponse response = callUri(uri, HttpStatusCodes.BAD_REQUEST);
+ assertNotNull(getBody(response));
+ }
+
+ protected void notFound(final String uri) throws Exception {
+ final HttpResponse response = callUri(uri, HttpStatusCodes.NOT_FOUND);
+ assertNotNull(getBody(response));
+ }
+
+ protected void deleteUri(final String uri, final HttpStatusCodes expectedStatusCode)
+ throws Exception, AssertionError {
+ final HttpResponse response = callUri(ODataHttpMethod.DELETE, uri, null, null, null, null, expectedStatusCode);
+ if (expectedStatusCode != HttpStatusCodes.NO_CONTENT) {
+ response.getEntity().getContent().close();
+ }
+ }
+
+ protected void deleteUriOk(final String uri) throws Exception {
+ deleteUri(uri, HttpStatusCodes.NO_CONTENT);
+ }
+
+ protected HttpResponse postUri(final String uri, final String requestBody, final String requestContentType,
+ final HttpStatusCodes expectedStatusCode) throws Exception {
+ return callUri(ODataHttpMethod.POST, uri, null, null, requestBody, requestContentType, expectedStatusCode);
+ }
+
+ protected HttpResponse postUri(final String uri, final String requestBody, final String requestContentType,
+ final String additionalHeader, final String additionalHeaderValue, final HttpStatusCodes expectedStatusCode)
+ throws Exception {
+ return callUri(ODataHttpMethod.POST, uri, additionalHeader, additionalHeaderValue, requestBody, requestContentType,
+ expectedStatusCode);
+ }
+
+ protected void putUri(final String uri,
+ final String requestBody, final String requestContentType,
+ final HttpStatusCodes expectedStatusCode) throws Exception {
+ final HttpResponse response =
+ callUri(ODataHttpMethod.PUT, uri, null, null, requestBody, requestContentType, expectedStatusCode);
+ if (expectedStatusCode != HttpStatusCodes.NO_CONTENT) {
+ response.getEntity().getContent().close();
+ }
+ }
+
+ protected void putUri(final String uri, final String acceptHeader,
+ final String requestBody, final String requestContentType,
+ final HttpStatusCodes expectedStatusCode) throws Exception {
+ final HttpResponse response =
+ callUri(ODataHttpMethod.PUT, uri,
+ org.apache.olingo.odata2.api.commons.HttpHeaders.ACCEPT, acceptHeader, requestBody, requestContentType,
+ expectedStatusCode);
+ if (expectedStatusCode != HttpStatusCodes.NO_CONTENT) {
+ response.getEntity().getContent().close();
+ }
+ }
+
+ protected String getBody(final HttpResponse response) throws Exception {
+ assertNotNull(response);
+ assertNotNull(response.getEntity());
+ assertNotNull(response.getEntity().getContent());
+ return StringHelper.inputStreamToString(response.getEntity().getContent());
+ }
+
+ protected void checkMediaType(final HttpResponse response, final String expectedMediaType) {
+ assertEquals(expectedMediaType, response.getFirstHeader(HttpHeaders.CONTENT_TYPE).getValue());
+ }
+
+ protected void checkEtag(final HttpResponse response, final String expectedEtag) {
+ assertNotNull(response.getFirstHeader(HttpHeaders.ETAG));
+ final String entityTag = response.getFirstHeader(HttpHeaders.ETAG).getValue();
+ assertNotNull(entityTag);
+ assertEquals(expectedEtag, entityTag);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/78da059d/odata2-annotation-processor/annotation-processor-webref/src/test/java/org/apache/olingo/odata2/annotation/processor/ref/AbstractRefXmlTest.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-webref/src/test/java/org/apache/olingo/odata2/annotation/processor/ref/AbstractRefXmlTest.java b/odata2-annotation-processor/annotation-processor-webref/src/test/java/org/apache/olingo/odata2/annotation/processor/ref/AbstractRefXmlTest.java
new file mode 100644
index 0000000..aefd16b
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-webref/src/test/java/org/apache/olingo/odata2/annotation/processor/ref/AbstractRefXmlTest.java
@@ -0,0 +1,89 @@
+/*******************************************************************************
+ * 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.odata2.annotation.processor.ref;
+
+import static org.custommonkey.xmlunit.XMLAssert.assertXpathExists;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.http.HttpResponse;
+import org.apache.olingo.odata2.api.commons.HttpStatusCodes;
+import org.apache.olingo.odata2.api.edm.Edm;
+import org.custommonkey.xmlunit.SimpleNamespaceContext;
+import org.custommonkey.xmlunit.XMLUnit;
+import org.custommonkey.xmlunit.exceptions.XpathException;
+import org.junit.Before;
+import org.xml.sax.SAXException;
+
+/**
+ * Abstract base class for tests employing the reference scenario reading or writing XML.
+ *
+ */
+public class AbstractRefXmlTest extends AbstractRefTest {
+ @Before
+ public void setXmlNamespacePrefixes() {
+ Map<String, String> prefixMap = new HashMap<String, String>();
+ prefixMap.put(Edm.PREFIX_ATOM, Edm.NAMESPACE_ATOM_2005);
+ prefixMap.put(Edm.PREFIX_APP, Edm.NAMESPACE_APP_2007);
+ prefixMap.put(Edm.PREFIX_D, Edm.NAMESPACE_D_2007_08);
+ prefixMap.put(Edm.PREFIX_M, Edm.NAMESPACE_M_2007_08);
+ prefixMap.put(Edm.PREFIX_EDM, Edm.NAMESPACE_EDM_2008_09);
+ prefixMap.put(Edm.PREFIX_EDMX, Edm.NAMESPACE_EDMX_2007_06);
+ prefixMap.put(Edm.PREFIX_XML, Edm.NAMESPACE_XML_1998);
+ XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(prefixMap));
+ }
+
+ @Override
+ protected void badRequest(final String uri) throws Exception {
+ final HttpResponse response = callUri(uri, HttpStatusCodes.BAD_REQUEST);
+ validateXmlError(getBody(response));
+ }
+
+ @Override
+ protected void notFound(final String uri) throws Exception {
+ final HttpResponse response = callUri(uri, HttpStatusCodes.NOT_FOUND);
+ validateXmlError(getBody(response));
+ }
+
+ protected void validateXmlError(final String xml) throws XpathException, IOException, SAXException {
+ assertXpathExists("/m:error", xml);
+ assertXpathExists("/m:error/m:code", xml);
+ assertXpathExists("/m:error/m:message[@xml:lang=\"en\"]", xml);
+ }
+
+ protected String readFile(final String filename) throws IOException {
+ InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(filename);
+ if (in == null) {
+ throw new IOException("Requested file '" + filename + "' was not found.");
+ }
+
+ byte[] tmp = new byte[8192];
+ int count = in.read(tmp);
+ StringBuffer b = new StringBuffer();
+ while (count >= 0) {
+ b.append(new String(tmp, 0, count));
+ count = in.read(tmp);
+ }
+
+ return b.toString();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/78da059d/odata2-annotation-processor/annotation-processor-webref/src/test/java/org/apache/olingo/odata2/annotation/processor/ref/ServiceJsonTest.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-webref/src/test/java/org/apache/olingo/odata2/annotation/processor/ref/ServiceJsonTest.java b/odata2-annotation-processor/annotation-processor-webref/src/test/java/org/apache/olingo/odata2/annotation/processor/ref/ServiceJsonTest.java
new file mode 100644
index 0000000..9c0a049
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-webref/src/test/java/org/apache/olingo/odata2/annotation/processor/ref/ServiceJsonTest.java
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * 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.odata2.annotation.processor.ref;
+
+import static org.custommonkey.xmlunit.XMLAssert.assertXpathExists;
+import static org.junit.Assert.assertEquals;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.http.HttpResponse;
+import org.apache.olingo.odata2.api.commons.HttpContentType;
+import org.apache.olingo.odata2.api.commons.HttpHeaders;
+import org.apache.olingo.odata2.api.commons.HttpStatusCodes;
+import org.apache.olingo.odata2.api.edm.Edm;
+import org.custommonkey.xmlunit.SimpleNamespaceContext;
+import org.custommonkey.xmlunit.XMLUnit;
+import org.junit.Test;
+
+/**
+ * Tests employing the reference scenario reading the service document in JSON format.
+ *
+ */
+public class ServiceJsonTest extends AbstractRefTest {
+ @Test
+ public void serviceDocumentDollarFormatJson() throws Exception {
+ final HttpResponse response = callUri("?$format=json");
+ // checkMediaType(response, HttpContentType.APPLICATION_JSON);
+ assertEquals("{\"d\":{\"EntitySets\":["
+ + "\"Buildings\",\"Employees\",\"Managers\",\"Photos\",\"Rooms\",\"Teams\"]}}",
+ getBody(response));
+ }
+
+ @Test
+ public void serviceDocumentAcceptHeaderJson() throws Exception {
+ final HttpResponse response = callUri("", HttpHeaders.ACCEPT, HttpContentType.APPLICATION_JSON);
+ assertEquals("{\"d\":{\"EntitySets\":["
+ + "\"Buildings\",\"Employees\",\"Managers\",\"Photos\",\"Rooms\",\"Teams\"]}}",
+ getBody(response));
+ }
+
+ @Test
+ public void serviceDocumentAcceptHeaderInvalidCharset() throws Exception {
+ final HttpResponse response =
+ callUri("", HttpHeaders.ACCEPT, HttpContentType.APPLICATION_XML + "; charset=iso-latin-1",
+ HttpStatusCodes.NOT_ACCEPTABLE);
+ final String body = getBody(response);
+ Map<String, String> prefixMap = new HashMap<String, String>();
+ prefixMap.put("a", Edm.NAMESPACE_M_2007_08);
+ XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(prefixMap));
+ assertXpathExists("/a:error", body);
+ assertXpathExists("/a:error/a:code", body);
+ assertXpathExists("/a:error/a:message", body);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/78da059d/odata2-annotation-processor/annotation-processor-webref/src/test/java/org/apache/olingo/odata2/annotation/processor/ref/ServiceXmlTest.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-webref/src/test/java/org/apache/olingo/odata2/annotation/processor/ref/ServiceXmlTest.java b/odata2-annotation-processor/annotation-processor-webref/src/test/java/org/apache/olingo/odata2/annotation/processor/ref/ServiceXmlTest.java
new file mode 100644
index 0000000..4d49883
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-webref/src/test/java/org/apache/olingo/odata2/annotation/processor/ref/ServiceXmlTest.java
@@ -0,0 +1,123 @@
+/*******************************************************************************
+ * 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.odata2.annotation.processor.ref;
+
+import static org.custommonkey.xmlunit.XMLAssert.assertXpathEvaluatesTo;
+import static org.custommonkey.xmlunit.XMLAssert.assertXpathExists;
+
+import java.io.IOException;
+
+import org.apache.http.HttpResponse;
+import org.apache.olingo.odata2.api.commons.HttpContentType;
+import org.apache.olingo.odata2.api.commons.HttpHeaders;
+import org.apache.olingo.odata2.api.commons.HttpStatusCodes;
+import org.custommonkey.xmlunit.exceptions.XpathException;
+import org.junit.Test;
+import org.xml.sax.SAXException;
+
+/**
+ * Tests employing the reference scenario reading the service document in XML format
+ */
+public class ServiceXmlTest extends AbstractRefXmlTest {
+
+ @Test
+ public void serviceDocument() throws Exception {
+ final HttpResponse response = callUri("/");
+ checkMediaType(response, HttpContentType.APPLICATION_ATOM_SVC_UTF8);
+ final String body = getBody(response);
+
+ assertXpathEvaluatesTo("Employees", "/app:service/app:workspace/app:collection[@href=\"Employees\"]", body);
+ assertXpathEvaluatesTo("Teams", "/app:service/app:workspace/app:collection[@href=\"Teams\"]", body);
+ assertXpathEvaluatesTo("Rooms", "/app:service/app:workspace/app:collection[@href=\"Rooms\"]", body);
+ assertXpathEvaluatesTo("Managers", "/app:service/app:workspace/app:collection[@href=\"Managers\"]", body);
+ assertXpathEvaluatesTo("Buildings", "/app:service/app:workspace/app:collection[@href=\"Buildings\"]", body);
+ assertXpathEvaluatesTo("Photos", "/app:service/app:workspace/app:collection[@href=\"Photos\"]", body);
+
+ notFound("invalid.svc");
+ }
+
+ @Test
+ public void serviceDocumentDefault() throws Exception {
+ final HttpResponse response = callUri("");
+ checkMediaType(response, HttpContentType.APPLICATION_ATOM_SVC_UTF8);
+ validateXmlServiceDocument(getBody(response));
+ }
+
+ @Test
+ public void serviceDocumentDollarFormatAtom() throws Exception {
+ HttpResponse response = callUri("?$format=atom");
+ checkMediaType(response, HttpContentType.APPLICATION_ATOM_SVC_UTF8);
+ validateXmlServiceDocument(getBody(response));
+ }
+
+ @Test
+ public void serviceDocumentDollarFormatXml() throws Exception {
+ HttpResponse response = callUri("?$format=xml");
+ checkMediaType(response, HttpContentType.APPLICATION_XML_UTF8);
+ validateXmlServiceDocument(getBody(response));
+ }
+
+ @Test
+ public void serviceDocumentAcceptHeaderAtom() throws Exception {
+ final HttpResponse response =
+ callUri("", HttpHeaders.ACCEPT, HttpContentType.APPLICATION_ATOM_XML, HttpStatusCodes.NOT_ACCEPTABLE);
+ checkMediaType(response, HttpContentType.APPLICATION_XML);
+ validateXmlError(getBody(response));
+ }
+
+ @Test
+ public void serviceDocumentAcceptHeaderUtf8Atom() throws Exception {
+ final HttpResponse response =
+ callUri("", HttpHeaders.ACCEPT, HttpContentType.APPLICATION_ATOM_XML_UTF8, HttpStatusCodes.NOT_ACCEPTABLE);
+ checkMediaType(response, HttpContentType.APPLICATION_XML);
+ validateXmlError(getBody(response));
+ }
+
+ @Test
+ public void serviceDocumentAcceptHeaderXml() throws Exception {
+ HttpResponse response = callUri("", HttpHeaders.ACCEPT, HttpContentType.APPLICATION_XML);
+ checkMediaType(response, HttpContentType.APPLICATION_XML_UTF8);
+ validateXmlServiceDocument(getBody(response));
+ }
+
+ @Test
+ public void serviceDocumentAcceptHeaderUtf8Xml() throws Exception {
+ HttpResponse response = callUri("", HttpHeaders.ACCEPT, HttpContentType.APPLICATION_XML_UTF8);
+ checkMediaType(response, HttpContentType.APPLICATION_XML_UTF8);
+ validateXmlServiceDocument(getBody(response));
+ }
+
+ private void validateXmlServiceDocument(final String payload) throws IOException, SAXException, XpathException {
+ assertXpathExists("/app:service", payload);
+ assertXpathExists("/app:service/app:workspace", payload);
+ assertXpathExists("/app:service/app:workspace/atom:title", payload);
+ assertXpathExists("/app:service/app:workspace/app:collection[@href=\"Employees\"]", payload);
+ assertXpathExists("/app:service/app:workspace/app:collection[@href=\"Employees\"]/atom:title", payload);
+ assertXpathExists("/app:service/app:workspace/app:collection[@href=\"Teams\"]", payload);
+ assertXpathExists("/app:service/app:workspace/app:collection[@href=\"Teams\"]/atom:title", payload);
+ assertXpathExists("/app:service/app:workspace/app:collection[@href=\"Rooms\"]", payload);
+ assertXpathExists("/app:service/app:workspace/app:collection[@href=\"Rooms\"]/atom:title", payload);
+ assertXpathExists("/app:service/app:workspace/app:collection[@href=\"Managers\"]", payload);
+ assertXpathExists("/app:service/app:workspace/app:collection[@href=\"Managers\"]/atom:title", payload);
+ assertXpathExists("/app:service/app:workspace/app:collection[@href=\"Buildings\"]", payload);
+ assertXpathExists("/app:service/app:workspace/app:collection[@href=\"Buildings\"]/atom:title", payload);
+ assertXpathExists("/app:service/app:workspace/app:collection[@href=\"Photos\"]", payload);
+ assertXpathExists("/app:service/app:workspace/app:collection[@href=\"Photos\"]/atom:title", payload);
+ }
+}