Search in sources :

Example 6 with MockMetacard

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);
}
Also used : QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) SolrProviderTestUtil.deleteAll(ddf.catalog.source.solr.provider.SolrProviderTestUtil.deleteAll) MetacardTypeImpl(ddf.catalog.data.impl.MetacardTypeImpl) BeforeClass(org.junit.BeforeClass) SolrClient(org.codice.solr.client.solrj.SolrClient) MiniSolrCloudCluster(org.apache.solr.cloud.MiniSolrCloudCluster) LoggerFactory(org.slf4j.LoggerFactory) SolrProviderTestUtil.queryAndVerifyCount(ddf.catalog.source.solr.provider.SolrProviderTestUtil.queryAndVerifyCount) ArrayList(java.util.ArrayList) BASIC_METACARD(ddf.catalog.data.impl.MetacardImpl.BASIC_METACARD) GeotoolsFilterAdapterImpl(ddf.catalog.filter.proxy.adapter.GeotoolsFilterAdapterImpl) Lists(com.google.common.collect.Lists) CreateResponse(ddf.catalog.operation.CreateResponse) Metacard(ddf.catalog.data.Metacard) QueryRequest(ddf.catalog.operation.QueryRequest) SolrProviderTestUtil.create(ddf.catalog.source.solr.provider.SolrProviderTestUtil.create) ClassRule(org.junit.ClassRule) JettyConfig(org.apache.solr.client.solrj.embedded.JettyConfig) Awaitility.await(org.awaitility.Awaitility.await) QueryImpl(ddf.catalog.operation.impl.QueryImpl) AfterClass(org.junit.AfterClass) Logger(org.slf4j.Logger) Matchers(org.hamcrest.Matchers) Test(org.junit.Test) Collectors(java.util.stream.Collectors) MetacardType(ddf.catalog.data.MetacardType) TimeUnit(java.util.concurrent.TimeUnit) MockMetacard(ddf.catalog.source.solr.provider.MockMetacard) List(java.util.List) Rule(org.junit.Rule) TestCase.assertTrue(junit.framework.TestCase.assertTrue) Library(ddf.catalog.source.solr.provider.Library) Paths(java.nio.file.Paths) SolrCloudClientFactory(org.codice.solr.factory.impl.SolrCloudClientFactory) Optional(java.util.Optional) Filter(org.opengis.filter.Filter) SolrProviderTestUtil.getFilterBuilder(ddf.catalog.source.solr.provider.SolrProviderTestUtil.getFilterBuilder) Assert(org.junit.Assert) TemporaryFolder(org.junit.rules.TemporaryFolder) Filter(org.opengis.filter.Filter) CreateResponse(ddf.catalog.operation.CreateResponse) MockMetacard(ddf.catalog.source.solr.provider.MockMetacard) Test(org.junit.Test)

Example 7 with MockMetacard

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);
}
Also used : QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) SolrProviderTestUtil.deleteAll(ddf.catalog.source.solr.provider.SolrProviderTestUtil.deleteAll) MetacardTypeImpl(ddf.catalog.data.impl.MetacardTypeImpl) BeforeClass(org.junit.BeforeClass) SolrClient(org.codice.solr.client.solrj.SolrClient) MiniSolrCloudCluster(org.apache.solr.cloud.MiniSolrCloudCluster) LoggerFactory(org.slf4j.LoggerFactory) SolrProviderTestUtil.queryAndVerifyCount(ddf.catalog.source.solr.provider.SolrProviderTestUtil.queryAndVerifyCount) ArrayList(java.util.ArrayList) BASIC_METACARD(ddf.catalog.data.impl.MetacardImpl.BASIC_METACARD) GeotoolsFilterAdapterImpl(ddf.catalog.filter.proxy.adapter.GeotoolsFilterAdapterImpl) Lists(com.google.common.collect.Lists) CreateResponse(ddf.catalog.operation.CreateResponse) Metacard(ddf.catalog.data.Metacard) QueryRequest(ddf.catalog.operation.QueryRequest) SolrProviderTestUtil.create(ddf.catalog.source.solr.provider.SolrProviderTestUtil.create) ClassRule(org.junit.ClassRule) JettyConfig(org.apache.solr.client.solrj.embedded.JettyConfig) Awaitility.await(org.awaitility.Awaitility.await) QueryImpl(ddf.catalog.operation.impl.QueryImpl) AfterClass(org.junit.AfterClass) Logger(org.slf4j.Logger) Matchers(org.hamcrest.Matchers) Test(org.junit.Test) Collectors(java.util.stream.Collectors) MetacardType(ddf.catalog.data.MetacardType) TimeUnit(java.util.concurrent.TimeUnit) MockMetacard(ddf.catalog.source.solr.provider.MockMetacard) List(java.util.List) Rule(org.junit.Rule) TestCase.assertTrue(junit.framework.TestCase.assertTrue) Library(ddf.catalog.source.solr.provider.Library) Paths(java.nio.file.Paths) SolrCloudClientFactory(org.codice.solr.factory.impl.SolrCloudClientFactory) Optional(java.util.Optional) Filter(org.opengis.filter.Filter) SolrProviderTestUtil.getFilterBuilder(ddf.catalog.source.solr.provider.SolrProviderTestUtil.getFilterBuilder) Assert(org.junit.Assert) TemporaryFolder(org.junit.rules.TemporaryFolder) CreateResponse(ddf.catalog.operation.CreateResponse) MockMetacard(ddf.catalog.source.solr.provider.MockMetacard) Test(org.junit.Test)

