Search in sources :

Example 1 with Nsili

use of org.codice.alliance.nsili.common.Nsili in project alliance by codice.

the class NsiliSourceTest method buildSource.

private NsiliSource buildSource() throws Exception {
    NsiliSource source;
    Nsili nsili = mock(Nsili.class);
    Response clientResponse = mock(Response.class);
    when(clientResponse.getEntity()).thenReturn("");
    InputStream mockInputStream = mock(InputStream.class);
    when(nsili.getIorFile()).thenReturn(mockInputStream);
    SecureCxfClientFactory factory = getMockFactory(nsili);
    HashMap<String, String[]> resultAttributes = new HashMap<>();
    HashMap<String, List<String>> sortableAttributes = generateMockSortableAttributes();
    source = Mockito.spy(new NsiliSource(factory, resultAttributes, sortableAttributes, new NsiliFilterDelegate(attributeInformationMap, NsiliConstants.NSIL_ALL_VIEW), orb));
    source.setIorUrl(IOR_URL);
    source.setServerUsername(NsiliSource.SERVER_USERNAME);
    source.setServerPassword(NsiliSource.SERVER_PASSWORD);
    source.setMaxHitCount(MAX_HIT_COUNT);
    source.setId(ID);
    source.setPollInterval(POLL_INTERVAL);
    source.setDataModelMgr(getMockDataModelMgr());
    source.setCatalogMgr(getMockCatalogMgr());
    source.setFilterAdapter(new GeotoolsFilterAdapterImpl());
    source.setNumberWorkerThreads(6);
    source.setAdditionalQueryParams("and (not NSIL_PRODUCT:NSIL_CARD.status = 'OBSOLETE')");
    // Suppress CORBA communications to test refresh
    doNothing().when(source).init();
    when(mockAvailabilityTask.isAvailable()).thenReturn(true);
    source.setAvailabilityTask(mockAvailabilityTask);
    return source;
}
Also used : Nsili(org.codice.alliance.nsili.common.Nsili) Response(javax.ws.rs.core.Response) SourceResponse(ddf.catalog.operation.SourceResponse) SecureCxfClientFactory(org.codice.ddf.cxf.SecureCxfClientFactory) HashMap(java.util.HashMap) InputStream(java.io.InputStream) List(java.util.List) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) GeotoolsFilterAdapterImpl(ddf.catalog.filter.proxy.adapter.GeotoolsFilterAdapterImpl)

Example 2 with Nsili

use of org.codice.alliance.nsili.common.Nsili in project alliance by codice.

the class NsiliSource method getIorStringFromHttpSource.

/**
 * Uses the SecureClientCxfFactory to obtain the IOR string from the provided URL via HTTP(S).
 */
private void getIorStringFromHttpSource() {
    createClientFactory();
    Nsili nsili = factory.getClient();
    try (InputStream inputStream = nsili.getIorFile()) {
        iorString = IOUtils.toString(inputStream, StandardCharsets.ISO_8859_1.name());
        // Remove leading/trailing whitespace as the CORBA init can't handle that.
        iorString = iorString.trim();
    } catch (IOException e) {
        LOGGER.debug("{} : Unable to process IOR String.", sourceId, e);
    } catch (Exception e) {
        LOGGER.debug("{} : Error retrieving IOR file for {}.", sourceId, iorUrl, e);
    }
}
Also used : Nsili(org.codice.alliance.nsili.common.Nsili) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) URISyntaxException(java.net.URISyntaxException) ResourceNotFoundException(ddf.catalog.resource.ResourceNotFoundException) IOException(java.io.IOException) ResourceNotSupportedException(ddf.catalog.resource.ResourceNotSupportedException) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

InputStream (java.io.InputStream)2 Nsili (org.codice.alliance.nsili.common.Nsili)2 GeotoolsFilterAdapterImpl (ddf.catalog.filter.proxy.adapter.GeotoolsFilterAdapterImpl)1 SourceResponse (ddf.catalog.operation.SourceResponse)1 ResourceNotFoundException (ddf.catalog.resource.ResourceNotFoundException)1 ResourceNotSupportedException (ddf.catalog.resource.ResourceNotSupportedException)1 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 ExecutionException (java.util.concurrent.ExecutionException)1 Response (javax.ws.rs.core.Response)1 SecureCxfClientFactory (org.codice.ddf.cxf.SecureCxfClientFactory)1 Matchers.anyString (org.mockito.Matchers.anyString)1