use of ddf.catalog.data.impl.MetacardImpl 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.impl.MetacardImpl 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.impl.MetacardImpl 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));
}
use of ddf.catalog.data.impl.MetacardImpl in project ddf by codice.
the class CatalogFrameworkImplTest method testInjectsAttributesOnDelete.
@Test
public void testInjectsAttributesOnDelete() throws Exception {
final String title = "Delete this";
final String injectAttributeName = "new attribute";
final double injectAttributeValue = 11.1;
final MetacardImpl metacard = new MetacardImpl();
metacard.setTitle(title);
metacard.setAttribute(injectAttributeName, injectAttributeValue);
final String id = framework.create(new CreateRequestImpl(Collections.singletonList(metacard), null)).getCreatedMetacards().get(0).getId();
final DeleteRequest request = new DeleteRequestImpl(id);
final AttributeDescriptor injectAttribute = new AttributeDescriptorImpl(injectAttributeName, true, true, false, false, BasicTypes.DOUBLE_TYPE);
stubMetacardInjection(injectAttribute);
List<Result> mockFederationResults = Stream.of(metacard).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);
when(mockRemoteDeleteOperations.performRemoteDelete(any(), any())).then(returnsSecondArg());
deleteOperations.setRemoteDeleteOperations(mockRemoteDeleteOperations);
final DeleteResponse response = framework.delete(request);
final Metacard deletedMetacard = response.getDeletedMetacards().get(0);
final MetacardType originalMetacardType = metacard.getMetacardType();
final MetacardType deletedMetacardType = deletedMetacard.getMetacardType();
assertThat(deletedMetacardType.getName(), is(originalMetacardType.getName()));
final Set<AttributeDescriptor> expectedAttributeDescriptors = new HashSet<>(originalMetacardType.getAttributeDescriptors());
expectedAttributeDescriptors.add(injectAttribute);
assertThat(deletedMetacardType.getAttributeDescriptors(), is(expectedAttributeDescriptors));
assertThat(deletedMetacard.getTitle(), is(title));
assertThat(deletedMetacard.getAttribute(injectAttributeName).getValue(), is(injectAttributeValue));
}
use of ddf.catalog.data.impl.MetacardImpl in project ddf by codice.
the class CatalogFrameworkImplTest method testDeleteWithStores.
// TODO (DDF-2436) -
@Ignore
@Test
public void testDeleteWithStores() 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<>();
Map<String, FederatedSource> sourceMap = new HashMap<>();
MockCatalogStore store = new MockCatalogStore("catalogStoreId-1", true);
storeMap.put(store.getId(), store);
sourceMap.put(store.getId(), store);
CatalogFramework framework = createDummyCatalogFramework(provider, storeMap, sourceMap, eventAdmin);
FilterFactory filterFactory = new FilterFactoryImpl();
Filter filter = filterFactory.like(filterFactory.property(Metacard.METADATA), "*", "*", "?", "/", false);
List<Metacard> metacards = new ArrayList<>();
String id = UUID.randomUUID().toString().replaceAll("-", "");
MetacardImpl newCard = new MetacardImpl();
newCard.setId(id);
newCard.setAttribute("myKey", "myValue1");
metacards.add(newCard);
Map<String, Serializable> reqProps = new HashMap<>();
HashSet<String> destinations = new HashSet<>();
destinations.add("mockMemoryProvider");
destinations.add("catalogStoreId-1");
framework.create(new CreateRequestImpl(metacards, reqProps, destinations));
DeleteRequest deleteRequest = new DeleteRequestImpl(Collections.singletonList(id), Metacard.ID, new HashMap<>(), destinations);
DeleteResponse response = framework.delete(deleteRequest);
assertThat(response.getDeletedMetacards().size(), is(1));
QueryResponse queryResponse = framework.query(new QueryRequestImpl(new QueryImpl(filter), true));
assertThat(queryResponse.getResults().size(), is(0));
}
Aggregations