NpmSearchResponseMapper extends ComponentSupport { public NpmSearchResponse readFromInputStream(final InputStream searchResponseStream) throws IOException { try (InputStream in = new BufferedInputStream(searchResponseStream)) { return mapper.readValue(in, NpmSearchResponse.class); } } NpmSearchResponseMapper(); String writeString(final NpmSearchResponse searchResponse); NpmSearchResponse readFromInputStream(final InputStream searchResponseStream);  }
@Test public void testReadInputStream() throws Exception { try (InputStream in = getClass().getResourceAsStream("sample-search-response.json")) { NpmSearchResponseMapper underTest = new NpmSearchResponseMapper(); NpmSearchResponse response = underTest.readFromInputStream(in); assertThat(response.getObjects(), hasSize(1)); assertThat(response.getTotal(), is(1)); assertThat(response.getTime(), is("Wed Jan 25 2017 19:23:35 GMT+0000 (UTC)")); NpmSearchResponseObject object = response.getObjects().get(0); assertThat(object.getSearchScore(), is(closeTo(100000.914, 0.01))); NpmSearchResponseScore score = object.getScore(); assertThat(score.getFinalScore(), is(closeTo(0.9237841281241451, 0.01))); NpmSearchResponseScoreDetail detail = score.getDetail(); assertThat(detail.getQuality(), is(closeTo(0.9270640902288084, 0.01))); assertThat(detail.getPopularity(), is(closeTo(0.8484861649808381, 0.01))); assertThat(detail.getMaintenance(), is(closeTo(0.9962706951777409, 0.01))); NpmSearchResponsePackage packageEntry = object.getPackageEntry(); assertThat(packageEntry.getName(), is("yargs")); assertThat(packageEntry.getVersion(), is("6.6.0")); assertThat(packageEntry.getDescription(), is("yargs the modern, pirate-themed, successor to optimist.")); assertThat(packageEntry.getKeywords(), containsInAnyOrder("argument", "args", "option", "parser", "parsing", "cli", "command")); assertThat(packageEntry.getDate(), is("2016-12-30T16:53:16.023Z")); NpmSearchResponsePackageLinks links = packageEntry.getLinks(); assertThat(links.getNpm(), is("https: assertThat(links.getHomepage(), is("http: assertThat(links.getRepository(), is("https: assertThat(links.getBugs(), is("https: NpmSearchResponsePerson publisher = packageEntry.getPublisher(); assertThat(publisher.getUsername(), is("bcoe")); assertThat(publisher.getEmail(), is("ben@npmjs.com")); List<NpmSearchResponsePerson> maintainers = packageEntry.getMaintainers(); assertThat(maintainers, hasSize(4)); assertThat(maintainers.get(0).getUsername(), is("bcoe")); assertThat(maintainers.get(0).getEmail(), is("ben@npmjs.com")); assertThat(maintainers.get(1).getUsername(), is("chevex")); assertThat(maintainers.get(1).getEmail(), is("alex.ford@codetunnel.com")); assertThat(maintainers.get(2).getUsername(), is("nexdrew")); assertThat(maintainers.get(2).getEmail(), is("andrew@npmjs.com")); assertThat(maintainers.get(3).getUsername(), is("nylen")); assertThat(maintainers.get(3).getEmail(), is("jnylen@gmail.com")); } }