Search in sources :

Example 6 with Metacard

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);
    }
}
Also used : Metacard(ddf.catalog.data.Metacard) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) URI(java.net.URI) Date(java.util.Date) MetacardType(ddf.catalog.data.MetacardType) Test(org.junit.Test)

Example 7 with Metacard

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);
    }
}
Also used : Metacard(ddf.catalog.data.Metacard) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) URI(java.net.URI) Date(java.util.Date) MetacardType(ddf.catalog.data.MetacardType) Test(org.junit.Test)

Example 8 with Metacard

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());
}
Also used : Metacard(ddf.catalog.data.Metacard) Date(java.util.Date) Test(org.junit.Test)

Example 9 with Metacard

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));
}
Also used : Metacard(ddf.catalog.data.Metacard) MetacardType(ddf.catalog.data.MetacardType) Test(org.junit.Test)

Example 10 with Metacard

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;
}
Also used : UpdateImpl(ddf.catalog.operation.impl.UpdateImpl) Serializable(java.io.Serializable) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Update(ddf.catalog.operation.Update) UpdateResponse(ddf.catalog.operation.UpdateResponse) Entry(java.util.Map.Entry) Metacard(ddf.catalog.data.Metacard) UpdateResponseImpl(ddf.catalog.operation.impl.UpdateResponseImpl)

Aggregations

Metacard (ddf.catalog.data.Metacard)746 Test (org.junit.Test)470 ArrayList (java.util.ArrayList)206 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)149 InputStream (java.io.InputStream)136 HashMap (java.util.HashMap)129 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)115 Result (ddf.catalog.data.Result)109 Serializable (java.io.Serializable)100 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)90 QueryRequest (ddf.catalog.operation.QueryRequest)84 QueryImpl (ddf.catalog.operation.impl.QueryImpl)80 QueryResponse (ddf.catalog.operation.QueryResponse)78 SourceResponse (ddf.catalog.operation.SourceResponse)76 IOException (java.io.IOException)75 List (java.util.List)74 Map (java.util.Map)67 Filter (org.opengis.filter.Filter)67 CreateResponse (ddf.catalog.operation.CreateResponse)66 HashSet (java.util.HashSet)65