You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by mi...@apache.org on 2013/09/10 19:04:11 UTC
[2/2] git commit: Refactoring for OLINGO-15 (ATOM/XML-Part)
Refactoring for OLINGO-15 (ATOM/XML-Part)
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/060f9c65
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/060f9c65
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/060f9c65
Branch: refs/heads/master
Commit: 060f9c6569eab280f60a3e67300422a48c1a432d
Parents: ce78a0b
Author: Michael Bolz <mi...@apache.org>
Authored: Tue Sep 10 16:08:33 2013 +0200
Committer: Michael Bolz <mi...@apache.org>
Committed: Tue Sep 10 18:55:58 2013 +0200
----------------------------------------------------------------------
.../olingo/odata2/core/ODataRequestHandler.java | 35 +++++++++++--
.../olingo/odata2/core/commons/ContentType.java | 5 +-
.../odata2/core/ep/AtomEntityProvider.java | 29 +++--------
.../odata2/core/ep/ProviderFacadeImplTest.java | 2 +-
.../core/ep/producer/AtomEntryProducerTest.java | 5 +-
.../core/ep/producer/AtomFeedProducerTest.java | 5 +-
.../core/ep/producer/XmlErrorProducerTest.java | 3 +-
.../core/ep/producer/XmlExpandProducerTest.java | 5 +-
.../core/ep/producer/XmlFunctionImportTest.java | 13 +++--
.../ep/producer/XmlLinkEntityProducerTest.java | 5 +-
.../ep/producer/XmlLinksEntityProducerTest.java | 5 +-
.../ep/producer/XmlPropertyProducerTest.java | 20 ++++---
.../core/ep/producer/XmlSelectProducerTest.java | 5 +-
.../odata2/fit/ref/EntryXmlChangeTest.java | 55 +++++++++++++++++++-
14 files changed, 125 insertions(+), 67 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/060f9c65/odata-core/src/main/java/org/apache/olingo/odata2/core/ODataRequestHandler.java
----------------------------------------------------------------------
diff --git a/odata-core/src/main/java/org/apache/olingo/odata2/core/ODataRequestHandler.java b/odata-core/src/main/java/org/apache/olingo/odata2/core/ODataRequestHandler.java
index 7a375d9..cf09bb3 100644
--- a/odata-core/src/main/java/org/apache/olingo/odata2/core/ODataRequestHandler.java
+++ b/odata-core/src/main/java/org/apache/olingo/odata2/core/ODataRequestHandler.java
@@ -19,6 +19,7 @@
package org.apache.olingo.odata2.core;
import java.util.Arrays;
+import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -119,7 +120,7 @@ public class ODataRequestHandler {
extendedResponse = extendedResponse.header(ODataHttpHeaders.DATASERVICEVERSION, serverDataServiceVersion);
}
if(!odataResponse.containsHeader("Content-Type")) {
- extendedResponse.header(HttpHeaders.CONTENT_TYPE, acceptContentType);
+ setContentType(extendedResponse, acceptContentType, method, uriInfo.getUriType());
}
final UriType uriType = uriInfo.getUriType();
@@ -127,9 +128,7 @@ public class ODataRequestHandler {
final HttpStatusCodes s = odataResponse.getStatus() == null ? method == ODataHttpMethod.POST ? uriType == UriType.URI9 ? HttpStatusCodes.OK : uriType == UriType.URI7B ? HttpStatusCodes.NO_CONTENT : HttpStatusCodes.CREATED : method == ODataHttpMethod.PUT || method == ODataHttpMethod.PATCH || method == ODataHttpMethod.MERGE || method == ODataHttpMethod.DELETE ? HttpStatusCodes.NO_CONTENT : HttpStatusCodes.OK : odataResponse.getStatus();
extendedResponse = extendedResponse.idLiteral(location).status(s);
-
odataResponse = extendedResponse.build();
-
} catch (final Exception e) {
exception = e;
odataResponse = new ODataExceptionWrapper(context, request.getQueryParameters(), request.getAcceptHeaders()).wrapInExceptionResponse(e);
@@ -140,6 +139,24 @@ public class ODataRequestHandler {
return debugValue == null ? odataResponse : new ODataDebugResponseWrapper(context, odataResponse, uriInfo, exception, debugValue).wrapResponse();
}
+ private void setContentType(ODataResponseBuilder extendedResponse, String acceptContentType, ODataHttpMethod method, UriType uriType) {
+ ContentType contentType = ContentType.parse(acceptContentType);
+ if(contentType != null && contentType.getODataFormat() == ODataFormat.ATOM) {
+ if(uriType == UriType.URI1 || uriType == UriType.URI6B) {
+ if(ODataHttpMethod.GET.equals(method)) {
+ contentType = ContentType.create(contentType, ContentType.PARAMETER_TYPE, "feed");
+ } else {
+ contentType = ContentType.create(contentType, ContentType.PARAMETER_TYPE, "entry");
+ }
+ } else if(uriType == UriType.URI2 || uriType == UriType.URI6A) {
+ contentType = ContentType.create(contentType, ContentType.PARAMETER_TYPE, "entry");
+ }
+ extendedResponse.header(HttpHeaders.CONTENT_TYPE, contentType.toContentTypeString());
+ } else {
+ extendedResponse.header(HttpHeaders.CONTENT_TYPE, acceptContentType);
+ }
+ }
+
/**
* Do the content negotiation based on requested content type (in HTTP accept header) and from {@link ODataService}
* supported content types (via {@link ODataService#getSupportedContentTypes(Class)}).
@@ -152,11 +169,21 @@ public class ODataRequestHandler {
private String doContentNegotiation(final ODataRequest request, UriInfoImpl uriInfo) throws ODataException {
if(uriInfo.isCount() || uriInfo.isValue()) {
return request.getRequestHeaderValue("Accept");
+ } else if(ODataHttpMethod.POST.equals(request.getMethod()) &&
+ (uriInfo.getUriType() == UriType.URI1 || uriInfo.getUriType() == UriType.URI6B)) {
+
+ List<String> supportedContentTypes = new LinkedList<String>(getSupportedContentTypes(uriInfo));
+ supportedContentTypes.add(0, ContentType.APPLICATION_ATOM_XML_ENTRY_CS_UTF_8.toContentTypeString());
+ supportedContentTypes.add(1, ContentType.APPLICATION_ATOM_XML_ENTRY.toContentTypeString());
+ supportedContentTypes.remove(ContentType.APPLICATION_ATOM_XML_FEED.toContentTypeString());
+ supportedContentTypes.remove(ContentType.APPLICATION_ATOM_XML_FEED_CS_UTF_8.toContentTypeString());
+
+ return new ContentNegotiator().doContentNegotiation(uriInfo, request.getAcceptHeaders(), supportedContentTypes);
} else {
return new ContentNegotiator().doContentNegotiation(uriInfo, request.getAcceptHeaders(), getSupportedContentTypes(uriInfo));
}
}
-
+
private String getServerDataServiceVersion() throws ODataException {
return service.getVersion() == null ? ODataServiceVersion.V20 : service.getVersion();
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/060f9c65/odata-core/src/main/java/org/apache/olingo/odata2/core/commons/ContentType.java
----------------------------------------------------------------------
diff --git a/odata-core/src/main/java/org/apache/olingo/odata2/core/commons/ContentType.java b/odata-core/src/main/java/org/apache/olingo/odata2/core/commons/ContentType.java
index a1499f8..80ab262 100644
--- a/odata-core/src/main/java/org/apache/olingo/odata2/core/commons/ContentType.java
+++ b/odata-core/src/main/java/org/apache/olingo/odata2/core/commons/ContentType.java
@@ -96,6 +96,7 @@ public class ContentType {
public static final String PARAMETER_CHARSET = "charset";
public static final String PARAMETER_ODATA = "odata";
public static final String PARAMETER_Q = "q";
+ public static final String PARAMETER_TYPE = "type";
public static final String CHARSET_UTF_8 = "utf-8";
public static final ContentType WILDCARD = new ContentType(MEDIA_TYPE_WILDCARD, MEDIA_TYPE_WILDCARD);
@@ -104,9 +105,9 @@ public class ContentType {
public static final ContentType APPLICATION_XML_CS_UTF_8 = ContentType.create(APPLICATION_XML, PARAMETER_CHARSET, CHARSET_UTF_8);
public static final ContentType APPLICATION_ATOM_XML = new ContentType("application", "atom+xml", ODataFormat.ATOM);
public static final ContentType APPLICATION_ATOM_XML_CS_UTF_8 = ContentType.create(APPLICATION_ATOM_XML, PARAMETER_CHARSET, CHARSET_UTF_8);
- public static final ContentType APPLICATION_ATOM_XML_ENTRY = new ContentType("application", "atom+xml", ODataFormat.ATOM, parameterMap("type", "entry"));
+ public static final ContentType APPLICATION_ATOM_XML_ENTRY = new ContentType("application", "atom+xml", ODataFormat.ATOM, parameterMap(PARAMETER_TYPE, "entry"));
public static final ContentType APPLICATION_ATOM_XML_ENTRY_CS_UTF_8 = ContentType.create(APPLICATION_ATOM_XML_ENTRY, PARAMETER_CHARSET, CHARSET_UTF_8);
- public static final ContentType APPLICATION_ATOM_XML_FEED = new ContentType("application", "atom+xml", ODataFormat.ATOM, parameterMap("type", "feed"));
+ public static final ContentType APPLICATION_ATOM_XML_FEED = new ContentType("application", "atom+xml", ODataFormat.ATOM, parameterMap(PARAMETER_TYPE, "feed"));
public static final ContentType APPLICATION_ATOM_XML_FEED_CS_UTF_8 = ContentType.create(APPLICATION_ATOM_XML_FEED, PARAMETER_CHARSET, CHARSET_UTF_8);
public static final ContentType APPLICATION_ATOM_SVC = new ContentType("application", "atomsvc+xml", ODataFormat.ATOM);
public static final ContentType APPLICATION_ATOM_SVC_CS_UTF_8 = ContentType.create(APPLICATION_ATOM_SVC, PARAMETER_CHARSET, CHARSET_UTF_8);
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/060f9c65/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/AtomEntityProvider.java
----------------------------------------------------------------------
diff --git a/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/AtomEntityProvider.java b/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/AtomEntityProvider.java
index 41a71ec..bffbe70 100644
--- a/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/AtomEntityProvider.java
+++ b/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/AtomEntityProvider.java
@@ -73,7 +73,6 @@ public class AtomEntityProvider implements ContentTypeBasedEntityProvider {
/** Default used charset for writer and response content header */
private static final String DEFAULT_CHARSET = ContentType.CHARSET_UTF_8;
private static final String XML_VERSION = "1.0";
- private final ODataFormat odataFormat;
public AtomEntityProvider() throws EntityProviderException {
this(ODataFormat.ATOM);
@@ -84,12 +83,7 @@ public class AtomEntityProvider implements ContentTypeBasedEntityProvider {
}
public AtomEntityProvider(final ODataFormat odataFormat) throws EntityProviderException {
- switch (odataFormat) {
- case ATOM:
- case XML:
- this.odataFormat = odataFormat;
- break;
- default:
+ if(odataFormat != ODataFormat.ATOM && odataFormat != ODataFormat.XML) {
throw new EntityProviderException(EntityProviderException.ILLEGAL_ARGUMENT.addContent("Got unsupported ODataFormat '" + odataFormat + "'."));
}
}
@@ -120,7 +114,6 @@ public class AtomEntityProvider implements ContentTypeBasedEntityProvider {
csb.closeWrite();
ODataResponseBuilder response = ODataResponse.entity(csb.getInputStream())
- .contentHeader(ContentType.APPLICATION_XML.toContentTypeString())
.header(ODataHttpHeaders.DATASERVICEVERSION, ODataServiceVersion.V10)
.status(status);
return response.build();
@@ -150,7 +143,7 @@ public class AtomEntityProvider implements ContentTypeBasedEntityProvider {
csb.closeWrite();
ODataResponse response = ODataResponse.entity(csb.getInputStream())
- .contentHeader(ContentType.APPLICATION_ATOM_SVC_CS_UTF_8.toContentTypeString())
+ .contentHeader(ContentType.APPLICATION_ATOM_SVC.receiveWithCharsetParameter(DEFAULT_CHARSET).toContentTypeString())
.build();
return response;
@@ -180,7 +173,6 @@ public class AtomEntityProvider implements ContentTypeBasedEntityProvider {
csb.closeWrite();
ODataResponseBuilder response = ODataResponse.entity(csb.getInputStream())
- .contentHeader(getContentHeader(ContentType.APPLICATION_ATOM_XML_ENTRY))
.eTag(as.getETag())
.idLiteral(as.getLocation());
return response.build();
@@ -213,7 +205,7 @@ public class AtomEntityProvider implements ContentTypeBasedEntityProvider {
writer.flush();
csb.closeWrite();
- return ODataResponse.entity(csb.getInputStream()).contentHeader(getContentHeader(ContentType.APPLICATION_XML)).build();
+ return ODataResponse.entity(csb.getInputStream()).build();
} catch (EntityProviderException e) {
csb.close();
throw e;
@@ -239,7 +231,7 @@ public class AtomEntityProvider implements ContentTypeBasedEntityProvider {
writer.flush();
csb.closeWrite();
- ODataResponse response = ODataResponse.entity(csb.getInputStream()).contentHeader(getContentHeader(ContentType.APPLICATION_ATOM_XML_FEED)).build();
+ ODataResponse response = ODataResponse.entity(csb.getInputStream()).build();
return response;
} catch (EntityProviderException e) {
csb.close();
@@ -250,13 +242,6 @@ public class AtomEntityProvider implements ContentTypeBasedEntityProvider {
}
}
- private String getContentHeader(final ContentType mediaType) {
- if (odataFormat == ODataFormat.XML) {
- return ContentType.APPLICATION_XML_CS_UTF_8.toContentTypeString();
- }
- return ContentType.create(mediaType, ContentType.PARAMETER_CHARSET, DEFAULT_CHARSET).toContentTypeString();
- }
-
@Override
public ODataResponse writeLink(final EdmEntitySet entitySet, final Map<String, Object> data, final EntityProviderWriteProperties properties) throws EntityProviderException {
CircleStreamBuffer csb = new CircleStreamBuffer();
@@ -273,7 +258,7 @@ public class AtomEntityProvider implements ContentTypeBasedEntityProvider {
writer.flush();
csb.closeWrite();
- return ODataResponse.entity(csb.getInputStream()).contentHeader(getContentHeader(ContentType.APPLICATION_XML)).build();
+ return ODataResponse.entity(csb.getInputStream()).build();
} catch (EntityProviderException e) {
csb.close();
throw e;
@@ -300,7 +285,7 @@ public class AtomEntityProvider implements ContentTypeBasedEntityProvider {
writer.flush();
csb.closeWrite();
- return ODataResponse.entity(csb.getInputStream()).contentHeader(getContentHeader(ContentType.APPLICATION_XML)).build();
+ return ODataResponse.entity(csb.getInputStream()).build();
} catch (EntityProviderException e) {
csb.close();
throw e;
@@ -323,7 +308,7 @@ public class AtomEntityProvider implements ContentTypeBasedEntityProvider {
writer.flush();
csb.closeWrite();
- return ODataResponse.entity(csb.getInputStream()).contentHeader(getContentHeader(ContentType.APPLICATION_XML)).build();
+ return ODataResponse.entity(csb.getInputStream()).build();
} catch (EntityProviderException e) {
csb.close();
throw e;
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/060f9c65/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/ProviderFacadeImplTest.java
----------------------------------------------------------------------
diff --git a/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/ProviderFacadeImplTest.java b/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/ProviderFacadeImplTest.java
index 08f83d8..c3820c5 100644
--- a/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/ProviderFacadeImplTest.java
+++ b/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/ProviderFacadeImplTest.java
@@ -166,7 +166,7 @@ public class ProviderFacadeImplTest {
public void writeProperty() throws Exception {
final EdmProperty property = (EdmProperty) MockFacade.getMockEdm().getEntityType("RefScenario", "Employee").getProperty("EntryDate");
final ODataResponse result = new ProviderFacadeImpl().writeProperty(HttpContentType.APPLICATION_XML, property, 987654321000L);
- assertEquals(HttpContentType.APPLICATION_XML_UTF8, result.getContentHeader());
+ assertNull("EntityProvider should not set content header", result.getContentHeader());
assertTrue(StringHelper.inputStreamToString((InputStream) result.getEntity())
.endsWith("\">2001-04-19T04:25:21</EntryDate>"));
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/060f9c65/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/AtomEntryProducerTest.java
----------------------------------------------------------------------
diff --git a/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/AtomEntryProducerTest.java b/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/AtomEntryProducerTest.java
index 92fc37a..efcab4f 100644
--- a/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/AtomEntryProducerTest.java
+++ b/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/AtomEntryProducerTest.java
@@ -23,6 +23,7 @@ import static org.custommonkey.xmlunit.XMLAssert.assertXpathExists;
import static org.custommonkey.xmlunit.XMLAssert.assertXpathNotExists;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -301,7 +302,7 @@ public class AtomEntryProducerTest extends AbstractProviderTest {
private String verifyResponse(final ODataResponse response) throws IOException {
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(ContentType.APPLICATION_ATOM_XML_ENTRY_CS_UTF_8.toContentTypeString(), response.getContentHeader());
+ assertNull("EntityProvider should not set content header", response.getContentHeader());
String xmlString = StringHelper.inputStreamToString((InputStream) response.getEntity());
return xmlString;
}
@@ -567,7 +568,7 @@ public class AtomEntryProducerTest extends AbstractProviderTest {
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(ContentType.APPLICATION_ATOM_XML_ENTRY_CS_UTF_8.toContentTypeString(), response.getContentHeader());
+ assertNull("EntityProvider should not set content header", response.getContentHeader());
assertEquals("W/\"<\">.3\"", response.getETag());
String xmlString = StringHelper.inputStreamToString((InputStream) response.getEntity());
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/060f9c65/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/AtomFeedProducerTest.java
----------------------------------------------------------------------
diff --git a/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/AtomFeedProducerTest.java b/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/AtomFeedProducerTest.java
index 3fe183d..7d1d957 100644
--- a/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/AtomFeedProducerTest.java
+++ b/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/AtomFeedProducerTest.java
@@ -21,8 +21,8 @@ package org.apache.olingo.odata2.core.ep.producer;
import static org.custommonkey.xmlunit.XMLAssert.assertXpathEvaluatesTo;
import static org.custommonkey.xmlunit.XMLAssert.assertXpathExists;
import static org.custommonkey.xmlunit.XMLAssert.assertXpathNotExists;
-import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -36,7 +36,6 @@ import org.apache.olingo.odata2.api.ep.EntityProviderException;
import org.apache.olingo.odata2.api.ep.EntityProviderWriteProperties;
import org.apache.olingo.odata2.api.processor.ODataResponse;
import org.apache.olingo.odata2.api.uri.info.GetEntitySetUriInfo;
-import org.apache.olingo.odata2.core.commons.ContentType;
import org.apache.olingo.odata2.core.ep.AbstractProviderTest;
import org.apache.olingo.odata2.core.ep.AtomEntityProvider;
import org.apache.olingo.odata2.testutil.helper.StringHelper;
@@ -123,7 +122,7 @@ public class AtomFeedProducerTest extends AbstractProviderTest {
private String verifyResponse(final ODataResponse response) throws IOException {
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(ContentType.APPLICATION_ATOM_XML_FEED_CS_UTF_8.toContentTypeString(), response.getContentHeader());
+ assertNull("EntityProvider should not set content header", response.getContentHeader());
String xmlString = StringHelper.inputStreamToString((InputStream) response.getEntity());
return xmlString;
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/060f9c65/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlErrorProducerTest.java
----------------------------------------------------------------------
diff --git a/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlErrorProducerTest.java b/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlErrorProducerTest.java
index 9421eae..6049ccc 100644
--- a/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlErrorProducerTest.java
+++ b/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlErrorProducerTest.java
@@ -23,6 +23,7 @@ import static org.custommonkey.xmlunit.XMLAssert.assertXpathExists;
import static org.custommonkey.xmlunit.XMLAssert.assertXpathNotExists;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import java.io.IOException;
import java.io.InputStream;
@@ -227,7 +228,7 @@ public class XmlErrorProducerTest extends AbstractXmlProducerTestHelper {
private String verifyResponse(final ODataResponse response) throws IOException {
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(ContentType.APPLICATION_XML.toContentTypeString(), response.getContentHeader());
+ assertNull("EntityProvider should not set content header", response.getContentHeader());
assertEquals(expectedStatus, response.getStatus());
assertNotNull(response.getHeader(ODataHttpHeaders.DATASERVICEVERSION));
assertEquals(ODataServiceVersion.V10, response.getHeader(ODataHttpHeaders.DATASERVICEVERSION));
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/060f9c65/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlExpandProducerTest.java
----------------------------------------------------------------------
diff --git a/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlExpandProducerTest.java b/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlExpandProducerTest.java
index 30fafef..c8221e1 100644
--- a/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlExpandProducerTest.java
+++ b/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlExpandProducerTest.java
@@ -20,8 +20,8 @@ package org.apache.olingo.odata2.core.ep.producer;
import static org.custommonkey.xmlunit.XMLAssert.assertXpathExists;
import static org.custommonkey.xmlunit.XMLAssert.assertXpathNotExists;
-import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import java.io.IOException;
import java.io.InputStream;
@@ -51,7 +51,6 @@ import org.apache.olingo.odata2.api.uri.ExpandSelectTreeNode;
import org.apache.olingo.odata2.api.uri.PathSegment;
import org.apache.olingo.odata2.api.uri.UriInfo;
import org.apache.olingo.odata2.core.ODataPathSegmentImpl;
-import org.apache.olingo.odata2.core.commons.ContentType;
import org.apache.olingo.odata2.core.ep.AbstractProviderTest;
import org.apache.olingo.odata2.core.ep.AtomEntityProvider;
import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
@@ -399,7 +398,7 @@ public class XmlExpandProducerTest extends AbstractProviderTest {
private String verifyResponse(final ODataResponse response) throws IOException {
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(ContentType.APPLICATION_ATOM_XML_ENTRY_CS_UTF_8.toContentTypeString(), response.getContentHeader());
+ assertNull("EntitypProvider should not set content header", response.getContentHeader());
String xmlString = StringHelper.inputStreamToString((InputStream) response.getEntity());
return xmlString;
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/060f9c65/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlFunctionImportTest.java
----------------------------------------------------------------------
diff --git a/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlFunctionImportTest.java b/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlFunctionImportTest.java
index ecc6f0a..126a7b4 100644
--- a/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlFunctionImportTest.java
+++ b/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlFunctionImportTest.java
@@ -20,15 +20,14 @@ package org.apache.olingo.odata2.core.ep.producer;
import static org.custommonkey.xmlunit.XMLAssert.assertXpathEvaluatesTo;
import static org.custommonkey.xmlunit.XMLAssert.assertXpathExists;
-import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import java.io.InputStream;
import java.util.Arrays;
import org.apache.olingo.odata2.api.edm.EdmFunctionImport;
import org.apache.olingo.odata2.api.processor.ODataResponse;
-import org.apache.olingo.odata2.core.commons.ContentType;
import org.apache.olingo.odata2.core.ep.AbstractProviderTest;
import org.apache.olingo.odata2.testutil.helper.StringHelper;
import org.apache.olingo.odata2.testutil.mock.MockFacade;
@@ -50,7 +49,7 @@ public class XmlFunctionImportTest extends AbstractProviderTest {
final ODataResponse response = createAtomEntityProvider().writeFunctionImport(functionImport, employeeData.get("Age"), DEFAULT_PROPERTIES);
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(ContentType.APPLICATION_XML.toString() + ";charset=utf-8", response.getContentHeader());
+ assertNull("EntitypProvider must not set content header", response.getContentHeader());
final String xml = StringHelper.inputStreamToString((InputStream) response.getEntity());
assertNotNull(xml);
@@ -66,7 +65,7 @@ public class XmlFunctionImportTest extends AbstractProviderTest {
final ODataResponse response = createAtomEntityProvider().writeFunctionImport(functionImport, employeeData.get("Location"), DEFAULT_PROPERTIES);
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(ContentType.APPLICATION_XML.toString() + ";charset=utf-8", response.getContentHeader());
+ assertNull("EntitypProvider must not set content header", response.getContentHeader());
final String xml = StringHelper.inputStreamToString((InputStream) response.getEntity());
assertNotNull(xml);
@@ -83,7 +82,7 @@ public class XmlFunctionImportTest extends AbstractProviderTest {
final ODataResponse response = createAtomEntityProvider().writeFunctionImport(functionImport, Arrays.asList("1", "2", "3"), DEFAULT_PROPERTIES);
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(ContentType.APPLICATION_XML.toString() + ";charset=utf-8", response.getContentHeader());
+ assertNull("EntitypProvider must not set content header", response.getContentHeader());
final String xml = StringHelper.inputStreamToString((InputStream) response.getEntity());
assertNotNull(xml);
@@ -101,7 +100,7 @@ public class XmlFunctionImportTest extends AbstractProviderTest {
final ODataResponse response = createAtomEntityProvider().writeFunctionImport(functionImport, Arrays.asList(employeeData.get("Location")), DEFAULT_PROPERTIES);
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(ContentType.APPLICATION_XML.toString() + ";charset=utf-8", response.getContentHeader());
+ assertNull("EntitypProvider must not set content header", response.getContentHeader());
final String xml = StringHelper.inputStreamToString((InputStream) response.getEntity());
assertNotNull(xml);
@@ -119,7 +118,7 @@ public class XmlFunctionImportTest extends AbstractProviderTest {
final ODataResponse response = createAtomEntityProvider().writeFunctionImport(functionImport, employeeData, DEFAULT_PROPERTIES);
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(ContentType.APPLICATION_ATOM_XML_ENTRY_CS_UTF_8.toContentTypeString(), response.getContentHeader());
+ assertNull("EntityProvider should not set content header", response.getContentHeader());
final String xml = StringHelper.inputStreamToString((InputStream) response.getEntity());
assertNotNull(xml);
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/060f9c65/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlLinkEntityProducerTest.java
----------------------------------------------------------------------
diff --git a/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlLinkEntityProducerTest.java b/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlLinkEntityProducerTest.java
index c9c40db..9dd2a27 100644
--- a/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlLinkEntityProducerTest.java
+++ b/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlLinkEntityProducerTest.java
@@ -20,14 +20,13 @@ package org.apache.olingo.odata2.core.ep.producer;
import static org.custommonkey.xmlunit.XMLAssert.assertXpathEvaluatesTo;
import static org.custommonkey.xmlunit.XMLAssert.assertXpathExists;
-import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import java.io.InputStream;
import org.apache.olingo.odata2.api.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.processor.ODataResponse;
-import org.apache.olingo.odata2.core.commons.ContentType;
import org.apache.olingo.odata2.core.ep.AbstractProviderTest;
import org.apache.olingo.odata2.testutil.helper.StringHelper;
import org.apache.olingo.odata2.testutil.mock.MockFacade;
@@ -49,7 +48,7 @@ public class XmlLinkEntityProducerTest extends AbstractProviderTest {
final ODataResponse content = createAtomEntityProvider().writeLink(entitySet, employeeData, DEFAULT_PROPERTIES);
assertNotNull(content);
assertNotNull(content.getEntity());
- assertEquals(ContentType.APPLICATION_XML.toString() + ";charset=utf-8", content.getContentHeader());
+ assertNull("EntitypProvider should not set content header", content.getContentHeader());
final String xml = StringHelper.inputStreamToString((InputStream) content.getEntity());
assertNotNull(xml);
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/060f9c65/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlLinksEntityProducerTest.java
----------------------------------------------------------------------
diff --git a/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlLinksEntityProducerTest.java b/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlLinksEntityProducerTest.java
index 34292c3..8fa36ff 100644
--- a/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlLinksEntityProducerTest.java
+++ b/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlLinksEntityProducerTest.java
@@ -20,15 +20,14 @@ package org.apache.olingo.odata2.core.ep.producer;
import static org.custommonkey.xmlunit.XMLAssert.assertXpathEvaluatesTo;
import static org.custommonkey.xmlunit.XMLAssert.assertXpathExists;
-import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import java.io.InputStream;
import org.apache.olingo.odata2.api.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.ep.EntityProviderWriteProperties;
import org.apache.olingo.odata2.api.processor.ODataResponse;
-import org.apache.olingo.odata2.core.commons.ContentType;
import org.apache.olingo.odata2.core.ep.AbstractProviderTest;
import org.apache.olingo.odata2.testutil.helper.StringHelper;
import org.apache.olingo.odata2.testutil.mock.MockFacade;
@@ -51,7 +50,7 @@ public class XmlLinksEntityProducerTest extends AbstractProviderTest {
final ODataResponse response = createAtomEntityProvider().writeLinks(entitySet, roomsData, DEFAULT_PROPERTIES);
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(ContentType.APPLICATION_XML.toString() + ";charset=utf-8", response.getContentHeader());
+ assertNull("EntitypProvider must not set content header", response.getContentHeader());
final String xml = StringHelper.inputStreamToString((InputStream) response.getEntity());
assertNotNull(xml);
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/060f9c65/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlPropertyProducerTest.java
----------------------------------------------------------------------
diff --git a/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlPropertyProducerTest.java b/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlPropertyProducerTest.java
index a0e13e6..06690d1 100644
--- a/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlPropertyProducerTest.java
+++ b/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlPropertyProducerTest.java
@@ -20,17 +20,15 @@ package org.apache.olingo.odata2.core.ep.producer;
import static org.custommonkey.xmlunit.XMLAssert.assertXpathEvaluatesTo;
import static org.custommonkey.xmlunit.XMLAssert.assertXpathExists;
-import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import java.io.InputStream;
-import org.apache.olingo.odata2.api.commons.HttpContentType;
import org.apache.olingo.odata2.api.edm.EdmEntityType;
import org.apache.olingo.odata2.api.edm.EdmProperty;
import org.apache.olingo.odata2.api.edm.EdmTyped;
import org.apache.olingo.odata2.api.processor.ODataResponse;
-import org.apache.olingo.odata2.core.commons.ContentType;
import org.apache.olingo.odata2.core.ep.AbstractProviderTest;
import org.apache.olingo.odata2.core.ep.AtomEntityProvider;
import org.apache.olingo.odata2.testutil.helper.StringHelper;
@@ -56,7 +54,7 @@ public class XmlPropertyProducerTest extends AbstractProviderTest {
ODataResponse response = s.writeProperty(edmProperty, employeeData.get("EmployeeId"));
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(ContentType.APPLICATION_XML.toString() + ";charset=utf-8", response.getContentHeader());
+
String xml = StringHelper.inputStreamToString((InputStream) response.getEntity());
assertNotNull(xml);
@@ -75,7 +73,7 @@ public class XmlPropertyProducerTest extends AbstractProviderTest {
ODataResponse response = s.writeProperty(edmProperty, employeeData.get("Age"));
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(ContentType.APPLICATION_XML.toString() + ";charset=utf-8", response.getContentHeader());
+
String xml = StringHelper.inputStreamToString((InputStream) response.getEntity());
assertNotNull(xml);
@@ -93,7 +91,7 @@ public class XmlPropertyProducerTest extends AbstractProviderTest {
ODataResponse response = s.writeProperty(edmProperty, employeeData.get("ImageUrl"));
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(ContentType.APPLICATION_XML.toString() + ";charset=utf-8", response.getContentHeader());
+
String xml = StringHelper.inputStreamToString((InputStream) response.getEntity());
assertNotNull(xml);
@@ -108,8 +106,8 @@ public class XmlPropertyProducerTest extends AbstractProviderTest {
ODataResponse response = createAtomEntityProvider().writeProperty(property, photoData.get("Image"));
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(HttpContentType.APPLICATION_XML_UTF8, response.getContentHeader());
-
+ assertNull("EntityProvider should not set content header", response.getContentHeader());
+
final String xml = StringHelper.inputStreamToString((InputStream) response.getEntity());
assertNotNull(xml);
assertXpathExists("/d:Image", xml);
@@ -123,8 +121,8 @@ public class XmlPropertyProducerTest extends AbstractProviderTest {
ODataResponse response = createAtomEntityProvider().writeProperty(property, photoData.get("BinaryData"));
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(HttpContentType.APPLICATION_XML_UTF8, response.getContentHeader());
-
+ assertNull("EntityProvider should not set content header", response.getContentHeader());
+
final String xml = StringHelper.inputStreamToString((InputStream) response.getEntity());
assertNotNull(xml);
assertXpathExists("/d:BinaryData", xml);
@@ -143,7 +141,7 @@ public class XmlPropertyProducerTest extends AbstractProviderTest {
ODataResponse response = s.writeProperty(edmProperty, employeeData.get("Location"));
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(ContentType.APPLICATION_XML.toString() + ";charset=utf-8", response.getContentHeader());
+
String xml = StringHelper.inputStreamToString((InputStream) response.getEntity());
assertNotNull(xml);
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/060f9c65/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlSelectProducerTest.java
----------------------------------------------------------------------
diff --git a/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlSelectProducerTest.java b/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlSelectProducerTest.java
index 8c0f98c..b762e68 100644
--- a/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlSelectProducerTest.java
+++ b/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/XmlSelectProducerTest.java
@@ -20,8 +20,8 @@ package org.apache.olingo.odata2.core.ep.producer;
import static org.custommonkey.xmlunit.XMLAssert.assertXpathExists;
import static org.custommonkey.xmlunit.XMLAssert.assertXpathNotExists;
-import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import java.io.IOException;
import java.io.InputStream;
@@ -38,7 +38,6 @@ import org.apache.olingo.odata2.api.uri.ExpandSelectTreeNode;
import org.apache.olingo.odata2.api.uri.PathSegment;
import org.apache.olingo.odata2.api.uri.UriInfo;
import org.apache.olingo.odata2.core.ODataPathSegmentImpl;
-import org.apache.olingo.odata2.core.commons.ContentType;
import org.apache.olingo.odata2.core.ep.AbstractProviderTest;
import org.apache.olingo.odata2.core.ep.AtomEntityProvider;
import org.apache.olingo.odata2.core.uri.ExpandSelectTreeCreator;
@@ -287,7 +286,7 @@ public class XmlSelectProducerTest extends AbstractProviderTest {
private String verifyResponse(final ODataResponse response) throws IOException {
assertNotNull(response);
assertNotNull(response.getEntity());
- assertEquals(ContentType.APPLICATION_ATOM_XML_ENTRY_CS_UTF_8.toContentTypeString(), response.getContentHeader());
+ assertNull("EntityProvider should not set content header", response.getContentHeader());
String xmlString = StringHelper.inputStreamToString((InputStream) response.getEntity());
return xmlString;
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/060f9c65/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/EntryXmlChangeTest.java
----------------------------------------------------------------------
diff --git a/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/EntryXmlChangeTest.java b/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/EntryXmlChangeTest.java
index 67304f8..343001e 100644
--- a/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/EntryXmlChangeTest.java
+++ b/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/EntryXmlChangeTest.java
@@ -25,14 +25,13 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import org.apache.http.HttpResponse;
-import org.junit.Test;
-
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.commons.ODataHttpMethod;
import org.apache.olingo.odata2.api.edm.Edm;
import org.apache.olingo.odata2.testutil.helper.StringHelper;
+import org.junit.Test;
/**
* Tests employing the reference scenario changing entities in XML format.
@@ -88,6 +87,58 @@ public class EntryXmlChangeTest extends AbstractRefXmlTest {
}
@Test
+ public void createWithAcceptHeaderEntry() throws Exception {
+ // Create an entry for a type that has no media resource.
+ String requestBody = getBody(callUri("Teams('1')"))
+ .replace("'1'", "'9'")
+ .replace("Id>1", "Id>9")
+ .replace("Team 1", "Team X")
+ .replaceAll("<link.+?/>", "");
+ String requestContentType = HttpContentType.APPLICATION_ATOM_XML_ENTRY;
+ HttpStatusCodes expectedStatusCode = HttpStatusCodes.CREATED;
+ String headerName = "Accept";
+ String headerValue = "application/atom+xml;type=entry";
+ HttpResponse response = callUri(ODataHttpMethod.POST, "Teams()", headerName, headerValue, requestBody, requestContentType, expectedStatusCode );
+
+ checkMediaType(response, HttpContentType.APPLICATION_ATOM_XML_UTF8 + ";type=entry");
+ assertEquals(getEndpoint() + "Teams('4')", response.getFirstHeader(HttpHeaders.LOCATION).getValue());
+ assertNull(response.getFirstHeader(HttpHeaders.ETAG));
+ assertXpathEvaluatesTo("Team X", "/atom:entry/atom:content/m:properties/d:Name", getBody(response));
+
+ // Create an entry for a type that has no media resource.
+ // Add navigation to Employee('4') and Employee('5').
+ requestBody = "<entry xmlns=\"" + Edm.NAMESPACE_ATOM_2005 + "\"" + "\n"
+ + " xmlns:d=\"" + Edm.NAMESPACE_D_2007_08 + "\"" + "\n"
+ + " xmlns:m=\"" + Edm.NAMESPACE_M_2007_08 + "\">" + "\n"
+ + " <author><name>no author</name></author>" + "\n"
+ + " <content type=\"application/xml\">" + "\n"
+ + " <m:properties>" + "\n"
+ + " <d:Id>109</d:Id>" + "\n"
+ + " <d:Name/>" + "\n"
+ + " <d:Seats>4</d:Seats>" + "\n"
+ + " <d:Version>2</d:Version>" + "\n"
+ + " </m:properties>" + "\n"
+ + " </content>" + "\n"
+ + " <id>Rooms('104')</id>" + "\n"
+ + " <title>Room 104</title>" + "\n"
+ + " <updated>2011-08-10T12:00:23Z</updated>" + "\n"
+ + " <link href=\"Employees('4')\"" + "\n"
+ + " rel=\"" + Edm.NAMESPACE_REL_2007_08 + "nr_Employees\"" + "\n"
+ + " type=\"" + HttpContentType.APPLICATION_ATOM_XML_FEED_UTF8 + "\"/>" + "\n"
+ + " <link href=\"Employees('5')\"" + "\n"
+ + " rel=\"" + Edm.NAMESPACE_REL_2007_08 + "nr_Employees\"" + "\n"
+ + " type=\"" + HttpContentType.APPLICATION_ATOM_XML_FEED_UTF8 + "\"/>" + "\n"
+ + "</entry>";
+ response = postUri("Rooms", requestBody, HttpContentType.APPLICATION_ATOM_XML_ENTRY, HttpStatusCodes.CREATED);
+ checkMediaType(response, HttpContentType.APPLICATION_ATOM_XML_UTF8 + ";type=entry");
+ assertEquals(getEndpoint() + "Rooms('104')", response.getFirstHeader(HttpHeaders.LOCATION).getValue());
+ checkEtag(response, "W/\"2\"");
+ assertXpathEvaluatesTo("4", "/atom:entry/atom:content/m:properties/d:Seats", getBody(response));
+ checkUri("Rooms('104')/nr_Employees('4')");
+ checkUri("Rooms('104')/nr_Employees('5')");
+ }
+
+ @Test
public void createWithLargeProperty() throws Exception {
final String largeTeamName = StringHelper.generateData(888888);
// Create an entry for a type that has no media resource.