use of ddf.catalog.data.MetacardType in project ddf by codice.
the class MetacardTypeImplTest method testHistoryType.
@Test
public void testHistoryType() {
List<MetacardType> metacardTypeList = new ArrayList<>();
metacardTypeList.add(VERSION_ATTRIBUTES);
MetacardType metacardType = new MetacardTypeImpl(TEST_NAME, metacardTypeList);
assertMetacardAttributes(metacardType, CORE_ATTRIBUTES.getAttributeDescriptors());
assertMetacardAttributes(metacardType, VERSION_ATTRIBUTES.getAttributeDescriptors());
}
use of ddf.catalog.data.MetacardType in project ddf by codice.
the class MetacardTypeImplTest method testDuplicateAttributes.
@Test
public void testDuplicateAttributes() {
MetacardType duplicateAttributeMetacardType = new MetacardTypeImpl("testType", Collections.singleton(new AttributeDescriptorImpl(Core.CHECKSUM, true, /* indexed */
true, /* stored */
false, /* tokenized */
false, /* multivalued */
BasicTypes.SHORT_TYPE)));
List<MetacardType> metacardTypeList = new ArrayList<>();
metacardTypeList.add(DATE_TIME_ATTRIBUTES);
metacardTypeList.add(duplicateAttributeMetacardType);
MetacardType metacardType = new MetacardTypeImpl(TEST_NAME, metacardTypeList);
int expectedSize = DATE_TIME_ATTRIBUTES.getAttributeDescriptors().size() + CORE_ATTRIBUTES.getAttributeDescriptors().size() + SECURITY_ATTRIBUTES.getAttributeDescriptors().size();
assertThat(metacardType.getAttributeDescriptors().size(), is(expectedSize));
}
use of ddf.catalog.data.MetacardType 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.MetacardType in project ddf by codice.
the class CatalogFrameworkImplTest method getMetacards.
private List<Metacard> getMetacards(String title, Date expiration) {
List<Metacard> metacards = new ArrayList<>();
MetacardImpl basicMetacardHasBoth = new MetacardImpl(BasicTypes.BASIC_METACARD);
basicMetacardHasBoth.setId("1");
basicMetacardHasBoth.setTitle(title);
basicMetacardHasBoth.setExpirationDate(expiration);
metacards.add(basicMetacardHasBoth);
MetacardImpl basicMetacardHasTitle = new MetacardImpl(BasicTypes.BASIC_METACARD);
basicMetacardHasTitle.setId("2");
basicMetacardHasTitle.setTitle(title);
metacards.add(basicMetacardHasTitle);
MetacardImpl basicMetacardHasExpiration = new MetacardImpl(BasicTypes.BASIC_METACARD);
basicMetacardHasExpiration.setId("3");
basicMetacardHasExpiration.setExpirationDate(expiration);
metacards.add(basicMetacardHasExpiration);
MetacardImpl basicMetacardHasNeither = new MetacardImpl(BasicTypes.BASIC_METACARD);
basicMetacardHasNeither.setId("4");
metacards.add(basicMetacardHasNeither);
MetacardType customMetacardType = new MetacardTypeImpl(CUSTOM_METACARD_TYPE_NAME, BasicTypes.BASIC_METACARD.getAttributeDescriptors());
MetacardImpl customMetacardHasNeither = new MetacardImpl(customMetacardType);
customMetacardHasNeither.setId("5");
metacards.add(customMetacardHasNeither);
return metacards;
}
use of ddf.catalog.data.MetacardType 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