@Override protected void pointToEmptyInput(ItemReader<Foo> tested) { JsonItemReader<Foo> reader = (JsonItemReader<Foo>) tested; reader.setResource(new ByteArrayResource("[]".getBytes())); reader.open(new ExecutionContext()); }
@Test public void testNonReadableResource() { // given this.expectedException.expect(ItemStreamException.class); this.expectedException.expectMessage("Failed to initialize the reader"); this.expectedException.expectCause(Matchers.instanceOf(IllegalStateException.class)); this.itemReader = new JsonItemReader<>(new NonReadableResource(), this.jsonObjectReader); // when this.itemReader.open(new ExecutionContext()); // then // expected exception }
@Test public void testNonExistentResource() { // given this.expectedException.expect(ItemStreamException.class); this.expectedException.expectMessage("Failed to initialize the reader"); this.expectedException.expectCause(Matchers.instanceOf(IllegalStateException.class)); this.itemReader = new JsonItemReader<>(new NonExistentResource(), this.jsonObjectReader); // when this.itemReader.open(new ExecutionContext()); // then // expected exception }
@Test public void testInvalidResourceFormat() { this.expectedException.expect(ItemStreamException.class); this.expectedException.expectMessage("Failed to initialize the reader"); this.expectedException.expectCause(instanceOf(IllegalStateException.class)); JsonItemReader<Trade> itemReader = new JsonItemReaderBuilder<Trade>() .jsonObjectReader(getJsonObjectReader()) .resource(new ByteArrayResource("{}, {}".getBytes())) .name("tradeJsonItemReader") .build(); itemReader.open(new ExecutionContext()); }
@Test public void testInvalidResourceContent() throws Exception { this.expectedException.expect(ParseException.class); this.expectedException.expectCause(Matchers.instanceOf(getJsonParsingException())); JsonItemReader<Trade> itemReader = new JsonItemReaderBuilder<Trade>() .jsonObjectReader(getJsonObjectReader()) .resource(new ByteArrayResource("[{]".getBytes())) .name("tradeJsonItemReader") .build(); itemReader.open(new ExecutionContext()); itemReader.read(); } }
@Test public void testEmptyResource() throws Exception { JsonItemReader<Trade> itemReader = new JsonItemReaderBuilder<Trade>() .jsonObjectReader(getJsonObjectReader()) .resource(new ByteArrayResource("[]".getBytes())) .name("tradeJsonItemReader") .build(); itemReader.open(new ExecutionContext()); Trade trade = itemReader.read(); Assert.assertNull(trade); }
.build(); itemReader.open(new ExecutionContext());