Search in sources :

Example 81 with MetacardType

use of ddf.catalog.data.MetacardType in project ddf by codice.

the class TestXmlInputTransformer method testFallbackToBasicMetacardForUnknowMetacardType.

@Test
public void testFallbackToBasicMetacardForUnknowMetacardType() throws FileNotFoundException, IOException, CatalogTransformerException, ParseException {
    List<MetacardType> metacardTypes = new ArrayList<MetacardType>(1);
    metacardTypes.add(BasicTypes.BASIC_METACARD);
    xit.setMetacardTypes(metacardTypes);
    Metacard metacard = xit.transform(new FileInputStream("src/test/resources/unknownMetacard1.xml"));
    LOGGER.info("ID: {}", metacard.getId());
    LOGGER.info("Type: {}", metacard.getMetacardType().getName());
    LOGGER.info("Source: {}", metacard.getSourceId());
    LOGGER.info("Attributes: ");
    for (AttributeDescriptor descriptor : metacard.getMetacardType().getAttributeDescriptors()) {
        Attribute attribute = metacard.getAttribute(descriptor.getName());
        LOGGER.info("\t" + descriptor.getName() + ": " + ((attribute == null) ? attribute : attribute.getValue()));
    }
    assertThat(metacard.getMetacardType().getName(), is(BasicTypes.BASIC_METACARD.getName()));
    assertThat("1234567890987654321", is(metacard.getId()));
    assertThat("foobar", is(metacard.getSourceId()));
    assertThat("POLYGON ((35 10, 10 20, 15 40, 45 45, 35 10), (20 30, 35 35, 30 20, 20 30))", is(metacard.getAttribute(Metacard.GEOGRAPHY).getValue()));
    assertThat("Title!", is(metacard.getAttribute(Metacard.TITLE).getValue()));
    assertArrayEquals(Base64.getDecoder().decode("AAABAAABAQEAAQAAAQEBAAEAAAEBAQABAAABAQEAAQAAAQEBAAEAAAEBAQABAAABAQE="), (byte[]) metacard.getAttribute(Metacard.THUMBNAIL).getValue());
    assertThat(metacard.getAttribute(Metacard.METADATA).getValue().toString(), startsWith("<foo xmlns=\"http://foo.com\">"));
    assertThat((new SimpleDateFormat("MMM d, yyyy HH:mm:ss.SSS z")).parse("Dec 27, 2012 16:31:01.641 MST"), is(metacard.getAttribute(Metacard.EXPIRATION).getValue()));
    assertEquals(DESCRIPTION, metacard.getAttribute("description").getValue());
    assertEquals(POINT_OF_CONTACT, metacard.getAttribute("point-of-contact").getValue());
}
Also used : Metacard(ddf.catalog.data.Metacard) Attribute(ddf.catalog.data.Attribute) ArrayList(java.util.ArrayList) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) SimpleDateFormat(java.text.SimpleDateFormat) MetacardType(ddf.catalog.data.MetacardType) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 82 with MetacardType

use of ddf.catalog.data.MetacardType in project ddf by codice.

the class TestXmlMetacardTransformer method testMetacardTypeNameEmpty.

@Test
public void testMetacardTypeNameEmpty() throws Exception {
    Metacard mc = mock(Metacard.class);
    MetacardType mct = mock(MetacardType.class);
    when(mct.getName()).thenReturn("");
    when(mct.getAttributeDescriptors()).thenReturn(Collections.<AttributeDescriptor>emptySet());
    when(mc.getMetacardType()).thenReturn(mct);
    when(mc.getId()).thenReturn(null);
    when(mc.getSourceId()).thenReturn(null);
    String outputXml = transform(mc);
    assertXpathEvaluatesTo(MetacardType.DEFAULT_METACARD_TYPE_NAME, "/m:metacard/m:type", outputXml);
}
Also used : Metacard(ddf.catalog.data.Metacard) MetacardType(ddf.catalog.data.MetacardType) Test(org.junit.Test)

