forked from airlift/airlift
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a test to ensure that setting limits for JSON is respected when setReadContraints method is used. FasterXML/jackson-core#1207
- Loading branch information
Showing
2 changed files
with
69 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package io.airlift.json; | ||
|
||
import com.fasterxml.jackson.core.JsonFactory; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.google.common.base.Strings; | ||
import org.testng.annotations.Test; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class TestLimits | ||
{ | ||
@Test | ||
public void testNameLimitDefaultJsonFactory() | ||
throws IOException | ||
{ | ||
testNameLengthLimit(new ObjectMapperProvider()); | ||
} | ||
|
||
@Test | ||
public void testNameLimitCustomJsonFactory() | ||
throws IOException | ||
{ | ||
JsonFactory myJsonFactory = new JsonFactory(); | ||
testNameLengthLimit(new ObjectMapperProvider(myJsonFactory)); | ||
} | ||
|
||
private void testNameLengthLimit(ObjectMapperProvider objectMapperProvider) | ||
throws IOException | ||
{ | ||
ObjectMapper objectMapper = objectMapperProvider.get(); | ||
String longName = Strings.repeat("a", 100000); | ||
|
||
String content = String.format("{ \"%s\" : \"value\" }", longName); | ||
JsonNode jsonNode = objectMapper.reader().readTree(content); | ||
assertThat(jsonNode.has(longName)).isTrue(); | ||
assertThat(jsonNode.findValue(longName).asText()).isEqualTo("value"); | ||
} | ||
|
||
@Test | ||
public void testStringLimitDefaultJsonFactory() | ||
throws IOException | ||
{ | ||
testNameLengthLimit(new ObjectMapperProvider()); | ||
} | ||
|
||
@Test | ||
public void testStringLimitCustomJsonFactory() | ||
throws IOException | ||
{ | ||
JsonFactory myJsonFactory = new JsonFactory(); | ||
testNameLengthLimit(new ObjectMapperProvider(myJsonFactory)); | ||
} | ||
|
||
private void testStringLengthLimit(ObjectMapperProvider objectMapperProvider) | ||
throws IOException | ||
{ | ||
ObjectMapper objectMapper = objectMapperProvider.get(); | ||
String longValue = Strings.repeat("a", 100000); | ||
|
||
String content = String.format("{ \"key\" : \"%s\" }", longValue); | ||
JsonNode jsonNode = objectMapper.reader().readTree(content); | ||
assertThat(jsonNode.findValue("key").asText()).isEqualTo(longValue); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters