Search in sources :

Example 1 with GeoEntryIndexer

use of org.codice.ddf.spatial.geocoding.GeoEntryIndexer 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);
}
Also used : GeoEntryIndexer(org.codice.ddf.spatial.geocoding.GeoEntryIndexer) Geocoding(org.codice.ddf.spatial.admin.module.service.Geocoding) GeoEntryExtractor(org.codice.ddf.spatial.geocoding.GeoEntryExtractor) Before(org.junit.Before)

Example 2 with GeoEntryIndexer

use of org.codice.ddf.spatial.geocoding.GeoEntryIndexer 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();
}
Also used : GeoEntryIndexer(org.codice.ddf.spatial.geocoding.GeoEntryIndexer) ProgressCallback(org.codice.ddf.spatial.geocoding.ProgressCallback) Matchers.anyString(org.mockito.Matchers.anyString) Matchers.containsString(org.hamcrest.Matchers.containsString) GeoEntryExtractor(org.codice.ddf.spatial.geocoding.GeoEntryExtractor) GeoEntryIndexingException(org.codice.ddf.spatial.geocoding.GeoEntryIndexingException) Test(org.junit.Test)

Example 3 with GeoEntryIndexer

use of org.codice.ddf.spatial.geocoding.GeoEntryIndexer in project ddf by codice.

the class TestGeoNamesUpdateCommand method testExceptionDuringExtraction.

@Test
public void testExceptionDuringExtraction() throws IOException, GeoNamesRemoteDownloadException, GeoEntryExtractionException, GeoEntryIndexingException {
    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) {
        }

        @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));
        }
    };
    geoNamesUpdateCommand.setGeoEntryIndexer(geoEntryIndexer);
    geoNamesUpdateCommand.setGeoEntryExtractor(geoEntryExtractor);
    geoNamesUpdateCommand.setResource("temp.txt");
    geoNamesUpdateCommand.execute();
    assertThat(consoleInterceptor.getOutput(), containsString(errorText));
    consoleInterceptor.resetSystemOut();
    consoleInterceptor.closeBuffer();
}
Also used : GeoEntryIndexer(org.codice.ddf.spatial.geocoding.GeoEntryIndexer) GeoEntryExtractionException(org.codice.ddf.spatial.geocoding.GeoEntryExtractionException) ProgressCallback(org.codice.ddf.spatial.geocoding.ProgressCallback) ArrayList(java.util.ArrayList) List(java.util.List) Matchers.anyString(org.mockito.Matchers.anyString) Matchers.containsString(org.hamcrest.Matchers.containsString) ExtractionCallback(org.codice.ddf.spatial.geocoding.GeoEntryExtractor.ExtractionCallback) GeoEntryExtractor(org.codice.ddf.spatial.geocoding.GeoEntryExtractor) Test(org.junit.Test)

Example 4 with GeoEntryIndexer

use of org.codice.ddf.spatial.geocoding.GeoEntryIndexer in project ddf by codice.

the class TestGeoNamesUpdateCommand method testProgressOutput.

@Test
public void testProgressOutput() throws IOException {
    final GeoEntryExtractor geoEntryExtractor = spy(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) {
            extractionCallback.updateProgress(50);
            assertThat(consoleInterceptor.getOutput(), containsString("50%"));
            extractionCallback.updateProgress(100);
            assertThat(consoleInterceptor.getOutput(), containsString("100%"));
        }

        @Override
        public void setUrl(String url) {
            return;
        }
    });
    final GeoEntryExtractor geoEntryUrlExtractor = spy(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) {
            extractionCallback.updateProgress(50);
            assertThat(consoleInterceptor.getOutput(), containsString("50%"));
            extractionCallback.updateProgress(100);
            assertThat(consoleInterceptor.getOutput(), containsString("100%"));
        }

        @Override
        public void setUrl(String url) {
            return;
        }
    });
    final GeoEntryIndexer geoEntryIndexer = spy(new GeoEntryIndexer() {

        @Override
        public void updateIndex(final List<GeoEntry> newEntries, final boolean create, final ProgressCallback progressCallback) {
        }

        @Override
        public void updateIndex(final String resource, final GeoEntryExtractor geoEntryExtractor, final boolean create, final ProgressCallback progressCallback) throws GeoNamesRemoteDownloadException, GeoEntryIndexingException, GeoEntryExtractionException {
            final ExtractionCallback extractionCallback = new ExtractionCallback() {

                @Override
                public void extracted(final GeoEntry newEntry) {
                }

                @Override
                public void updateProgress(final int progress) {
                    progressCallback.updateProgress(progress);
                }
            };
            geoEntryExtractor.pushGeoEntriesToExtractionCallback(resource, extractionCallback);
        }
    });
    List<GeoEntryExtractor> geoEntryExtractors = new ArrayList<GeoEntryExtractor>();
    geoEntryExtractors.add(geoEntryExtractor);
    geoEntryExtractors.add(geoEntryUrlExtractor);
    geoNamesUpdateCommand.setGeoEntryExtractor(geoEntryExtractor);
    geoNamesUpdateCommand.setGeoEntryIndexer(geoEntryIndexer);
    geoNamesUpdateCommand.setResource("test");
    geoNamesUpdateCommand.execute();
    consoleInterceptor.resetSystemOut();
    consoleInterceptor.closeBuffer();
}
Also used : GeoNamesRemoteDownloadException(org.codice.ddf.spatial.geocoding.GeoNamesRemoteDownloadException) ProgressCallback(org.codice.ddf.spatial.geocoding.ProgressCallback) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) Matchers.containsString(org.hamcrest.Matchers.containsString) GeoEntryExtractor(org.codice.ddf.spatial.geocoding.GeoEntryExtractor) GeoEntryIndexer(org.codice.ddf.spatial.geocoding.GeoEntryIndexer) GeoEntry(org.codice.ddf.spatial.geocoding.GeoEntry) GeoEntryExtractionException(org.codice.ddf.spatial.geocoding.GeoEntryExtractionException) ArrayList(java.util.ArrayList) List(java.util.List) ExtractionCallback(org.codice.ddf.spatial.geocoding.GeoEntryExtractor.ExtractionCallback) GeoEntryIndexingException(org.codice.ddf.spatial.geocoding.GeoEntryIndexingException) Test(org.junit.Test)

Aggregations

GeoEntryExtractor (org.codice.ddf.spatial.geocoding.GeoEntryExtractor)4 GeoEntryIndexer (org.codice.ddf.spatial.geocoding.GeoEntryIndexer)4 ProgressCallback (org.codice.ddf.spatial.geocoding.ProgressCallback)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 Test (org.junit.Test)3 Matchers.anyString (org.mockito.Matchers.anyString)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 GeoEntryExtractionException (org.codice.ddf.spatial.geocoding.GeoEntryExtractionException)2 ExtractionCallback (org.codice.ddf.spatial.geocoding.GeoEntryExtractor.ExtractionCallback)2 GeoEntryIndexingException (org.codice.ddf.spatial.geocoding.GeoEntryIndexingException)2 Geocoding (org.codice.ddf.spatial.admin.module.service.Geocoding)1 GeoEntry (org.codice.ddf.spatial.geocoding.GeoEntry)1 GeoNamesRemoteDownloadException (org.codice.ddf.spatial.geocoding.GeoNamesRemoteDownloadException)1 Before (org.junit.Before)1