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));
}
Aggregations