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"));
}
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);
}
}
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));
}
}
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));
}
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));
}
Aggregations