Search in sources :

Example 21 with DeleteResponse

use of ddf.catalog.operation.DeleteResponse in project ddf by codice.

the class FilterPluginTest method testPluginFilterDeleteBad.

@Test
public void testPluginFilterDeleteBad() throws StopProcessingException {
    DeleteResponse response = plugin.processPostDelete(badDeleteResponse);
    assertThat(response.getDeletedMetacards().size(), is(0));
}
Also used : DeleteResponse(ddf.catalog.operation.DeleteResponse) Test(org.junit.Test)

Example 22 with DeleteResponse

use of ddf.catalog.operation.DeleteResponse in project ddf by codice.

the class CachingFederationStrategyTest method testProcessDeleteResponseSolrServiceTitle.

@Test
public void testProcessDeleteResponseSolrServiceTitle() throws Exception {
    Map<String, Serializable> testMap = new HashMap<>();
    SolrCacheSource cacheSource = new SolrCacheSource(new SolrCache(clientAdaptor));
    testMap.put(Constants.SERVICE_TITLE, cacheSource.getId());
    DeleteResponse response = mock(DeleteResponse.class);
    DeleteRequest request = mock(DeleteRequest.class);
    when(request.hasProperties()).thenReturn(true);
    when(request.getProperties()).thenReturn(testMap);
    when(response.getRequest()).thenReturn(request);
    assertThat(response, is(strategy.process(response)));
}
Also used : Serializable(java.io.Serializable) DeleteResponse(ddf.catalog.operation.DeleteResponse) HashMap(java.util.HashMap) DeleteRequest(ddf.catalog.operation.DeleteRequest) Test(org.junit.Test)

Example 23 with DeleteResponse

use of ddf.catalog.operation.DeleteResponse in project ddf by codice.

the class MockMemoryProvider method delete.

