use of ddf.catalog.data.MetacardType in project ddf by codice.
the class MetacardTypeImplTest method testSerializationNullDescriptors.
@Test
public void testSerializationNullDescriptors() throws IOException, ClassNotFoundException {
MetacardTypeImpl metacardType = new MetacardTypeImpl("basic", (Set<AttributeDescriptor>) null);
String fileLocation = "target/metacardType.ser";
Serializer<MetacardType> serializer = new Serializer<>();
serializer.serialize(metacardType, fileLocation);
MetacardType readMetacardType = serializer.deserialize(fileLocation);
assertThat(metacardType.getName(), is(readMetacardType.getName()));
Set<AttributeDescriptor> oldAd = metacardType.getAttributeDescriptors();
Set<AttributeDescriptor> newAd = readMetacardType.getAttributeDescriptors();
assertThat(oldAd.isEmpty(), is(true));
assertThat(newAd.isEmpty(), is(true));
}
use of ddf.catalog.data.MetacardType in project ddf by codice.
the class MetacardTypeImplTest method testAllTypes.
@Test
public void testAllTypes() {
List<MetacardType> metacardTypeList = new ArrayList<>();
metacardTypeList.add(DATE_TIME_ATTRIBUTES);
metacardTypeList.add(MEDIA_ATTRIBUTES);
metacardTypeList.add(LOCATION_ATTRIBUTES);
metacardTypeList.add(CONTACT_ATTRIBUTES);
metacardTypeList.add(TOPIC_ATTRIBUTES);
metacardTypeList.add(VERSION_ATTRIBUTES);
metacardTypeList.add(ASSOCIATIONS_ATTRIBUTES);
metacardTypeList.add(VALIDATION_ATTRIBUTES);
MetacardType metacardType = new MetacardTypeImpl(TEST_NAME, metacardTypeList);
assertMetacardAttributes(metacardType, CORE_ATTRIBUTES.getAttributeDescriptors());
assertMetacardAttributes(metacardType, DATE_TIME_ATTRIBUTES.getAttributeDescriptors());
assertMetacardAttributes(metacardType, MEDIA_ATTRIBUTES.getAttributeDescriptors());
assertMetacardAttributes(metacardType, LOCATION_ATTRIBUTES.getAttributeDescriptors());
assertMetacardAttributes(metacardType, CONTACT_ATTRIBUTES.getAttributeDescriptors());
assertMetacardAttributes(metacardType, TOPIC_ATTRIBUTES.getAttributeDescriptors());
assertMetacardAttributes(metacardType, VERSION_ATTRIBUTES.getAttributeDescriptors());
assertMetacardAttributes(metacardType, ASSOCIATIONS_ATTRIBUTES.getAttributeDescriptors());
assertMetacardAttributes(metacardType, VALIDATION_ATTRIBUTES.getAttributeDescriptors());
}
use of ddf.catalog.data.MetacardType in project ddf by codice.
the class QualifiedMetacardTypeTest method testDefaultNamespaceNotEqual.
@Test
public void testDefaultNamespaceNotEqual() {
MetacardType mt1 = new MetacardTypeImpl(QUALIFIED_METACARD_TYPE_NAME_3, qmtAttributes);
QualifiedMetacardTypeImpl qmt1 = new QualifiedMetacardTypeImpl(QUALIFIED_METACARD_TYPE_NAMESPACE_2, mt1);
MetacardType mt2 = new MetacardTypeImpl(QUALIFIED_METACARD_TYPE_NAME_3, qmtAttributes);
QualifiedMetacardTypeImpl qmt2 = new QualifiedMetacardTypeImpl(null, mt2);
assertTrue(!qmt1.equals(qmt2));
assertTrue(!qmt2.equals(qmt1));
assertTrue(qmt1.hashCode() != qmt2.hashCode());
}
use of ddf.catalog.data.MetacardType in project ddf by codice.
the class CatalogFrameworkImplTest method testCreateStorageWithAttributeOverridesInvalidType.
/**
* Tests that the framework properly passes a create request to the local provider with attribute overrides.
*/
@Test
public void testCreateStorageWithAttributeOverridesInvalidType() throws Exception {
List<ContentItem> contentItems = new ArrayList<>();
Map<String, Serializable> propertiesMap = new HashMap<>();
HashMap<String, Object> attributeMap = new HashMap<>();
attributeMap.put(Metacard.CREATED, "bad date");
propertiesMap.put(Constants.ATTRIBUTE_OVERRIDES_KEY, attributeMap);
MetacardImpl newCard = new MetacardImpl();
newCard.setId(null);
MetacardType metacardType = mock(MetacardType.class);
AttributeDescriptor dateAttributeDescriptor = new AttributeDescriptorImpl(Metacard.CREATED, true, true, true, true, new AttributeType<Date>() {
private static final long serialVersionUID = 1L;
@Override
public Class<Date> getBinding() {
return Date.class;
}
@Override
public AttributeFormat getAttributeFormat() {
return AttributeFormat.DATE;
}
});
when(metacardType.getAttributeDescriptor(Metacard.TITLE)).thenReturn(dateAttributeDescriptor);
newCard.setType(metacardType);
ByteSource byteSource = new ByteSource() {
@Override
public InputStream openStream() throws IOException {
return new ByteArrayInputStream("blah".getBytes());
}
};
ContentItemImpl newItem = new ContentItemImpl(uuidGenerator.generateUuid(), byteSource, "application/octet-stream", "blah", 0L, newCard);
contentItems.add(newItem);
CreateResponse response = framework.create(new CreateStorageRequestImpl(contentItems, propertiesMap));
assertEquals(response.getCreatedMetacards().size(), provider.size());
assertEquals(response.getCreatedMetacards().size(), storageProvider.size());
for (Metacard curCard : response.getCreatedMetacards()) {
assertNotNull(curCard.getId());
// Assert value is not set for invalid format
assertThat(curCard.getCreatedDate(), nullValue());
}
}
use of ddf.catalog.data.MetacardType in project ddf by codice.
the class CatalogFrameworkImplTest method stubMetacardInjection.
/****************************
* utility methods
******************************/
private void stubMetacardInjection(AttributeDescriptor... injectedAttributes) {
doAnswer(invocationOnMock -> {
Metacard original = (Metacard) invocationOnMock.getArguments()[0];
MetacardType originalMetacardType = original.getMetacardType();
MetacardType newMetacardType = new MetacardTypeImpl(originalMetacardType.getName(), originalMetacardType, Sets.newHashSet(injectedAttributes));
MetacardImpl newMetacard = new MetacardImpl(original);
newMetacard.setType(newMetacardType);
newMetacard.setSourceId(original.getSourceId());
return newMetacard;
}).when(attributeInjector).injectAttributes(any(Metacard.class));
}
Aggregations