Search in sources :

Example 51 with CreateResponse

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);
}
Also used : Metacard(ddf.catalog.data.Metacard) MockMetacard(ddf.catalog.source.solr.provider.MockMetacard) Filter(org.opengis.filter.Filter) CreateResponse(ddf.catalog.operation.CreateResponse) ArrayList(java.util.ArrayList) MockMetacard(ddf.catalog.source.solr.provider.MockMetacard) Test(org.junit.Test)

Example 52 with CreateResponse

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);
}
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 53 with CreateResponse

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);
}
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 54 with CreateResponse

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));
}
Also used : NamedList(org.apache.solr.common.util.NamedList) CreateResponse(ddf.catalog.operation.CreateResponse) CreateRequest(ddf.catalog.operation.CreateRequest) SolrDocumentList(org.apache.solr.common.SolrDocumentList) Security(org.codice.ddf.security.Security) Subject(ddf.security.Subject) SolrQuery(org.apache.solr.client.solrj.SolrQuery) Callable(java.util.concurrent.Callable) SolrDocument(org.apache.solr.common.SolrDocument) SolrClient(org.codice.solr.client.solrj.SolrClient) SolrMetacardClientImpl(ddf.catalog.source.solr.SolrMetacardClientImpl) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) CatalogFramework(ddf.catalog.CatalogFramework) Test(org.junit.Test)

Example 55 with CreateResponse

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());
}
Also used : UpdateResponse(ddf.catalog.operation.UpdateResponse) QueryImpl(ddf.catalog.operation.impl.QueryImpl) SourceResponse(ddf.catalog.operation.SourceResponse) Filter(org.opengis.filter.Filter) CreateResponse(ddf.catalog.operation.CreateResponse) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) SolrProviderTest(ddf.catalog.source.solr.SolrProviderTest) Test(org.junit.Test)

Aggregations

CreateResponse (ddf.catalog.operation.CreateResponse)111 Test (org.junit.Test)82 Metacard (ddf.catalog.data.Metacard)76 CreateRequestImpl (ddf.catalog.operation.impl.CreateRequestImpl)44 ArrayList (java.util.ArrayList)42 CreateRequest (ddf.catalog.operation.CreateRequest)36 QueryImpl (ddf.catalog.operation.impl.QueryImpl)29 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)29 CreateResponseImpl (ddf.catalog.operation.impl.CreateResponseImpl)27 HashMap (java.util.HashMap)25 Serializable (java.io.Serializable)23 List (java.util.List)23 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)22 DeleteResponse (ddf.catalog.operation.DeleteResponse)22 UpdateResponse (ddf.catalog.operation.UpdateResponse)21 Filter (org.opengis.filter.Filter)21 IngestException (ddf.catalog.source.IngestException)20 SourceResponse (ddf.catalog.operation.SourceResponse)18 QueryRequest (ddf.catalog.operation.QueryRequest)17 MetacardType (ddf.catalog.data.MetacardType)16