use of ddf.catalog.operation.CreateResponse in project ddf by codice.
the class SolrProviderRealTimeQueryTest method testRealTimeQueryMultipleByIdAndTitle.
@Test
public void testRealTimeQueryMultipleByIdAndTitle() throws Exception {
final String metacardTitle1 = "testRealTimeQueryMultipleIds1";
final String metacardTitle2 = "testRealTimeQueryMultipleIds2";
deleteAll(provider);
MockMetacard metacard1 = new MockMetacard(Library.getFlagstaffRecord());
metacard1.setTitle(metacardTitle1);
MockMetacard metacard2 = new MockMetacard(Library.getFlagstaffRecord());
metacard1.setTitle(metacardTitle2);
List<Metacard> metacards = new ArrayList<>(2);
metacards.add(metacard1);
metacards.add(metacard2);
CreateResponse createResponse = create(metacards, provider);
List<Metacard> createdMetacards = createResponse.getCreatedMetacards();
// Real time queries only work when querying by ID, so a query by title only will
// return 0 results.
queryAndVerifyCount(0, getFilterBuilder().attribute(Metacard.TITLE).is().equalTo().text(metacardTitle1), provider);
queryAndVerifyCount(0, getFilterBuilder().attribute(Metacard.TITLE).is().equalTo().text(metacardTitle2), provider);
// this filter will look like ((id = <id0> AND title = <title0>) OR (id = <id1> AND title =
// <title1>))
Filter filter = getFilterBuilder().anyOf(getFilterBuilder().allOf(getFilterBuilder().attribute(Metacard.ID).is().equalTo().text(createdMetacards.get(0).getId()), getFilterBuilder().attribute(Metacard.TITLE).is().equalTo().text(createdMetacards.get(0).getTitle())), getFilterBuilder().allOf(getFilterBuilder().attribute(Metacard.ID).is().equalTo().text(createdMetacards.get(1).getId()), getFilterBuilder().attribute(Metacard.TITLE).is().equalTo().text(createdMetacards.get(1).getTitle())));
// When performing a real time query by ID, we get the results.
queryAndVerifyCount(2, filter, provider);
}
use of ddf.catalog.operation.CreateResponse in project ddf by codice.
the class SolrProviderRealTimeQueryTest method testRealTimeQueryNotId.
@Test
public void testRealTimeQueryNotId() throws Exception {
final String metacardTitle = "testRealTimeQueryNotId";
deleteAll(provider);
MockMetacard metacard = new MockMetacard(Library.getFlagstaffRecord());
metacard.setTitle(metacardTitle);
CreateResponse createResponse = create(metacard, provider);
Optional<String> id = createResponse.getCreatedMetacards().stream().map(m -> m.getId()).findFirst();
assertTrue("Metacard creation failed for metacard with title: " + metacardTitle, id.isPresent());
// Verify the result is actually visible (searchable) in Solr using a real time query by ID.
queryAndVerifyCount(1, getFilterBuilder().attribute(Metacard.ID).is().equalTo().text(id.get()), provider);
Filter filter = getFilterBuilder().not(getFilterBuilder().attribute(Metacard.ID).equalTo().text(id.get()));
// Verify a "not ID query" does not return the result.
queryAndVerifyCount(0, filter, provider);
}
use of ddf.catalog.operation.CreateResponse in project ddf by codice.
the class SolrProviderRealTimeQueryTest method testRealTimeQueryByIdAndTitle.
@Test
public void testRealTimeQueryByIdAndTitle() throws Exception {
final String metacardTitle = "testRealTimeQueryByIdAndTitle";
deleteAll(provider);
MockMetacard metacard = new MockMetacard(Library.getFlagstaffRecord());
metacard.setTitle(metacardTitle);
CreateResponse createResponse = create(metacard, provider);
Optional<String> id = createResponse.getCreatedMetacards().stream().map(m -> m.getId()).findFirst();
if (!id.isPresent()) {
Assert.fail("Metacard creation failed for metacard with title: " + metacardTitle);
}
// Real time queries only work when querying by ID, so a real time query by title only will
// return
// 0 results.
queryAndVerifyCount(0, getFilterBuilder().attribute(Metacard.TITLE).is().equalTo().text(metacardTitle), provider);
// When performing a real time query by ID and title, we get the result.
queryAndVerifyCount(1, getFilterBuilder().allOf(getFilterBuilder().attribute(Metacard.ID).is().equalTo().text(id.get()), getFilterBuilder().attribute(Metacard.TITLE).is().equalTo().text(metacardTitle)), provider);
}
use of ddf.catalog.operation.CreateResponse 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));
}
use of ddf.catalog.operation.CreateResponse in project ddf by codice.
the class SolrProviderSpatial method testSpatialCreateAndUpdateWithClockwiseRectangle.
@Test
public void testSpatialCreateAndUpdateWithClockwiseRectangle() throws Exception {
deleteAll(provider);
// CREATE
MockMetacard metacard = new MockMetacard(Library.getFlagstaffRecord());
metacard.setLocation(Library.CLOCKWISE_ARIZONA_RECTANGLE_WKT);
CreateResponse createResponse = create(Collections.singletonList(metacard), provider);
assertEquals(1, createResponse.getCreatedMetacards().size());
Filter filter = getFilterBuilder().attribute(Metacard.GEOGRAPHY).intersecting().wkt(Library.FLAGSTAFF_AIRPORT_POINT_WKT);
SourceResponse sourceResponse = provider.query(new QueryRequestImpl(new QueryImpl(filter)));
assertEquals("Failed to find correct record.", 1, sourceResponse.getResults().size());
// UPDATE
MockMetacard updatedMetacard = new MockMetacard(Library.getTampaRecord());
updatedMetacard.setLocation(Library.CLOCKWISE_ARIZONA_RECTANGLE_WKT);
String[] ids = { metacard.getId() };
UpdateResponse updateResponse = update(ids, Collections.singletonList(updatedMetacard), provider);
assertEquals(1, updateResponse.getUpdatedMetacards().size());
filter = getFilterBuilder().attribute(Metacard.GEOGRAPHY).intersecting().wkt(Library.FLAGSTAFF_AIRPORT_POINT_WKT);
sourceResponse = provider.query(new QueryRequestImpl(new QueryImpl(filter)));
assertEquals("Failed to find correct record.", 1, sourceResponse.getResults().size());
}
Aggregations