use of org.codice.ddf.spatial.geocoding.GeoEntryExtractor in project ddf by codice.
the class TestGeocodingMbean method setUp.
@Before
public void setUp() {
geocoding = new Geocoding();
geoEntryExtractor = Mockito.mock(GeoEntryExtractor.class);
geoEntryIndexer = Mockito.mock(GeoEntryIndexer.class);
geocoding.setGeoEntryIndexer(geoEntryIndexer);
geocoding.setGeoEntryExtractor(geoEntryExtractor);
}
use of org.codice.ddf.spatial.geocoding.GeoEntryExtractor in project ddf by codice.
the class TestGeoNamesUpdateCommand method testExceptionDuringIndexing.
@Test
public void testExceptionDuringIndexing() throws GeoNamesRemoteDownloadException, GeoEntryExtractionException, GeoEntryIndexingException {
final String errorText = "Indexing error text";
final GeoEntryExtractor geoEntryExtractor = mock(GeoEntryExtractor.class);
final GeoEntryIndexer geoEntryIndexer = mock(GeoEntryIndexer.class);
final GeoEntryIndexingException geoEntryIndexingException = new GeoEntryIndexingException(errorText);
doThrow(geoEntryIndexingException).when(geoEntryIndexer).updateIndex(anyString(), any(GeoEntryExtractor.class), anyBoolean(), any(ProgressCallback.class));
geoNamesUpdateCommand.setGeoEntryIndexer(geoEntryIndexer);
geoNamesUpdateCommand.setGeoEntryExtractor(geoEntryExtractor);
geoNamesUpdateCommand.setResource("temp");
geoNamesUpdateCommand.execute();
assertThat(consoleInterceptor.getOutput(), containsString(errorText));
consoleInterceptor.resetSystemOut();
}
use of org.codice.ddf.spatial.geocoding.GeoEntryExtractor in project ddf by codice.
the class TestGeoNamesLuceneIndexerExceptions method testExceptionWhenAddingDocumentByExtractor.
@Test
public void testExceptionWhenAddingDocumentByExtractor() throws GeoEntryIndexingException, GeoEntryExtractionException, GeoNamesRemoteDownloadException, IOException {
configureMocks();
geoNamesLuceneIndexer.setIndexLocation(ABSOLUTE_PATH + TEST_PATH + "index");
try {
final GeoEntryExtractor geoEntryExtractor = new GeoEntryExtractor() {
@Override
public List<GeoEntry> getGeoEntries(final String resource, final ProgressCallback progressCallback) {
return null;
}
@Override
public void pushGeoEntriesToExtractionCallback(final String resource, final ExtractionCallback extractionCallback) throws GeoEntryExtractionException {
extractionCallback.updateProgress(0);
try {
extractionCallback.extracted(GEO_ENTRY);
} catch (GeoEntryIndexingException e) {
throw new GeoEntryExtractionException("Unable to add entry.", e);
}
}
@Override
public void setUrl(String url) {
return;
}
};
geoNamesLuceneIndexer.updateIndex("", geoEntryExtractor, true, null);
fail("Should have thrown a GeoEntryExtractionException; extractionCallback.extract() threw " + "a GeoEntryIndexingException because addDocument() threw an " + "IOException.");
} catch (GeoEntryExtractionException e) {
assertThat(e.getCause(), instanceOf(GeoEntryIndexingException.class));
}
}
use of org.codice.ddf.spatial.geocoding.GeoEntryExtractor in project ddf by codice.
the class GeoNamesCatalogIndexer method updateIndex.
@Override
public void updateIndex(String resource, GeoEntryExtractor geoEntryExtractor, boolean create, ProgressCallback progressCallback) throws GeoEntryIndexingException, GeoEntryExtractionException, GeoNamesRemoteDownloadException {
if (StringUtils.isBlank(resource)) {
LOGGER.debug("The resource was null or empty.");
return;
}
List<Metacard> metacardList = new ArrayList<>();
final GeoEntryExtractor.ExtractionCallback extractionCallback = new GeoEntryExtractor.ExtractionCallback() {
@Override
public void extracted(final GeoEntry newEntry) throws GeoEntryIndexingException {
Metacard metacard = transformGeoEntryToMetacard(newEntry);
if (metacard != null) {
metacardList.add(metacard);
}
}
@Override
public void updateProgress(final int progress) {
if (progressCallback != null) {
progressCallback.updateProgress(progress);
}
}
};
if (create) {
RetryPolicy retryPolicy = new RetryPolicy().withDelay(10, TimeUnit.SECONDS).withMaxDuration(5, TimeUnit.MINUTES).retryOn(Exception.class);
Failsafe.with(retryPolicy).run(() -> removeGeoNamesMetacardsFromCatalog(resource, extractionCallback));
}
geoEntryExtractor.pushGeoEntriesToExtractionCallback(resource, extractionCallback);
if (CollectionUtils.isEmpty(metacardList)) {
LOGGER.debug("No Metacards were created from the resource.");
return;
}
executeCreateMetacardRequest(metacardList);
LOGGER.trace("All data created for: {}", resource);
}
use of org.codice.ddf.spatial.geocoding.GeoEntryExtractor in project ddf by codice.
the class GazetteerUpdateCommandTest method testExceptionDuringExtraction.
@Test
public void testExceptionDuringExtraction() throws Exception {
final String errorText = "Extraction error text";
final GeoEntryExtractor geoEntryExtractor = mock(GeoEntryExtractor.class);
final GeoEntryExtractionException geoEntryExtractionException = new GeoEntryExtractionException(errorText);
doThrow(geoEntryExtractionException).when(geoEntryExtractor).pushGeoEntriesToExtractionCallback(anyString(), any(ExtractionCallback.class));
final GeoEntryIndexer geoEntryIndexer = new GeoEntryIndexer() {
@Override
public void updateIndex(final List<GeoEntry> newEntries, final boolean create, final ProgressCallback progressCallback, final String entrySource) {
/* stub */
}
@Override
public void updateIndex(final String resource, final GeoEntryExtractor geoEntryExtractor, final boolean create, final ProgressCallback progressCallback) throws GeoNamesRemoteDownloadException, GeoEntryExtractionException, GeoEntryIndexingException {
geoEntryExtractor.pushGeoEntriesToExtractionCallback(resource, mock(ExtractionCallback.class));
}
};
gazetteerUpdateCommand.setGeoEntryIndexer(geoEntryIndexer);
gazetteerUpdateCommand.setGeoEntryExtractor(geoEntryExtractor);
gazetteerUpdateCommand.setResource("temp.txt");
gazetteerUpdateCommand.executeWithSubject();
assertThat(consoleInterceptor.getOutput(), containsString(errorText));
consoleInterceptor.resetSystemOut();
consoleInterceptor.closeBuffer();
}
Aggregations