Skip to content

Commit

Permalink
[OLINGO-1560] Updated micro version of dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
mibo committed Feb 26, 2022
1 parent 7d4ad31 commit 2fbd91d
Show file tree
Hide file tree
Showing 12 changed files with 142 additions and 130 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@
*/
package org.apache.olingo.fit.tecsvc.http;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.net.HttpURLConnection;
import java.net.URL;

import org.apache.commons.io.IOUtils;
import org.apache.olingo.client.api.ODataClient;
import org.apache.olingo.commons.api.format.ContentType;
Expand All @@ -33,8 +26,18 @@
import org.apache.olingo.commons.api.http.HttpStatusCode;
import org.apache.olingo.fit.AbstractBaseTestITCase;
import org.apache.olingo.fit.tecsvc.TecSvcConst;
import org.junit.Assert;
import org.junit.Test;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.Charset;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

public class AcceptHeaderAcceptCharsetHeaderITCase extends AbstractBaseTestITCase {

private static final String SERVICE_URI = TecSvcConst.BASE_URI + "/";
Expand All @@ -50,7 +53,7 @@ public void validAcceptHeader() throws Exception {

assertEquals(HttpStatusCode.OK.getStatusCode(), connection.getResponseCode());

final String content = IOUtils.toString(connection.getInputStream());
final String content = IOUtils.toString(connection.getInputStream(), Charset.defaultCharset());
assertNotNull(content);
}

Expand All @@ -65,7 +68,7 @@ public void invalidAcceptHeader1() throws Exception {

assertEquals(HttpStatusCode.BAD_REQUEST.getStatusCode(), connection.getResponseCode());

final String content = IOUtils.toString(connection.getErrorStream());
final String content = IOUtils.toString(connection.getErrorStream(), Charset.defaultCharset());
assertTrue(content.contains("The content-type range ' abc' is not supported as "
+ "value of the Accept header."));
}
Expand All @@ -81,7 +84,7 @@ public void invalidAcceptHeader2() throws Exception {

assertEquals(HttpStatusCode.NOT_ACCEPTABLE.getStatusCode(), connection.getResponseCode());

final String content = IOUtils.toString(connection.getErrorStream());
final String content = IOUtils.toString(connection.getErrorStream(), Charset.defaultCharset());
assertTrue(content.contains("The content-type range 'application/xyz' is "
+ "not supported as value of the Accept header."));
}
Expand All @@ -106,7 +109,7 @@ public void validAcceptCharsetHeader() throws Exception {
assertEquals("minimal", contentType.getParameter("odata.metadata"));
assertEquals("utf-8", contentType.getParameter("charset"));

final String content = IOUtils.toString(connection.getInputStream());
final String content = IOUtils.toString(connection.getInputStream(), Charset.defaultCharset());
assertNotNull(content);
}

Expand All @@ -121,7 +124,7 @@ public void invalidAcceptCharsetHeader1() throws Exception {

assertEquals(HttpStatusCode.NOT_ACCEPTABLE.getStatusCode(), connection.getResponseCode());

final String content = IOUtils.toString(connection.getErrorStream());
final String content = IOUtils.toString(connection.getErrorStream(), Charset.defaultCharset());
assertTrue(content.contains("The charset specified in Accept charset header "
+ "'US-ASCII' is not supported."));
}
Expand All @@ -137,7 +140,7 @@ public void invalidAcceptCharsetHeader2() throws Exception {

assertEquals(HttpStatusCode.NOT_ACCEPTABLE.getStatusCode(), connection.getResponseCode());

final String content = IOUtils.toString(connection.getErrorStream());
final String content = IOUtils.toString(connection.getErrorStream(), Charset.defaultCharset());
assertTrue(content.contains("The charset specified in Accept charset header 'abc' is not supported."));
}

Expand All @@ -161,7 +164,7 @@ public void unsupportedAcceptHeaderWithSupportedAcceptCharsetHeader() throws Exc
assertEquals("minimal", contentType.getParameter("odata.metadata"));
assertEquals("utf8", contentType.getParameter("charset"));

final String content = IOUtils.toString(connection.getInputStream());
final String content = IOUtils.toString(connection.getInputStream(), Charset.defaultCharset());
assertNotNull(content);
}

