use of ddf.catalog.data.AttributeDescriptor in project ddf by codice.
the class MetacardImplTest method testSerializingEmptyMetacard.
@Test
public void testSerializingEmptyMetacard() throws IOException, ClassNotFoundException {
MetacardImpl metacard = new MetacardImpl();
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();
assertEquals(metacardType.getName(), readMetacardType.getName());
for (AttributeDescriptor ad : readMetacardType.getAttributeDescriptors()) {
assertNull(readMetacard.getAttribute(ad.getName()));
}
}
use of ddf.catalog.data.AttributeDescriptor in project ddf by codice.
the class AttributeDescriptorImplTest method testSerialization.
@Test
public void testSerialization() throws FileNotFoundException, IOException, ClassNotFoundException {
AttributeDescriptorImpl adImpl = new AttributeDescriptorImpl("name", true, true, true, false, BasicTypes.BINARY_TYPE);
Serializer<AttributeDescriptor> serializer = new Serializer<AttributeDescriptor>();
String fileLocation = "target/attributeDescriptor1.ser";
serializer.serialize(adImpl, fileLocation);
AttributeDescriptor readAdImpl = serializer.deserialize(fileLocation);
assertEquals(adImpl.getName(), readAdImpl.getName());
assertEquals(adImpl.getType().getAttributeFormat(), readAdImpl.getType().getAttributeFormat());
assertEquals(adImpl.getType().getBinding(), readAdImpl.getType().getBinding());
assertEquals(adImpl.isIndexed(), readAdImpl.isIndexed());
assertEquals(adImpl.isMultiValued(), readAdImpl.isMultiValued());
assertEquals(adImpl.isStored(), readAdImpl.isStored());
assertEquals(adImpl.isTokenized(), readAdImpl.isTokenized());
}
use of ddf.catalog.data.AttributeDescriptor in project ddf by codice.
the class MetacardTypeImplTest method testExtendingMetacardTypeCombinesDescriptors.
@Test
public void testExtendingMetacardTypeCombinesDescriptors() {
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 String metacardTypeName = "extended";
final MetacardType extended = new MetacardTypeImpl(metacardTypeName, BASIC_METACARD, additionalDescriptors);
assertThat(extended.getName(), is(metacardTypeName));
final Set<AttributeDescriptor> expectedDescriptors = new HashSet<>(BASIC_METACARD.getAttributeDescriptors());
expectedDescriptors.addAll(additionalDescriptors);
assertThat(extended.getAttributeDescriptors(), is(expectedDescriptors));
}
use of ddf.catalog.data.AttributeDescriptor in project ddf by codice.
the class CatalogFrameworkImplTest method testInjectsAttributesOnUpdate.
@Test
public void testInjectsAttributesOnUpdate() throws Exception {
final String injectAttributeName = "new attribute";
final AttributeDescriptor injectAttribute = new AttributeDescriptorImpl(injectAttributeName, true, true, false, false, BasicTypes.DOUBLE_TYPE);
stubMetacardInjection(injectAttribute);
final String id = framework.create(new CreateRequestImpl(Collections.singletonList(new MetacardImpl()), null)).getCreatedMetacards().get(0).getId();
final String title = "Update";
final double injectAttributeValue = -1;
final MetacardImpl metacard = new MetacardImpl();
metacard.setId(id);
metacard.setTitle(title);
metacard.setAttribute(injectAttributeName, injectAttributeValue);
final UpdateRequest request = new UpdateRequestImpl(id, metacard);
List<Result> mockFederationResults = Stream.of(metacard).map(m -> {
Result mockResult = mock(Result.class);
when(mockResult.getMetacard()).thenReturn(m);
return mockResult;
}).collect(Collectors.toList());
QueryResponseImpl queryResponse = new QueryResponseImpl(mock(QueryRequest.class), mockFederationResults, 1);
when(mockFederationStrategy.federate(anyList(), anyObject())).thenReturn(queryResponse);
final UpdateResponse response = framework.update(request);
final Metacard updatedMetacard = response.getUpdatedMetacards().get(0).getNewMetacard();
final MetacardType originalMetacardType = metacard.getMetacardType();
final MetacardType updatedMetacardType = updatedMetacard.getMetacardType();
assertThat(updatedMetacardType.getName(), is(originalMetacardType.getName()));
final Set<AttributeDescriptor> expectedAttributeDescriptors = new HashSet<>(originalMetacardType.getAttributeDescriptors());
expectedAttributeDescriptors.add(injectAttribute);
assertThat(updatedMetacardType.getAttributeDescriptors(), is(expectedAttributeDescriptors));
assertThat(updatedMetacard.getTitle(), is(title));
assertThat(updatedMetacard.getAttribute(injectAttributeName).getValue(), is(injectAttributeValue));
}
use of ddf.catalog.data.AttributeDescriptor in project ddf by codice.
the class CatalogFrameworkImplTest method testInjectsAttributesOnCreate.
@Test
public void testInjectsAttributesOnCreate() throws Exception {
final String title = "Create";
final String injectAttributeName = "new attribute";
final double injectAttributeValue = 2;
final MetacardImpl originalMetacard = new MetacardImpl(BASIC_METACARD);
originalMetacard.setTitle(title);
originalMetacard.setAttribute(injectAttributeName, injectAttributeValue);
final List<Metacard> metacards = Collections.singletonList(originalMetacard);
final CreateRequest request = new CreateRequestImpl(metacards, null);
final AttributeDescriptor injectAttribute = new AttributeDescriptorImpl(injectAttributeName, true, true, false, false, BasicTypes.DOUBLE_TYPE);
stubMetacardInjection(injectAttribute);
final CreateResponse response = framework.create(request);
final Metacard createdMetacard = response.getCreatedMetacards().get(0);
final MetacardType createdMetacardType = createdMetacard.getMetacardType();
final MetacardType originalMetacardType = originalMetacard.getMetacardType();
assertThat(createdMetacardType.getName(), is(originalMetacardType.getName()));
final Set<AttributeDescriptor> expectedAttributeDescriptors = new HashSet<>(originalMetacardType.getAttributeDescriptors());
expectedAttributeDescriptors.add(injectAttribute);
assertThat(createdMetacardType.getAttributeDescriptors(), is(expectedAttributeDescriptors));
assertThat(createdMetacard.getTitle(), is(title));
assertThat(createdMetacard.getAttribute(injectAttributeName).getValue(), is(injectAttributeValue));
}
Aggregations