use of ddf.catalog.data.impl.MetacardImpl in project ddf by codice.
the class XmlAttributeSecurityPolicyPluginTest method testMetadataParse.
@Test
public void testMetadataParse() {
Assert.assertNull(metacard.getSecurity());
Map<String, Set<String>> stringSetMap = plugin.parseSecurityMetadata(metacard);
Collection<Set<String>> vals = stringSetMap.values();
Iterator<Set<String>> iterator = vals.iterator();
Set<String> list = iterator.next();
Assert.assertTrue(list.contains("high"));
Assert.assertTrue(list.contains("med"));
Assert.assertTrue(list.contains("low"));
Assert.assertTrue(list.contains("up"));
list = iterator.next();
Assert.assertTrue(list.size() == 3);
Assert.assertTrue(list.contains("A"));
Assert.assertTrue(list.contains("B"));
Assert.assertTrue(list.contains("C"));
list = iterator.next();
Assert.assertTrue(list.size() == 1);
Assert.assertTrue(list.contains("USA"));
// Test same element, result should be default and the same element
metacard = new MetacardImpl();
metacard.setMetadata(TEST_METADATA_2);
plugin.setSecurityAttributeUnions(Arrays.asList("countries"));
plugin.setSecurityAttributeIntersections(new ArrayList<>());
stringSetMap = plugin.parseSecurityMetadata(metacard);
vals = stringSetMap.values();
iterator = vals.iterator();
list = iterator.next();
Assert.assertTrue(list.size() == 5);
Assert.assertTrue(list.contains("USA"));
Assert.assertTrue(list.contains("CAN"));
Assert.assertTrue(list.contains("GBR"));
Assert.assertTrue(list.contains("DEN"));
Assert.assertTrue(list.contains("AUS"));
}
use of ddf.catalog.data.impl.MetacardImpl in project ddf by codice.
the class SecurityPluginTest method testNominalCaseCreateWithEmailAndResourceTag.
@Test
public void testNominalCaseCreateWithEmailAndResourceTag() throws Exception {
Subject mockSubject = setupMockSubject();
ThreadContext.bind(mockSubject);
MetacardImpl metacardWithTags = new MetacardImpl();
Set<String> setOfTags = new HashSet<String>();
setOfTags.add("resource");
metacardWithTags.setTags(setOfTags);
CreateRequest request = new CreateRequestImpl(metacardWithTags);
SecurityPlugin plugin = new SecurityPlugin();
request = plugin.processPreCreate(request);
assertThat(request.getPropertyValue(SecurityConstants.SECURITY_SUBJECT), equalTo(mockSubject));
assertThat(request.getMetacards().size(), is(1));
assertThat(request.getMetacards().get(0).getAttribute(Metacard.POINT_OF_CONTACT).getValue(), equalTo(TEST_USER));
}
use of ddf.catalog.data.impl.MetacardImpl in project ddf by codice.
the class PointOfContactPolicyPluginTest method processPreUpdateReturnsPolicyWhenOldPointOfContactIsNull.
@Test
public void processPreUpdateReturnsPolicyWhenOldPointOfContactIsNull() throws java.lang.Exception {
MetacardImpl oldMetacard = getMetacardWithPointOfContact(null);
PolicyResponse response = pointOfContactPolicyPlugin.processPreUpdate(getMetacardWithPointOfContact(TEST_POINT_OF_CONTACT), setupAndGetInputProperties(oldMetacard));
responseHasPolicy(response);
}
use of ddf.catalog.data.impl.MetacardImpl in project ddf by codice.
the class TestGetRecordsResponseConverter method createMetacardList.
private List<Metacard> createMetacardList(int start, int finish) {
List<Metacard> list = new LinkedList<>();
for (int i = start; i <= finish; i++) {
MetacardImpl metacard = new MetacardImpl();
metacard.setId(ID_PREFIX + i);
metacard.setSourceId(SOURCE_PREFIX + i);
metacard.setTitle(TITLE_PREFIX + i);
// for testing an attribute with multiple values
AttributeDescriptor ad = new AttributeDescriptorImpl(FORMAT, true, true, true, true, BasicTypes.STRING_TYPE);
Set<AttributeDescriptor> ads = new HashSet<>(metacard.getMetacardType().getAttributeDescriptors());
ads.add(ad);
metacard.setType(new MetacardTypeImpl("test", ads));
metacard.setLocation(WKT);
AttributeImpl attr = new AttributeImpl(FORMAT, FORMAT);
attr.addValue(FORMAT);
metacard.setAttribute(attr);
// for testing an attribute with no attribute descriptor
metacard.setAttribute(RELATION, RELATION);
list.add(metacard);
}
return list;
}
use of ddf.catalog.data.impl.MetacardImpl in project ddf by codice.
the class TestCswRecordConverter method getTestMetacard.
private MetacardImpl getTestMetacard() {
MetacardImpl metacard = new MetacardImpl(getCswMetacardType());
metacard.setContentTypeName("I have some content type");
metacard.setAttribute(new AttributeImpl(Media.FORMAT, "I have some format type"));
metacard.setContentTypeVersion("1.0.0");
metacard.setCreatedDate(CREATED_DATE.getTime());
metacard.setEffectiveDate(EFFECTIVE_DATE.getTime());
metacard.setId("ID");
metacard.setLocation("POLYGON ((30 10, 10 20, 20 40, 40 40, 30 10))");
metacard.setMetadata("<xml>metadata a whole bunch of metadata</xml>");
metacard.setModifiedDate(MODIFIED_DATE.getTime());
metacard.setResourceSize("123TB");
metacard.setSourceId("sourceID");
metacard.setTitle("This is my title");
metacard.setAttribute(new AttributeImpl(Core.LANGUAGE, "english"));
metacard.setAttribute(new AttributeImpl(Contact.PUBLISHER_NAME, "bob"));
metacard.setAttribute(new AttributeImpl(Contact.CREATOR_NAME, "steve"));
metacard.setAttribute(new AttributeImpl(Contact.CONTRIBUTOR_NAME, "rick"));
metacard.setAttribute(new AttributeImpl(Topic.CATEGORY, Arrays.asList("topic1", "topic2")));
metacard.setAttribute(new AttributeImpl(Core.DESCRIPTION, "This is a description"));
try {
metacard.setResourceURI(new URI(ACTION_URL));
} catch (URISyntaxException e) {
LOGGER.debug("URISyntaxException", e);
}
return metacard;
}
Aggregations