List of usage examples for com.fasterxml.jackson.core JsonProcessingException JsonProcessingException
protected JsonProcessingException(Throwable rootCause)
From source file:com.amazonaws.services.kinesis.multilang.messages.MessageTest.java
@Test public void toStringTest() { Message[] messages = new Message[] { new CheckpointMessage("1234567890", null), new InitializeMessage("shard-123"), new ProcessRecordsMessage(new ArrayList<Record>() { {// w w w . ja va2 s.c om this.add(new Record() { { this.withData(ByteBuffer.wrap("cat".getBytes())); this.withPartitionKey("cat"); this.withSequenceNumber("555"); } }); } }), new ShutdownMessage(ShutdownReason.ZOMBIE), new StatusMessage("processRecords"), new InitializeMessage(), new ProcessRecordsMessage() }; for (int i = 0; i < messages.length; i++) { Assert.assertTrue("Each message should contain the action field", messages[i].toString().contains("action")); } // Hit this constructor JsonFriendlyRecord defaultJsonFriendlyRecord = new JsonFriendlyRecord(); Assert.assertNull(defaultJsonFriendlyRecord.getPartitionKey()); Assert.assertNull(defaultJsonFriendlyRecord.getData()); Assert.assertNull(defaultJsonFriendlyRecord.getSequenceNumber()); Assert.assertNull(new ShutdownMessage(null).getReason()); // Hit the bad object mapping path Message withBadMapper = new Message() { }.withObjectMapper(new ObjectMapper() { /** * */ private static final long serialVersionUID = 1L; @Override public String writeValueAsString(Object m) throws JsonProcessingException { throw new JsonProcessingException(new Throwable()) { }; } }); String s = withBadMapper.toString(); Assert.assertNotNull(s); }
From source file:org.venice.piazza.servicecontroller.messaging.handlers.DescribeServiceHandlerTest.java
/** * Test that the service metadata could not be retrieved * due to a marshalling error/* www . j av a 2s.co m*/ */ @Test public void testUnSuccessDescribeServiceException() { String testServiceId = "a842aae2-bd74-4c4b-9a65-c45e8cd9060"; ResponseEntity<String> responseEntity = new ResponseEntity<String>("null", HttpStatus.OK); try { Mockito.when(omMock.writeValueAsString(Mockito.anyString())).thenThrow(new JsonProcessingException("") { }); } catch (JsonProcessingException jpe) { jpe.printStackTrace(); } ResponseEntity<String> result = dsHandler.handle(testServiceId); assertEquals("The response entity was correct for this describe request", responseEntity, result); assertEquals("The response code is 200", responseEntity.getStatusCode(), HttpStatus.OK); assertEquals("The body of the response is correct", responseEntity.getBody(), "null"); }
From source file:org.trellisldp.event.EventSerializerTest.java
private static void sneakyJsonException() { sneakyThrow(new JsonProcessingException("expected") { }); }