Example 83 with MetacardType

use of ddf.catalog.data.MetacardType in project ddf by codice.

the class TestMetacardTypeAdapter method testUnmarshalWithDdfMetacardTypeName.

@Test
public void testUnmarshalWithDdfMetacardTypeName() throws CatalogTransformerException {
    MetacardType unknownMetacardType = new MetacardTypeImpl(KNOWN_TYPE_NAME, (Set<AttributeDescriptor>) null);
    List<MetacardType> metacardTypes = new ArrayList<MetacardType>(1);
    metacardTypes.add(unknownMetacardType);
    MetacardTypeAdapter metacardTypeAdpater = new MetacardTypeAdapter(metacardTypes);
    MetacardType metacardType = metacardTypeAdpater.unmarshal(DDF_METACARD_TYPE_NAME);
    assertThat(metacardType.getName(), is(BasicTypes.BASIC_METACARD.getName()));
}
Also used : ArrayList(java.util.ArrayList) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) MetacardTypeAdapter(ddf.catalog.transformer.xml.adapter.MetacardTypeAdapter) MetacardTypeImpl(ddf.catalog.data.impl.MetacardTypeImpl) MetacardType(ddf.catalog.data.MetacardType) Test(org.junit.Test)

Example 84 with MetacardType

use of ddf.catalog.data.MetacardType in project ddf by codice.

the class TestMetacardTypeAdapter method testUnmarshalWithEmptyTypeName.

@Test
public void testUnmarshalWithEmptyTypeName() throws CatalogTransformerException {
    MetacardTypeAdapter metacardTypeAdpater = new MetacardTypeAdapter();
    MetacardType metacardType = metacardTypeAdpater.unmarshal(EMPTY_TYPE_NAME);
    assertThat(metacardType.getName(), is(BasicTypes.BASIC_METACARD.getName()));
}
Also used : MetacardTypeAdapter(ddf.catalog.transformer.xml.adapter.MetacardTypeAdapter) MetacardType(ddf.catalog.data.MetacardType) Test(org.junit.Test)

Example 85 with MetacardType

use of ddf.catalog.data.MetacardType in project ddf by codice.

the class TestMetacardTypeAdapter method testUnmarshalWithNullTypeName.

@Test
public void testUnmarshalWithNullTypeName() throws CatalogTransformerException {
    MetacardTypeAdapter metacardTypeAdpater = new MetacardTypeAdapter();
    MetacardType metacardType = metacardTypeAdpater.unmarshal(NULL_TYPE_NAME);
    assertThat(metacardType.getName(), is(BasicTypes.BASIC_METACARD.getName()));
}
Also used : MetacardTypeAdapter(ddf.catalog.transformer.xml.adapter.MetacardTypeAdapter) MetacardType(ddf.catalog.data.MetacardType) Test(org.junit.Test)

Aggregations

MetacardType (ddf.catalog.data.MetacardType)88 Test (org.junit.Test)57 AttributeDescriptor (ddf.catalog.data.AttributeDescriptor)41 Metacard (ddf.catalog.data.Metacard)35 ArrayList (java.util.ArrayList)29 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)20 MetacardTypeImpl (ddf.catalog.data.impl.MetacardTypeImpl)17 HashSet (java.util.HashSet)15 Attribute (ddf.catalog.data.Attribute)12 Serializable (java.io.Serializable)10 IOException (java.io.IOException)8 Date (java.util.Date)8 HashMap (java.util.HashMap)8 List (java.util.List)8 Map (java.util.Map)8 AttributeDescriptorImpl (ddf.catalog.data.impl.AttributeDescriptorImpl)7 InputStream (java.io.InputStream)7 Set (java.util.Set)7 ContentItem (ddf.catalog.content.data.ContentItem)6 ContentItemImpl (ddf.catalog.content.data.impl.ContentItemImpl)6