use of ddf.catalog.data.Metacard in project ddf by codice.
the class SolrProviderTest method testContextualXmlTagsNotIndexed.
@Test
public void testContextualXmlTagsNotIndexed() throws Exception {
deleteAllIn(provider);
create(Arrays.asList((Metacard) new MockMetacard(Library.getFlagstaffRecord())));
String xmlTag = "lastBuildDate";
queryAndVerifyCount(0, filterBuilder.attribute(Metacard.METADATA).is().like().text(xmlTag));
queryAndVerifyCount(0, filterBuilder.attribute(Metacard.METADATA).is().like().text(xmlTag + "*"));
}
use of ddf.catalog.data.Metacard in project ddf by codice.
the class SolrProviderTest method testNumericalOperations.
@Test()
public void testNumericalOperations() throws Exception {
deleteAllIn(provider);
/* SETUP */
String doubleField = "hertz";
double doubleFieldValue = 16065.435;
String floatField = "inches";
float floatFieldValue = 4.435f;
String intField = "count";
int intFieldValue = 4;
String longField = "milliseconds";
long longFieldValue = 9876543293L;
String shortField = "daysOfTheWeek";
short shortFieldValue = 1;
Set<AttributeDescriptor> descriptors = numericalDescriptors(doubleField, floatField, intField, longField, shortField);
MetacardTypeImpl mType = new MetacardTypeImpl("anotherCustom", descriptors);
MetacardImpl customMetacard1 = new MetacardImpl(mType);
customMetacard1.setAttribute(Metacard.ID, "");
customMetacard1.setAttribute(doubleField, doubleFieldValue);
customMetacard1.setAttribute(floatField, floatFieldValue);
customMetacard1.setAttribute(intField, intFieldValue);
customMetacard1.setAttribute(longField, longFieldValue);
customMetacard1.setAttribute(shortField, shortFieldValue);
MetacardImpl customMetacard2 = new MetacardImpl(mType);
customMetacard2.setAttribute(Metacard.ID, "");
customMetacard2.setAttribute(doubleField, doubleFieldValue + 10.0);
customMetacard2.setAttribute(floatField, (floatFieldValue + 10.0f));
customMetacard2.setAttribute(intField, intFieldValue + 1);
customMetacard2.setAttribute(longField, longFieldValue + 10L);
customMetacard2.setAttribute(shortField, (shortFieldValue + 1));
create(Arrays.asList((Metacard) customMetacard1, customMetacard2));
// on exact DOUBLE
greaterThanQueryAssertion(doubleField, doubleFieldValue, 1);
greaterThanOrEqualToQueryAssertion(doubleField, doubleFieldValue, 2);
// beyond the DOUBLE
greaterThanQueryAssertion(doubleField, doubleFieldValue - 0.00000001, 2);
greaterThanOrEqualToQueryAssertion(doubleField, doubleFieldValue - 0.00000001, 2);
greaterThanQueryAssertion(doubleField, doubleFieldValue + 12.0, 0);
greaterThanOrEqualToQueryAssertion(doubleField, doubleFieldValue + 12.0, 0);
// on exact FLOAT
greaterThanQueryAssertion(floatField, floatFieldValue, 1);
greaterThanOrEqualToQueryAssertion(floatField, floatFieldValue, 2);
// beyond the FLOAT
greaterThanQueryAssertion(floatField, floatFieldValue - 0.00001f, 2);
greaterThanOrEqualToQueryAssertion(floatField, floatFieldValue - 0.00001f, 2);
greaterThanQueryAssertion(floatField, floatFieldValue + 12.0f, 0);
greaterThanOrEqualToQueryAssertion(floatField, floatFieldValue + 12.0f, 0);
// on exact LONG
greaterThanQueryAssertion(longField, longFieldValue, 1);
greaterThanOrEqualToQueryAssertion(longField, longFieldValue, 2);
// beyond the LONG
greaterThanQueryAssertion(longField, longFieldValue - 1L, 2);
greaterThanOrEqualToQueryAssertion(longField, longFieldValue - 1L, 2);
greaterThanQueryAssertion(longField, longFieldValue + 12L, 0);
greaterThanOrEqualToQueryAssertion(longField, longFieldValue + 12L, 0);
// on exact INT
greaterThanQueryAssertion(intField, intFieldValue, 1);
greaterThanOrEqualToQueryAssertion(intField, intFieldValue, 2);
// beyond the INT
greaterThanQueryAssertion(intField, intFieldValue - 1, 2);
greaterThanOrEqualToQueryAssertion(intField, intFieldValue - 1, 2);
greaterThanQueryAssertion(intField, intFieldValue + 2, 0);
greaterThanOrEqualToQueryAssertion(intField, intFieldValue + 2, 0);
// on exact SHORT
greaterThanQueryAssertion(shortField, shortFieldValue, 1);
greaterThanOrEqualToQueryAssertion(shortField, shortFieldValue, 2);
// beyond the SHORT
greaterThanQueryAssertion(shortField, (short) (shortFieldValue - 1), 2);
greaterThanOrEqualToQueryAssertion(shortField, (short) (shortFieldValue - 1), 2);
greaterThanQueryAssertion(shortField, (short) (shortFieldValue + 2), 0);
greaterThanOrEqualToQueryAssertion(shortField, (short) (shortFieldValue + 2), 0);
}
use of ddf.catalog.data.Metacard in project ddf by codice.
the class SolrProviderTest method testGetContentTypesOneNoVersion.
@Test
public void testGetContentTypesOneNoVersion() throws Exception {
deleteAllIn(provider);
MockMetacard metacard1 = new MockMetacard(Library.getFlagstaffRecord());
metacard1.setContentTypeName(SAMPLE_CONTENT_TYPE_1);
metacard1.setContentTypeVersion(null);
List<Metacard> list = Arrays.asList((Metacard) metacard1);
create(list);
Set<ContentType> contentTypes = provider.getContentTypes();
assertEquals(1, contentTypes.size());
assertThat(contentTypes, hasItem((ContentType) new ContentTypeImpl(SAMPLE_CONTENT_TYPE_1, null)));
}
use of ddf.catalog.data.Metacard in project ddf by codice.
the class CatalogFrameworkImplTest method testCreateWithStores.
@Test
public void testCreateWithStores() throws Exception {
MockEventProcessor eventAdmin = new MockEventProcessor();
MockMemoryProvider provider = new MockMemoryProvider("Provider", "Provider", "v1.0", "DDF", new HashSet<>(), true, new Date());
Map<String, CatalogStore> storeMap = new HashMap<>();
MockCatalogStore store = new MockCatalogStore("catalogStoreId-1", true);
storeMap.put(store.getId(), store);
CatalogFramework framework = createDummyCatalogFramework(provider, storeMap, null, eventAdmin);
List<Metacard> metacards = new ArrayList<>();
MetacardImpl newCard = new MetacardImpl();
newCard.setId(null);
metacards.add(newCard);
Map<String, Serializable> reqProps = new HashMap<>();
HashSet<String> destinations = new HashSet<>();
//==== test writing to store and not local ====
destinations.add("catalogStoreId-1");
CreateResponse response = framework.create(new CreateRequestImpl(metacards, reqProps, destinations));
assertEquals(0, provider.size());
assertEquals(response.getCreatedMetacards().size(), store.size());
assertEquals(1, store.size());
assertFalse(eventAdmin.wasEventPosted());
//==== test writing to store and local ====
destinations.add("mockMemoryProvider");
newCard.setId(null);
reqProps = new HashMap<>();
response = framework.create(new CreateRequestImpl(metacards, reqProps, destinations));
assertEquals(1, provider.size());
assertEquals(response.getCreatedMetacards().size(), provider.size());
assertEquals(2, store.size());
assertTrue(eventAdmin.wasEventPosted());
//==== test writing to local when no destination ====
destinations.clear();
newCard.setId(null);
reqProps = new HashMap<>();
response = framework.create(new CreateRequestImpl(metacards, reqProps, destinations));
assertEquals(2, provider.size());
assertEquals(response.getCreatedMetacards().size(), 1);
assertEquals(2, store.size());
}
use of ddf.catalog.data.Metacard in project ddf by codice.
the class CatalogFrameworkImplTest method testUpdateStorage.
/**
* Tests that the framework properly passes an update request to the local provider.
*/
@Test
public void testUpdateStorage() throws Exception {
List<ContentItem> contentItems = new ArrayList<>();
MetacardImpl metacard = new MetacardImpl();
metacard.setId(null);
ByteSource byteSource = new ByteSource() {
@Override
public InputStream openStream() throws IOException {
return new ByteArrayInputStream("blah".getBytes());
}
};
ContentItemImpl contentItem = new ContentItemImpl(uuidGenerator.generateUuid(), byteSource, "application/octet-stream", "blah", 0L, metacard);
contentItems.add(contentItem);
CreateResponse response = framework.create(new CreateStorageRequestImpl(contentItems, null));
Metacard insertedCard = response.getCreatedMetacards().get(0);
List<ContentItem> updatedContentItems = new ArrayList<>();
updatedContentItems.add(new ContentItemImpl(insertedCard.getId(), byteSource, "application/octet-stream", insertedCard));
UpdateStorageRequest request = new UpdateStorageRequestImpl(updatedContentItems, null);
List<Result> mockFederationResults = Stream.of(insertedCard).map(m -> {
Result mockResult = mock(Result.class);
when(mockResult.getMetacard()).thenReturn(m);
return mockResult;
}).collect(Collectors.toList());
QueryResponseImpl queryResponse = new QueryResponseImpl(mock(QueryRequest.class), mockFederationResults, 1);
when(mockFederationStrategy.federate(anyList(), anyObject())).thenReturn(queryResponse);
// send update to framework
List<Update> returnedCards = framework.update(request).getUpdatedMetacards();
assertThat(returnedCards, hasSize(1));
final Metacard newMetacard = returnedCards.get(0).getNewMetacard();
assertThat(newMetacard.getId(), notNullValue());
assertThat(newMetacard.getResourceURI().toString(), is(contentItem.getUri()));
assertThat(newMetacard.getResourceSize(), is(Long.toString(byteSource.size())));
assertThat(response.getCreatedMetacards(), hasSize(storageProvider.size()));
// make sure that the event was posted correctly
assertThat(eventAdmin.wasEventPosted(), is(true));
}
Aggregations