Search in sources :

Example 26 with PolicyResponse

use of ddf.catalog.plugin.PolicyResponse in project ddf by codice.

the class MetacardAttributeSecurityPolicyPluginTest method testProcessPreUpdate.

@Test
public void testProcessPreUpdate() throws StopProcessingException {
    PolicyResponse policyResponse = plugin.processPreUpdate(metacard, new HashMap<>());
    assertThat(policyResponse.itemPolicy().size(), is(2));
    assertTrue(policyResponse.itemPolicy().get("mapped.security").contains("A"));
    assertTrue(policyResponse.itemPolicy().get("mapped.security").contains("B"));
    assertTrue(policyResponse.itemPolicy().get("mapped.security").contains("C"));
    assertTrue(policyResponse.itemPolicy().get("mapped.countries").contains("USA"));
    assertTrue(policyResponse.itemPolicy().get("mapped.countries").contains("CAN"));
    assertNull(policyResponse.itemPolicy().get("parsed.security"));
    assertNull(policyResponse.itemPolicy().get("parsed.countries"));
    assertNull(policyResponse.itemPolicy().get("parsed.other"));
}
Also used : PolicyResponse(ddf.catalog.plugin.PolicyResponse) Test(org.junit.Test)

Example 27 with PolicyResponse

use of ddf.catalog.plugin.PolicyResponse in project ddf by codice.

the class MetacardAttributeSecurityPolicyPluginTest method testProcessPreDelete.

@Test
public void testProcessPreDelete() throws StopProcessingException {
    PolicyResponse policyResponse = plugin.processPreDelete(Arrays.asList(metacard, metacard1), new HashMap<>());
    assertThat(policyResponse.operationPolicy().size(), is(2));
    assertTrue(policyResponse.operationPolicy().get("mapped.security").contains("A"));
    assertTrue(policyResponse.operationPolicy().get("mapped.security").contains("B"));
    assertTrue(policyResponse.operationPolicy().get("mapped.security").contains("C"));
    assertTrue(policyResponse.operationPolicy().get("mapped.security").contains("X"));
    assertTrue(policyResponse.operationPolicy().get("mapped.security").contains("Y"));
    assertTrue(policyResponse.operationPolicy().get("mapped.security").contains("Z"));
    assertTrue(policyResponse.operationPolicy().get("mapped.countries").contains("USA"));
    assertTrue(policyResponse.operationPolicy().get("mapped.countries").contains("CAN"));
    assertTrue(policyResponse.operationPolicy().get("mapped.countries").contains("GBR"));
    assertNull(policyResponse.itemPolicy().get("parsed.security"));
    assertNull(policyResponse.itemPolicy().get("parsed.countries"));
}
Also used : PolicyResponse(ddf.catalog.plugin.PolicyResponse) Test(org.junit.Test)

Example 28 with PolicyResponse

use of ddf.catalog.plugin.PolicyResponse in project ddf by codice.

the class MetacardAttributeSecurityPolicyPluginTest method testProcessPostDelete.

@Test
public void testProcessPostDelete() throws StopProcessingException {
    PolicyResponse policyResponse = plugin.processPostDelete(metacard, new HashMap<>());
    assertThat(policyResponse.itemPolicy().size(), is(2));
    assertTrue(policyResponse.itemPolicy().get("mapped.security").contains("A"));
    assertTrue(policyResponse.itemPolicy().get("mapped.security").contains("B"));
    assertTrue(policyResponse.itemPolicy().get("mapped.security").contains("C"));
    assertTrue(policyResponse.itemPolicy().get("mapped.countries").contains("USA"));
    assertTrue(policyResponse.itemPolicy().get("mapped.countries").contains("CAN"));
    assertNull(policyResponse.itemPolicy().get("parsed.security"));
    assertNull(policyResponse.itemPolicy().get("parsed.countries"));
    assertNull(policyResponse.itemPolicy().get("parsed.other"));
}
Also used : PolicyResponse(ddf.catalog.plugin.PolicyResponse) Test(org.junit.Test)

Example 29 with PolicyResponse

use of ddf.catalog.plugin.PolicyResponse in project ddf by codice.

the class MetacardAttributeSecurityPolicyPluginTest method testUnionAttributes.

@Test
public void testUnionAttributes() throws Exception {
    plugin.setUnionMetacardAttributes(Arrays.asList("source1=dest", "source2=dest", "source3=dest", "source4=dest2"));
    PolicyResponse policyResponse = plugin.processPreCreate(metacard2, new HashMap<>());
    Map<String, Set<String>> itemPolicy = policyResponse.itemPolicy();
    assertThat(itemPolicy.size(), is(2));
    assertThat(itemPolicy.get("dest").size(), is(6));
    assertTrue(itemPolicy.get("dest").containsAll(ImmutableSet.of("A", "B", "C", "D", "E", "F")));
    assertThat(itemPolicy.get("dest2").size(), is(3));
    assertTrue(itemPolicy.get("dest2").containsAll(ImmutableSet.of("F", "G", "H")));
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) PolicyResponse(ddf.catalog.plugin.PolicyResponse) Test(org.junit.Test)

Example 30 with PolicyResponse

use of ddf.catalog.plugin.PolicyResponse in project ddf by codice.

the class MetacardAttributeSecurityPolicyPluginTest method testProcessPostResource.

@Test
public void testProcessPostResource() throws StopProcessingException {
    PolicyResponse policyResponse = plugin.processPostResource(mock(ResourceResponse.class), metacard);
    assertThat(policyResponse.itemPolicy().size(), is(2));
    assertTrue(policyResponse.itemPolicy().get("mapped.security").contains("A"));
    assertTrue(policyResponse.itemPolicy().get("mapped.security").contains("B"));
    assertTrue(policyResponse.itemPolicy().get("mapped.security").contains("C"));
    assertTrue(policyResponse.itemPolicy().get("mapped.countries").contains("USA"));
    assertTrue(policyResponse.itemPolicy().get("mapped.countries").contains("CAN"));
    assertNull(policyResponse.itemPolicy().get("parsed.security"));
    assertNull(policyResponse.itemPolicy().get("parsed.countries"));
    assertNull(policyResponse.itemPolicy().get("parsed.other"));
}
Also used : ResourceResponse(ddf.catalog.operation.ResourceResponse) PolicyResponse(ddf.catalog.plugin.PolicyResponse) Test(org.junit.Test)

Aggregations

PolicyResponse (ddf.catalog.plugin.PolicyResponse)75 Test (org.junit.Test)64 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)20 Metacard (ddf.catalog.data.Metacard)19 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)14 Serializable (java.io.Serializable)14 Set (java.util.Set)14 Result (ddf.catalog.data.Result)13 HashMap (java.util.HashMap)12 PolicyPlugin (ddf.catalog.plugin.PolicyPlugin)10 HashSet (java.util.HashSet)7 ResultImpl (ddf.catalog.data.impl.ResultImpl)6 ResourceResponse (ddf.catalog.operation.ResourceResponse)6 Query (ddf.catalog.operation.Query)5 StopProcessingException (ddf.catalog.plugin.StopProcessingException)4 ImmutableSet (com.google.common.collect.ImmutableSet)3 ResourceRequest (ddf.catalog.operation.ResourceRequest)3 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 OPERATION_TRANSACTION_KEY (ddf.catalog.Constants.OPERATION_TRANSACTION_KEY)2