use of ddf.catalog.data.Metacard 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.Metacard 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.Metacard in project ddf by codice.
the class MetacardImplTest method testMetacardAttributes.
/**
* make sure type conversion works in MetacardImpl
*/
@Test
public void testMetacardAttributes() {
Metacard metacard = new MetacardImpl();
Date now = new Date();
metacard.setAttribute(new AttributeImpl(Metacard.EFFECTIVE, now));
assertEquals(now, metacard.getEffectiveDate());
}
use of ddf.catalog.data.Metacard in project ddf by codice.
the class MetacardImplTest method testSerializingEmptyWrappedMetacardType.
@Test
public void testSerializingEmptyWrappedMetacardType() throws IOException, ClassNotFoundException {
MetacardImpl metacard = new MetacardImpl(new MetacardImpl(new EmptyMetacardType()));
Serializer<Metacard> serializer = new Serializer<Metacard>();
serializer.serialize(metacard, DEFAULT_SERIALIZATION_FILE_LOCATION);
Metacard readMetacard = serializer.deserialize(DEFAULT_SERIALIZATION_FILE_LOCATION);
MetacardType metacardType = metacard.getMetacardType();
MetacardType readMetacardType = readMetacard.getMetacardType();
assertNotNull(readMetacardType);
assertTrue(readMetacardType.getName() == null);
assertTrue(readMetacardType.getAttributeDescriptor(null) == null);
assertTrue(readMetacardType.getAttributeDescriptors().isEmpty());
assertEquals(metacardType.getName(), readMetacardType.getName());
assertEquals(metacardType.getAttributeDescriptor(null), readMetacardType.getAttributeDescriptor(null));
}
use of ddf.catalog.data.Metacard in project ddf by codice.
the class MockMemoryProvider method update.
@Override
public UpdateResponse update(UpdateRequest request) {
String methodName = "update";
LOGGER.debug("Entering: {}", methodName);
hasReceivedUpdate = true;
hasReceivedUpdateByIdentifier = true;
List<Entry<Serializable, Metacard>> updatedCards = request.getUpdates();
Map<String, Serializable> properties = new HashMap<>();
List<Update> returnedMetacards = new ArrayList<>(updatedCards.size());
for (Entry<Serializable, Metacard> curCard : updatedCards) {
if (store.containsKey(curCard.getValue().getId())) {
LOGGER.debug("Store contains the key");
Metacard oldMetacard = store.get(curCard.getValue().getId());
store.put(curCard.getValue().getId(), curCard.getValue());
properties.put(curCard.getValue().getId(), curCard.getValue());
LOGGER.debug("adding returnedMetacard");
returnedMetacards.add(new UpdateImpl(curCard.getValue(), oldMetacard));
} else {
LOGGER.debug("Key not contained in the store");
}
}
UpdateResponse response = new UpdateResponseImpl(request, properties, returnedMetacards);
LOGGER.debug("Exiting:{}", methodName);
return response;
}
Aggregations