@Override
public DeleteResponse delete(DeleteRequest deleteRequest) {
    hasReceivedDelete = true;
    @SuppressWarnings("unchecked") List<String> ids = (List<String>) deleteRequest.getAttributeValues();
    Map<String, Serializable> properties = new HashMap<>();
    List<Metacard> returnedMetacards = new ArrayList<>(ids.size());
    for (int i = 0; i < ids.size(); i++) {
        String id = (String) ids.get(i);
        UUID curUUID = UUID.fromString(id);
        if (store.containsKey(curUUID.toString())) {
            Metacard card = store.remove(curUUID.toString());
            if (card != null) {
                returnedMetacards.add(card);
            }
        }
    }
    DeleteResponse response = new DeleteResponseImpl(deleteRequest, properties, returnedMetacards);
    return response;
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Metacard(ddf.catalog.data.Metacard) DeleteResponse(ddf.catalog.operation.DeleteResponse) DeleteResponseImpl(ddf.catalog.operation.impl.DeleteResponseImpl) List(java.util.List) ArrayList(java.util.ArrayList) UUID(java.util.UUID)

Example 24 with DeleteResponse

use of ddf.catalog.operation.DeleteResponse in project ddf by codice.

the class CatalogBackupPluginTest method getDeleteResponse.

private DeleteResponse getDeleteResponse(List<String> metacardIds) {
    MetacardType mockMetacardType = mock(MetacardType.class);
    when(mockMetacardType.getName()).thenReturn(MetacardType.DEFAULT_METACARD_TYPE_NAME);
    List<Metacard> deletedMetacards = new ArrayList<>(metacardIds.size());
    for (String metacardId : metacardIds) {
        Metacard mockMetacard = mock(Metacard.class);
        when(mockMetacard.getId()).thenReturn(metacardId);
        when(mockMetacard.getMetacardType()).thenReturn(mockMetacardType);
        deletedMetacards.add(mockMetacard);
    }
    DeleteRequest request = mock(DeleteRequest.class);
    DeleteResponse mockDeleteResponse = mock(DeleteResponse.class);
    when(mockDeleteResponse.getDeletedMetacards()).thenReturn(deletedMetacards);
    when(mockDeleteResponse.getRequest()).thenReturn(request);
    return mockDeleteResponse;
}
Also used : Metacard(ddf.catalog.data.Metacard) DeleteResponse(ddf.catalog.operation.DeleteResponse) ArrayList(java.util.ArrayList) DeleteRequest(ddf.catalog.operation.DeleteRequest) MetacardType(ddf.catalog.data.MetacardType)

Example 25 with DeleteResponse

use of ddf.catalog.operation.DeleteResponse in project ddf by codice.

the class ContentProducerDataAccessObjectTest method testCreateContentItem.

@Test
public void testCreateContentItem() throws Exception {
    File testFile = temporaryFolder.newFile("testCreateContentItem.txt");
    //make sample list of metacard and set of keys
    List<MetacardImpl> metacardList = ImmutableList.of(new MetacardImpl());
    Set<String> keys = ImmutableSet.of(String.valueOf(testFile.getAbsolutePath().hashCode()));
    //mock out responses for create, delete, update
    CreateResponse mockCreateResponse = mock(CreateResponse.class);
    doReturn(metacardList).when(mockCreateResponse).getCreatedMetacards();
    DeleteResponse mockDeleteResponse = mock(DeleteResponse.class);
    doReturn(metacardList).when(mockDeleteResponse).getDeletedMetacards();
    UpdateResponse mockUpdateResponse = mock(UpdateResponse.class);
    doReturn(metacardList).when(mockUpdateResponse).getUpdatedMetacards();
    //setup mockFileSystemPersistenceProvider
    FileSystemPersistenceProvider mockFileSystemPersistenceProvider = mock(FileSystemPersistenceProvider.class);
    doReturn(keys).when(mockFileSystemPersistenceProvider).loadAllKeys();
    doReturn("sample").when(mockFileSystemPersistenceProvider).loadFromPersistence(any(String.class));
    //setup mockCatalogFramework
    CatalogFramework mockCatalogFramework = mock(CatalogFramework.class);
    doReturn(mockCreateResponse).when(mockCatalogFramework).create(any(CreateStorageRequest.class));
    doReturn(mockDeleteResponse).when(mockCatalogFramework).delete(any(DeleteRequest.class));
    //setup mockComponent
    ContentComponent mockComponent = mock(ContentComponent.class);
    doReturn(mockCatalogFramework).when(mockComponent).getCatalogFramework();
    //setup mockEndpoint
    ContentEndpoint mockEndpoint = mock(ContentEndpoint.class);
    doReturn(mockComponent).when(mockEndpoint).getComponent();
    WatchEvent.Kind<Path> kind;
    String mimeType = "txt";
    Map<String, Object> headers = new HashedMap();
    Map<String, Serializable> attributeOverrides = new HashMap<>();
    attributeOverrides.put("example", ImmutableList.of("something", "something1"));
    attributeOverrides.put("example2", ImmutableList.of("something2"));
    headers.put(Constants.ATTRIBUTE_OVERRIDES_KEY, attributeOverrides);
    kind = StandardWatchEventKinds.ENTRY_CREATE;
    contentProducerDataAccessObject.createContentItem(mockFileSystemPersistenceProvider, mockEndpoint, testFile, kind, mimeType, headers);
    kind = StandardWatchEventKinds.ENTRY_DELETE;
    contentProducerDataAccessObject.createContentItem(mockFileSystemPersistenceProvider, mockEndpoint, testFile, kind, mimeType, headers);
    kind = StandardWatchEventKinds.ENTRY_MODIFY;
    contentProducerDataAccessObject.createContentItem(mockFileSystemPersistenceProvider, mockEndpoint, testFile, kind, mimeType, headers);
}
Also used : Path(java.nio.file.Path) Serializable(java.io.Serializable) HashMap(java.util.HashMap) CreateResponse(ddf.catalog.operation.CreateResponse) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) UpdateResponse(ddf.catalog.operation.UpdateResponse) DeleteResponse(ddf.catalog.operation.DeleteResponse) CatalogFramework(ddf.catalog.CatalogFramework) WatchEvent(java.nio.file.WatchEvent) HashedMap(org.apache.commons.collections.map.HashedMap) GenericFile(org.apache.camel.component.file.GenericFile) File(java.io.File) DeleteRequest(ddf.catalog.operation.DeleteRequest) CreateStorageRequest(ddf.catalog.content.operation.CreateStorageRequest) Test(org.junit.Test)

Aggregations

DeleteResponse (ddf.catalog.operation.DeleteResponse)54 Test (org.junit.Test)37 Metacard (ddf.catalog.data.Metacard)23 DeleteRequest (ddf.catalog.operation.DeleteRequest)23 ArrayList (java.util.ArrayList)19 DeleteRequestImpl (ddf.catalog.operation.impl.DeleteRequestImpl)18 HashMap (java.util.HashMap)17 Serializable (java.io.Serializable)15 DeleteResponseImpl (ddf.catalog.operation.impl.DeleteResponseImpl)14 CreateResponse (ddf.catalog.operation.CreateResponse)13 List (java.util.List)11 QueryResponse (ddf.catalog.operation.QueryResponse)9 QueryRequest (ddf.catalog.operation.QueryRequest)8 IngestException (ddf.catalog.source.IngestException)8 Result (ddf.catalog.data.Result)7 UpdateResponse (ddf.catalog.operation.UpdateResponse)7 QueryImpl (ddf.catalog.operation.impl.QueryImpl)7 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)7 CatalogFramework (ddf.catalog.CatalogFramework)6 Update (ddf.catalog.operation.Update)6