use of ddf.catalog.source.solr.provider.MockMetacard in project ddf by codice.
the class SolrProviderRealTimeQueryTest method testRealTimeQueryByIdOrTitle.
@Test
public void testRealTimeQueryByIdOrTitle() throws Exception {
final String metacardTitle = "testRealTimeQueryById";
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 happen when querying by ID, so a query by title only will
// return 0 results.
queryAndVerifyCount(0, getFilterBuilder().attribute(Metacard.TITLE).is().equalTo().text(metacardTitle), provider);
Filter filter = getFilterBuilder().anyOf(getFilterBuilder().attribute(Metacard.ID).is().equalTo().text(id.get()), getFilterBuilder().attribute(Metacard.TITLE).is().equalTo().text(metacardTitle));
// Verify an "ID or Title" query does not perform a real time get, and therefore,
// does not return a result.
queryAndVerifyCount(0, filter, provider);
}
use of ddf.catalog.source.solr.provider.MockMetacard in project ddf by codice.
the class SolrProviderRealTimeQueryTest method testRealTimeQueryById.
@Test
public void testRealTimeQueryById() throws Exception {
final String metacardTitle = "testRealTimeQueryById";
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, we get the result.
queryAndVerifyCount(1, getFilterBuilder().attribute(Metacard.ID).is().equalTo().text(id.get()), provider);
}
use of ddf.catalog.source.solr.provider.MockMetacard in project ddf by codice.
the class SolrProviderRealTimeQueryTest method testRealTimeQueryNotId2.
/*similar to testRealTimeQueryNotId but this time we'll use a random ID for the filter. In this case
the created metacard will match the filter but should not be returned because we shouldn't be doing a
real time query.*/
@Test
public void testRealTimeQueryNotId2() 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("can't match this"));
// Verify a "not ID query" does not return the result.
queryAndVerifyCount(0, filter, provider);
}
Aggregations