Example 8 with MockMetacard

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);
}
Also used : QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) SolrProviderTestUtil.deleteAll(ddf.catalog.source.solr.provider.SolrProviderTestUtil.deleteAll) MetacardTypeImpl(ddf.catalog.data.impl.MetacardTypeImpl) BeforeClass(org.junit.BeforeClass) SolrClient(org.codice.solr.client.solrj.SolrClient) MiniSolrCloudCluster(org.apache.solr.cloud.MiniSolrCloudCluster) LoggerFactory(org.slf4j.LoggerFactory) SolrProviderTestUtil.queryAndVerifyCount(ddf.catalog.source.solr.provider.SolrProviderTestUtil.queryAndVerifyCount) ArrayList(java.util.ArrayList) BASIC_METACARD(ddf.catalog.data.impl.MetacardImpl.BASIC_METACARD) GeotoolsFilterAdapterImpl(ddf.catalog.filter.proxy.adapter.GeotoolsFilterAdapterImpl) Lists(com.google.common.collect.Lists) CreateResponse(ddf.catalog.operation.CreateResponse) Metacard(ddf.catalog.data.Metacard) QueryRequest(ddf.catalog.operation.QueryRequest) SolrProviderTestUtil.create(ddf.catalog.source.solr.provider.SolrProviderTestUtil.create) ClassRule(org.junit.ClassRule) JettyConfig(org.apache.solr.client.solrj.embedded.JettyConfig) Awaitility.await(org.awaitility.Awaitility.await) QueryImpl(ddf.catalog.operation.impl.QueryImpl) AfterClass(org.junit.AfterClass) Logger(org.slf4j.Logger) Matchers(org.hamcrest.Matchers) Test(org.junit.Test) Collectors(java.util.stream.Collectors) MetacardType(ddf.catalog.data.MetacardType) TimeUnit(java.util.concurrent.TimeUnit) MockMetacard(ddf.catalog.source.solr.provider.MockMetacard) List(java.util.List) Rule(org.junit.Rule) TestCase.assertTrue(junit.framework.TestCase.assertTrue) Library(ddf.catalog.source.solr.provider.Library) Paths(java.nio.file.Paths) SolrCloudClientFactory(org.codice.solr.factory.impl.SolrCloudClientFactory) Optional(java.util.Optional) Filter(org.opengis.filter.Filter) SolrProviderTestUtil.getFilterBuilder(ddf.catalog.source.solr.provider.SolrProviderTestUtil.getFilterBuilder) Assert(org.junit.Assert) TemporaryFolder(org.junit.rules.TemporaryFolder) Filter(org.opengis.filter.Filter) CreateResponse(ddf.catalog.operation.CreateResponse) MockMetacard(ddf.catalog.source.solr.provider.MockMetacard) Test(org.junit.Test)

Aggregations

MockMetacard (ddf.catalog.source.solr.provider.MockMetacard)8 Test (org.junit.Test)8 Metacard (ddf.catalog.data.Metacard)7 MetacardType (ddf.catalog.data.MetacardType)7 MetacardTypeImpl (ddf.catalog.data.impl.MetacardTypeImpl)7 CreateResponse (ddf.catalog.operation.CreateResponse)7 QueryRequest (ddf.catalog.operation.QueryRequest)7 QueryImpl (ddf.catalog.operation.impl.QueryImpl)7 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)7 ArrayList (java.util.ArrayList)7 Filter (org.opengis.filter.Filter)7 Lists (com.google.common.collect.Lists)6 BASIC_METACARD (ddf.catalog.data.impl.MetacardImpl.BASIC_METACARD)6 GeotoolsFilterAdapterImpl (ddf.catalog.filter.proxy.adapter.GeotoolsFilterAdapterImpl)6 Library (ddf.catalog.source.solr.provider.Library)6 SolrProviderTestUtil.create (ddf.catalog.source.solr.provider.SolrProviderTestUtil.create)6 SolrProviderTestUtil.deleteAll (ddf.catalog.source.solr.provider.SolrProviderTestUtil.deleteAll)6 SolrProviderTestUtil.getFilterBuilder (ddf.catalog.source.solr.provider.SolrProviderTestUtil.getFilterBuilder)6 SolrProviderTestUtil.queryAndVerifyCount (ddf.catalog.source.solr.provider.SolrProviderTestUtil.queryAndVerifyCount)6 Paths (java.nio.file.Paths)6