You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by ch...@apache.org on 2017/04/12 09:31:11 UTC
olingo-odata4 git commit: [OLINGO-1106] JUnit for Custom Query
Options in batch
Repository: olingo-odata4
Updated Branches:
refs/heads/master 548c6e4a1 -> af116170a
[OLINGO-1106] JUnit for Custom Query Options in batch
Signed-off-by: Christian Amend <ch...@sap.com>
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/af116170
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/af116170
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/af116170
Branch: refs/heads/master
Commit: af116170a2fe89dbaef3f859e65d596f79206c4e
Parents: 548c6e4
Author: Archana Rai <ar...@sap.com>
Authored: Tue Apr 11 13:52:29 2017 +0530
Committer: Christian Amend <ch...@sap.com>
Committed: Wed Apr 12 11:18:55 2017 +0200
----------------------------------------------------------------------
.../fit/tecsvc/http/BasicBatchITCase.java | 105 ++++++++++++++++++-
1 file changed, 104 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/af116170/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/BasicBatchITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/BasicBatchITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/BasicBatchITCase.java
index 1fb31a2..fa8cb1b 100644
--- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/BasicBatchITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/BasicBatchITCase.java
@@ -70,6 +70,55 @@ public class BasicBatchITCase extends AbstractBaseTestITCase {
reader.close();
}
+
+ /* Tests for custom query options. Services may support additional custom query options
+ * not defined in the OData specification, but they MUST NOT begin with the "$" .*/
+
+ @Test
+ public void testCustomQuery1() throws IOException {
+ final String content = getRequest("ESAllPrim(32767)");
+ final HttpURLConnection connection = batchWithCustomQuery(content, "#");
+ final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
+
+ assertTrue(reader.readLine().contains("batch_"));
+ checkMimeHeader(reader);
+ blankLine(reader);
+
+ assertEquals("HTTP/1.1 200 OK", reader.readLine());
+ assertEquals("OData-Version: 4.0", reader.readLine());
+ assertEquals("Content-Type: application/json;odata.metadata=minimal", reader.readLine());
+ assertEquals("Content-Length: 605", reader.readLine());
+ blankLine(reader);
+
+ reader.close();
+ }
+
+ @Test
+ public void testCustomQuery2() throws IOException {
+ final String content = getRequest("ESAllPrim(32767)");
+ final HttpURLConnection connection = batchWithCustomQuery(content, "");
+ final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
+
+ assertTrue(reader.readLine().contains("batch_"));
+ checkMimeHeader(reader);
+ blankLine(reader);
+
+ assertEquals("HTTP/1.1 200 OK", reader.readLine());
+ assertEquals("OData-Version: 4.0", reader.readLine());
+ assertEquals("Content-Type: application/json;odata.metadata=minimal", reader.readLine());
+ assertEquals("Content-Length: 605", reader.readLine());
+ blankLine(reader);
+
+ reader.close();
+ }
+
+ @Test
+ public void testCustomQuery3() throws IOException {
+ final String content = getRequest("ESAllPrim(32767)");
+ batchFailWithCustomQuery(content, "$");
+ }
+
+
@Test
public void testInvalidRelativeURI() throws IOException {
@@ -144,10 +193,48 @@ public class BasicBatchITCase extends AbstractBaseTestITCase {
return connection;
}
+
+ private HttpURLConnection batchWithCustomQuery(final String content, final String query)
+ throws IOException {
+ HttpURLConnection connection = getConnectionForCustomQuery(content, query);
+ assertEquals(HttpStatusCode.OK.getStatusCode(), connection.getResponseCode());
+ return connection;
+ }
+
+ private HttpURLConnection batchFailWithCustomQuery(final String content, final String query)
+ throws IOException {
+ final HttpURLConnection connection = getConnectionForCustomQuery(content, query);
+
+ assertEquals(HttpStatusCode.BAD_REQUEST.getStatusCode(), connection.getResponseCode());
+
+ return connection;
+ }
private HttpURLConnection getConnection(final String content) throws MalformedURLException, IOException,
ProtocolException {
- final URL url = new URL(SERVICE_URI + "$batch");
+ final URL url = getUrl();
+ final HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+ connection.setRequestMethod(HttpMethod.POST.toString());
+ connection.setRequestProperty(HttpHeader.CONTENT_TYPE, CONTENT_TYPE_HEADER_VALUE);
+ connection.setRequestProperty(HttpHeader.ACCEPT, ACCEPT_HEADER_VALUE);
+ connection.setDoOutput(true);
+ final OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());
+ writer.append(content);
+ writer.close();
+ connection.connect();
+ return connection;
+ }
+
+ private HttpURLConnection getConnectionForCustomQuery(final String content, final String query)
+ throws MalformedURLException, IOException, ProtocolException {
+ URL url = null;
+ if(query.equals("$")){
+ url = getUrlForCustomQueryWith$();
+ }else if(query.equals("#")){
+ url = getUrlWithSpecialCharacters();
+ }else{
+ url = getUrlForCustomQuery();
+ }
final HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod(HttpMethod.POST.toString());
connection.setRequestProperty(HttpHeader.CONTENT_TYPE, CONTENT_TYPE_HEADER_VALUE);
@@ -159,6 +246,22 @@ public class BasicBatchITCase extends AbstractBaseTestITCase {
connection.connect();
return connection;
}
+
+ private URL getUrlWithSpecialCharacters() throws MalformedURLException {
+ return new URL(SERVICE_URI + "$batch" + "?#language=de");
+ }
+
+ private URL getUrlForCustomQuery() throws MalformedURLException {
+ return new URL(SERVICE_URI + "$batch" + "?language=de");
+ }
+
+ private URL getUrlForCustomQueryWith$() throws MalformedURLException {
+ return new URL(SERVICE_URI + "$batch" + "?$language=de");
+ }
+
+ private URL getUrl() throws MalformedURLException {
+ return new URL(SERVICE_URI + "$batch");
+ }
@Override
protected ODataClient getClient() {