Search in sources :

Example 66 with ResultImpl

use of ddf.catalog.data.impl.ResultImpl in project ddf by codice.

the class RefreshRegistryEntriesTest method testNoUpdatesOnOlder.

@Test
public void testNoUpdatesOnOlder() throws Exception {
    MetacardImpl localMcard = getPopulatedTestRegistryMetacard(TEST_METACARD_ID, RegistryObjectMetacardType.REGISTRY_ID, 0, true);
    Metacard remoteMcard = getPopulatedTestRegistryMetacard("remoteMcardId", RegistryObjectMetacardType.REGISTRY_ID, -5000L);
    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, never()).updateRegistryEntry(any(Metacard.class));
}
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) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Example 67 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 68 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 69 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 70 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)

Aggregations

ResultImpl (ddf.catalog.data.impl.ResultImpl)91 Result (ddf.catalog.data.Result)59 Test (org.junit.Test)56 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)47 Metacard (ddf.catalog.data.Metacard)46 ArrayList (java.util.ArrayList)35 SourceResponse (ddf.catalog.operation.SourceResponse)30 QueryRequest (ddf.catalog.operation.QueryRequest)28 SourceResponseImpl (ddf.catalog.operation.impl.SourceResponseImpl)20 QueryResponseImpl (ddf.catalog.operation.impl.QueryResponseImpl)18 QueryResponse (ddf.catalog.operation.QueryResponse)15 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)15 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)12 BinaryContent (ddf.catalog.data.BinaryContent)10 MetacardTransformer (ddf.catalog.transform.MetacardTransformer)10 QueryImpl (ddf.catalog.operation.impl.QueryImpl)9 Query (ddf.catalog.operation.Query)7 PolicyResponse (ddf.catalog.plugin.PolicyResponse)7 File (java.io.File)7 Before (org.junit.Before)7