Expand All @@ -177,7 +180,7 @@ public void supportedAcceptHeaderWithUnSupportedAcceptCharsetHeader() throws Exc

assertEquals(HttpStatusCode.NOT_ACCEPTABLE.getStatusCode(), connection.getResponseCode());

final String content = IOUtils.toString(connection.getErrorStream());
final String content = IOUtils.toString(connection.getErrorStream(), Charset.defaultCharset());
assertTrue(content.contains("The charset specified in Accept charset header "
+ "'iso-8859-1' is not supported."));
}
Expand All @@ -201,7 +204,7 @@ public void validFormatWithAcceptCharsetHeader() throws Exception {
assertEquals("minimal", contentType.getParameter("odata.metadata"));
assertEquals("utf-8", contentType.getParameter("charset"));

final String content = IOUtils.toString(connection.getInputStream());
final String content = IOUtils.toString(connection.getInputStream(), Charset.defaultCharset());
assertNotNull(content);
}

Expand All @@ -216,7 +219,7 @@ public void validFormatWithUnsupportedAcceptCharsetHeader() throws Exception {

assertEquals(HttpStatusCode.NOT_ACCEPTABLE.getStatusCode(), connection.getResponseCode());

final String content = IOUtils.toString(connection.getErrorStream());
final String content = IOUtils.toString(connection.getErrorStream(), Charset.defaultCharset());
assertTrue(content.contains("The charset specified in Accept charset header "
+ "'iso-8859-1' is not supported."));
}
Expand All @@ -232,7 +235,7 @@ public void validFormatWithIllegalAcceptCharsetHeader() throws Exception {

assertEquals(HttpStatusCode.NOT_ACCEPTABLE.getStatusCode(), connection.getResponseCode());

final String content = IOUtils.toString(connection.getErrorStream());
final String content = IOUtils.toString(connection.getErrorStream(), Charset.defaultCharset());
assertTrue(content.contains("The charset specified in Accept charset "
+ "header 'abc' is not supported."));
}
Expand All @@ -257,7 +260,7 @@ public void multipleValuesInAcceptCharsetHeader1() throws Exception {
assertEquals("utf-8", contentType.getParameter("charset"));
assertEquals("0.1", contentType.getParameter("q"));

final String content = IOUtils.toString(connection.getInputStream());
final String content = IOUtils.toString(connection.getInputStream(), Charset.defaultCharset());
assertNotNull(content);
}

Expand All @@ -280,7 +283,7 @@ public void multipleValuesInAcceptCharsetHeader2() throws Exception {
assertEquals("utf8", contentType.getParameter("charset"));
assertEquals("minimal", contentType.getParameter("odata.metadata"));

final String content = IOUtils.toString(connection.getInputStream());
final String content = IOUtils.toString(connection.getInputStream(), Charset.defaultCharset());
assertNotNull(content);
}

Expand All @@ -302,7 +305,7 @@ public void multipleValuesInAcceptHeader1() throws Exception {
assertEquals(1, contentType.getParameters().size());
assertEquals("minimal", contentType.getParameter("odata.metadata"));

final String content = IOUtils.toString(connection.getInputStream());
final String content = IOUtils.toString(connection.getInputStream(), Charset.defaultCharset());
assertNotNull(content);
}

Expand All @@ -318,7 +321,7 @@ public void multipleValuesInAcceptHeaderWithOneIncorrectValue() throws Exception

assertEquals(HttpStatusCode.BAD_REQUEST.getStatusCode(), connection.getResponseCode());

final String content = IOUtils.toString(connection.getErrorStream());
final String content = IOUtils.toString(connection.getErrorStream(), Charset.defaultCharset());
assertTrue(content.contains("The content-type range ' abc' is not supported as value of the Accept header."));
}

