use of com.fasterxml.jackson.databind.exc.ValueInstantiationException in project ksql by confluentinc.
the class CommandTest method shouldThrowExceptionWhenCommandVersionHigher.
@Test
public void shouldThrowExceptionWhenCommandVersionHigher() {
final String commandStr = "{" + "\"statement\": \"test statement;\", " + "\"streamsProperties\": {\"foo\": \"bar\"}, " + "\"originalProperties\": {\"biz\": \"baz\"}, " + "\"version\": " + (Command.VERSION + 1) + "}";
final ObjectMapper mapper = PlanJsonMapper.INSTANCE.get();
final ValueInstantiationException thrown = assertThrows("Expected deserialization to throw, but it didn't", ValueInstantiationException.class, () -> mapper.readValue(commandStr, Command.class));
assertTrue(thrown.getCause() instanceof IncompatibleKsqlCommandVersionException);
}
use of com.fasterxml.jackson.databind.exc.ValueInstantiationException in project ambry by linkedin.
the class AccountContainerTest method testAccountAndContainerSerDeWithoutIdAndName.
@Test
public void testAccountAndContainerSerDeWithoutIdAndName() throws IOException {
assumeTrue(Container.getCurrentJsonVersion() == JSON_VERSION_2);
// remove account id
JSONObject newRefAccountJson = new JSONObject(refAccountJson, JSONObject.getNames(refAccountJson));
newRefAccountJson.remove(ACCOUNT_ID_KEY);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try (Writer writer = new OutputStreamWriter(outputStream, StandardCharsets.UTF_8)) {
newRefAccountJson.write(writer);
}
try {
objectMapper.readValue(outputStream.toByteArray(), Account.class);
fail("Missing account id should fail");
} catch (ValueInstantiationException e) {
assertTrue(e.getCause() instanceof IllegalStateException);
}
newRefAccountJson = new JSONObject(refAccountJson, JSONObject.getNames(refAccountJson));
newRefAccountJson.remove(ACCOUNT_NAME_KEY);
outputStream = new ByteArrayOutputStream();
try (Writer writer = new OutputStreamWriter(outputStream, StandardCharsets.UTF_8)) {
newRefAccountJson.write(writer);
}
try {
objectMapper.readValue(outputStream.toByteArray(), Account.class);
fail("Missing account name should fail");
} catch (ValueInstantiationException e) {
assertTrue(e.getCause() instanceof IllegalStateException);
}
newRefAccountJson = new JSONObject(refAccountJson, JSONObject.getNames(refAccountJson));
newRefAccountJson.getJSONArray(CONTAINERS_KEY).getJSONObject(0).remove(CONTAINER_ID_KEY);
outputStream = new ByteArrayOutputStream();
try (Writer writer = new OutputStreamWriter(outputStream, StandardCharsets.UTF_8)) {
newRefAccountJson.write(writer);
}
try {
objectMapper.readValue(outputStream.toByteArray(), Account.class);
fail("Missing container id should fail");
} catch (ValueInstantiationException e) {
assertTrue(e.getCause() instanceof IllegalStateException);
}
newRefAccountJson = new JSONObject(refAccountJson, JSONObject.getNames(refAccountJson));
newRefAccountJson.getJSONArray(CONTAINERS_KEY).getJSONObject(0).remove(CONTAINER_NAME_KEY);
outputStream = new ByteArrayOutputStream();
try (Writer writer = new OutputStreamWriter(outputStream, StandardCharsets.UTF_8)) {
newRefAccountJson.write(writer);
}
try {
objectMapper.readValue(outputStream.toByteArray(), Account.class);
fail("Missing container name should fail");
} catch (ValueInstantiationException e) {
assertTrue(e.getCause() instanceof IllegalStateException);
}
}
Aggregations