Search in sources :

Example 41 with MetacardType

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

the class MetacardTypeImplTest method testSerializationNullDescriptors.

@Test
public void testSerializationNullDescriptors() throws IOException, ClassNotFoundException {
    MetacardTypeImpl metacardType = new MetacardTypeImpl("basic", (Set<AttributeDescriptor>) null);
    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()));
    Set<AttributeDescriptor> oldAd = metacardType.getAttributeDescriptors();
    Set<AttributeDescriptor> newAd = readMetacardType.getAttributeDescriptors();
    assertThat(oldAd.isEmpty(), is(true));
    assertThat(newAd.isEmpty(), is(true));
}
Also used : AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) MetacardType(ddf.catalog.data.MetacardType) Test(org.junit.Test)

Example 42 with MetacardType

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

the class MetacardTypeImplTest method testAllTypes.

@Test
public void testAllTypes() {
    List<MetacardType> metacardTypeList = new ArrayList<>();
    metacardTypeList.add(DATE_TIME_ATTRIBUTES);
    metacardTypeList.add(MEDIA_ATTRIBUTES);
    metacardTypeList.add(LOCATION_ATTRIBUTES);
    metacardTypeList.add(CONTACT_ATTRIBUTES);
    metacardTypeList.add(TOPIC_ATTRIBUTES);
    metacardTypeList.add(VERSION_ATTRIBUTES);
    metacardTypeList.add(ASSOCIATIONS_ATTRIBUTES);
    metacardTypeList.add(VALIDATION_ATTRIBUTES);
    MetacardType metacardType = new MetacardTypeImpl(TEST_NAME, metacardTypeList);
    assertMetacardAttributes(metacardType, CORE_ATTRIBUTES.getAttributeDescriptors());
    assertMetacardAttributes(metacardType, DATE_TIME_ATTRIBUTES.getAttributeDescriptors());
    assertMetacardAttributes(metacardType, MEDIA_ATTRIBUTES.getAttributeDescriptors());
    assertMetacardAttributes(metacardType, LOCATION_ATTRIBUTES.getAttributeDescriptors());
    assertMetacardAttributes(metacardType, CONTACT_ATTRIBUTES.getAttributeDescriptors());
    assertMetacardAttributes(metacardType, TOPIC_ATTRIBUTES.getAttributeDescriptors());
    assertMetacardAttributes(metacardType, VERSION_ATTRIBUTES.getAttributeDescriptors());
    assertMetacardAttributes(metacardType, ASSOCIATIONS_ATTRIBUTES.getAttributeDescriptors());
    assertMetacardAttributes(metacardType, VALIDATION_ATTRIBUTES.getAttributeDescriptors());
}
Also used : ArrayList(java.util.ArrayList) MetacardType(ddf.catalog.data.MetacardType) Test(org.junit.Test)

Example 43 with MetacardType

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

the class QualifiedMetacardTypeTest method testDefaultNamespaceNotEqual.

@Test
public void testDefaultNamespaceNotEqual() {
    MetacardType mt1 = new MetacardTypeImpl(QUALIFIED_METACARD_TYPE_NAME_3, qmtAttributes);
    QualifiedMetacardTypeImpl qmt1 = new QualifiedMetacardTypeImpl(QUALIFIED_METACARD_TYPE_NAMESPACE_2, mt1);
    MetacardType mt2 = new MetacardTypeImpl(QUALIFIED_METACARD_TYPE_NAME_3, qmtAttributes);
    QualifiedMetacardTypeImpl qmt2 = new QualifiedMetacardTypeImpl(null, mt2);
    assertTrue(!qmt1.equals(qmt2));
    assertTrue(!qmt2.equals(qmt1));
    assertTrue(qmt1.hashCode() != qmt2.hashCode());
}
Also used : QualifiedMetacardType(ddf.catalog.data.QualifiedMetacardType) MetacardType(ddf.catalog.data.MetacardType) Test(org.junit.Test)

Example 44 with MetacardType

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

the class CatalogFrameworkImplTest method testCreateStorageWithAttributeOverridesInvalidType.

