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));
}
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())));
}
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));
}
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);
}
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));
}
Aggregations