Search in sources :

Example 51 with UpdateRequest

use of ddf.catalog.operation.UpdateRequest in project ddf by codice.

the class WorkspaceAccessPluginTest method testStopProcessingWhenNotOwner.

@Test(expected = StopProcessingException.class)
public void testStopProcessingWhenNotOwner() throws Exception {
    String id = "0";
    WorkspaceMetacardImpl before = WorkspaceMetacardImpl.from(ImmutableMap.of(Metacard.ID, id, Core.METACARD_OWNER, "owner", WorkspaceAttributes.WORKSPACE_SHARING, ImmutableList.of()));
    WorkspaceMetacardImpl after = WorkspaceMetacardImpl.from(ImmutableMap.of(Metacard.ID, id, Core.METACARD_OWNER, "owner", WorkspaceAttributes.WORKSPACE_SHARING, ImmutableList.of("<xml/>")));
    UpdateRequest update = mockUpdateRequest(ImmutableMap.of(id, after));
    doReturn(false).when(subject).isPermitted(any(Permission.class));
    accessPlugin.processPreUpdate(update, ImmutableMap.of(id, before));
}
Also used : UpdateRequest(ddf.catalog.operation.UpdateRequest) KeyValuePermission(ddf.security.permission.KeyValuePermission) Permission(org.apache.shiro.authz.Permission) KeyValueCollectionPermission(ddf.security.permission.KeyValueCollectionPermission) WorkspaceMetacardImpl(org.codice.ddf.catalog.ui.metacard.workspace.WorkspaceMetacardImpl) Test(org.junit.Test)

Example 52 with UpdateRequest

use of ddf.catalog.operation.UpdateRequest in project ddf by codice.

the class WorkspaceAccessPluginTest method testPermittedWhenOwnerOnUpdatedRoles.

@Test
public void testPermittedWhenOwnerOnUpdatedRoles() throws Exception {
    String id = "0";
    WorkspaceMetacardImpl before = WorkspaceMetacardImpl.from(ImmutableMap.of(Metacard.ID, id, Core.METACARD_OWNER, "before", WorkspaceAttributes.WORKSPACE_SHARING, ImmutableList.of()));
    WorkspaceMetacardImpl after = WorkspaceMetacardImpl.from(ImmutableMap.of(Metacard.ID, id, Core.METACARD_OWNER, "after", WorkspaceAttributes.WORKSPACE_SHARING, ImmutableList.of("<xml/>")));
    UpdateRequest update = mockUpdateRequest(ImmutableMap.of(id, after));
    ArgumentCaptor<KeyValueCollectionPermission> args = ArgumentCaptor.forClass(KeyValueCollectionPermission.class);
    doReturn(true).when(subject).isPermitted(args.capture());
    accessPlugin.processPreUpdate(update, ImmutableMap.of(id, before));
    KeyValuePermission permission = (KeyValuePermission) args.getValue().getKeyValuePermissionList().get(0);
    assertThat(permission.getKey(), is(Constants.EMAIL_ADDRESS_CLAIM_URI));
    // NOTE: the permission should contain the owner of the before metacard, not after
    assertThat(permission.getValues(), is(ImmutableSet.of(before.getOwner())));
}
Also used : KeyValueCollectionPermission(ddf.security.permission.KeyValueCollectionPermission) UpdateRequest(ddf.catalog.operation.UpdateRequest) KeyValuePermission(ddf.security.permission.KeyValuePermission) WorkspaceMetacardImpl(org.codice.ddf.catalog.ui.metacard.workspace.WorkspaceMetacardImpl) Test(org.junit.Test)

Example 53 with UpdateRequest

use of ddf.catalog.operation.UpdateRequest in project ddf by codice.

the class WorkspaceAccessPluginTest method testSetOwnerRole.

@Test
public void testSetOwnerRole() throws Exception {
    String id = "0";
    WorkspaceMetacardImpl before = WorkspaceMetacardImpl.from(ImmutableMap.of(Metacard.ID, id, Core.METACARD_OWNER, "user1"));
    WorkspaceMetacardImpl after = WorkspaceMetacardImpl.from(ImmutableMap.of(Metacard.ID, id, Core.METACARD_OWNER, "user2"));
    UpdateRequest update = mockUpdateRequest(ImmutableMap.of(id, after));
    ArgumentCaptor<KeyValueCollectionPermission> args = ArgumentCaptor.forClass(KeyValueCollectionPermission.class);
    doReturn(true).when(subject).isPermitted(any(Permission.class));
    accessPlugin.processPreUpdate(update, ImmutableMap.of(id, before));
}
Also used : KeyValueCollectionPermission(ddf.security.permission.KeyValueCollectionPermission) UpdateRequest(ddf.catalog.operation.UpdateRequest) KeyValuePermission(ddf.security.permission.KeyValuePermission) Permission(org.apache.shiro.authz.Permission) KeyValueCollectionPermission(ddf.security.permission.KeyValueCollectionPermission) WorkspaceMetacardImpl(org.codice.ddf.catalog.ui.metacard.workspace.WorkspaceMetacardImpl) Test(org.junit.Test)