/**
     * Tests that the framework properly passes a create request to the local provider with attribute overrides.
     */
@Test
public void testCreateStorageWithAttributeOverridesInvalidType() throws Exception {
    List<ContentItem> contentItems = new ArrayList<>();
    Map<String, Serializable> propertiesMap = new HashMap<>();
    HashMap<String, Object> attributeMap = new HashMap<>();
    attributeMap.put(Metacard.CREATED, "bad date");
    propertiesMap.put(Constants.ATTRIBUTE_OVERRIDES_KEY, attributeMap);
    MetacardImpl newCard = new MetacardImpl();
    newCard.setId(null);
    MetacardType metacardType = mock(MetacardType.class);
    AttributeDescriptor dateAttributeDescriptor = new AttributeDescriptorImpl(Metacard.CREATED, true, true, true, true, new AttributeType<Date>() {

        private static final long serialVersionUID = 1L;

        @Override
        public Class<Date> getBinding() {
            return Date.class;
        }

        @Override
        public AttributeFormat getAttributeFormat() {
            return AttributeFormat.DATE;
        }
    });
    when(metacardType.getAttributeDescriptor(Metacard.TITLE)).thenReturn(dateAttributeDescriptor);
    newCard.setType(metacardType);
    ByteSource byteSource = new ByteSource() {

        @Override
        public InputStream openStream() throws IOException {
            return new ByteArrayInputStream("blah".getBytes());
        }
    };
    ContentItemImpl newItem = new ContentItemImpl(uuidGenerator.generateUuid(), byteSource, "application/octet-stream", "blah", 0L, newCard);
    contentItems.add(newItem);
    CreateResponse response = framework.create(new CreateStorageRequestImpl(contentItems, propertiesMap));
    assertEquals(response.getCreatedMetacards().size(), provider.size());
    assertEquals(response.getCreatedMetacards().size(), storageProvider.size());
    for (Metacard curCard : response.getCreatedMetacards()) {
        assertNotNull(curCard.getId());
        // Assert value is not set for invalid format
        assertThat(curCard.getCreatedDate(), nullValue());
    }
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) CreateResponse(ddf.catalog.operation.CreateResponse) ArrayList(java.util.ArrayList) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) Matchers.anyString(org.mockito.Matchers.anyString) CreateStorageRequestImpl(ddf.catalog.content.operation.impl.CreateStorageRequestImpl) AttributeDescriptorImpl(ddf.catalog.data.impl.AttributeDescriptorImpl) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) MetacardType(ddf.catalog.data.MetacardType) Date(java.util.Date) Metacard(ddf.catalog.data.Metacard) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteSource(com.google.common.io.ByteSource) Matchers.anyObject(org.mockito.Matchers.anyObject) ContentItem(ddf.catalog.content.data.ContentItem) ContentItemImpl(ddf.catalog.content.data.impl.ContentItemImpl) Test(org.junit.Test)

Example 45 with MetacardType

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

the class CatalogFrameworkImplTest method stubMetacardInjection.

/****************************
     * utility methods
     ******************************/
private void stubMetacardInjection(AttributeDescriptor... injectedAttributes) {
    doAnswer(invocationOnMock -> {
        Metacard original = (Metacard) invocationOnMock.getArguments()[0];
        MetacardType originalMetacardType = original.getMetacardType();
        MetacardType newMetacardType = new MetacardTypeImpl(originalMetacardType.getName(), originalMetacardType, Sets.newHashSet(injectedAttributes));
        MetacardImpl newMetacard = new MetacardImpl(original);
        newMetacard.setType(newMetacardType);
        newMetacard.setSourceId(original.getSourceId());
        return newMetacard;
    }).when(attributeInjector).injectAttributes(any(Metacard.class));
}
Also used : Metacard(ddf.catalog.data.Metacard) MetacardTypeImpl(ddf.catalog.data.impl.MetacardTypeImpl) MetacardType(ddf.catalog.data.MetacardType) MetacardImpl(ddf.catalog.data.impl.MetacardImpl)

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