org.apache.olingo.odata2.api.commons.HttpStatusCodes Java Examples
The following examples show how to use
org.apache.olingo.odata2.api.commons.HttpStatusCodes.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ODataRequestHandlerValidationTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test public void wrongNavigationPath() throws Exception { wrongNavigationPath(ODataHttpMethod.PUT, UriType.URI3, HttpStatusCodes.BAD_REQUEST); wrongNavigationPath(ODataHttpMethod.PATCH, UriType.URI3, HttpStatusCodes.BAD_REQUEST); wrongNavigationPath(ODataHttpMethod.PUT, UriType.URI4, HttpStatusCodes.BAD_REQUEST); wrongNavigationPath(ODataHttpMethod.PATCH, UriType.URI4, HttpStatusCodes.BAD_REQUEST); wrongNavigationPath(ODataHttpMethod.DELETE, UriType.URI4, HttpStatusCodes.METHOD_NOT_ALLOWED); wrongNavigationPath(ODataHttpMethod.PUT, UriType.URI5, HttpStatusCodes.BAD_REQUEST); wrongNavigationPath(ODataHttpMethod.PATCH, UriType.URI5, HttpStatusCodes.BAD_REQUEST); wrongNavigationPath(ODataHttpMethod.DELETE, UriType.URI5, HttpStatusCodes.METHOD_NOT_ALLOWED); wrongNavigationPath(ODataHttpMethod.PUT, UriType.URI7A, HttpStatusCodes.BAD_REQUEST); wrongNavigationPath(ODataHttpMethod.PATCH, UriType.URI7A, HttpStatusCodes.BAD_REQUEST); wrongNavigationPath(ODataHttpMethod.DELETE, UriType.URI7A, HttpStatusCodes.BAD_REQUEST); wrongNavigationPath(ODataHttpMethod.POST, UriType.URI6B, HttpStatusCodes.BAD_REQUEST); wrongNavigationPath(ODataHttpMethod.POST, UriType.URI7B, HttpStatusCodes.BAD_REQUEST); wrongNavigationPath(ODataHttpMethod.PUT, UriType.URI17, HttpStatusCodes.BAD_REQUEST); wrongNavigationPath(ODataHttpMethod.DELETE, UriType.URI17, HttpStatusCodes.BAD_REQUEST); }
Example #2
Source File: ODataServletTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test public void contentLengthCalculatedStream() throws Exception { final Method createResponse = ODataServlet.class.getDeclaredMethod("createResponse", HttpServletResponse.class, ODataResponse.class); createResponse.setAccessible(true); final ODataServlet servlet = new ODataServlet(); final String content = "Test\r\n"; final ODataResponse response = ODataResponseImpl.status(HttpStatusCodes.OK).entity(new ByteArrayInputStream(content.getBytes("utf-8"))) .build(); prepareResponseMockToWrite(respMock); prepareServlet(servlet); createResponse.invoke(servlet, respMock, response); Mockito.verify(respMock).setContentLength(content.getBytes("utf-8").length); }
Example #3
Source File: ODataExceptionMapperImplTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test public void servletRequestWithClassloader() throws Exception { MultivaluedMap<String, String> value = new MultivaluedHashMap<String, String>(); value.putSingle("Accept", "AcceptValue"); value.put("AcceptMulti", Arrays.asList("AcceptValue_1", "AcceptValue_2")); when(exceptionMapper.httpHeaders.getRequestHeaders()).thenReturn(value); when(exceptionMapper.servletConfig.getInitParameter(ODataServiceFactory.FACTORY_LABEL)).thenReturn( ODataServiceFactoryWithCallbackImpl.class.getName()); when(exceptionMapper.servletRequest.getAttribute(ODataServiceFactory.FACTORY_CLASSLOADER_LABEL)).thenReturn( ODataServiceFactoryWithCallbackImpl.class.getClassLoader()); Response response = exceptionMapper.toResponse(new Exception()); // verify assertNotNull(response); assertEquals(HttpStatusCodes.BAD_REQUEST.getStatusCode(), response.getStatus()); String errorMessage = (String) response.getEntity(); assertEquals("bla", errorMessage); }
Example #4
Source File: MiscChangeTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test public void updateMediaResource() throws Exception { final String url = "Managers('1')/$value"; putUri(url, "00", HttpContentType.APPLICATION_OCTET_STREAM, HttpStatusCodes.NO_CONTENT); HttpResponse response = callUri(url); checkMediaType(response, HttpContentType.APPLICATION_OCTET_STREAM); assertEquals("00", getBody(response)); response = callUri(ODataHttpMethod.PUT, "Container2.Photos(Id=2,Type='image%2Fbmp')/$value", HttpHeaders.IF_MATCH, "W/\"2\"", "00", IMAGE_GIF, HttpStatusCodes.NO_CONTENT); checkEtag(response, "W/\"2\""); response = callUri(ODataHttpMethod.PATCH, url, null, null, "00", HttpContentType.APPLICATION_OCTET_STREAM, HttpStatusCodes.METHOD_NOT_ALLOWED); response.getEntity().getContent().close(); response = callUri(ODataHttpMethod.MERGE, url, null, null, "00", HttpContentType.APPLICATION_OCTET_STREAM, HttpStatusCodes.METHOD_NOT_ALLOWED); response.getEntity().getContent().close(); }
Example #5
Source File: ContentNegotiationGetRequestTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test public void testURI_17_EntitySimpleTypeDollarValue() throws Exception { // create test set FitTestSet testSet = FitTestSet.create(UriType.URI17, "/Employees('1')/Age/$value") .expectedStatusCode(HttpStatusCodes.OK).expectedContentType("text/plain; charset=utf-8").init(); // every combination of $format and $value is a 'BAD REQUEST' testSet.setTestParam(Arrays.asList("?$format=json", "?$format=xml", "?$format=atom"), ACCEPT_HEADER_VALUES, HttpStatusCodes.BAD_REQUEST, "application/xml"); // final List<String> jsonAcceptHeaders = Arrays.asList( "application/json", "application/json; charset=utf-8" ); // TODO: check which behavior is currently wanted testSet.setTestParam(Arrays.asList("?$format=json", "?$format=xml", "?$format=atom"), jsonAcceptHeaders, HttpStatusCodes.BAD_REQUEST, "application/json"); testSet.execute(getEndpoint()); }
Example #6
Source File: DebugDisabledTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test public void checkDebugCallbackFalseMustResultInNoDebugResponse() throws Exception { startCustomServer(DebugCallbackFactoryFlase.class); HttpResponse response = executeGetRequest("/?odata-debug=json"); assertEquals(HttpStatusCodes.OK.getStatusCode(), response.getStatusLine().getStatusCode()); String payload = StringHelper.inputStreamToString(response.getEntity().getContent()); assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><servicedocument/>", payload); response = executeGetRequest("/?odata-debug=html"); assertEquals(HttpStatusCodes.OK.getStatusCode(), response.getStatusLine().getStatusCode()); payload = StringHelper.inputStreamToString(response.getEntity().getContent()); assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><servicedocument/>", payload); response = executeGetRequest("/?odata-debug=download"); assertEquals(HttpStatusCodes.OK.getStatusCode(), response.getStatusLine().getStatusCode()); payload = StringHelper.inputStreamToString(response.getEntity().getContent()); assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><servicedocument/>", payload); stopCustomServer(); }
Example #7
Source File: JsonFunctionImportTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test public void noReturnTypeAction() throws Exception { final EdmFunctionImport functionImport = MockFacade.getMockEdm().getDefaultEntityContainer().getFunctionImport("AddEmployee"); final String uri = "http://host:80/service/"; final EntityProviderWriteProperties properties = EntityProviderWriteProperties.serviceRoot(URI.create(uri)).build(); Map<String, Object> employeeData = new HashMap<String, Object>(); employeeData.put("EmployeeId", "1"); employeeData.put("getImageType", "image/jpeg"); final ODataResponse response = new JsonEntityProvider().writeFunctionImport(functionImport, employeeData, properties); assertNotNull(response); assertNull(response.getEntity()); assertNull(response.getContentHeader()); assertEquals(HttpStatusCodes.ACCEPTED, response.getStatus()); }
Example #8
Source File: EntryJsonCreateTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test public void createEntryEmployee() throws Exception { String content = "{iVBORw0KGgoAAAANSUhEUgAAAB4AAAAwCAIAAACJ9F2zAAAAA}"; assertNotNull(content); HttpResponse response = postUri("Employees", content, HttpContentType.TEXT_PLAIN, HttpHeaders.ACCEPT, HttpContentType.APPLICATION_JSON, HttpStatusCodes.CREATED); checkMediaType(response, HttpContentType.APPLICATION_JSON); String body = getBody(response); LinkedTreeMap<?, ?> map = getLinkedTreeMap(body); assertEquals("7", map.get("EmployeeId")); assertEquals("Employee 7", map.get("EmployeeName")); assertNull(map.get("EntryData")); response = callUri("Employees('7')/$value"); checkMediaType(response, HttpContentType.TEXT_PLAIN); }
Example #9
Source File: ODataExceptionMapperImpl.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Override public Response toResponse(final Exception exception) { ODataResponse response; try { if (exception instanceof WebApplicationException) { response = handleWebApplicationException(exception); } else { response = handleException(exception); } } catch (Exception e) { response = ODataResponse.entity("Exception during error handling occured!") .contentHeader(ContentType.TEXT_PLAIN.toContentTypeString()) .status(HttpStatusCodes.INTERNAL_SERVER_ERROR).build(); } // Convert OData response to JAX-RS response. return RestUtil.convertResponse(response); }
Example #10
Source File: ODataDebugResponseWrapperTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test public void minimal() throws Exception { final ODataContext context = mockContext(ODataHttpMethod.PUT); final ODataResponse wrappedResponse = mockResponse(HttpStatusCodes.NO_CONTENT, null, null); ODataResponse response = new ODataDebugResponseWrapper(context, wrappedResponse, mock(UriInfo.class), null, ODataDebugResponseWrapper.ODATA_DEBUG_JSON).wrapResponse(); final String actualJson = StringHelper.inputStreamToString((InputStream) response.getEntity()); assertEquals(EXPECTED.replace(ODataHttpMethod.GET.name(), ODataHttpMethod.PUT.name()) .replace(Integer.toString(HttpStatusCodes.OK.getStatusCode()), Integer.toString(HttpStatusCodes.NO_CONTENT.getStatusCode())) .replace(HttpStatusCodes.OK.getInfo(), HttpStatusCodes.NO_CONTENT.getInfo()), actualJson); response = new ODataDebugResponseWrapper(context, wrappedResponse, mock(UriInfo.class), null, ODataDebugResponseWrapper.ODATA_DEBUG_HTML).wrapResponse(); final String html = StringHelper.inputStreamToString((InputStream) response.getEntity()); assertTrue(html.contains(HttpStatusCodes.NO_CONTENT.getInfo())); }
Example #11
Source File: EntryJsonChangeTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test public void createEntryThreeLevels() throws Exception { final String requestBody = "{\"Id\":\"99\",\"Name\":\"Building 4\",\"Image\":null," + "\"nb_Rooms\":[{\"Id\":\"201\",\"Name\":\"Room 201\",\"Seats\":1,\"Version\":1," + "\"nr_Employees\":[{\"EmployeeId\":\"99\",\"EmployeeName\":\"Ms X\",\"Age\":22," + "\"Location\":{\"City\":{\"PostalCode\":null,\"CityName\":null},\"Country\":null}," + "\"EntryDate\":\"\\/Date(1424242424242)\\/\"," + "\"ne_Manager\":{\"__deferred\":{\"uri\":\"" + getEndpoint() + "Managers('1')\"}}}]}]}"; final HttpResponse response = postUri("Buildings()", requestBody, HttpContentType.APPLICATION_JSON, HttpStatusCodes.CREATED); assertFalse(getBody(response).isEmpty()); checkUri("Buildings('4')"); assertEquals("1", getBody(callUri("Buildings('4')/nb_Rooms('104')/Seats/$value"))); assertEquals("2015-02-18T06:53:44.242", getBody(callUri("Buildings('4')/nb_Rooms('104')/nr_Employees('7')/EntryDate/$value"))); assertEquals(MANAGER_NAME, getBody(callUri("Buildings('4')/nb_Rooms('104')/nr_Employees('7')/ne_Manager/EmployeeName/$value"))); }
Example #12
Source File: EntryXmlChangeTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test public void createWithLargeProperty() throws Exception { final String largeTeamName = StringHelper.generateData(888888); // Create an entry for a type that has no media resource. final String requestBody = getBody(callUri("Teams('1')")) .replace("'1'", "'9'") .replace("Id>1", "Id>9") .replace("Team 1", largeTeamName) .replaceAll("<link.+?/>", ""); HttpResponse response = postUri("Teams()", requestBody, HttpContentType.APPLICATION_ATOM_XML_ENTRY, HttpStatusCodes.CREATED); checkMediaType(response, HttpContentType.APPLICATION_ATOM_XML_UTF8 + ";type=entry"); assertEquals(getEndpoint() + "Teams('4')", response.getFirstHeader(HttpHeaders.LOCATION).getValue()); assertNull(response.getFirstHeader(HttpHeaders.ETAG)); assertXpathEvaluatesTo(largeTeamName, "/atom:entry/atom:content/m:properties/d:Name", getBody(response)); }
Example #13
Source File: BasicHttpTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Test public void tunneledByPost() throws Exception { tunnelPost("X-HTTP-Method", ODataHttpMethod.MERGE); tunnelPost("X-HTTP-Method", ODataHttpMethod.PATCH); tunnelPost("X-HTTP-Method", ODataHttpMethod.DELETE); tunnelPost("X-HTTP-Method", ODataHttpMethod.PUT); tunnelPost("X-HTTP-Method", ODataHttpMethod.GET); tunnelPost("X-HTTP-Method", ODataHttpMethod.POST); tunnelPost("X-HTTP-Method", "HEAD", HttpStatusCodes.NOT_FOUND); tunnelPost("X-HTTP-Method-Override", ODataHttpMethod.MERGE); tunnelPost("X-HTTP-Method-Override", ODataHttpMethod.PATCH); tunnelPost("X-HTTP-Method-Override", ODataHttpMethod.DELETE); tunnelPost("X-HTTP-Method-Override", ODataHttpMethod.PUT); tunnelPost("X-HTTP-Method-Override", ODataHttpMethod.GET); tunnelPost("X-HTTP-Method-Override", ODataHttpMethod.POST); tunnelPost("X-HTTP-Method-Override", "HEAD", HttpStatusCodes.NOT_FOUND); }
Example #14
Source File: EntryJsonChangeTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@Test public void createEntryWithNavigation() throws Exception { final String requestBody = "{\"Id\":\"199\",\"Name\":\"Room 199\"}"; final HttpResponse response = postUri("Buildings('1')/nb_Rooms()", requestBody, HttpContentType.APPLICATION_JSON, HttpStatusCodes.CREATED); assertFalse(getBody(response).isEmpty()); checkUri("Rooms('104')?$format=json"); assertEquals("1", getBody(callUri("Rooms('104')/nr_Building/Id/$value"))); checkUri("Buildings('1')/nb_Rooms('104')?$format=json"); }
Example #15
Source File: ODataExceptionWrapperTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@Test public void testCallbackWithLocales1() throws Exception { UriInfo uriInfo = getMockedUriInfo(); HttpHeaders httpHeaders = Mockito.mock(HttpHeaders.class); List<Locale> locales = new ArrayList<Locale>(); locales.add(Locale.GERMANY); locales.add(Locale.FRANCE); when(httpHeaders.getAcceptableLanguages()).thenReturn(locales); ODataErrorCallback errorCallback = new ODataErrorCallback() { @Override public ODataResponse handleError(final ODataErrorContext context) throws ODataApplicationException { assertEquals("de", context.getLocale().getLanguage()); assertEquals("DE", context.getLocale().getCountry()); return ODataResponse.entity("bla").status(HttpStatusCodes.BAD_REQUEST).contentHeader("text/html").build(); } }; ODataExceptionWrapper exceptionWrapper = createWrapper1(uriInfo, httpHeaders, errorCallback); ODataResponse response = exceptionWrapper.wrapInExceptionResponse( new ODataApplicationException("Error",Locale.GERMANY)); // verify assertNotNull(response); assertEquals(HttpStatusCodes.BAD_REQUEST.getStatusCode(), response.getStatus().getStatusCode()); String errorMessage = (String) response.getEntity(); assertEquals("bla", errorMessage); String contentTypeHeader = response.getContentHeader(); assertEquals("text/html", contentTypeHeader); }
Example #16
Source File: ODataServletTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@Test public void testInputStreamResponse() throws Exception { ODataServlet servlet = new ODataServlet(); prepareServlet(servlet); final ByteArrayOutputStream bout = new ByteArrayOutputStream(); final ServletOutputStream out = new ServletOutputStream() { @Override public void write(int i) throws IOException { bout.write(i); } }; Mockito.when(respMock.getOutputStream()).thenReturn(out); HttpServletResponse servletResponse = Mockito.mock(HttpServletResponse.class); Mockito.when(servletResponse.getOutputStream()).thenReturn(out); ODataResponse odataResponse = Mockito.mock(ODataResponse.class); Mockito.when(odataResponse.getStatus()).thenReturn(HttpStatusCodes.ACCEPTED); Mockito.when(odataResponse.getHeaderNames()).thenReturn(new HashSet<String>()); InputStream input = new ByteArrayInputStream("SomeData".getBytes()); Mockito.when(odataResponse.getEntity()).thenReturn(input); servlet.createResponse(servletResponse, odataResponse, true); String outputContent = new String(bout.toByteArray()); Assert.assertEquals("", outputContent); }
Example #17
Source File: BasicHttpTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@Test public void tunneledBadRequest() throws Exception { final HttpPost post = new HttpPost(URI.create(getEndpoint().toString() + "aaa/bbb/ccc")); post.setHeader("X-HTTP-Method", "MERGE"); post.setHeader("X-HTTP-Method-Override", "PATCH"); final HttpResponse response = getHttpClient().execute(post); assertEquals(HttpStatusCodes.BAD_REQUEST.getStatusCode(), response.getStatusLine().getStatusCode()); final String payload = StringHelper.inputStreamToString(response.getEntity().getContent()); assertTrue(payload.contains("error")); }
Example #18
Source File: ODataExceptionMapperImplTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
private String verifyResponse(final Response response, final String message, final HttpStatusCodes statusCode) throws Exception { assertNotNull(response); assertEquals(statusCode.getStatusCode(), response.getStatus()); String errorXml = StringHelper.inputStreamToString((InputStream) response.getEntity()); assertXpathExists("/a:error/a:code", errorXml); assertXpathEvaluatesTo(message, "/a:error/a:message", errorXml); return errorXml; }
Example #19
Source File: EntryXmlChangeTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@Test public void createMediaResourceWithNavigation() throws Exception { HttpResponse response = postUri("Teams('1')/nt_Employees", "X", HttpContentType.TEXT_PLAIN, HttpStatusCodes.CREATED); checkMediaType(response, HttpContentType.APPLICATION_ATOM_XML_UTF8 + ";type=entry"); assertEquals(getEndpoint() + "Employees('7')", response.getFirstHeader(HttpHeaders.LOCATION).getValue()); assertXpathEvaluatesTo("7", "/atom:entry/m:properties/d:EmployeeId", getBody(response)); response = callUri("Employees('7')/$value"); checkMediaType(response, HttpContentType.TEXT_PLAIN); assertEquals("X", getBody(response)); }
Example #20
Source File: AbstractContentNegotiationTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
private static List<FitTest> create(final FitTestSet fitTestSet, final List<String> queryOptions, final List<String> acceptHeaders, final HttpStatusCodes expectedStatusCode, final String expectedContentType) { Map<String, ContentType> acceptHeader2ContentType = new HashMap<String, ContentType>(); for (String acceptHeader : acceptHeaders) { acceptHeader2ContentType.put(acceptHeader, ContentType.create(expectedContentType)); } String content = fitTestSet.content; List<String> reqContentTypes = fitTestSet.requestContentTypes; return create(fitTestSet.uriType, fitTestSet.httpMethod, fitTestSet.path, queryOptions, acceptHeaders, acceptHeader2ContentType, content, reqContentTypes, expectedStatusCode); }
Example #21
Source File: LinksJsonChangeTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@Test public void createLink() throws Exception { final String uriString = "Rooms('3')/$links/nr_Employees"; final String requestBody = "{\"uri\":\"" + getEndpoint() + "Employees('6')\"}"; postUri(uriString, requestBody, HttpContentType.APPLICATION_JSON, HttpStatusCodes.NO_CONTENT); assertEquals("{\"d\":" + requestBody + "}", getBody(callUri(uriString + "('6')?$format=json"))); }
Example #22
Source File: EntryXmlChangeTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@Test public void createInvalidXml() throws Exception { getBody(callUri("Employees('7')", HttpStatusCodes.NOT_FOUND)); final String updateBody = "<invalidXml></invalid>"; final HttpResponse postResult = postUri("Employees", updateBody, HttpContentType.APPLICATION_ATOM_XML_ENTRY, HttpStatusCodes.CREATED); checkMediaType(postResult, HttpContentType.APPLICATION_ATOM_XML_UTF8 + ";type=entry"); assertXpathEvaluatesTo("7", "/atom:entry/m:properties/d:EmployeeId", getBody(postResult)); final String requestBodyAfter = getBody(callUri("Employees('7')")); assertXpathEvaluatesTo("7", "/atom:entry/m:properties/d:EmployeeId", requestBodyAfter); }
Example #23
Source File: EntryJsonCreateInlineTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@Test public void createEntryRoomWithInvalidFeed() throws Exception { String content = "{\"d\":{\"__metadata\":{\"id\":\"" + getEndpoint() + "Rooms('1')\"," + "\"uri\":\"" + getEndpoint() + "Rooms('1')\",\"type\":\"RefScenario.Room\"," + "\"etag\":\"W/\\\"3\\\"\"}," + "\"Id\":\"1\",\"Name\":\"Room 104\",\"Seats\":4,\"Version\":2," + "\"nr_Employees\":{\"__deferred\":{\"uri\":\"" + getEndpoint() + "Rooms('1')/nr_Employees\"}}," + "\"nr_Building\":{\"results\":[]}}}"; postUri("Rooms", content, HttpContentType.APPLICATION_JSON, HttpHeaders.ACCEPT, HttpContentType.APPLICATION_JSON, HttpStatusCodes.BAD_REQUEST); }
Example #24
Source File: ODataExceptionWrapper.java From olingo-odata2 with Apache License 2.0 | 5 votes |
private void fillErrorContext(final Exception exception) { errorContext.setContentType(contentType); errorContext.setException(exception); errorContext.setHttpStatus(HttpStatusCodes.INTERNAL_SERVER_ERROR); errorContext.setErrorCode(null); errorContext.setMessage(exception.getMessage()); errorContext.setLocale(DEFAULT_RESPONSE_LOCALE); errorContext.setRequestUri(requestUri); if (httpRequestHeaders != null) { for (Entry<String, List<String>> entry : httpRequestHeaders.entrySet()) { errorContext.putRequestHeader(entry.getKey(), entry.getValue()); } } }
Example #25
Source File: MiscChangeTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@Test public void deletePropertyValue() throws Exception { deleteUriOk("Employees('2')/Age/$value"); deleteUriOk("Employees('2')/Location/City/PostalCode/$value"); deleteUri("Employees('2')/Age", HttpStatusCodes.METHOD_NOT_ALLOWED); deleteUri("Employees('2')/Foo/$value", HttpStatusCodes.NOT_FOUND); deleteUri("Employees('2')/EmployeeId/$value", HttpStatusCodes.METHOD_NOT_ALLOWED); deleteUri("Employees('2')/Location/City/$value", HttpStatusCodes.NOT_FOUND); deleteUri("Employees('2')/ne_Manager/Age/$value", HttpStatusCodes.BAD_REQUEST); }
Example #26
Source File: ServiceXmlTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@Test public void serviceDocumentAcceptHeaderAtom() throws Exception { final HttpResponse response = callUri("", HttpHeaders.ACCEPT, HttpContentType.APPLICATION_ATOM_XML, HttpStatusCodes.NOT_ACCEPTABLE); checkMediaType(response, HttpContentType.APPLICATION_XML); validateXmlError(getBody(response)); }
Example #27
Source File: EntryXmlChangeTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@Test public void createMinimal() throws Exception { final String requestBody = "<entry xmlns=\"" + Edm.NAMESPACE_ATOM_2005 + "\"" + "\n" + " xmlns:d=\"" + Edm.NAMESPACE_D_2007_08 + "\"" + "\n" + " xmlns:m=\"" + Edm.NAMESPACE_M_2007_08 + "\">" + "\n" + " <content><m:properties><d:Id>99</d:Id></m:properties></content>" + "\n" + "</entry>"; final HttpResponse response = postUri("Teams()", requestBody, HttpContentType.APPLICATION_ATOM_XML_ENTRY, HttpStatusCodes.CREATED); checkMediaType(response, HttpContentType.APPLICATION_ATOM_XML_UTF8 + ";type=entry"); assertEquals(getEndpoint() + "Teams('4')", response.getFirstHeader(HttpHeaders.LOCATION).getValue()); }
Example #28
Source File: ServiceResolutionTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@Test public void testNoMatrixParameterInODataPath() throws IOException, ODataException { server.setPathSplit(0); startServer(); final HttpGet get = new HttpGet(URI.create(server.getEndpoint().toString() + "$metadata;matrix")); final HttpResponse response = httpClient.execute(get); final InputStream stream = response.getEntity().getContent(); final String body = StringHelper.inputStreamToString(stream); assertTrue(body.contains("metadata")); assertTrue(body.contains("matrix")); assertEquals(HttpStatusCodes.NOT_FOUND.getStatusCode(), response.getStatusLine().getStatusCode()); }
Example #29
Source File: AbstractRefTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
protected void putUri(final String uri, final String acceptHeader, final String requestBody, final String requestContentType, final HttpStatusCodes expectedStatusCode) throws Exception { final HttpResponse response = callUri(ODataHttpMethod.PUT, uri, org.apache.olingo.odata2.api.commons.HttpHeaders.ACCEPT, acceptHeader, requestBody, requestContentType, expectedStatusCode); if (expectedStatusCode != HttpStatusCodes.NO_CONTENT) { response.getEntity().getContent().close(); } }
Example #30
Source File: ServiceJsonTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@Test public void serviceDocumentAcceptHeaderInvalidCharset() throws Exception { final HttpResponse response = callUri("", HttpHeaders.ACCEPT, HttpContentType.APPLICATION_XML + "; charset=iso-latin-1", HttpStatusCodes.NOT_ACCEPTABLE); final String body = getBody(response); Map<String, String> prefixMap = new HashMap<String, String>(); prefixMap.put("a", Edm.NAMESPACE_M_2007_08); XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(prefixMap)); assertXpathExists("/a:error", body); assertXpathExists("/a:error/a:code", body); assertXpathExists("/a:error/a:message", body); }