Example 54 with UpdateRequest

use of ddf.catalog.operation.UpdateRequest in project ddf by codice.

the class WorkspaceAccessPluginTest method testBasicUpdate.

@Test
public void testBasicUpdate() throws Exception {
    String id = "0";
    Map<String, Serializable> attrs = ImmutableMap.of(Metacard.ID, id, Core.METACARD_OWNER, "guest");
    Map<String, Metacard> updates = ImmutableMap.of(id, WorkspaceMetacardImpl.from(attrs));
    UpdateRequest update = mockUpdateRequest(updates);
    // should ignore any workspace metacards with no updated roles
    accessPlugin.processPreUpdate(update, updates);
}
Also used : Serializable(java.io.Serializable) Metacard(ddf.catalog.data.Metacard) UpdateRequest(ddf.catalog.operation.UpdateRequest) Test(org.junit.Test)

Example 55 with UpdateRequest

use of ddf.catalog.operation.UpdateRequest in project ddf by codice.

the class CachingFederationStrategyTest method testProcessUpdateResponse.

@Test
public void testProcessUpdateResponse() throws Exception {
    Map<String, Serializable> testMap = new HashMap<>();
    testMap.put(Constants.SERVICE_TITLE, MOCK_RESPONSE_TITLE);
    UpdateResponse response = mock(UpdateResponseImpl.class);
    UpdateRequest request = mock(UpdateRequestImpl.class);
    when(request.hasProperties()).thenReturn(true);
    when(request.getProperties()).thenReturn(testMap);
    when(response.getRequest()).thenReturn(request);
    MetacardImpl newMetacard = mock(MetacardImpl.class);
    when(newMetacard.getId()).thenReturn("new metacard");
    when(newMetacard.getSourceId()).thenReturn("new source ID");
    UpdateImpl updateImpl = mock(UpdateImpl.class);
    when(updateImpl.getNewMetacard()).thenReturn(newMetacard);
    List<Update> cards = Arrays.asList(updateImpl);
    ArgumentCaptor<List<Metacard>> metacardsCaptor = ArgumentCaptor.forClass((Class) List.class);
    when(response.getUpdatedMetacards()).thenReturn(cards);
    doNothing().when(cache).create(metacardsCaptor.capture());
    assertThat(response, is(strategy.process(response)));
    assertThat(metacardsCaptor.getValue().contains(newMetacard), is(true));
}
Also used : UpdateImpl(ddf.catalog.operation.impl.UpdateImpl) UpdateResponse(ddf.catalog.operation.UpdateResponse) Serializable(java.io.Serializable) HashMap(java.util.HashMap) UpdateRequest(ddf.catalog.operation.UpdateRequest) List(java.util.List) ArrayList(java.util.ArrayList) Update(ddf.catalog.operation.Update) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Aggregations

UpdateRequest (ddf.catalog.operation.UpdateRequest)61 Test (org.junit.Test)44 Metacard (ddf.catalog.data.Metacard)41 ArrayList (java.util.ArrayList)32 Serializable (java.io.Serializable)25 UpdateResponse (ddf.catalog.operation.UpdateResponse)23 UpdateRequestImpl (ddf.catalog.operation.impl.UpdateRequestImpl)23 HashMap (java.util.HashMap)21 Update (ddf.catalog.operation.Update)17 List (java.util.List)16 Entry (java.util.Map.Entry)16 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)15 Map (java.util.Map)12 SimpleEntry (java.util.AbstractMap.SimpleEntry)11 IngestException (ddf.catalog.source.IngestException)10 URI (java.net.URI)10 Result (ddf.catalog.data.Result)9 CreateRequest (ddf.catalog.operation.CreateRequest)9 CatalogFramework (ddf.catalog.CatalogFramework)8 CreateResponse (ddf.catalog.operation.CreateResponse)8