Search in sources :

Example 1 with SolrMetacardClientImpl

use of ddf.catalog.source.solr.SolrMetacardClientImpl in project ddf by codice.

the class ReindexCommandTest method testReindex.

@Test
public void testReindex() throws Exception {
    ThreadContext.bind(mock(Subject.class));
    SolrClient cloudClient = mock(SolrClient.class);
    NamedList<Object> pingStatus = new NamedList<>();
    pingStatus.add("status", "OK");
    when(cloudClient.isAvailable()).thenReturn(true);
    QueryResponse hitCountResponse = mock(QueryResponse.class);
    SolrDocumentList hitCountResults = mock(SolrDocumentList.class);
    when(hitCountResults.getNumFound()).thenReturn(1L);
    when(hitCountResponse.getResults()).thenReturn(hitCountResults);
    SolrDocument doc = new SolrDocument();
    doc.put("id_txt", "1234");
    SolrDocumentList dataDocumentList = new SolrDocumentList();
    dataDocumentList.add(doc);
    dataDocumentList.setNumFound(1L);
    QueryResponse dataResponse = mock(QueryResponse.class);
    when(dataResponse.getResults()).thenReturn(dataDocumentList);
    when(dataResponse.getNextCursorMark()).thenReturn("cursor1234");
    SolrDocumentList emptyDocList = new SolrDocumentList();
    dataDocumentList.add(doc);
    QueryResponse emptyResponse = mock(QueryResponse.class);
    when(emptyResponse.getResults()).thenReturn(emptyDocList);
    when(cloudClient.query(any(SolrQuery.class))).thenReturn(hitCountResponse, dataResponse, emptyResponse);
    SolrMetacardClientImpl solrMetacardClient = mock(SolrMetacardClientImpl.class);
    when(solrMetacardClient.createMetacard(any())).thenReturn(getTestMetacard());
    CreateResponse createResponse = mock(CreateResponse.class);
    CatalogFramework catalogFramework = mock(CatalogFramework.class);
    when(catalogFramework.create(any(CreateRequest.class))).thenReturn(createResponse);
    Security security = mock(Security.class);
    Subject subject = mock(Subject.class);
    when(security.runAsAdmin(any())).thenReturn(subject);
    when(subject.execute(any(Callable.class))).thenAnswer(c -> ((Callable) c.getArguments()[0]).call());
    ReindexCommand command = new ReindexCommand();
    command.setSolrjClient(cloudClient);
    command.setMetacardClient(solrMetacardClient);
    command.setNumThread(1);
    command.setCollection("catalog");
    command.setSolrHost("http://localhost:8994/solr");
    command.setCatalogFramework(catalogFramework);
    command.security = security;
    command.execute();
    verify(catalogFramework, times(1)).create(any(CreateRequest.class));
}
Also used : NamedList(org.apache.solr.common.util.NamedList) CreateResponse(ddf.catalog.operation.CreateResponse) CreateRequest(ddf.catalog.operation.CreateRequest) SolrDocumentList(org.apache.solr.common.SolrDocumentList) Security(org.codice.ddf.security.Security) Subject(ddf.security.Subject) SolrQuery(org.apache.solr.client.solrj.SolrQuery) Callable(java.util.concurrent.Callable) SolrDocument(org.apache.solr.common.SolrDocument) SolrClient(org.codice.solr.client.solrj.SolrClient) SolrMetacardClientImpl(ddf.catalog.source.solr.SolrMetacardClientImpl) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) CatalogFramework(ddf.catalog.CatalogFramework) Test(org.junit.Test)

Aggregations

CatalogFramework (ddf.catalog.CatalogFramework)1 CreateRequest (ddf.catalog.operation.CreateRequest)1 CreateResponse (ddf.catalog.operation.CreateResponse)1 SolrMetacardClientImpl (ddf.catalog.source.solr.SolrMetacardClientImpl)1 Subject (ddf.security.Subject)1 Callable (java.util.concurrent.Callable)1 SolrQuery (org.apache.solr.client.solrj.SolrQuery)1 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)1 SolrDocument (org.apache.solr.common.SolrDocument)1 SolrDocumentList (org.apache.solr.common.SolrDocumentList)1 NamedList (org.apache.solr.common.util.NamedList)1 Security (org.codice.ddf.security.Security)1 SolrClient (org.codice.solr.client.solrj.SolrClient)1 Test (org.junit.Test)1