use of ddf.catalog.data.impl.ResultImpl in project ddf by codice.
the class RefreshRegistryEntriesTest method testWriteRemoteUpdates.
@Test
public void testWriteRemoteUpdates() throws Exception {
Metacard localMcard = getPopulatedTestRegistryMetacard(TEST_METACARD_ID, RegistryObjectMetacardType.REGISTRY_ID, 0, true);
Metacard remoteMcard = getPopulatedTestRegistryMetacard("remoteMcardId", RegistryObjectMetacardType.REGISTRY_ID, 1000L);
when(federationAdminService.getInternalRegistryMetacards()).thenReturn(Collections.singletonList(localMcard));
SourceResponse response = new SourceResponseImpl(null, Collections.singletonList(new ResultImpl(remoteMcard)));
when(registryStore.query(any(QueryRequest.class))).thenReturn(response);
refreshRegistryEntries.setRegistryStores(Collections.singletonList(registryStore));
when(registryStore.isPullAllowed()).thenReturn(true);
when(registryStore.isAvailable()).thenReturn(true);
refreshRegistryEntries.refreshRegistryEntries();
verify(federationAdminService).updateRegistryEntry(remoteMcard);
}
use of ddf.catalog.data.impl.ResultImpl in project ddf by codice.
the class RefreshRegistryEntriesTest method testMultipleStores.
@Test
public void testMultipleStores() throws Exception {
Metacard mcard = getPopulatedTestRegistryMetacard();
RegistryStore registryStore2 = mock(RegistryStore.class);
when(registryStore2.getId()).thenReturn("id2");
when(registryStore2.getRegistryId()).thenReturn("regId2");
when(registryStore2.isAvailable()).thenReturn(true);
when(registryStore2.isPullAllowed()).thenReturn(true);
SourceResponse response = new SourceResponseImpl(null, Collections.singletonList(new ResultImpl(mcard)));
when(registryStore2.query(any(QueryRequest.class))).thenReturn(response);
when(registryStore.query(any(QueryRequest.class))).thenThrow(new UnsupportedQueryException());
when(registryStore.isAvailable()).thenReturn(true);
when(registryStore.isPullAllowed()).thenReturn(true);
when(registryStore2.query(any(QueryRequest.class))).thenReturn(response);
List<RegistryStore> stores = new ArrayList<>();
stores.add(registryStore);
stores.add(registryStore2);
refreshRegistryEntries.setRegistryStores(stores);
refreshRegistryEntries.refreshRegistryEntries();
verify(federationAdminService).addRegistryEntries(Collections.singletonList(mcard), null);
}
use of ddf.catalog.data.impl.ResultImpl in project ddf by codice.
the class RefreshRegistryEntriesTest method testCreateRemoteEntriesPullNotAllowed.
@Test
public void testCreateRemoteEntriesPullNotAllowed() throws Exception {
Metacard remoteMetacard = getPopulatedTestRegistryMetacard();
when(federationAdminService.getInternalRegistryMetacards()).thenReturn(Collections.emptyList());
SourceResponse response = new SourceResponseImpl(null, Collections.singletonList(new ResultImpl(remoteMetacard)));
when(registryStore.query(any(QueryRequest.class))).thenReturn(response);
refreshRegistryEntries.setRegistryStores(Collections.singletonList(registryStore));
when(registryStore.isPullAllowed()).thenReturn(false);
when(registryStore.isAvailable()).thenReturn(true);
refreshRegistryEntries.refreshRegistryEntries();
verify(federationAdminService, never()).addRegistryEntries(Collections.singletonList(remoteMetacard), null);
}
use of ddf.catalog.data.impl.ResultImpl in project ddf by codice.
the class RegistryPolicyPluginTest method testReadRegistryOperations.
@Test
public void testReadRegistryOperations() throws Exception {
RegistryPolicyPlugin rpp = createRegistryPlugin();
rpp.setRegistryBypassPolicyStrings(Collections.singletonList("role=system-admin"));
rpp.setReadAccessPolicyStrings(Collections.singletonList("role=guest"));
Metacard mcard = new MetacardImpl();
mcard.setAttribute(new AttributeImpl(Metacard.TAGS, RegistryConstants.REGISTRY_TAG));
mcard.setAttribute(new AttributeImpl(RegistryObjectMetacardType.REGISTRY_ID, "validId"));
mcard.setAttribute(new AttributeImpl(Metacard.ID, "1234567890abcdefg987654321"));
PolicyResponse response = rpp.processPostQuery(new ResultImpl(mcard), null);
assertThat(response.itemPolicy(), equalTo(rpp.getReadAccessPolicy()));
}
use of ddf.catalog.data.impl.ResultImpl in project ddf by codice.
the class RegistryIdPostIngestPluginTest method testInit.
@Test
public void testInit() throws Exception {
Metacard metacard = getDefaultMetacard();
QueryResponseImpl response = new QueryResponseImpl(null, Collections.singletonList(new ResultImpl(metacard)), 1L);
when(security.runAsAdminWithException(any(PrivilegedExceptionAction.class))).thenAnswer(invocation -> ((PrivilegedExceptionAction) invocation.getArguments()[0]).run());
when(security.runWithSubjectOrElevate(any(Callable.class))).thenAnswer(invocation -> ((Callable) invocation.getArguments()[0]).call());
when(framework.query(any(QueryRequest.class))).thenReturn(response);
registryIdPostIngestPlugin.init();
assertThat(registryIdPostIngestPlugin.getRegistryIds().size(), equalTo(1));
assertThat(registryIdPostIngestPlugin.getRegistryIds().iterator().next(), equalTo("regId"));
}
Aggregations