Expand All @@ -334,7 +337,7 @@ public void multipleValuesInAcceptHeaderWithIncorrectParam() throws Exception {

assertEquals(HttpStatusCode.BAD_REQUEST.getStatusCode(), connection.getResponseCode());

final String content = IOUtils.toString(connection.getErrorStream());
final String content = IOUtils.toString(connection.getErrorStream(), Charset.defaultCharset());
assertTrue(content.contains("The content-type range 'application/json;q=<1' is not "
+ "supported as value of the Accept header."));
}
Expand All @@ -351,7 +354,7 @@ public void multipleValuesInAcceptHeaderWithIncorrectCharset() throws Exception

assertEquals(HttpStatusCode.BAD_REQUEST.getStatusCode(), connection.getResponseCode());

final String content = IOUtils.toString(connection.getErrorStream());
final String content = IOUtils.toString(connection.getErrorStream(), Charset.defaultCharset());
assertTrue(content.contains("The charset specified in Accept header "
+ "'application/json;charset=utf<8' is not supported."));
}
Expand All @@ -367,7 +370,7 @@ public void acceptHeaderWithIncorrectParams() throws Exception {

assertEquals(HttpStatusCode.NOT_ACCEPTABLE.getStatusCode(), connection.getResponseCode());

final String content = IOUtils.toString(connection.getErrorStream());
final String content = IOUtils.toString(connection.getErrorStream(), Charset.defaultCharset());
assertTrue(content.contains("The content-type range 'application/json;abc=xyz' is not "
+ "supported as value of the Accept header."));
}
Expand All @@ -382,7 +385,7 @@ public void formatWithIllegalCharset1() throws Exception {

assertEquals(HttpStatusCode.NOT_ACCEPTABLE.getStatusCode(), connection.getResponseCode());

final String content = IOUtils.toString(connection.getErrorStream());
final String content = IOUtils.toString(connection.getErrorStream(), Charset.defaultCharset());
assertTrue(content.contains("The $format option 'application/json;charset=abc' is not supported."));
}

Expand All @@ -396,7 +399,7 @@ public void formatWithWrongParams() throws Exception {

assertEquals(HttpStatusCode.NOT_ACCEPTABLE.getStatusCode(), connection.getResponseCode());

final String content = IOUtils.toString(connection.getErrorStream());
final String content = IOUtils.toString(connection.getErrorStream(), Charset.defaultCharset());
assertTrue(content.contains("The $format option 'application/json;abc=xyz' is not supported."));
}

Expand All @@ -411,7 +414,7 @@ public void validFormatWithIncorrectParamsInAcceptCharsetHeader() throws Excepti

assertEquals(HttpStatusCode.BAD_REQUEST.getStatusCode(), connection.getResponseCode());

final String content = IOUtils.toString(connection.getErrorStream());
final String content = IOUtils.toString(connection.getErrorStream(), Charset.defaultCharset());
assertTrue(content.contains("The Accept charset header 'utf-8;abc=xyz' is not supported."));
}

Expand All @@ -426,7 +429,7 @@ public void validFormatWithIncorrectAcceptCharsetHeader() throws Exception {

assertEquals(HttpStatusCode.BAD_REQUEST.getStatusCode(), connection.getResponseCode());

final String content = IOUtils.toString(connection.getErrorStream());
final String content = IOUtils.toString(connection.getErrorStream(), Charset.defaultCharset());
assertTrue(content.contains("The Accept charset header 'utf<8' is not supported."));
}

Expand All @@ -441,7 +444,7 @@ public void validFormatWithIncorrectMultipleAcceptCharsetHeader1() throws Except

assertEquals(HttpStatusCode.BAD_REQUEST.getStatusCode(), connection.getResponseCode());

final String content = IOUtils.toString(connection.getErrorStream());
final String content = IOUtils.toString(connection.getErrorStream(), Charset.defaultCharset());
assertTrue(content.contains("The Accept charset header 'utf<8' is not supported."));
}

Expand All @@ -456,7 +459,7 @@ public void validFormatWithIncorrectMultipleAcceptCharsetHeader2() throws Except

