mirror of
https://github.com/apache/olingo-odata4.git
synced 2025-03-07 00:59:08 +00:00
[OLINGO-482] Added test case
This commit is contained in:
parent
3fd3843662
commit
ab39763f3e
@ -27,9 +27,13 @@ import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.olingo.commons.api.ODataException;
|
||||
@ -45,6 +49,7 @@ import org.apache.olingo.server.api.OData;
|
||||
import org.apache.olingo.server.api.ODataApplicationException;
|
||||
import org.apache.olingo.server.api.ODataRequest;
|
||||
import org.apache.olingo.server.api.ODataResponse;
|
||||
import org.apache.olingo.server.api.ODataServerError;
|
||||
import org.apache.olingo.server.api.ServiceMetadata;
|
||||
import org.apache.olingo.server.api.edm.provider.EdmProvider;
|
||||
import org.apache.olingo.server.api.edm.provider.EntitySet;
|
||||
@ -63,6 +68,7 @@ import org.apache.olingo.server.api.processor.CountEntityCollectionProcessor;
|
||||
import org.apache.olingo.server.api.processor.CountPrimitiveCollectionProcessor;
|
||||
import org.apache.olingo.server.api.processor.EntityCollectionProcessor;
|
||||
import org.apache.olingo.server.api.processor.EntityProcessor;
|
||||
import org.apache.olingo.server.api.processor.ErrorProcessor;
|
||||
import org.apache.olingo.server.api.processor.MediaEntityProcessor;
|
||||
import org.apache.olingo.server.api.processor.MetadataProcessor;
|
||||
import org.apache.olingo.server.api.processor.PrimitiveCollectionProcessor;
|
||||
@ -618,8 +624,32 @@ public class ODataHandlerTest {
|
||||
dispatchMethodNotAllowed(HttpMethod.DELETE, uri, processor);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unsupportedRequestContentType() throws Exception {
|
||||
EntityProcessor processor = mock(EntityProcessor.class);
|
||||
ErrorProcessor errorProcessor = mock(ErrorProcessor.class);
|
||||
dispatch(HttpMethod.POST, "ESAllPrim", "", HttpHeader.CONTENT_TYPE, "some/unsupported", errorProcessor);
|
||||
verifyZeroInteractions(processor);
|
||||
verify(errorProcessor).processError(any(ODataRequest.class), any(ODataResponse.class), any(ODataServerError.class),
|
||||
any(ContentType.class));
|
||||
}
|
||||
|
||||
private ODataResponse dispatch(final HttpMethod method, final String path, final String query,
|
||||
final String headerName, final String headerValue, final Processor processor) {
|
||||
Map<String, List<String>> headers = null;
|
||||
if(headerName != null) {
|
||||
headers = Collections.singletonMap(headerName, Collections.singletonList(headerValue));
|
||||
}
|
||||
List<Processor> processors = null;
|
||||
if(processor != null) {
|
||||
processors = Collections.singletonList(processor);
|
||||
}
|
||||
return dispatch(method, path, query, headers, processors);
|
||||
}
|
||||
|
||||
|
||||
private ODataResponse dispatch(final HttpMethod method, final String path, final String query,
|
||||
final Map<String, List<String>> headers, final List<Processor> processors) {
|
||||
ODataRequest request = new ODataRequest();
|
||||
request.setMethod(method);
|
||||
request.setRawBaseUri(BASE_URI);
|
||||
@ -629,11 +659,17 @@ public class ODataHandlerTest {
|
||||
request.setRawODataPath(path);
|
||||
request.setRawQueryPath(query);
|
||||
|
||||
if (headerName != null) {
|
||||
request.addHeader(headerName, Collections.singletonList(headerValue));
|
||||
if (headers != null) {
|
||||
Set<Map.Entry<String, List<String>>> headerSet = headers.entrySet();
|
||||
for (Map.Entry<String, List<String>> headerItem : headerSet) {
|
||||
request.addHeader(headerItem.getKey(), headerItem.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
if(request.getHeaders(HttpHeader.CONTENT_TYPE) == null) {
|
||||
request.addHeader(HttpHeader.CONTENT_TYPE, Collections.singletonList(
|
||||
ODataFormat.JSON.getContentType(ODataServiceVersion.V40).toContentTypeString()));
|
||||
}
|
||||
request.addHeader(HttpHeader.CONTENT_TYPE, Collections.singletonList(
|
||||
ODataFormat.JSON.getContentType(ODataServiceVersion.V40).toContentTypeString()));
|
||||
|
||||
final OData odata = OData.newInstance();
|
||||
final ServiceMetadata metadata = odata.createServiceMetadata(
|
||||
@ -641,8 +677,10 @@ public class ODataHandlerTest {
|
||||
|
||||
ODataHandler handler = new ODataHandler(odata, metadata);
|
||||
|
||||
if (processor != null) {
|
||||
handler.register(processor);
|
||||
if (processors != null && !processors.isEmpty()) {
|
||||
for (Processor p : processors) {
|
||||
handler.register(p);
|
||||
}
|
||||
}
|
||||
|
||||
final ODataResponse response = handler.process(request);
|
||||
|
Loading…
x
Reference in New Issue
Block a user