use of org.codice.ddf.catalog.ui.metacard.workspace.WorkspaceMetacardImpl in project ddf by codice.
the class TestAttributeMetacardFormatter method testFormatNonDefault.
@Test
public void testFormatNonDefault() {
String template = "%[attribute=id]";
String id = "the-id";
WorkspaceMetacardImpl workspaceMetacard = new WorkspaceMetacardImpl(id);
AttributeMetacardFormatter attributeMetacardFormatter = new AttributeMetacardFormatter("n/a");
String result = attributeMetacardFormatter.format(template, workspaceMetacard, 0L);
assertThat(result, is(id));
}
use of org.codice.ddf.catalog.ui.metacard.workspace.WorkspaceMetacardImpl in project ddf by codice.
the class TestWorkspaceServiceImpl method testGetWorkspaceMetacardsByWorkspaceId.
@Test
public void testGetWorkspaceMetacardsByWorkspaceId() throws UnsupportedQueryException, SourceUnavailableException, FederationException {
String id = "123";
String subject = "subject";
mockCatalogFrameworkQuery(id, subject);
Filter workspaceTagFilter = mockWorkspaceTagFilter();
Filter metacardIdFilter = mock(Filter.class);
when(filterService.buildMetacardIdFilter(id)).thenReturn(metacardIdFilter);
And andFilter = mock(And.class);
when(filterBuilder.allOf(metacardIdFilter, workspaceTagFilter)).thenReturn(andFilter);
Or orFilter = mock(Or.class);
when(filterBuilder.anyOf(Collections.singletonList(andFilter))).thenReturn(orFilter);
List<WorkspaceMetacardImpl> workspaceMetacards = workspaceService.getWorkspaceMetacards(Collections.singleton(id));
assertMetacardList(id, subject, workspaceMetacards);
}
use of org.codice.ddf.catalog.ui.metacard.workspace.WorkspaceMetacardImpl 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 org.codice.ddf.catalog.ui.metacard.workspace.WorkspaceMetacardImpl 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 org.codice.ddf.catalog.ui.metacard.workspace.WorkspaceMetacardImpl 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));
}
Aggregations