assertEquals(HttpStatusCode.BAD_REQUEST.getStatusCode(), connection.getResponseCode());

final String content = IOUtils.toString(connection.getErrorStream());
final String content = IOUtils.toString(connection.getErrorStream(), Charset.defaultCharset());
assertTrue(content.contains("The Accept charset header 'utf-8;q=<' is not supported."));
}

Expand All @@ -471,7 +474,7 @@ public void validFormatWithIncorrectQParamInAcceptCharsetHeader() throws Excepti

assertEquals(HttpStatusCode.BAD_REQUEST.getStatusCode(), connection.getResponseCode());

final String content = IOUtils.toString(connection.getErrorStream());
final String content = IOUtils.toString(connection.getErrorStream(), Charset.defaultCharset());
assertTrue(content.contains("The Accept charset header 'utf-8;q=<' is not supported."));
}

Expand All @@ -486,7 +489,7 @@ public void validFormatWithIncorrectParamInAcceptCharsetHeader() throws Exceptio

assertEquals(HttpStatusCode.BAD_REQUEST.getStatusCode(), connection.getResponseCode());

final String content = IOUtils.toString(connection.getErrorStream());
final String content = IOUtils.toString(connection.getErrorStream(), Charset.defaultCharset());
assertTrue(content.contains("The Accept charset header 'utf-8;abc=xyz' is not supported."));
}

Expand All @@ -499,10 +502,13 @@ public void validFormatWithIncorrectCharset() throws Exception {
connection.setRequestProperty(HttpHeader.ACCEPT, "application/json;charset=utf-8");
connection.connect();

assertEquals(HttpStatusCode.BAD_REQUEST.getStatusCode(), connection.getResponseCode());

final String content = IOUtils.toString(connection.getErrorStream());
assertTrue(content.contains("The $format option 'application/json;charset=utf<8' is not supported."));
try {
assertEquals(HttpStatusCode.BAD_REQUEST.getStatusCode(), connection.getResponseCode());
final String content = IOUtils.toString(connection.getInputStream(), Charset.defaultCharset());
Assert.fail("Expect IOException.");
} catch (IOException e) {
assertTrue(e.getMessage().contains("application/json;charset=utf<8"));
}
}

@Test
Expand All @@ -524,7 +530,7 @@ public void formatWithAcceptCharset() throws Exception {
assertEquals("minimal", contentType.getParameter("odata.metadata"));
assertEquals("utf-8", contentType.getParameter("charset"));

final String content = IOUtils.toString(connection.getInputStream());
final String content = IOUtils.toString(connection.getInputStream(), Charset.defaultCharset());
assertNotNull(content);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
Expand Down Expand Up @@ -65,7 +66,7 @@ public void boundActionReturningBaseType() throws Exception {

assertEquals(HttpStatusCode.CREATED.getStatusCode(), connection.getResponseCode());

final String content = IOUtils.toString(connection.getInputStream());
final String content = IOUtils.toString(connection.getInputStream(), Charset.defaultCharset());
final String expected = "\"PropertyInt16\":1,\"PropertyString\":\"1\","
+ "\"PropertyComp\":{\"PropertyInt16\":11,"
+ "\"PropertyComp\":{\"PropertyString\":\"StringValue\","
Expand Down Expand Up @@ -110,7 +111,7 @@ public void boundActionReturningEntityWithNavigationSegInAction() throws Excepti

assertEquals(HttpStatusCode.OK.getStatusCode(), connection.getResponseCode());

final String content = IOUtils.toString(connection.getInputStream());
final String content = IOUtils.toString(connection.getInputStream(), Charset.defaultCharset());
final String expected = "\"PropertyInt16\":1,\"PropertyString\":\"1\","
+ "\"PropertyComp\":{\"PropertyInt16\":30,\"PropertyComp\":"
+ "{\"PropertyString\":\"StringValue\",\"PropertyBinary\":\"ASNFZ4mrze8=\","
Expand Down
Loading

0 comments on commit 2fbd91d

Please sign in to comment.