use of com.fasterxml.jackson.core.JsonParseException in project dcos-commons by mesosphere.
the class DefaultServiceSpecTest method invalidTaskName.
@Test
public void invalidTaskName() throws Exception {
ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource("invalid-task-name.yml").getFile());
try {
DefaultServiceSpec.newGenerator(file, SCHEDULER_CONFIG).build();
Assert.fail("Expected exception");
} catch (JsonMappingException e) {
Assert.assertTrue(e.getCause().toString(), e.getCause() instanceof JsonParseException);
JsonParseException cause = (JsonParseException) e.getCause();
Assert.assertTrue(cause.getMessage(), cause.getMessage().contains("Duplicate field 'meta-data-task'"));
}
}
use of com.fasterxml.jackson.core.JsonParseException in project elasticsearch by elastic.
the class BaseXContentTestCase method testChecksForDuplicates.
public void testChecksForDuplicates() throws Exception {
assumeTrue("Test only makes sense if XContent parser has strict duplicate checks enabled", XContent.isStrictDuplicateDetectionEnabled());
XContentBuilder builder = builder().startObject().field("key", 1).field("key", 2).endObject();
JsonParseException pex = expectThrows(JsonParseException.class, () -> createParser(builder).map());
assertThat(pex.getMessage(), startsWith("Duplicate field 'key'"));
}
use of com.fasterxml.jackson.core.JsonParseException in project elasticsearch by elastic.
the class FunctionScoreQueryBuilderTests method testMalformedThrowsException.
public void testMalformedThrowsException() throws IOException {
String json = "{\n" + " \"function_score\":{\n" + " \"query\":{\n" + " \"term\":{\n" + " \"name.last\":\"banon\"\n" + " }\n" + " },\n" + " \"functions\": [\n" + " {\n" + " {\n" + " }\n" + " ]\n" + " }\n" + "}";
JsonParseException e = expectThrows(JsonParseException.class, () -> parseQuery(json));
assertThat(e.getMessage(), containsString("Unexpected character ('{"));
}
use of com.fasterxml.jackson.core.JsonParseException in project jackson-core by FasterXML.
the class ParserErrorHandlingTest method _testMangledNumbers.
private void _testMangledNumbers(int mode) throws Exception {
String doc = "123true";
JsonParser p = createParser(mode, doc);
try {
JsonToken t = p.nextToken();
fail("Should have gotten an exception; instead got token: " + t);
} catch (JsonParseException e) {
verifyException(e, "expected space");
}
p.close();
// Also test with floats
doc = "1.5false";
p = createParser(mode, doc);
try {
JsonToken t = p.nextToken();
fail("Should have gotten an exception; instead got token: " + t);
} catch (JsonParseException e) {
verifyException(e, "expected space");
}
p.close();
}
use of com.fasterxml.jackson.core.JsonParseException in project jackson-core by FasterXML.
the class ParserErrorHandlingTest method doTestInvalidKeyword1.
private void doTestInvalidKeyword1(int mode, String value) throws IOException {
String doc = "{ \"key1\" : " + value + " }";
JsonParser p = createParser(mode, doc);
assertToken(JsonToken.START_OBJECT, p.nextToken());
// get the exception early or late...
try {
assertToken(JsonToken.FIELD_NAME, p.nextToken());
p.nextToken();
fail("Expected an exception for malformed value keyword");
} catch (JsonParseException jex) {
verifyException(jex, "Unrecognized token");
verifyException(jex, value);
} finally {
p.close();
}
// Try as root-level value as well:
// may need space after for DataInput
doc = value + " ";
p = createParser(mode, doc);
try {
p.nextToken();
fail("Expected an exception for malformed value keyword");
} catch (JsonParseException jex) {
verifyException(jex, "Unrecognized token");
verifyException(jex, value);
} finally {
p.close();
}
}
Aggregations