[OLINGO-995] Support HEAD for metadata and service document
This commit is contained in:
parent
c0f1b997ef
commit
38c9a76eb6
|
@ -19,6 +19,7 @@
|
|||
package org.apache.olingo.fit.tecsvc.http;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.net.HttpURLConnection;
|
||||
|
@ -38,6 +39,36 @@ public class BasicHttpITCase extends AbstractBaseTestITCase {
|
|||
|
||||
private static final String SERVICE_URI = TecSvcConst.BASE_URI + "/";
|
||||
|
||||
@Test
|
||||
public void testHeadMethodOnServiceDocument() throws Exception {
|
||||
URL url = new URL(SERVICE_URI);
|
||||
|
||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
connection.setRequestMethod(HttpMethod.HEAD.name());
|
||||
connection.setRequestProperty(HttpHeader.ACCEPT, "application/json");
|
||||
connection.connect();
|
||||
|
||||
assertEquals(HttpStatusCode.OK.getStatusCode(), connection.getResponseCode());
|
||||
assertNull(connection.getHeaderField(HttpHeader.CONTENT_TYPE));
|
||||
assertEquals("", IOUtils.toString(connection.getInputStream()));
|
||||
connection.disconnect();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHeadMethodOnMetadataDocument() throws Exception {
|
||||
URL url = new URL(SERVICE_URI + "$metadata");
|
||||
|
||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
connection.setRequestMethod(HttpMethod.HEAD.name());
|
||||
connection.setRequestProperty(HttpHeader.ACCEPT, "application/xml");
|
||||
connection.connect();
|
||||
|
||||
assertEquals(HttpStatusCode.OK.getStatusCode(), connection.getResponseCode());
|
||||
assertNull(connection.getHeaderField(HttpHeader.CONTENT_TYPE));
|
||||
assertEquals("", IOUtils.toString(connection.getInputStream()));
|
||||
connection.disconnect();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormat() throws Exception {
|
||||
URL url = new URL(SERVICE_URI + "?$format=json");
|
||||
|
|
|
@ -28,6 +28,7 @@ public enum HttpMethod {
|
|||
PUT,
|
||||
PATCH,
|
||||
MERGE,
|
||||
DELETE
|
||||
DELETE,
|
||||
HEAD
|
||||
|
||||
}
|
||||
|
|
|
@ -23,6 +23,10 @@ package org.apache.olingo.commons.api.http;
|
|||
* and additional status codes as defined in RFC 6585
|
||||
*/
|
||||
public enum HttpStatusCode {
|
||||
|
||||
CONTINUE(100, "Continue"),
|
||||
SWITCHING_PROTOCOLS(101, "Switching Protocols"),
|
||||
|
||||
OK(200, "OK"),
|
||||
CREATED(201, "Created"),
|
||||
ACCEPTED(202, "Accepted"),
|
||||
|
|
|
@ -23,6 +23,7 @@ import java.nio.charset.Charset;
|
|||
|
||||
import org.apache.olingo.commons.api.format.ContentType;
|
||||
import org.apache.olingo.commons.api.http.HttpHeader;
|
||||
import org.apache.olingo.commons.api.http.HttpMethod;
|
||||
import org.apache.olingo.commons.api.http.HttpStatusCode;
|
||||
import org.apache.olingo.server.api.OData;
|
||||
import org.apache.olingo.server.api.ODataApplicationException;
|
||||
|
@ -71,6 +72,10 @@ public class DefaultProcessor implements MetadataProcessor, ServiceDocumentProce
|
|||
// Send the correct response
|
||||
if (isNotModified) {
|
||||
response.setStatusCode(HttpStatusCode.NOT_MODIFIED.getStatusCode());
|
||||
} else {
|
||||
// HTTP HEAD requires no payload but a 200 OK response
|
||||
if (HttpMethod.HEAD == request.getMethod()) {
|
||||
response.setStatusCode(HttpStatusCode.OK.getStatusCode());
|
||||
} else {
|
||||
ODataSerializer serializer = odata.createSerializer(requestedContentType);
|
||||
response.setContent(serializer.serviceDocument(serviceMetadata, null).getContent());
|
||||
|
@ -78,6 +83,7 @@ public class DefaultProcessor implements MetadataProcessor, ServiceDocumentProce
|
|||
response.setHeader(HttpHeader.CONTENT_TYPE, requestedContentType.toContentTypeString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readMetadata(final ODataRequest request, final ODataResponse response, final UriInfo uriInfo,
|
||||
|
@ -96,6 +102,10 @@ public class DefaultProcessor implements MetadataProcessor, ServiceDocumentProce
|
|||
// Send the correct response
|
||||
if (isNotModified) {
|
||||
response.setStatusCode(HttpStatusCode.NOT_MODIFIED.getStatusCode());
|
||||
} else {
|
||||
// HTTP HEAD requires no payload but a 200 OK response
|
||||
if (HttpMethod.HEAD == request.getMethod()) {
|
||||
response.setStatusCode(HttpStatusCode.OK.getStatusCode());
|
||||
} else {
|
||||
ODataSerializer serializer = odata.createSerializer(requestedContentType);
|
||||
response.setContent(serializer.metadataDocument(serviceMetadata).getContent());
|
||||
|
@ -103,6 +113,7 @@ public class DefaultProcessor implements MetadataProcessor, ServiceDocumentProce
|
|||
response.setHeader(HttpHeader.CONTENT_TYPE, requestedContentType.toContentTypeString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processError(final ODataRequest request, final ODataResponse response,
|
||||
|
|
|
@ -86,7 +86,7 @@ public class ODataDispatcher {
|
|||
ODataLibraryException {
|
||||
switch (uriInfo.getKind()) {
|
||||
case metadata:
|
||||
checkMethod(request.getMethod(), HttpMethod.GET);
|
||||
checkMethods(request.getMethod(), HttpMethod.GET, HttpMethod.HEAD);
|
||||
final ContentType requestedContentType = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
|
||||
request, handler.getCustomContentTypeSupport(), RepresentationType.METADATA);
|
||||
handler.selectProcessor(MetadataProcessor.class)
|
||||
|
@ -94,7 +94,7 @@ public class ODataDispatcher {
|
|||
break;
|
||||
|
||||
case service:
|
||||
checkMethod(request.getMethod(), HttpMethod.GET);
|
||||
checkMethods(request.getMethod(), HttpMethod.GET, HttpMethod.HEAD);
|
||||
if ("".equals(request.getRawODataPath())) {
|
||||
handler.selectProcessor(RedirectProcessor.class)
|
||||
.redirect(request, response);
|
||||
|
@ -309,11 +309,11 @@ public class ODataDispatcher {
|
|||
if (resource instanceof UriResourceProperty
|
||||
|| resource instanceof UriResourceFunction
|
||||
&& ((UriResourceFunction) resource).getType().getKind() == EdmTypeKind.PRIMITIVE) {
|
||||
final EdmType type = resource instanceof UriResourceProperty ?
|
||||
((UriResourceProperty) resource).getType() : ((UriResourceFunction) resource).getType();
|
||||
final EdmType type = resource instanceof UriResourceProperty ? ((UriResourceProperty) resource).getType()
|
||||
: ((UriResourceFunction) resource).getType();
|
||||
final RepresentationType valueRepresentationType =
|
||||
type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Binary) ?
|
||||
RepresentationType.BINARY : RepresentationType.VALUE;
|
||||
type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Binary) ? RepresentationType.BINARY
|
||||
: RepresentationType.VALUE;
|
||||
if (method == HttpMethod.GET) {
|
||||
final ContentType requestedContentType = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
|
||||
request, handler.getCustomContentTypeSupport(), valueRepresentationType);
|
||||
|
@ -363,8 +363,8 @@ public class ODataDispatcher {
|
|||
private void handleComplexDispatching(final ODataRequest request, final ODataResponse response,
|
||||
final boolean isCollection) throws ODataApplicationException, ODataLibraryException {
|
||||
final HttpMethod method = request.getMethod();
|
||||
final RepresentationType complexRepresentationType = isCollection ?
|
||||
RepresentationType.COLLECTION_COMPLEX : RepresentationType.COMPLEX;
|
||||
final RepresentationType complexRepresentationType = isCollection ? RepresentationType.COLLECTION_COMPLEX
|
||||
: RepresentationType.COMPLEX;
|
||||
if (method == HttpMethod.GET) {
|
||||
final ContentType requestedContentType = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
|
||||
request, handler.getCustomContentTypeSupport(), complexRepresentationType);
|
||||
|
@ -405,8 +405,8 @@ public class ODataDispatcher {
|
|||
private void handlePrimitiveDispatching(final ODataRequest request, final ODataResponse response,
|
||||
final boolean isCollection) throws ODataApplicationException, ODataLibraryException {
|
||||
final HttpMethod method = request.getMethod();
|
||||
final RepresentationType representationType = isCollection ?
|
||||
RepresentationType.COLLECTION_PRIMITIVE : RepresentationType.PRIMITIVE;
|
||||
final RepresentationType representationType = isCollection ? RepresentationType.COLLECTION_PRIMITIVE
|
||||
: RepresentationType.PRIMITIVE;
|
||||
if (method == HttpMethod.GET) {
|
||||
final ContentType requestedContentType = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
|
||||
request, handler.getCustomContentTypeSupport(), representationType);
|
||||
|
@ -533,6 +533,18 @@ public class ODataDispatcher {
|
|||
}
|
||||
}
|
||||
|
||||
private void checkMethods(final HttpMethod requestMethod, final HttpMethod... allowedMethods)
|
||||
throws ODataHandlerException {
|
||||
//Check if the request method is one of the allowed ones
|
||||
for (int i = 0; i < allowedMethods.length; i++) {
|
||||
if (requestMethod == allowedMethods[i]) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
//request method does not match any allowed method
|
||||
throwMethodNotAllowed(requestMethod);
|
||||
}
|
||||
|
||||
private void throwMethodNotAllowed(final HttpMethod httpMethod) throws ODataHandlerException {
|
||||
throw new ODataHandlerException("HTTP method " + httpMethod + " is not allowed.",
|
||||
ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, httpMethod.toString());
|
||||
|
|
|
@ -92,7 +92,8 @@ public class ODataExceptionHelper {
|
|||
|| ODataHandlerException.MessageKeys.INVALID_HTTP_METHOD.equals(e.getMessageKey())
|
||||
|| ODataHandlerException.MessageKeys.AMBIGUOUS_XHTTP_METHOD.equals(e.getMessageKey())
|
||||
|| ODataHandlerException.MessageKeys.MISSING_CONTENT_TYPE.equals(e.getMessageKey())
|
||||
|| ODataHandlerException.MessageKeys.INVALID_CONTENT_TYPE.equals(e.getMessageKey())) {
|
||||
|| ODataHandlerException.MessageKeys.INVALID_CONTENT_TYPE.equals(e.getMessageKey())
|
||||
|| ODataHandlerException.MessageKeys.UNSUPPORTED_CONTENT_TYPE.equals(e.getMessageKey())) {
|
||||
serverError.setStatusCode(HttpStatusCode.BAD_REQUEST.getStatusCode());
|
||||
} else if (ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED.equals(e.getMessageKey())) {
|
||||
serverError.setStatusCode(HttpStatusCode.METHOD_NOT_ALLOWED.getStatusCode());
|
||||
|
|
|
@ -229,9 +229,14 @@ public class ODataHttpHandlerImpl implements ODataHttpHandler {
|
|||
}
|
||||
|
||||
static HttpMethod extractMethod(final HttpServletRequest httpRequest) throws ODataLibraryException {
|
||||
final HttpMethod httpRequestMethod;
|
||||
try {
|
||||
httpRequestMethod = HttpMethod.valueOf(httpRequest.getMethod());
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new ODataHandlerException("HTTP method not allowed" + httpRequest.getMethod(), e,
|
||||
ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, httpRequest.getMethod());
|
||||
}
|
||||
try {
|
||||
HttpMethod httpRequestMethod = HttpMethod.valueOf(httpRequest.getMethod());
|
||||
|
||||
if (httpRequestMethod == HttpMethod.POST) {
|
||||
String xHttpMethod = httpRequest.getHeader(HttpHeader.X_HTTP_METHOD);
|
||||
String xHttpMethodOverride = httpRequest.getHeader(HttpHeader.X_HTTP_METHOD_OVERRIDE);
|
||||
|
|
|
@ -106,9 +106,26 @@ public class ExceptionHelperTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void httpHandlerExceptions() {
|
||||
for (MessageKey key : ODataHandlerException.MessageKeys.values()) {
|
||||
final ODataHandlerException e = new ODataHandlerException(DEV_MSG, key);
|
||||
ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e, null);
|
||||
|
||||
if (key.equals(ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED)
|
||||
|| key.equals(ODataHandlerException.MessageKeys.PROCESSOR_NOT_IMPLEMENTED)) {
|
||||
checkStatusCode(serverError, HttpStatusCode.NOT_IMPLEMENTED, e);
|
||||
} else if (key.equals(ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED)) {
|
||||
checkStatusCode(serverError, HttpStatusCode.METHOD_NOT_ALLOWED, e);
|
||||
} else {
|
||||
checkStatusCode(serverError, HttpStatusCode.BAD_REQUEST, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void checkStatusCode(final ODataServerError serverError, final HttpStatusCode statusCode,
|
||||
final ODataLibraryException exception) {
|
||||
assertEquals("FailedKey: " + exception.getMessageKey().getKey(),
|
||||
serverError.getStatusCode(), statusCode.getStatusCode());
|
||||
statusCode.getStatusCode(), serverError.getStatusCode());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,6 +49,7 @@ public class ODataHttpHandlerImplTest {
|
|||
{ "POST", "PATCH", null, "PATCH" },
|
||||
|
||||
{ "POST", "GET", "GET", "GET" },
|
||||
{ "HEAD", null, null, "HEAD" }
|
||||
};
|
||||
|
||||
for (String[] m : mm) {
|
||||
|
@ -68,8 +69,7 @@ public class ODataHttpHandlerImplTest {
|
|||
String[][] mm = {
|
||||
{ "POST", "bla", null },
|
||||
{ "POST", "PUT", "PATCH" },
|
||||
{ "OPTIONS", null, null },
|
||||
{ "HEAD", null, null },
|
||||
{ "OPTIONS", null, null }
|
||||
};
|
||||
|
||||
for (String[] m : mm) {
|
||||
|
|
|
@ -18,11 +18,10 @@
|
|||
*/
|
||||
package org.apache.olingo.server.core;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.Charset;
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
|
@ -31,6 +30,8 @@ import static org.mockito.Mockito.times;
|
|||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Collections;
|
||||
import java.util.Locale;
|
||||
|
||||
|
@ -90,12 +91,26 @@ public class ODataHandlerImplTest {
|
|||
@Test
|
||||
public void serviceDocumentNonDefault() throws Exception {
|
||||
final ServiceDocumentProcessor processor = mock(ServiceDocumentProcessor.class);
|
||||
doThrow(new ODataApplicationException("msg", 100, Locale.ENGLISH)).when(processor)
|
||||
.readServiceDocument(any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class),
|
||||
any(ContentType.class));
|
||||
final ODataResponse response = dispatch(HttpMethod.GET, "/", processor);
|
||||
assertEquals(HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode());
|
||||
assertEquals(HttpStatusCode.CONTINUE.getStatusCode(), response.getStatusCode());
|
||||
|
||||
verify(processor).readServiceDocument(
|
||||
any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class), any(ContentType.class));
|
||||
|
||||
// We support HEAD now too
|
||||
final ServiceDocumentProcessor processor2 = mock(ServiceDocumentProcessor.class);
|
||||
doThrow(new ODataApplicationException("msg", 100, Locale.ENGLISH)).when(processor2)
|
||||
.readServiceDocument(any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class),
|
||||
any(ContentType.class));
|
||||
final ODataResponse response2 = dispatch(HttpMethod.HEAD, "/", processor2);
|
||||
assertEquals(HttpStatusCode.CONTINUE.getStatusCode(), response2.getStatusCode());
|
||||
|
||||
verify(processor2).readServiceDocument(
|
||||
any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class), any(ContentType.class));
|
||||
|
||||
dispatchMethodNotAllowed(HttpMethod.POST, "/", processor);
|
||||
dispatchMethodNotAllowed(HttpMethod.PATCH, "/", processor);
|
||||
dispatchMethodNotAllowed(HttpMethod.PUT, "/", processor);
|
||||
|
@ -116,6 +131,11 @@ public class ODataHandlerImplTest {
|
|||
|
||||
assertThat(doc, containsString("\"@odata.context\":\"$metadata\""));
|
||||
assertThat(doc, containsString("\"value\":"));
|
||||
|
||||
final ODataResponse response2 = dispatch(HttpMethod.HEAD, "/", null);
|
||||
assertEquals(HttpStatusCode.OK.getStatusCode(), response2.getStatusCode());
|
||||
assertNull(response2.getHeader(HttpHeader.CONTENT_TYPE));
|
||||
assertNull(response2.getContent());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -123,17 +143,35 @@ public class ODataHandlerImplTest {
|
|||
final ODataResponse response = dispatch(HttpMethod.GET, "", null);
|
||||
assertEquals(HttpStatusCode.TEMPORARY_REDIRECT.getStatusCode(), response.getStatusCode());
|
||||
assertEquals(BASE_URI + "/", response.getHeader(HttpHeader.LOCATION));
|
||||
|
||||
final ODataResponse responseHead = dispatch(HttpMethod.HEAD, "", null);
|
||||
assertEquals(HttpStatusCode.TEMPORARY_REDIRECT.getStatusCode(), responseHead.getStatusCode());
|
||||
assertEquals(BASE_URI + "/", responseHead.getHeader(HttpHeader.LOCATION));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void metadataNonDefault() throws Exception {
|
||||
final MetadataProcessor processor = mock(MetadataProcessor.class);
|
||||
doThrow(new ODataApplicationException("msg", 100, Locale.ENGLISH)).when(processor)
|
||||
.readMetadata(
|
||||
any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class), any(ContentType.class));
|
||||
final ODataResponse response = dispatch(HttpMethod.GET, "$metadata", processor);
|
||||
assertEquals(HttpStatusCode.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode());
|
||||
assertEquals(HttpStatusCode.CONTINUE.getStatusCode(), response.getStatusCode());
|
||||
|
||||
verify(processor).readMetadata(
|
||||
any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class), any(ContentType.class));
|
||||
|
||||
// We support HEAD now too
|
||||
final MetadataProcessor processor2 = mock(MetadataProcessor.class);
|
||||
doThrow(new ODataApplicationException("msg", 100, Locale.ENGLISH)).when(processor2)
|
||||
.readMetadata(any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class),
|
||||
any(ContentType.class));
|
||||
final ODataResponse response2 = dispatch(HttpMethod.HEAD, "$metadata", processor2);
|
||||
assertEquals(HttpStatusCode.CONTINUE.getStatusCode(), response2.getStatusCode());
|
||||
|
||||
verify(processor2).readMetadata(
|
||||
any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class), any(ContentType.class));
|
||||
|
||||
dispatchMethodNotAllowed(HttpMethod.POST, "$metadata", processor);
|
||||
dispatchMethodNotAllowed(HttpMethod.PATCH, "$metadata", processor);
|
||||
dispatchMethodNotAllowed(HttpMethod.PUT, "$metadata", processor);
|
||||
|
@ -149,6 +187,11 @@ public class ODataHandlerImplTest {
|
|||
assertNotNull(response.getContent());
|
||||
assertThat(IOUtils.toString(response.getContent()),
|
||||
containsString("<edmx:Edmx Version=\"4.0\""));
|
||||
|
||||
final ODataResponse response2 = dispatch(HttpMethod.HEAD, "$metadata", null);
|
||||
assertEquals(HttpStatusCode.OK.getStatusCode(), response2.getStatusCode());
|
||||
assertNull(response2.getHeader(HttpHeader.CONTENT_TYPE));
|
||||
assertNull(response2.getContent());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -209,7 +252,6 @@ public class ODataHandlerImplTest {
|
|||
assertEquals(HttpStatusCode.BAD_REQUEST.getStatusCode(), response.getStatusCode());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void uriParserExceptionWithFormatQueryJson() throws Exception {
|
||||
final ODataResponse response = dispatch(HttpMethod.GET, "ESAllPrims", "$format=json", "", "", null);
|
||||
|
@ -226,7 +268,6 @@ public class ODataHandlerImplTest {
|
|||
response.getHeader(HttpHeader.CONTENT_TYPE));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void uriParserExceptionWithFormatJsonAcceptAtom() throws Exception {
|
||||
final ODataResponse response = dispatch(HttpMethod.GET, "ESAllPrims", "$format=json",
|
||||
|
@ -345,6 +386,7 @@ public class ODataHandlerImplTest {
|
|||
dispatchMethodNotAllowed(HttpMethod.PATCH, uri, processor);
|
||||
dispatchMethodNotAllowed(HttpMethod.PUT, uri, processor);
|
||||
dispatchMethodNotAllowed(HttpMethod.DELETE, uri, processor);
|
||||
dispatchMethodNotAllowed(HttpMethod.HEAD, uri, processor);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -359,6 +401,7 @@ public class ODataHandlerImplTest {
|
|||
dispatchMethodNotAllowed(HttpMethod.PATCH, uri, processor);
|
||||
dispatchMethodNotAllowed(HttpMethod.PUT, uri, processor);
|
||||
dispatchMethodNotAllowed(HttpMethod.DELETE, uri, processor);
|
||||
dispatchMethodNotAllowed(HttpMethod.HEAD, uri, processor);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -374,15 +417,22 @@ public class ODataHandlerImplTest {
|
|||
dispatchMethodNotAllowed(HttpMethod.PATCH, uri, processor);
|
||||
dispatchMethodNotAllowed(HttpMethod.PUT, uri, processor);
|
||||
dispatchMethodNotAllowed(HttpMethod.DELETE, uri, processor);
|
||||
dispatchMethodNotAllowed(HttpMethod.HEAD, uri, processor);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dispatchCountWithNavigation() throws Exception {
|
||||
final CountEntityCollectionProcessor processor = mock(CountEntityCollectionProcessor.class);
|
||||
dispatch(HttpMethod.GET, "ESAllPrim(0)/NavPropertyETTwoPrimMany/$count", processor);
|
||||
String uri = "ESAllPrim(0)/NavPropertyETTwoPrimMany/$count";
|
||||
dispatch(HttpMethod.GET, uri, processor);
|
||||
|
||||
verify(processor).countEntityCollection(
|
||||
any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class));
|
||||
dispatchMethodNotAllowed(HttpMethod.POST, uri, processor);
|
||||
dispatchMethodNotAllowed(HttpMethod.PATCH, uri, processor);
|
||||
dispatchMethodNotAllowed(HttpMethod.PUT, uri, processor);
|
||||
dispatchMethodNotAllowed(HttpMethod.DELETE, uri, processor);
|
||||
dispatchMethodNotAllowed(HttpMethod.HEAD, uri, processor);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -406,6 +456,7 @@ public class ODataHandlerImplTest {
|
|||
dispatchMethodNotAllowed(HttpMethod.PATCH, entityCountUri, entityCountProcessor);
|
||||
dispatchMethodNotAllowed(HttpMethod.PUT, entityCountUri, entityCountProcessor);
|
||||
dispatchMethodNotAllowed(HttpMethod.DELETE, entityCountUri, entityCountProcessor);
|
||||
dispatchMethodNotAllowed(HttpMethod.HEAD, entityCountUri, entityCountProcessor);
|
||||
|
||||
PrimitiveProcessor primitiveProcessor = mock(PrimitiveProcessor.class);
|
||||
dispatch(HttpMethod.GET, "FICRTString()", primitiveProcessor);
|
||||
|
@ -420,6 +471,7 @@ public class ODataHandlerImplTest {
|
|||
dispatchMethodWithError(HttpMethod.PATCH, valueUri, primitiveValueProcessor, HttpStatusCode.BAD_REQUEST);
|
||||
dispatchMethodWithError(HttpMethod.PUT, valueUri, primitiveValueProcessor, HttpStatusCode.BAD_REQUEST);
|
||||
dispatchMethodWithError(HttpMethod.DELETE, valueUri, primitiveValueProcessor, HttpStatusCode.BAD_REQUEST);
|
||||
dispatchMethodWithError(HttpMethod.HEAD, valueUri, primitiveValueProcessor, HttpStatusCode.BAD_REQUEST);
|
||||
|
||||
final String primitiveCollectionUri = "FICRTCollString()";
|
||||
PrimitiveCollectionProcessor primitiveCollectionProcessor = mock(PrimitiveCollectionProcessor.class);
|
||||
|
@ -430,6 +482,7 @@ public class ODataHandlerImplTest {
|
|||
dispatchMethodNotAllowed(HttpMethod.PATCH, primitiveCollectionUri, primitiveCollectionProcessor);
|
||||
dispatchMethodNotAllowed(HttpMethod.PUT, primitiveCollectionUri, primitiveCollectionProcessor);
|
||||
dispatchMethodNotAllowed(HttpMethod.DELETE, primitiveCollectionUri, primitiveCollectionProcessor);
|
||||
dispatchMethodNotAllowed(HttpMethod.HEAD, primitiveCollectionUri, primitiveCollectionProcessor);
|
||||
|
||||
final String primitiveCountUri = "FICRTCollString()/$count";
|
||||
final CountPrimitiveCollectionProcessor primitiveCountProcessor = mock(CountPrimitiveCollectionProcessor.class);
|
||||
|
@ -440,6 +493,7 @@ public class ODataHandlerImplTest {
|
|||
dispatchMethodNotAllowed(HttpMethod.PATCH, primitiveCountUri, primitiveCountProcessor);
|
||||
dispatchMethodNotAllowed(HttpMethod.PUT, primitiveCountUri, primitiveCountProcessor);
|
||||
dispatchMethodNotAllowed(HttpMethod.DELETE, primitiveCountUri, primitiveCountProcessor);
|
||||
dispatchMethodNotAllowed(HttpMethod.HEAD, primitiveCountUri, primitiveCountProcessor);
|
||||
|
||||
ComplexProcessor complexProcessor = mock(ComplexProcessor.class);
|
||||
dispatch(HttpMethod.GET, "FICRTCTTwoPrim()", complexProcessor);
|
||||
|
@ -460,6 +514,7 @@ public class ODataHandlerImplTest {
|
|||
dispatchMethodNotAllowed(HttpMethod.PATCH, complexCountUri, complexCountProcessor);
|
||||
dispatchMethodNotAllowed(HttpMethod.PUT, complexCountUri, complexCountProcessor);
|
||||
dispatchMethodNotAllowed(HttpMethod.DELETE, complexCountUri, complexCountProcessor);
|
||||
dispatchMethodNotAllowed(HttpMethod.HEAD, complexCountUri, complexCountProcessor);
|
||||
|
||||
final String mediaUri = "FICRTESMedia(ParameterInt16=1)/$value";
|
||||
final MediaEntityProcessor mediaProcessor = mock(MediaEntityProcessor.class);
|
||||
|
@ -470,6 +525,7 @@ public class ODataHandlerImplTest {
|
|||
dispatchMethodNotAllowed(HttpMethod.PATCH, mediaUri, mediaProcessor);
|
||||
dispatchMethodNotAllowed(HttpMethod.PUT, mediaUri, mediaProcessor);
|
||||
dispatchMethodNotAllowed(HttpMethod.DELETE, mediaUri, mediaProcessor);
|
||||
dispatchMethodNotAllowed(HttpMethod.HEAD, mediaUri, mediaProcessor);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -483,6 +539,7 @@ public class ODataHandlerImplTest {
|
|||
dispatchMethodNotAllowed(HttpMethod.PATCH, ContainerProvider.AIRT_STRING, primitiveProcessor);
|
||||
dispatchMethodNotAllowed(HttpMethod.PUT, ContainerProvider.AIRT_STRING, primitiveProcessor);
|
||||
dispatchMethodNotAllowed(HttpMethod.DELETE, ContainerProvider.AIRT_STRING, primitiveProcessor);
|
||||
dispatchMethodNotAllowed(HttpMethod.HEAD, ContainerProvider.AIRT_STRING, primitiveProcessor);
|
||||
|
||||
ActionPrimitiveCollectionProcessor primitiveCollectionProcessor = mock(ActionPrimitiveCollectionProcessor.class);
|
||||
dispatch(HttpMethod.POST, ContainerProvider.AIRT_COLL_STRING_TWO_PARAM, primitiveCollectionProcessor);
|
||||
|
@ -534,6 +591,7 @@ public class ODataHandlerImplTest {
|
|||
dispatchMethodNotAllowed(HttpMethod.PATCH, ContainerProvider.AIRT, voidProcessor);
|
||||
dispatchMethodNotAllowed(HttpMethod.PUT, ContainerProvider.AIRT, voidProcessor);
|
||||
dispatchMethodNotAllowed(HttpMethod.DELETE, ContainerProvider.AIRT, voidProcessor);
|
||||
dispatchMethodNotAllowed(HttpMethod.HEAD, ContainerProvider.AIRT, voidProcessor);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -563,6 +621,7 @@ public class ODataHandlerImplTest {
|
|||
any(ContentType.class), any(ContentType.class));
|
||||
|
||||
dispatchMethodNotAllowed(HttpMethod.POST, uri, processor);
|
||||
dispatchMethodNotAllowed(HttpMethod.HEAD, uri, processor);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -587,6 +646,7 @@ public class ODataHandlerImplTest {
|
|||
|
||||
dispatchMethodNotAllowed(HttpMethod.POST, uri, processor);
|
||||
dispatchMethodNotAllowed(HttpMethod.PATCH, uri, processor);
|
||||
dispatchMethodNotAllowed(HttpMethod.HEAD, uri, processor);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -605,6 +665,9 @@ public class ODataHandlerImplTest {
|
|||
|
||||
dispatch(HttpMethod.DELETE, uri, processor);
|
||||
verifyZeroInteractions(processor);
|
||||
|
||||
dispatch(HttpMethod.HEAD, uri, processor);
|
||||
verifyZeroInteractions(processor);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -633,6 +696,7 @@ public class ODataHandlerImplTest {
|
|||
|
||||
dispatchMethodNotAllowed(HttpMethod.POST, uri, processor);
|
||||
dispatchMethodNotAllowed(HttpMethod.PATCH, uri, processor);
|
||||
dispatchMethodNotAllowed(HttpMethod.HEAD, uri, processor);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -641,6 +705,7 @@ public class ODataHandlerImplTest {
|
|||
dispatch(HttpMethod.DELETE, "ESMedia(1)", processor);
|
||||
|
||||
verify(processor).deleteEntity(any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class));
|
||||
dispatchMethodNotAllowed(HttpMethod.HEAD, "ESMedia(1)", processor);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -666,6 +731,7 @@ public class ODataHandlerImplTest {
|
|||
verify(processor).deletePrimitive(any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class));
|
||||
|
||||
dispatchMethodNotAllowed(HttpMethod.POST, uri, processor);
|
||||
dispatchMethodNotAllowed(HttpMethod.HEAD, uri, processor);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -688,6 +754,7 @@ public class ODataHandlerImplTest {
|
|||
|
||||
dispatchMethodNotAllowed(HttpMethod.POST, uri, processor);
|
||||
dispatchMethodNotAllowed(HttpMethod.PATCH, uri, processor);
|
||||
dispatchMethodNotAllowed(HttpMethod.HEAD, uri, processor);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -708,6 +775,7 @@ public class ODataHandlerImplTest {
|
|||
verify(processor).deletePrimitiveCollection(any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class));
|
||||
|
||||
dispatchMethodNotAllowed(HttpMethod.POST, uri, processor);
|
||||
dispatchMethodNotAllowed(HttpMethod.HEAD, uri, processor);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -722,6 +790,7 @@ public class ODataHandlerImplTest {
|
|||
dispatchMethodNotAllowed(HttpMethod.PATCH, uri, processor);
|
||||
dispatchMethodNotAllowed(HttpMethod.PUT, uri, processor);
|
||||
dispatchMethodNotAllowed(HttpMethod.DELETE, uri, processor);
|
||||
dispatchMethodNotAllowed(HttpMethod.HEAD, uri, processor);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -747,6 +816,7 @@ public class ODataHandlerImplTest {
|
|||
verify(processor).deleteComplex(any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class));
|
||||
|
||||
dispatchMethodNotAllowed(HttpMethod.POST, uri, processor);
|
||||
dispatchMethodNotAllowed(HttpMethod.HEAD, uri, processor);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -767,6 +837,7 @@ public class ODataHandlerImplTest {
|
|||
verify(processor).deleteComplexCollection(any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class));
|
||||
|
||||
dispatchMethodNotAllowed(HttpMethod.POST, uri, processor);
|
||||
dispatchMethodNotAllowed(HttpMethod.HEAD, uri, processor);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -781,6 +852,7 @@ public class ODataHandlerImplTest {
|
|||
dispatchMethodNotAllowed(HttpMethod.PATCH, uri, processor);
|
||||
dispatchMethodNotAllowed(HttpMethod.PUT, uri, processor);
|
||||
dispatchMethodNotAllowed(HttpMethod.DELETE, uri, processor);
|
||||
dispatchMethodNotAllowed(HttpMethod.HEAD, uri, processor);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -809,6 +881,8 @@ public class ODataHandlerImplTest {
|
|||
|
||||
dispatch(HttpMethod.DELETE, uriMany, "$id=ESTwoPrim(1)", null, null, processor);
|
||||
verify(processor).deleteReference(any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class));
|
||||
|
||||
dispatchMethodNotAllowed(HttpMethod.HEAD, uri, processor);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -822,6 +896,7 @@ public class ODataHandlerImplTest {
|
|||
|
||||
dispatchMethodNotAllowed(HttpMethod.PATCH, uri, processor);
|
||||
dispatchMethodNotAllowed(HttpMethod.PUT, uri, processor);
|
||||
dispatchMethodNotAllowed(HttpMethod.HEAD, uri, processor);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue