Search in sources :

Example 41 with AttributeDescriptor

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);
    }
}
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 42 with AttributeDescriptor

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

Example 43 with AttributeDescriptor

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);
    }
}
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 44 with AttributeDescriptor

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

Example 45 with AttributeDescriptor

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);
}
Also used : AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) MetacardType(ddf.catalog.data.MetacardType) HashSet(java.util.HashSet)

Aggregations

AttributeDescriptor (ddf.catalog.data.AttributeDescriptor)111 Test (org.junit.Test)51 MetacardType (ddf.catalog.data.MetacardType)40 Metacard (ddf.catalog.data.Metacard)38 HashSet (java.util.HashSet)29 Attribute (ddf.catalog.data.Attribute)26 AttributeDescriptorImpl (ddf.catalog.data.impl.AttributeDescriptorImpl)24 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)24 MetacardTypeImpl (ddf.catalog.data.impl.MetacardTypeImpl)24 ArrayList (java.util.ArrayList)23 Serializable (java.io.Serializable)16 FeatureMetacardType (org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureMetacardType)9 CatalogTransformerException (ddf.catalog.transform.CatalogTransformerException)8 HashMap (java.util.HashMap)8 Map (java.util.Map)8 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)7 IOException (java.io.IOException)7 Date (java.util.Date)7 List (java.util.List)7 QName (javax.xml.namespace.QName)7