Skip to content

Commit

Permalink
Minor change to align with higher max string value length limit
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed May 14, 2023
1 parent df541d3 commit 6f81a4e
Showing 1 changed file with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ void setString(String string) {
/**********************************************************************
*/

private final static int TOO_LONG_STRING_VALUE = 20_100_000;

private final ObjectMapper MAPPER = newJsonMapper();

private ObjectMapper newJsonMapperWithUnlimitedStringSizeSupport() {
Expand All @@ -44,31 +46,32 @@ private ObjectMapper newJsonMapperWithUnlimitedStringSizeSupport() {
public void testBigString() throws Exception
{
try {
MAPPER.readValue(generateJson("string", 5001000), StringWrapper.class);
fail("expected JsonMappingException");
MAPPER.readValue(generateJson("string", TOO_LONG_STRING_VALUE), StringWrapper.class);
fail("expected DatabindException");
} catch (DatabindException e) {
assertTrue("unexpected exception message: " + e.getMessage(),
e.getMessage().startsWith("String length (5001000) exceeds the maximum length (5000000)"));
final String message = e.getMessage();
assertTrue("unexpected exception message: " + message, message.startsWith("String length"));
assertTrue("unexpected exception message: " + message, message.contains("exceeds the maximum length ("));
}
}

public void testBiggerString() throws Exception
{
try {
MAPPER.readValue(generateJson("string", 6_000_000), StringWrapper.class);
MAPPER.readValue(generateJson("string", TOO_LONG_STRING_VALUE), StringWrapper.class);
fail("expected JsonMappingException");
} catch (DatabindException e) {
final String message = e.getMessage();
// this test fails when the TextBuffer is being resized, so we don't yet know just how big the string is
// so best not to assert that the String length value in the message is the full 6000000 value
assertTrue("unexpected exception message: " + message, message.startsWith("String length"));
assertTrue("unexpected exception message: " + message, message.contains("exceeds the maximum length (5000000)"));
assertTrue("unexpected exception message: " + message, message.contains("exceeds the maximum length ("));
}
}

public void testUnlimitedString() throws Exception
{
final int len = 5_001_000;
final int len = TOO_LONG_STRING_VALUE;
StringWrapper sw = newJsonMapperWithUnlimitedStringSizeSupport()
.readValue(generateJson("string", len), StringWrapper.class);
assertEquals(len, sw.string.length());
Expand Down

0 comments on commit 6f81a4e

Please sign in to comment.