Search in sources :

Example 61 with CreateResponse

use of ddf.catalog.operation.CreateResponse in project ddf by codice.

the class SolrProviderTest method testCreateOperationWithSourceId.

@Test
public void testCreateOperationWithSourceId() throws IngestException, UnsupportedQueryException {
    deleteAllIn(provider);
    MockMetacard metacard = new MockMetacard(Library.getFlagstaffRecord());
    String id = UUID.randomUUID().toString();
    metacard.setId(id);
    metacard.setSourceId("ddfChild");
    Date oneDayAgo = new DateTime().minusDays(1).toDate();
    metacard.setCreatedDate(oneDayAgo);
    metacard.setExpirationDate(oneDayAgo);
    metacard.setEffectiveDate(oneDayAgo);
    metacard.setModifiedDate(oneDayAgo);
    CreateResponse createResponse = create(metacard);
    Metacard createdMetacard = createResponse.getCreatedMetacards().get(0);
    assertNotNull(createdMetacard.getId());
    assertEquals(MockMetacard.DEFAULT_TITLE, createdMetacard.getTitle());
    assertEquals(MockMetacard.DEFAULT_LOCATION, createdMetacard.getLocation());
    assertEquals(MockMetacard.DEFAULT_TYPE, createdMetacard.getContentTypeName());
    assertEquals(MockMetacard.DEFAULT_VERSION, createdMetacard.getContentTypeVersion());
    assertNotNull(createdMetacard.getMetadata());
    assertThat(createdMetacard.getMetadata(), containsString("<title>Flagstaff Chamber of Commerce</title>"));
    assertThat(createdMetacard.getMetadata().isEmpty(), is(not(true)));
    assertThat(createdMetacard.getCreatedDate(), is(oneDayAgo));
    assertThat(createdMetacard.getModifiedDate(), is(oneDayAgo));
    assertThat(createdMetacard.getEffectiveDate(), is(oneDayAgo));
    assertThat(createdMetacard.getExpirationDate(), is(oneDayAgo));
    assertTrue(Arrays.equals(metacard.getThumbnail(), createdMetacard.getThumbnail()));
    assertEquals(metacard.getLocation(), createdMetacard.getLocation());
    assertThat(createdMetacard.getSourceId(), is(metacard.getSourceId()));
    // --------------------
    FilterFactory filterFactory = new FilterFactoryImpl();
    // SIMPLE TITLE SEARCH
    Filter filter = filterFactory.like(filterFactory.property(Metacard.TITLE), MockMetacard.DEFAULT_TITLE, DEFAULT_TEST_WILDCARD, DEFAULT_TEST_SINGLE_WILDCARD, DEFAULT_TEST_ESCAPE, false);
    QueryImpl query = new QueryImpl(filter);
    query.setStartIndex(1);
    SourceResponse sourceResponse = provider.query(new QueryRequestImpl(query));
    List<Result> results = sourceResponse.getResults();
    Metacard mResult = results.get(0).getMetacard();
    assertEquals(1, results.size());
    assertNotNull(mResult.getId());
    assertEquals(MockMetacard.DEFAULT_TITLE, mResult.getTitle());
    assertEquals(MockMetacard.DEFAULT_LOCATION, mResult.getLocation());
    assertEquals(MockMetacard.DEFAULT_TYPE, mResult.getContentTypeName());
    assertEquals(MockMetacard.DEFAULT_VERSION, mResult.getContentTypeVersion());
    assertNotNull(mResult.getMetadata());
    assertThat(mResult.getMetadata(), containsString("<title>Flagstaff Chamber of Commerce</title>"));
    assertThat(mResult.getMetadata().isEmpty(), is(not(true)));
    assertThat(mResult.getCreatedDate(), is(oneDayAgo));
    assertThat(mResult.getModifiedDate(), is(oneDayAgo));
    assertThat(mResult.getEffectiveDate(), is(oneDayAgo));
    assertThat(mResult.getExpirationDate(), is(oneDayAgo));
    assertTrue(Arrays.equals(metacard.getThumbnail(), mResult.getThumbnail()));
    assertEquals(metacard.getLocation(), mResult.getLocation());
// assertThat(mResult.getSourceId(), is("ddf"));
}
Also used : SourceResponse(ddf.catalog.operation.SourceResponse) CreateResponse(ddf.catalog.operation.CreateResponse) Matchers.containsString(org.hamcrest.Matchers.containsString) Date(java.util.Date) DateTime(org.joda.time.DateTime) FilterFactory(org.opengis.filter.FilterFactory) Result(ddf.catalog.data.Result) Metacard(ddf.catalog.data.Metacard) QueryImpl(ddf.catalog.operation.impl.QueryImpl) Filter(org.opengis.filter.Filter) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) FilterFactoryImpl(org.geotools.filter.FilterFactoryImpl) Test(org.junit.Test)

Example 62 with CreateResponse

use of ddf.catalog.operation.CreateResponse in project ddf by codice.

the class SolrProviderTest method testCreatePendingNrtIndex.

