@SuppressWarnings("unchecked") @Test public void testGetUri() throws Exception { ETLStatistics etlStatistics = new ETLStatistics(); List<Taxon> list = null; URI actual = null; NsrExtractor extractor = new NsrExtractor(nsrFile, etlStatistics); NsrTaxonTransformer nsrTaxonTransformer = new NsrTaxonTransformer(etlStatistics); NsrMultiMediaTransformer mediaTransformer = new NsrMultiMediaTransformer(etlStatistics); for (XMLRecordInfo extracted : extractor) { CommonReflectionUtil.setField(AbstractTransformer.class, nsrTaxonTransformer, "objectID", "D3KF0JNQ0UA"); CommonReflectionUtil.setField(AbstractTransformer.class, nsrTaxonTransformer, "input", extracted); Object taxonObject = CommonReflectionUtil.callMethod(null, null, nsrTaxonTransformer, "doTransform"); CommonReflectionUtil.setField(AbstractTransformer.class, mediaTransformer, "objectID", "D3KF0JNQ0UA"); CommonReflectionUtil.setField(AbstractTransformer.class, mediaTransformer, "input", extracted); list = (List<Taxon>) taxonObject; mediaTransformer.setTaxon(list.get(0)); List<Element> imageElems = getDescendants(extracted.getRecord(), "image"); Object returned = ReflectionUtil.call(mediaTransformer, "getUri", new Class[] {Element.class}, new Object[] {imageElems.get(0)}); actual = (URI) returned; } String expectedURI = "http: assertNotNull("01",actual); assertEquals("02",expectedURI, actual.toString()); }
private URI getUri(Image image) { String url = val(image.getUrl()); if (url == null) { stats.objectsRejected++; if (!suppressErrors) { String sn = taxon.getAcceptedName().getFullScientificName(); error("Empty <url> element for \"%s\"", sn); } return null; } try { return new URI(url.trim()); } catch (URISyntaxException e) { stats.objectsRejected++; if (!suppressErrors) error("Invalid image URL: \"%s\"", url); return null; } }
NsrMultiMediaTransformer extends AbstractJSONTransformer<MultiMediaObject> { private URI getUri(Image image) { String url = val(image.getUrl()); if (url == null) { stats.objectsRejected++; if (!suppressErrors) { String sn = taxon.getAcceptedName().getFullScientificName(); error("Empty <url> element for \"%s\"", sn); } return null; } try { return new URI(url.trim()); } catch (URISyntaxException e) { stats.objectsRejected++; if (!suppressErrors) error("Invalid image URL: \"%s\"", url); return null; } } }
NsrMultiMediaTransformer extends AbstractJSONTransformer<MultiMediaObject> { private URI getUri(Image image) { String url = val(image.getUrl()); if (url == null) { stats.objectsRejected++; if (!suppressErrors) { String sn = taxon.getAcceptedName().getFullScientificName(); error("Empty <url> element for \"%s\"", sn); } return null; } try { return new URI(url.trim()); } catch (URISyntaxException e) { stats.objectsRejected++; if (!suppressErrors) error("Invalid image URL: \"%s\"", url); return null; } } NsrMultiMediaTransformer(ETLStatistics stats); }
NsrMultiMediaTransformer extends AbstractJSONTransformer<MultiMediaObject> { private URI getUri(Image image) { String url = val(image.getUrl()); if (url == null) { stats.objectsRejected++; if (!suppressErrors) { String sn = taxon.getAcceptedName().getFullScientificName(); error("Empty <url> element for \"%s\"", sn); } return null; } try { return new URI(url.trim()); } catch (URISyntaxException e) { stats.objectsRejected++; if (!suppressErrors) error("Invalid image URL: \"%s\"", url); return null; } } NsrMultiMediaTransformer(ETLStatistics stats); void setTaxon(Taxon taxon); }
NsrMultiMediaTransformer extends AbstractJSONTransformer<MultiMediaObject> { private URI getUri(Image image) { String url = val(image.getUrl()); if (url == null) { stats.objectsRejected++; if (!suppressErrors) { String sn = taxon.getAcceptedName().getFullScientificName(); error("Empty <url> element for \"%s\"", sn); } return null; } try { return new URI(url.trim()); } catch (URISyntaxException e) { stats.objectsRejected++; if (!suppressErrors) error("Invalid image URL: \"%s\"", url); return null; } } NsrMultiMediaTransformer(ETLStatistics stats); void setTaxon(Taxon taxon);  }