Search in sources :

Example 96 with ResultImpl

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);
}
Also used : Metacard(ddf.catalog.data.Metacard) SourceResponse(ddf.catalog.operation.SourceResponse) QueryRequest(ddf.catalog.operation.QueryRequest) SourceResponseImpl(ddf.catalog.operation.impl.SourceResponseImpl) ResultImpl(ddf.catalog.data.impl.ResultImpl) Test(org.junit.Test)

Example 97 with ResultImpl

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);
}
Also used : Metacard(ddf.catalog.data.Metacard) RegistryStore(org.codice.ddf.registry.api.internal.RegistryStore) SourceResponse(ddf.catalog.operation.SourceResponse) QueryRequest(ddf.catalog.operation.QueryRequest) SourceResponseImpl(ddf.catalog.operation.impl.SourceResponseImpl) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) ArrayList(java.util.ArrayList) ResultImpl(ddf.catalog.data.impl.ResultImpl) Test(org.junit.Test)

Example 98 with ResultImpl

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);
}
Also used : Metacard(ddf.catalog.data.Metacard) SourceResponse(ddf.catalog.operation.SourceResponse) QueryRequest(ddf.catalog.operation.QueryRequest) SourceResponseImpl(ddf.catalog.operation.impl.SourceResponseImpl) ResultImpl(ddf.catalog.data.impl.ResultImpl) Test(org.junit.Test)

Example 99 with ResultImpl

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()));
}
Also used : Metacard(ddf.catalog.data.Metacard) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) ResultImpl(ddf.catalog.data.impl.ResultImpl) PolicyResponse(ddf.catalog.plugin.PolicyResponse) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Example 100 with ResultImpl

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"));
}
Also used : Metacard(ddf.catalog.data.Metacard) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) QueryRequest(ddf.catalog.operation.QueryRequest) ResultImpl(ddf.catalog.data.impl.ResultImpl) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) Callable(java.util.concurrent.Callable) Test(org.junit.Test)

Aggregations

ResultImpl (ddf.catalog.data.impl.ResultImpl)159 Result (ddf.catalog.data.Result)114 Test (org.junit.Test)100 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)87 Metacard (ddf.catalog.data.Metacard)61 ArrayList (java.util.ArrayList)55 SourceResponse (ddf.catalog.operation.SourceResponse)50 QueryRequest (ddf.catalog.operation.QueryRequest)39 QueryResponse (ddf.catalog.operation.QueryResponse)31 SourceResponseImpl (ddf.catalog.operation.impl.SourceResponseImpl)31 QueryResponseImpl (ddf.catalog.operation.impl.QueryResponseImpl)29 BinaryContent (ddf.catalog.data.BinaryContent)26 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)21 MetacardTransformer (ddf.catalog.transform.MetacardTransformer)20 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)18 DAG (org.codice.alliance.nsili.common.UCO.DAG)17 File (java.io.File)14 Serializable (java.io.Serializable)12 QueryImpl (ddf.catalog.operation.impl.QueryImpl)11 FileOutputStream (java.io.FileOutputStream)10