TextExtractionStage extends AbstractProcessStage { String getUrl(LocalDocument doc) { Object urlObject = doc.getContentField(urlField); if (urlObject == null) { return null; } if (urlObject instanceof String) { return (String) urlObject; } else if (urlObject instanceof List<?>) { List<?> urlList = (List<?>) urlObject; if (!urlList.isEmpty()) { if (urlList.get(0) instanceof String) { return (String) urlList.get(0); } else { logger.warn("List in " + urlField + " did not contain Strings. Skipping"); return null; } } else { logger.warn("List was empty. Skipping"); } } else { logger.warn(urlField + " did not contain String nor List. Skipping"); } return null; }  @Override void process(LocalDocument doc); @Override void init(); void setUrlField(String urlField); void setContentField(String contentField); String getContentField(); void setMetadatPrefix(String prefix); String getMetadataPrefix(); long getMaxSizeInBytes(); void setMaxSizeInBytes(long size); String getFileSizeField(); void setFileSizeField(String fileSizeField); String getFileFormatField(); void setFileFormatField(String fileFormatField); List<String> getAllowedFileFormats(); void setAllowedFileFormats(List<String> allowedFileFormats);  }
@Test public void testGetUrl() { doc.putContentField("url", "http: String url = stage.getUrl(doc); String expected = "http: if (!expected.equals(url)) { fail("Failed to read url. Expected: " + expected + " Got: " + url); } }
@Test public void testGetUrlFromList() { doc.putContentField("url", Arrays.asList(new String[]{"http: String url = stage.getUrl(doc); String expected = "http: if (!expected.equals(url)) { fail("Failed to read url. Expected: " + expected + " Got: " + url); } }
@Test public void testGetUrlFromListWithMoreUrls() { doc.putContentField("url", Arrays.asList(new String[]{"http: String url = stage.getUrl(doc); String expected = "http: if (!expected.equals(url)) { fail("Failed to read url. Expected: " + expected + " Got: " + url); } }
@Test public void testGetUrlFromNull() { String url = stage.getUrl(doc); String expected = null; if (url != null) { fail("Failed to read url. Expected: " + expected + " Got: " + url); } }
@Test public void testGetUrlWithInteger() { doc.putContentField("url", new Integer(5)); String url = stage.getUrl(doc); String expected = null; if (url != null) { fail("Failed to read url. Expected: " + expected + " Got: " + url); } }