use of ddf.catalog.source.solr.provider.MockMetacard in project ddf by codice.
the class SolrProviderRealTimeQueryTest method testRealTimeQueryMultipleIds.
@Test
public void testRealTimeQueryMultipleIds() 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<String> ids = createResponse.getCreatedMetacards().stream().map(m -> m.getId()).collect(Collectors.toList());
// 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(metacardTitle1), provider);
queryAndVerifyCount(0, getFilterBuilder().attribute(Metacard.TITLE).is().equalTo().text(metacardTitle2), provider);
Filter filter = getFilterBuilder().anyOf(getFilterBuilder().attribute(Metacard.ID).is().equalTo().text(ids.get(0)), getFilterBuilder().attribute(Metacard.ID).is().equalTo().text(ids.get(1)));
// When performing a real time query by ID, we get the results.
queryAndVerifyCount(2, filter, provider);
}
use of ddf.catalog.source.solr.provider.MockMetacard 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.source.solr.provider.MockMetacard 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.source.solr.provider.MockMetacard 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.source.solr.provider.MockMetacard in project ddf by codice.
the class SolrProviderRealTimeQueryTest method testCommitNrt.
@Test
public void testCommitNrt() throws Exception {
final String nrtTitle = "testCommitNrt";
final String nonNrtTitle = "testCommitNonNrt";
deleteAll(provider);
MetacardType nrtMetacardType = new MetacardTypeImpl(COMMIT_NRT_TYPE, BASIC_METACARD.getAttributeDescriptors());
MockMetacard nrtMetacard = new MockMetacard(Library.getFlagstaffRecord(), nrtMetacardType);
nrtMetacard.setTitle(nrtTitle);
MockMetacard nonNrtMetacard = new MockMetacard(Library.getFlagstaffRecord());
nonNrtMetacard.setTitle(nonNrtTitle);
create(Lists.newArrayList(nrtMetacard, nonNrtMetacard), provider);
QueryRequest request = new QueryRequestImpl(new QueryImpl(getFilterBuilder().attribute(Metacard.TITLE).is().like().text("testCommit*Nrt")));
await().pollInterval(100, TimeUnit.MILLISECONDS).atMost(30, TimeUnit.SECONDS).until(() -> provider.query(request).getResults().size() == 2);
}
Aggregations