use of ddf.catalog.data.AttributeDescriptor in project ddf by codice.
the class MetacardImplTest method testSerializationSingle.
@Test
public void testSerializationSingle() throws IOException, ClassNotFoundException, URISyntaxException {
MetacardImpl metacard = new MetacardImpl();
Date now = new Date();
metacard.setTitle("Flagstaff");
metacard.setContentTypeName("nitf");
metacard.setContentTypeVersion("DDF_20");
metacard.setLocation("POINT (1 0)");
metacard.setMetadata("<something/>");
metacard.setCreatedDate(now);
metacard.setResourceURI(new URI("http://ddf.com"));
byte[] buffer = { -86 };
metacard.setThumbnail(buffer);
metacard.setSourceId("mySourceId");
metacard.setDescription("Northern Arizona City");
metacard.setPointOfContact("poc");
Serializer<Metacard> serializer = new Serializer<Metacard>();
/* WRITE */
serializer.serialize(metacard, DEFAULT_SERIALIZATION_FILE_LOCATION);
/* READ */
Metacard readMetacard = serializer.deserialize(DEFAULT_SERIALIZATION_FILE_LOCATION);
assertEquals(metacard.getTitle(), readMetacard.getTitle());
assertEquals(metacard.getContentTypeName(), readMetacard.getContentTypeName());
assertEquals(metacard.getContentTypeVersion(), readMetacard.getContentTypeVersion());
assertEquals(metacard.getLocation(), readMetacard.getLocation());
assertEquals(metacard.getMetadata(), readMetacard.getMetadata());
assertEquals(metacard.getCreatedDate(), readMetacard.getCreatedDate());
assertEquals(metacard.getExpirationDate(), readMetacard.getExpirationDate());
assertEquals(metacard.getResourceURI(), readMetacard.getResourceURI());
assertEquals(metacard.getResourceSize(), readMetacard.getResourceSize());
assertTrue(Arrays.equals(metacard.getThumbnail(), readMetacard.getThumbnail()));
assertEquals(metacard.getSourceId(), readMetacard.getSourceId());
assertEquals(metacard.getDescription(), readMetacard.getAttribute("description").getValue());
assertEquals(metacard.getPointOfContact(), readMetacard.getAttribute("point-of-contact").getValue());
MetacardType metacardType = metacard.getMetacardType();
MetacardType readMetacardType = readMetacard.getMetacardType();
assertEquals(metacardType.getName(), readMetacardType.getName());
Set<AttributeDescriptor> oldAd = metacardType.getAttributeDescriptors();
Set<AttributeDescriptor> newAd = readMetacardType.getAttributeDescriptors();
assertEquals(oldAd.size(), newAd.size());
for (int i = 0; i < oldAd.size(); i++) {
AttributeDescriptor oldDescriptor = oldAd.iterator().next();
boolean match = false;
for (AttributeDescriptor newDescriptor : newAd) {
if (oldDescriptor.equals(newDescriptor)) {
match = true;
break;
}
}
assertTrue(match);
}
}
use of ddf.catalog.data.AttributeDescriptor in project ddf by codice.
the class MetacardTypeImplTest method testSerializationSingle.
@Test
public void testSerializationSingle() throws IOException, ClassNotFoundException {
HashSet<AttributeDescriptor> descriptors = new HashSet<>();
descriptors.add(new AttributeDescriptorImpl(ID, true, true, false, false, BasicTypes.STRING_TYPE));
MetacardTypeImpl metacardType = new MetacardTypeImpl("basic", descriptors);
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()));
assertThat(metacardType.getAttributeDescriptor(ID).getName(), is(readMetacardType.getAttributeDescriptor(ID).getName()));
assertEquals(metacardType.getAttributeDescriptor(ID).getType().getBinding(), readMetacardType.getAttributeDescriptor(ID).getType().getBinding());
assertThat(metacardType.getAttributeDescriptor(ID).getType().getAttributeFormat(), is(readMetacardType.getAttributeDescriptor(ID).getType().getAttributeFormat()));
Set<AttributeDescriptor> oldAd = metacardType.getAttributeDescriptors();
Set<AttributeDescriptor> newAd = readMetacardType.getAttributeDescriptors();
assertThat(oldAd.iterator().next(), is(newAd.iterator().next()));
}
use of ddf.catalog.data.AttributeDescriptor in project ddf by codice.
the class MetacardImplTest method testSerializationSingleWrapped.
@Test
public void testSerializationSingleWrapped() throws IOException, ClassNotFoundException, URISyntaxException {
MetacardImpl innerMetacard = new MetacardImpl();
Date now = new Date();
innerMetacard.setTitle("Flagstaff");
innerMetacard.setContentTypeName("nitf");
innerMetacard.setContentTypeVersion("DDF_20");
innerMetacard.setLocation("POINT (1 0)");
innerMetacard.setMetadata("<something/>");
innerMetacard.setCreatedDate(now);
innerMetacard.setResourceURI(new URI("http://ddf.com"));
byte[] buffer = { -86 };
innerMetacard.setThumbnail(buffer);
innerMetacard.setDescription("Northern Arizona City");
innerMetacard.setPointOfContact("poc");
Metacard metacard = new MetacardImpl(innerMetacard);
Serializer<Metacard> serializer = new Serializer<Metacard>();
serializer.serialize(metacard, DEFAULT_SERIALIZATION_FILE_LOCATION);
Metacard readMetacard = serializer.deserialize(DEFAULT_SERIALIZATION_FILE_LOCATION);
assertEquals(metacard.getTitle(), readMetacard.getTitle());
assertEquals(metacard.getContentTypeName(), readMetacard.getContentTypeName());
assertEquals(metacard.getContentTypeVersion(), readMetacard.getContentTypeVersion());
assertEquals(metacard.getLocation(), readMetacard.getLocation());
assertEquals(metacard.getMetadata(), readMetacard.getMetadata());
assertEquals(metacard.getCreatedDate(), readMetacard.getCreatedDate());
assertEquals(metacard.getExpirationDate(), readMetacard.getExpirationDate());
assertEquals(metacard.getResourceURI(), readMetacard.getResourceURI());
assertEquals(metacard.getResourceSize(), readMetacard.getResourceSize());
assertEquals(metacard.getAttribute("description").getValue(), readMetacard.getAttribute("description").getValue());
assertEquals(metacard.getAttribute("point-of-contact").getValue(), readMetacard.getAttribute("point-of-contact").getValue());
assertTrue(Arrays.equals(metacard.getThumbnail(), readMetacard.getThumbnail()));
MetacardType metacardType = metacard.getMetacardType();
MetacardType readMetacardType = readMetacard.getMetacardType();
assertEquals(metacardType.getName(), readMetacardType.getName());
Set<AttributeDescriptor> oldAd = metacardType.getAttributeDescriptors();
Set<AttributeDescriptor> newAd = readMetacardType.getAttributeDescriptors();
assertEquals(oldAd.size(), newAd.size());
assertEquals(oldAd.size(), newAd.size());
for (int i = 0; i < oldAd.size(); i++) {
AttributeDescriptor oldDescriptor = oldAd.iterator().next();
boolean match = false;
for (AttributeDescriptor newDescriptor : newAd) {
if (oldDescriptor.equals(newDescriptor)) {
match = true;
break;
}
}
assertTrue(match);
}
}
use of ddf.catalog.data.AttributeDescriptor in project ddf by codice.
the class MetacardImplTest method testUpdatingWrappedMetacardFields.
@Test
public void testUpdatingWrappedMetacardFields() {
HashSet<AttributeDescriptor> descriptors = new HashSet<AttributeDescriptor>();
descriptors.add(new AttributeDescriptorImpl("test-string", true, /* indexed */
true, /* stored */
false, /* tokenized */
false, /* multivalued */
BasicTypes.STRING_TYPE));
MetacardType testType = new MetacardTypeImpl("test.type", descriptors);
MetacardImpl mi = new MetacardImpl(mc);
mi.setSourceId("testSource");
mi.setType(testType);
assertEquals("testSource", mi.getSourceId());
assertEquals(testType, mi.getMetacardType());
}
use of ddf.catalog.data.AttributeDescriptor in project ddf by codice.
the class MetacardTypeImplTest method compareExtendedMetacardTypeToEquivalentMetacardType.
private void compareExtendedMetacardTypeToEquivalentMetacardType(BiConsumer<MetacardType, MetacardType> assertions) {
final Set<AttributeDescriptor> originalDescriptors = new HashSet<>(BASIC_METACARD.getAttributeDescriptors());
final MetacardType baseMetacardType = new MetacardTypeImpl("base", originalDescriptors);
final Set<AttributeDescriptor> additionalDescriptors = new HashSet<>();
additionalDescriptors.add(new AttributeDescriptorImpl("foo", true, false, true, false, BasicTypes.BOOLEAN_TYPE));
additionalDescriptors.add(new AttributeDescriptorImpl("bar", false, true, false, true, BasicTypes.STRING_TYPE));
final MetacardType extendedMetacardType = new MetacardTypeImpl("type", baseMetacardType, additionalDescriptors);
final Set<AttributeDescriptor> combinedDescriptors = new HashSet<>(originalDescriptors);
combinedDescriptors.addAll(additionalDescriptors);
final MetacardType equivalentMetacardType = new MetacardTypeImpl("type", combinedDescriptors);
assertions.accept(extendedMetacardType, equivalentMetacardType);
}
Aggregations