Assert.assertTrue(e.getCause() instanceof IAE);
/** * {@inheritDoc} */ @Override public T read(InputStream inputStream, String mimeType, Charset charset) throws IOException { try { return objectMapper.readValue(inputStream, valueType); } catch (JsonMappingException jme) { if (jme.getCause() instanceof RuntimeException) { throw (RuntimeException) jme.getCause(); } else { throw jme; } } }
/** * {@inheritDoc} */ @Override public T read(InputStream inputStream, @Nullable String mimeType, @Nullable Charset charset) throws IOException { if (log.isLoggable(Level.FINEST)) { inputStream = IOUtils.buffer(inputStream); inputStream.mark(Integer.MAX_VALUE); String s = IOUtils.toString(inputStream, charset != null ? charset : StandardCharsets.UTF_8); log.log(Level.FINEST, "JSON: {0}", s); inputStream.reset(); } try { return objectMapper.readValue(inputStream, valueTypeRef); } catch (JsonMappingException jme) { if (jme.getCause() instanceof RuntimeException) { throw (RuntimeException) jme.getCause(); } else { throw jme; } } }
@Test public void invalidDuplicateCount() throws Exception { ClassLoader classLoader = getClass().getClassLoader(); File file = new File(classLoader.getResource("invalid-duplicate-count.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().contains("Duplicate field 'count'")); } }
@Test public void invalidDuplicatePodName() throws Exception { ClassLoader classLoader = getClass().getClassLoader(); File file = new File(classLoader.getResource("invalid-pod-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'")); } }
@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'")); } }
@Test public void invalidDuplicateResourceSetName() throws Exception { ClassLoader classLoader = getClass().getClassLoader(); File file = new File(classLoader.getResource("invalid-resource-set-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 'data-store-resources'")); } }
public void testExceptionWithInvalidForeignKey() throws Exception { EntityManagerFactory emf = Persistence.createEntityManagerFactory("persistenceUnit"); try { EntityManager em = emf.createEntityManager(); // false -> no forcing of lazy loading ObjectMapper mapper = mapperWithModule(true); Customer customer = em.find(Customer.class, 501); assertFalse(Hibernate.isInitialized(customer.getPayments())); // javax.persistence.EntityNotFoundException thrown here mapper.writerWithDefaultPrettyPrinter().writeValueAsString(customer); // JUnit 3.8 fail("Expected EntityNotFoundException exception"); } catch (JsonMappingException e) { assertEquals("Unable to find com.fasterxml.jackson.datatype.hibernate5.data.Product with id X10_1678", e.getCause().getMessage()); } finally { emf.close(); } }
((BadRequestException) e.getCause()).getScimError().getScimType(), BadRequestException.INVALID_PATH); ((BadRequestException) e.getCause()).getScimError().getScimType(), BadRequestException.INVALID_PATH); ((BadRequestException) e.getCause()).getScimError().getScimType(), BadRequestException.INVALID_PATH);