Search in sources :

Example 96 with MetacardImpl

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"));
}
Also used : Set(java.util.Set) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Example 97 with MetacardImpl

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));
}
Also used : CreateRequest(ddf.catalog.operation.CreateRequest) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) XSString(org.opensaml.core.xml.schema.XSString) Subject(ddf.security.Subject) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 98 with MetacardImpl

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);
}
Also used : PolicyResponse(ddf.catalog.plugin.PolicyResponse) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Example 99 with MetacardImpl

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;
}
Also used : Metacard(ddf.catalog.data.Metacard) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) AttributeDescriptor(ddf.catalog.data.AttributeDescriptor) MetacardTypeImpl(ddf.catalog.data.impl.MetacardTypeImpl) AttributeDescriptorImpl(ddf.catalog.data.impl.AttributeDescriptorImpl) LinkedList(java.util.LinkedList) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) HashSet(java.util.HashSet)

Example 100 with MetacardImpl

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;
}
Also used : AttributeImpl(ddf.catalog.data.impl.AttributeImpl) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) MetacardImpl(ddf.catalog.data.impl.MetacardImpl)

Aggregations

MetacardImpl (ddf.catalog.data.impl.MetacardImpl)384 Test (org.junit.Test)247 Metacard (ddf.catalog.data.Metacard)144 ArrayList (java.util.ArrayList)102 Result (ddf.catalog.data.Result)62 HashMap (java.util.HashMap)59 Date (java.util.Date)52 ResultImpl (ddf.catalog.data.impl.ResultImpl)51 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)49 URI (java.net.URI)38 Matchers.anyString (org.mockito.Matchers.anyString)38 QueryRequest (ddf.catalog.operation.QueryRequest)36 QueryResponse (ddf.catalog.operation.QueryResponse)35 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)35 Serializable (java.io.Serializable)33 HashSet (java.util.HashSet)31 QueryImpl (ddf.catalog.operation.impl.QueryImpl)29 MetacardTypeImpl (ddf.catalog.data.impl.MetacardTypeImpl)28 AttributeDescriptor (ddf.catalog.data.AttributeDescriptor)27 List (java.util.List)27