@Test
public void testCreatePendingNrtIndex() throws Exception {
    deleteAllIn(provider);
    ConfigurationStore.getInstance().setForceAutoCommit(false);
    try {
        MockMetacard metacard = new MockMetacard(Library.getFlagstaffRecord());
        CreateResponse response = create(metacard);
        String createdId = response.getCreatedMetacards().get(0).getId();
        Filter titleFilter = filterBuilder.attribute(Metacard.TITLE).like().text(MockMetacard.DEFAULT_TITLE);
        Filter idFilter = filterBuilder.attribute(Metacard.ID).equalTo().text(createdId);
        SourceResponse titleResponse = provider.query(new QueryRequestImpl(new QueryImpl(titleFilter)));
        SourceResponse idResponse = provider.query(new QueryRequestImpl(new QueryImpl(idFilter)));
        assertThat(titleResponse.getResults().size(), is(0));
        assertThat(idResponse.getResults().size(), is(1));
    } finally {
        ConfigurationStore.getInstance().setForceAutoCommit(true);
    }
}
Also used : 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) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 63 with CreateResponse

use of ddf.catalog.operation.CreateResponse in project ddf by codice.

the class SolrProviderTest method addAndDeleteMetacards.

private void addAndDeleteMetacards(int metacardCount) throws IngestException, UnsupportedQueryException {
    deleteAllIn(provider);
    List<Metacard> metacards = new ArrayList<Metacard>();
    for (int i = 0; i < metacardCount; i++) {
        metacards.add(new MockMetacard(Library.getFlagstaffRecord()));
    }
    CreateResponse createResponse = create(metacards);
    assertThat(createResponse.getCreatedMetacards().size(), is(metacards.size()));
    List<String> ids = new ArrayList<String>();
    for (Metacard mc : createResponse.getCreatedMetacards()) {
        ids.add(mc.getId());
    }
    DeleteResponse deleteResponse = delete(ids.toArray(new String[metacardCount]));
    List<Metacard> deletedMetacards = deleteResponse.getDeletedMetacards();
    assertThat(deletedMetacards.size(), is(metacards.size()));
    for (int i = 0; i < metacardCount; i++) {
        assertThat(deletedMetacards.get(i).getId(), isIn(ids));
    }
}
Also used : Metacard(ddf.catalog.data.Metacard) DeleteResponse(ddf.catalog.operation.DeleteResponse) CreateResponse(ddf.catalog.operation.CreateResponse) ArrayList(java.util.ArrayList) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 64 with CreateResponse

use of ddf.catalog.operation.CreateResponse in project ddf by codice.

the class TestRegistryStore method testCreateWithExistingMetacard.

@Test
public void testCreateWithExistingMetacard() throws Exception {
    Metacard mcard = getDefaultMetacard();
    queryResults.add(new ResultImpl(mcard));
    CreateRequest request = new CreateRequestImpl(mcard);
    CreateResponse response = registryStore.create(request);
    assertThat(response.getCreatedMetacards().get(0), is(mcard));
}
Also used : Metacard(ddf.catalog.data.Metacard) CreateRequest(ddf.catalog.operation.CreateRequest) CreateResponse(ddf.catalog.operation.CreateResponse) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) ResultImpl(ddf.catalog.data.impl.ResultImpl) Test(org.junit.Test)

Example 65 with CreateResponse

use of ddf.catalog.operation.CreateResponse in project ddf by codice.

the class FederationAdminServiceImplTest method testAddRegistryEntryString.

@Test
public void testAddRegistryEntryString() throws Exception {
    Metacard metacard = testMetacard;
    metacard.setAttribute(new AttributeImpl(Metacard.TAGS, Collections.singletonList(RegistryConstants.REGISTRY_TAG)));
    Metacard createdMetacard = testMetacard;
    Subject systemSubject = security.getSystemSubject();
    Map<String, Serializable> properties = new HashMap<>();
    properties.put(SecurityConstants.SECURITY_SUBJECT, systemSubject);
    CreateRequest request = new CreateRequestImpl(Collections.singletonList(metacard), properties, null);
    CreateResponse response = new CreateResponseImpl(request, null, Collections.singletonList(createdMetacard));
    when(registryTransformer.transform(any(InputStream.class))).thenReturn(metacard);
    when(catalogFramework.create(any(CreateRequest.class))).thenReturn(response);
    String createdMetacardId = federationAdminServiceImpl.addRegistryEntry(TEST_XML_STRING);
    assertThat(createdMetacardId, is(equalTo(RegistryObjectMetacardType.REGISTRY_ID)));
    verify(registryTransformer).transform(any(InputStream.class));
    verify(catalogFramework).create(any(CreateRequest.class));
}
Also used : Metacard(ddf.catalog.data.Metacard) Serializable(java.io.Serializable) HashMap(java.util.HashMap) CreateRequest(ddf.catalog.operation.CreateRequest) CreateResponse(ddf.catalog.operation.CreateResponse) InputStream(java.io.InputStream) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) Subject(ddf.security.Subject) CreateResponseImpl(ddf.catalog.operation.impl.CreateResponseImpl) 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