mirror of
https://github.com/apache/olingo-odata4.git
synced 2025-02-06 01:59:12 +00:00
[OLINGO-507] server dispatcher improvements
Change-Id: I9f65b0d7d9374b8bd136616b576320bf73518441 Signed-off-by: Christian Amend <chrisam@apache.org>
This commit is contained in:
parent
0b862cd68e
commit
0d310f01e2
@ -215,13 +215,13 @@ public class ODataHandler {
|
|||||||
case entitySet:
|
case entitySet:
|
||||||
case navigationProperty:
|
case navigationProperty:
|
||||||
if (((UriResourcePartTyped) lastPathSegment).isCollection()) {
|
if (((UriResourcePartTyped) lastPathSegment).isCollection()) {
|
||||||
if (method.equals(HttpMethod.GET)) {
|
if (method == HttpMethod.GET) {
|
||||||
final ContentType requestedContentType = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
|
final ContentType requestedContentType = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
|
||||||
request, customContentTypeSupport, RepresentationType.COLLECTION_ENTITY);
|
request, customContentTypeSupport, RepresentationType.COLLECTION_ENTITY);
|
||||||
|
|
||||||
selectProcessor(EntityCollectionProcessor.class)
|
selectProcessor(EntityCollectionProcessor.class)
|
||||||
.readEntityCollection(request, response, uriInfo, requestedContentType);
|
.readEntityCollection(request, response, uriInfo, requestedContentType);
|
||||||
} else if (method.equals(HttpMethod.POST)) {
|
} else if (method == HttpMethod.POST) {
|
||||||
if (isMedia(lastPathSegment)) {
|
if (isMedia(lastPathSegment)) {
|
||||||
final ContentType requestFormat = ContentType.parse(request.getHeader(HttpHeader.CONTENT_TYPE));
|
final ContentType requestFormat = ContentType.parse(request.getHeader(HttpHeader.CONTENT_TYPE));
|
||||||
final ContentType responseFormat = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
|
final ContentType responseFormat = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
|
||||||
@ -236,28 +236,31 @@ public class ODataHandler {
|
|||||||
.createEntity(request, response, uriInfo, requestFormat, responseFormat);
|
.createEntity(request, response, uriInfo, requestFormat, responseFormat);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new ODataHandlerException("HTTP method not allowed.",
|
throw new ODataHandlerException("HTTP method " + method + " is not allowed.",
|
||||||
ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, method.toString());
|
ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, method.toString());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (method.equals(HttpMethod.GET)) {
|
if (method == HttpMethod.GET) {
|
||||||
final ContentType requestedContentType = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
|
final ContentType requestedContentType = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
|
||||||
request, customContentTypeSupport, RepresentationType.ENTITY);
|
request, customContentTypeSupport, RepresentationType.ENTITY);
|
||||||
|
|
||||||
selectProcessor(EntityProcessor.class)
|
selectProcessor(EntityProcessor.class)
|
||||||
.readEntity(request, response, uriInfo, requestedContentType);
|
.readEntity(request, response, uriInfo, requestedContentType);
|
||||||
} else if (method.equals(HttpMethod.DELETE)) {
|
} else if (method == HttpMethod.PUT || method == HttpMethod.PATCH) {
|
||||||
|
throw new ODataHandlerException("not implemented",
|
||||||
|
ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
|
||||||
|
} else if (method == HttpMethod.DELETE) {
|
||||||
selectProcessor(isMedia(lastPathSegment) ? MediaEntityProcessor.class : EntityProcessor.class)
|
selectProcessor(isMedia(lastPathSegment) ? MediaEntityProcessor.class : EntityProcessor.class)
|
||||||
.deleteEntity(request, response, uriInfo);
|
.deleteEntity(request, response, uriInfo);
|
||||||
} else {
|
} else {
|
||||||
throw new ODataHandlerException("not implemented",
|
throw new ODataHandlerException("HTTP method " + method + " is not allowed.",
|
||||||
ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
|
ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, method.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case count:
|
case count:
|
||||||
if (method.equals(HttpMethod.GET)) {
|
if (method == HttpMethod.GET) {
|
||||||
final UriResource resource = uriInfo.getUriResourceParts().get(lastPathSegmentIndex - 1);
|
final UriResource resource = uriInfo.getUriResourceParts().get(lastPathSegmentIndex - 1);
|
||||||
if (resource instanceof UriResourceEntitySet || resource instanceof UriResourceNavigation) {
|
if (resource instanceof UriResourceEntitySet || resource instanceof UriResourceNavigation) {
|
||||||
selectProcessor(CountEntityCollectionProcessor.class)
|
selectProcessor(CountEntityCollectionProcessor.class)
|
||||||
@ -274,10 +277,10 @@ public class ODataHandler {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case primitiveProperty:
|
case primitiveProperty:
|
||||||
if (method.equals(HttpMethod.GET)) {
|
|
||||||
final UriResourceProperty propertyResource = (UriResourceProperty) lastPathSegment;
|
final UriResourceProperty propertyResource = (UriResourceProperty) lastPathSegment;
|
||||||
final RepresentationType representationType = propertyResource.isCollection() ?
|
final RepresentationType representationType = propertyResource.isCollection() ?
|
||||||
RepresentationType.COLLECTION_PRIMITIVE : RepresentationType.PRIMITIVE;
|
RepresentationType.COLLECTION_PRIMITIVE : RepresentationType.PRIMITIVE;
|
||||||
|
if (method == HttpMethod.GET) {
|
||||||
final ContentType requestedContentType = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
|
final ContentType requestedContentType = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
|
||||||
request, customContentTypeSupport, representationType);
|
request, customContentTypeSupport, representationType);
|
||||||
if (representationType == RepresentationType.PRIMITIVE) {
|
if (representationType == RepresentationType.PRIMITIVE) {
|
||||||
@ -287,67 +290,95 @@ public class ODataHandler {
|
|||||||
selectProcessor(PrimitiveCollectionProcessor.class)
|
selectProcessor(PrimitiveCollectionProcessor.class)
|
||||||
.readPrimitiveCollection(request, response, uriInfo, requestedContentType);
|
.readPrimitiveCollection(request, response, uriInfo, requestedContentType);
|
||||||
}
|
}
|
||||||
} else {
|
} else if (method == HttpMethod.PUT || method == HttpMethod.PATCH) {
|
||||||
throw new ODataHandlerException("not implemented",
|
throw new ODataHandlerException("not implemented",
|
||||||
ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
|
ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
|
||||||
|
} else if (method == HttpMethod.DELETE) {
|
||||||
|
if (representationType == RepresentationType.PRIMITIVE) {
|
||||||
|
selectProcessor(PrimitiveProcessor.class)
|
||||||
|
.deletePrimitive(request, response, uriInfo);
|
||||||
|
} else {
|
||||||
|
selectProcessor(PrimitiveCollectionProcessor.class)
|
||||||
|
.deletePrimitiveCollection(request, response, uriInfo);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new ODataHandlerException("HTTP method " + method + " is not allowed.",
|
||||||
|
ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, method.toString());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case complexProperty:
|
case complexProperty:
|
||||||
if (method.equals(HttpMethod.GET)) {
|
final UriResourceProperty complexPropertyResource = (UriResourceProperty) lastPathSegment;
|
||||||
final UriResourceProperty propertyResource = (UriResourceProperty) lastPathSegment;
|
final RepresentationType complexRepresentationType = complexPropertyResource.isCollection() ?
|
||||||
final RepresentationType representationType = propertyResource.isCollection() ?
|
|
||||||
RepresentationType.COLLECTION_COMPLEX : RepresentationType.COMPLEX;
|
RepresentationType.COLLECTION_COMPLEX : RepresentationType.COMPLEX;
|
||||||
|
if (method == HttpMethod.GET) {
|
||||||
final ContentType requestedContentType = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
|
final ContentType requestedContentType = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
|
||||||
request, customContentTypeSupport, representationType);
|
request, customContentTypeSupport, complexRepresentationType);
|
||||||
if (representationType == RepresentationType.COMPLEX) {
|
if (complexRepresentationType == RepresentationType.COMPLEX) {
|
||||||
selectProcessor(ComplexProcessor.class)
|
selectProcessor(ComplexProcessor.class)
|
||||||
.readComplex(request, response, uriInfo, requestedContentType);
|
.readComplex(request, response, uriInfo, requestedContentType);
|
||||||
} else {
|
} else {
|
||||||
selectProcessor(ComplexCollectionProcessor.class)
|
selectProcessor(ComplexCollectionProcessor.class)
|
||||||
.readComplexCollection(request, response, uriInfo, requestedContentType);
|
.readComplexCollection(request, response, uriInfo, requestedContentType);
|
||||||
}
|
}
|
||||||
} else {
|
} else if (method == HttpMethod.PUT || method == HttpMethod.PATCH) {
|
||||||
throw new ODataHandlerException("not implemented",
|
throw new ODataHandlerException("not implemented",
|
||||||
ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
|
ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
|
||||||
|
} else if (method == HttpMethod.DELETE) {
|
||||||
|
if (complexRepresentationType == RepresentationType.COMPLEX) {
|
||||||
|
selectProcessor(ComplexProcessor.class)
|
||||||
|
.deleteComplex(request, response, uriInfo);
|
||||||
|
} else {
|
||||||
|
selectProcessor(ComplexCollectionProcessor.class)
|
||||||
|
.deleteComplexCollection(request, response, uriInfo);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new ODataHandlerException("HTTP method " + method + " is not allowed.",
|
||||||
|
ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, method.toString());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case value:
|
case value:
|
||||||
final UriResource resource = uriInfo.getUriResourceParts().get(lastPathSegmentIndex - 1);
|
final UriResource resource = uriInfo.getUriResourceParts().get(lastPathSegmentIndex - 1);
|
||||||
if (resource instanceof UriResourceProperty) {
|
if (resource instanceof UriResourceProperty) {
|
||||||
if (method.equals(HttpMethod.GET)) {
|
if (method == HttpMethod.GET) {
|
||||||
final RepresentationType representationType =
|
final RepresentationType valueRepresentationType =
|
||||||
(EdmPrimitiveType) ((UriResourceProperty) resource).getType() ==
|
(EdmPrimitiveType) ((UriResourceProperty) resource).getType() ==
|
||||||
EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Binary) ?
|
EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Binary) ?
|
||||||
RepresentationType.BINARY : RepresentationType.VALUE;
|
RepresentationType.BINARY : RepresentationType.VALUE;
|
||||||
final ContentType requestedContentType = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
|
final ContentType requestedContentType = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
|
||||||
request, customContentTypeSupport, representationType);
|
request, customContentTypeSupport, valueRepresentationType);
|
||||||
|
|
||||||
selectProcessor(PrimitiveValueProcessor.class)
|
selectProcessor(PrimitiveValueProcessor.class)
|
||||||
.readPrimitiveValue(request, response, uriInfo, requestedContentType);
|
.readPrimitiveValue(request, response, uriInfo, requestedContentType);
|
||||||
} else {
|
} else if (method == HttpMethod.PUT) {
|
||||||
throw new ODataHandlerException("not implemented",
|
throw new ODataHandlerException("not implemented",
|
||||||
ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
|
ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
|
||||||
|
} else if (method == HttpMethod.DELETE) {
|
||||||
|
selectProcessor(PrimitiveValueProcessor.class)
|
||||||
|
.deletePrimitive(request, response, uriInfo);
|
||||||
|
} else {
|
||||||
|
throw new ODataHandlerException("HTTP method " + method + " is not allowed.",
|
||||||
|
ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, method.toString());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (method.equals(HttpMethod.GET)) {
|
if (method == HttpMethod.GET) {
|
||||||
final ContentType requestedContentType = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
|
final ContentType requestedContentType = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
|
||||||
request, customContentTypeSupport, RepresentationType.MEDIA);
|
request, customContentTypeSupport, RepresentationType.MEDIA);
|
||||||
selectProcessor(MediaEntityProcessor.class)
|
selectProcessor(MediaEntityProcessor.class)
|
||||||
.readMediaEntity(request, response, uriInfo, requestedContentType);
|
.readMediaEntity(request, response, uriInfo, requestedContentType);
|
||||||
} else if (method.equals(HttpMethod.PUT)) {
|
} else if (method == HttpMethod.PUT) {
|
||||||
final ContentType requestFormat = ContentType.parse(request.getHeader(HttpHeader.CONTENT_TYPE));
|
final ContentType requestFormat = ContentType.parse(request.getHeader(HttpHeader.CONTENT_TYPE));
|
||||||
final ContentType responseFormat = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
|
final ContentType responseFormat = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
|
||||||
request, customContentTypeSupport, RepresentationType.ENTITY);
|
request, customContentTypeSupport, RepresentationType.ENTITY);
|
||||||
selectProcessor(MediaEntityProcessor.class)
|
selectProcessor(MediaEntityProcessor.class)
|
||||||
.updateMediaEntity(request, response, uriInfo, requestFormat, responseFormat);
|
.updateMediaEntity(request, response, uriInfo, requestFormat, responseFormat);
|
||||||
} else if (method.equals(HttpMethod.DELETE)) {
|
} else if (method == HttpMethod.DELETE) {
|
||||||
selectProcessor(MediaEntityProcessor.class)
|
selectProcessor(MediaEntityProcessor.class)
|
||||||
.deleteEntity(request, response, uriInfo);
|
.deleteEntity(request, response, uriInfo);
|
||||||
} else {
|
} else {
|
||||||
throw new ODataHandlerException("not implemented",
|
throw new ODataHandlerException("HTTP method " + method + " is not allowed.",
|
||||||
ODataHandlerException.MessageKeys.FUNCTIONALITY_NOT_IMPLEMENTED);
|
ODataHandlerException.MessageKeys.HTTP_METHOD_NOT_ALLOWED, method.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -23,7 +23,6 @@ import static org.junit.Assert.assertEquals;
|
|||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertThat;
|
import static org.junit.Assert.assertThat;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
import static org.mockito.Matchers.eq;
|
|
||||||
import static org.mockito.Mockito.doThrow;
|
import static org.mockito.Mockito.doThrow;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
@ -222,22 +221,31 @@ public class ODataHandlerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void dispatchEntitySet() throws Exception {
|
public void dispatchEntitySet() throws Exception {
|
||||||
|
final String uri = "ESAllPrim";
|
||||||
final EntityCollectionProcessor processor = mock(EntityCollectionProcessor.class);
|
final EntityCollectionProcessor processor = mock(EntityCollectionProcessor.class);
|
||||||
dispatch(HttpMethod.GET, "ESAllPrim", processor);
|
|
||||||
|
|
||||||
|
dispatch(HttpMethod.GET, uri, processor);
|
||||||
verify(processor).readEntityCollection(
|
verify(processor).readEntityCollection(
|
||||||
any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class), any(ContentType.class));
|
any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class), any(ContentType.class));
|
||||||
|
|
||||||
|
dispatchMethodNotAllowed(HttpMethod.PATCH, uri, processor);
|
||||||
|
dispatchMethodNotAllowed(HttpMethod.PUT, uri, processor);
|
||||||
|
dispatchMethodNotAllowed(HttpMethod.DELETE, uri, processor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void dispatchEntitySetCount() throws Exception {
|
public void dispatchEntitySetCount() throws Exception {
|
||||||
|
final String uri = "ESAllPrim/$count";
|
||||||
final CountEntityCollectionProcessor processor = mock(CountEntityCollectionProcessor.class);
|
final CountEntityCollectionProcessor processor = mock(CountEntityCollectionProcessor.class);
|
||||||
dispatch(HttpMethod.GET, "ESAllPrim/$count", processor);
|
|
||||||
|
|
||||||
|
dispatch(HttpMethod.GET, uri, processor);
|
||||||
verify(processor).countEntityCollection(
|
verify(processor).countEntityCollection(
|
||||||
any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class));
|
any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class));
|
||||||
|
|
||||||
dispatchMethodNotAllowed(HttpMethod.POST, "ESAllPrim/$count", processor);
|
dispatchMethodNotAllowed(HttpMethod.POST, uri, processor);
|
||||||
|
dispatchMethodNotAllowed(HttpMethod.PATCH, uri, processor);
|
||||||
|
dispatchMethodNotAllowed(HttpMethod.PUT, uri, processor);
|
||||||
|
dispatchMethodNotAllowed(HttpMethod.DELETE, uri, processor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -251,63 +259,45 @@ public class ODataHandlerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void dispatchEntity() throws Exception {
|
public void dispatchEntity() throws Exception {
|
||||||
|
final String uri = "ESAllPrim(0)";
|
||||||
final EntityProcessor processor = mock(EntityProcessor.class);
|
final EntityProcessor processor = mock(EntityProcessor.class);
|
||||||
dispatch(HttpMethod.GET, "ESAllPrim(0)", processor);
|
|
||||||
|
|
||||||
|
dispatch(HttpMethod.GET, uri, processor);
|
||||||
verify(processor).readEntity(
|
verify(processor).readEntity(
|
||||||
any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class), any(ContentType.class));
|
any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class), any(ContentType.class));
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void dispatchEntityDelete() throws Exception {
|
|
||||||
final EntityProcessor processor = mock(EntityProcessor.class);
|
|
||||||
dispatch(HttpMethod.DELETE, "ESAllPrim(0)", processor);
|
|
||||||
|
|
||||||
|
dispatch(HttpMethod.DELETE, uri, processor);
|
||||||
verify(processor).deleteEntity(any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class));
|
verify(processor).deleteEntity(any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class));
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void dispatchEntityCreate() throws Exception {
|
|
||||||
final EntityProcessor processor = mock(EntityProcessor.class);
|
|
||||||
dispatch(HttpMethod.POST, "ESAllPrim", processor);
|
dispatch(HttpMethod.POST, "ESAllPrim", processor);
|
||||||
|
verify(processor).createEntity(any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class),
|
||||||
|
any(ContentType.class), any(ContentType.class));
|
||||||
|
|
||||||
verify(processor).createEntity(any(ODataRequest.class), any(ODataResponse.class),
|
dispatchMethodNotAllowed(HttpMethod.POST, uri, processor);
|
||||||
any(UriInfo.class), any(ContentType.class), any(ContentType.class));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void dispatchMedia() throws Exception {
|
public void dispatchMedia() throws Exception {
|
||||||
|
final String uri = "ESMedia(1)/$value";
|
||||||
final MediaEntityProcessor processor = mock(MediaEntityProcessor.class);
|
final MediaEntityProcessor processor = mock(MediaEntityProcessor.class);
|
||||||
dispatch(HttpMethod.GET, "ESMedia(1)/$value", processor);
|
|
||||||
|
|
||||||
|
dispatch(HttpMethod.GET, uri, processor);
|
||||||
verify(processor).readMediaEntity(
|
verify(processor).readMediaEntity(
|
||||||
any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class), any(ContentType.class));
|
any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class), any(ContentType.class));
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void dispatchMediaCreate() throws Exception {
|
|
||||||
final MediaEntityProcessor processor = mock(MediaEntityProcessor.class);
|
|
||||||
dispatch(HttpMethod.POST, "ESMedia", processor);
|
dispatch(HttpMethod.POST, "ESMedia", processor);
|
||||||
|
verify(processor).createMediaEntity(any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class),
|
||||||
|
any(ContentType.class), any(ContentType.class));
|
||||||
|
|
||||||
verify(processor).createMediaEntity(any(ODataRequest.class), any(ODataResponse.class),
|
dispatch(HttpMethod.PUT, uri, processor);
|
||||||
any(UriInfo.class), any(ContentType.class), any(ContentType.class));
|
verify(processor).updateMediaEntity(any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class),
|
||||||
}
|
any(ContentType.class), any(ContentType.class));
|
||||||
|
|
||||||
@Test
|
|
||||||
public void dispatchMediaUpdate() throws Exception {
|
|
||||||
final MediaEntityProcessor processor = mock(MediaEntityProcessor.class);
|
|
||||||
dispatch(HttpMethod.PUT, "ESMedia(1)/$value", processor);
|
|
||||||
|
|
||||||
verify(processor).updateMediaEntity(any(ODataRequest.class), any(ODataResponse.class),
|
|
||||||
any(UriInfo.class), any(ContentType.class), any(ContentType.class));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void dispatchMediaDelete() throws Exception {
|
|
||||||
final MediaEntityProcessor processor = mock(MediaEntityProcessor.class);
|
|
||||||
dispatch(HttpMethod.DELETE, "ESMedia(1)/$value", processor);
|
|
||||||
|
|
||||||
|
dispatch(HttpMethod.DELETE, uri, processor);
|
||||||
verify(processor).deleteEntity(any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class));
|
verify(processor).deleteEntity(any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class));
|
||||||
|
|
||||||
|
dispatchMethodNotAllowed(HttpMethod.POST, uri, processor);
|
||||||
|
dispatchMethodNotAllowed(HttpMethod.PATCH, uri, processor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -320,47 +310,77 @@ public class ODataHandlerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void dispatchPrimitiveProperty() throws Exception {
|
public void dispatchPrimitiveProperty() throws Exception {
|
||||||
|
final String uri = "ESAllPrim(0)/PropertyInt16";
|
||||||
final PrimitiveProcessor processor = mock(PrimitiveProcessor.class);
|
final PrimitiveProcessor processor = mock(PrimitiveProcessor.class);
|
||||||
dispatch(HttpMethod.GET, "ESAllPrim(0)/PropertyInt16", processor);
|
|
||||||
|
|
||||||
|
dispatch(HttpMethod.GET, uri, processor);
|
||||||
verify(processor).readPrimitive(
|
verify(processor).readPrimitive(
|
||||||
any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class), any(ContentType.class));
|
any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class), any(ContentType.class));
|
||||||
|
|
||||||
|
dispatch(HttpMethod.DELETE, uri, processor);
|
||||||
|
verify(processor).deletePrimitive(any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class));
|
||||||
|
|
||||||
|
dispatchMethodNotAllowed(HttpMethod.POST, uri, processor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void dispatchPrimitivePropertyValue() throws Exception {
|
public void dispatchPrimitivePropertyValue() throws Exception {
|
||||||
|
final String uri = "ESAllPrim(0)/PropertyInt16/$value";
|
||||||
final PrimitiveValueProcessor processor = mock(PrimitiveValueProcessor.class);
|
final PrimitiveValueProcessor processor = mock(PrimitiveValueProcessor.class);
|
||||||
dispatch(HttpMethod.GET, "ESAllPrim(0)/PropertyInt16/$value", processor);
|
|
||||||
|
|
||||||
verify(processor).readPrimitiveValue(any(ODataRequest.class), any(ODataResponse.class),
|
dispatch(HttpMethod.GET, uri, processor);
|
||||||
any(UriInfo.class), any(ContentType.class));
|
verify(processor).readPrimitiveValue(any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class),
|
||||||
|
any(ContentType.class));
|
||||||
|
|
||||||
|
dispatch(HttpMethod.DELETE, uri, processor);
|
||||||
|
verify(processor).deletePrimitive(any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class));
|
||||||
|
|
||||||
|
dispatchMethodNotAllowed(HttpMethod.POST, uri, processor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void dispatchPrimitiveCollectionProperty() throws Exception {
|
public void dispatchPrimitiveCollectionProperty() throws Exception {
|
||||||
|
final String uri = "ESMixPrimCollComp(7)/CollPropertyString";
|
||||||
final PrimitiveCollectionProcessor processor = mock(PrimitiveCollectionProcessor.class);
|
final PrimitiveCollectionProcessor processor = mock(PrimitiveCollectionProcessor.class);
|
||||||
dispatch(HttpMethod.GET, "ESMixPrimCollComp(7)/CollPropertyString", processor);
|
|
||||||
|
|
||||||
|
dispatch(HttpMethod.GET, uri, processor);
|
||||||
verify(processor).readPrimitiveCollection(
|
verify(processor).readPrimitiveCollection(
|
||||||
any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class), any(ContentType.class));
|
any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class), any(ContentType.class));
|
||||||
|
|
||||||
|
dispatch(HttpMethod.DELETE, uri, processor);
|
||||||
|
verify(processor).deletePrimitiveCollection(any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class));
|
||||||
|
|
||||||
|
dispatchMethodNotAllowed(HttpMethod.POST, uri, processor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void dispatchComplexProperty() throws Exception {
|
public void dispatchComplexProperty() throws Exception {
|
||||||
|
final String uri = "ESMixPrimCollComp(7)/PropertyComp";
|
||||||
final ComplexProcessor processor = mock(ComplexProcessor.class);
|
final ComplexProcessor processor = mock(ComplexProcessor.class);
|
||||||
dispatch(HttpMethod.GET, "ESMixPrimCollComp(7)/PropertyComp", processor);
|
|
||||||
|
|
||||||
|
dispatch(HttpMethod.GET, uri, processor);
|
||||||
verify(processor).readComplex(
|
verify(processor).readComplex(
|
||||||
any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class), any(ContentType.class));
|
any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class), any(ContentType.class));
|
||||||
|
|
||||||
|
dispatch(HttpMethod.DELETE, uri, processor);
|
||||||
|
verify(processor).deleteComplex(any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class));
|
||||||
|
|
||||||
|
dispatchMethodNotAllowed(HttpMethod.POST, uri, processor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void dispatchComplexCollectionProperty() throws Exception {
|
public void dispatchComplexCollectionProperty() throws Exception {
|
||||||
|
final String uri = "ESMixPrimCollComp(7)/CollPropertyComp";
|
||||||
final ComplexCollectionProcessor processor = mock(ComplexCollectionProcessor.class);
|
final ComplexCollectionProcessor processor = mock(ComplexCollectionProcessor.class);
|
||||||
dispatch(HttpMethod.GET, "ESMixPrimCollComp(7)/CollPropertyComp", processor);
|
|
||||||
|
|
||||||
|
dispatch(HttpMethod.GET, uri, processor);
|
||||||
verify(processor).readComplexCollection(
|
verify(processor).readComplexCollection(
|
||||||
any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class), any(ContentType.class));
|
any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class), any(ContentType.class));
|
||||||
|
|
||||||
|
dispatch(HttpMethod.DELETE, uri, processor);
|
||||||
|
verify(processor).deleteComplexCollection(any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class));
|
||||||
|
|
||||||
|
dispatchMethodNotAllowed(HttpMethod.POST, uri, processor);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ODataResponse dispatch(final HttpMethod method, final String path, final String query,
|
private ODataResponse dispatch(final HttpMethod method, final String path, final String query,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user