Search in sources :

Example 76 with UpdateResponse

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

the class HistorianTest method testNullContentItemStorageReadRequest.

@Test
public void testNullContentItemStorageReadRequest() throws StorageException, UnsupportedQueryException, SourceUnavailableException, IngestException, URISyntaxException {
    List<Metacard> metacards = getMetacardUpdatePair();
    // Parameters for historian
    UpdateStorageRequest storageRequest = mock(UpdateStorageRequest.class);
    UpdateStorageResponse storageResponse = mock(UpdateStorageResponse.class);
    UpdateResponse updateResponse = mock(UpdateResponse.class);
    // Make content item null
    storageProvider.storageMap.put(METACARD_ID, null);
    mockQuery(metacards.get(1));
    historian.version(storageRequest, storageResponse, updateResponse);
    // Verify that the content item DIDN't updated
    ReadStorageRequest request = mock(ReadStorageRequest.class);
    when(request.getResourceUri()).thenReturn(new URI(RESOURCE_URI));
    ContentItem item = storageProvider.read(request).getContentItem();
    assertThat(item, nullValue());
}
Also used : UpdateResponse(ddf.catalog.operation.UpdateResponse) DeletedMetacard(ddf.catalog.core.versioning.DeletedMetacard) Metacard(ddf.catalog.data.Metacard) ReadStorageRequest(ddf.catalog.content.operation.ReadStorageRequest) UpdateStorageResponse(ddf.catalog.content.operation.UpdateStorageResponse) UpdateStorageRequest(ddf.catalog.content.operation.UpdateStorageRequest) URI(java.net.URI) ContentItem(ddf.catalog.content.data.ContentItem) Test(org.junit.Test)

Example 77 with UpdateResponse

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

the class HistorianTest method testBadContentItemSize.

@Test
public void testBadContentItemSize() throws StorageException, UnsupportedQueryException, SourceUnavailableException, IngestException, URISyntaxException, IOException {
    // The metacard and updated metacard
    List<Metacard> metacards = getMetacardUpdatePair();
    // Parameters for historian
    UpdateStorageRequest storageRequest = mock(UpdateStorageRequest.class);
    UpdateStorageResponse storageResponse = mock(UpdateStorageResponse.class);
    UpdateResponse updateResponse = mock(UpdateResponse.class);
    Update update1 = mock(Update.class);
    when(update1.getOldMetacard()).thenReturn(metacards.get(0));
    when(updateResponse.getUpdatedMetacards()).thenReturn(ImmutableList.of(update1));
    storeMetacard(metacards.get(0));
    // send a request to update the metacard
    updateMetacard(storageRequest, storageResponse, metacards.get(1));
    storageProvider.update(storageRequest);
    when(storageProvider.storageMap.get(RESOURCE_URI).getSize()).thenThrow(IOException.class);
    mockQuery(metacards.get(1));
    historian.version(storageRequest, storageResponse, updateResponse);
    // Verify that the metacard updated
    Metacard update = readMetacard();
    assertThat(update, equalTo(metacards.get(1)));
}
Also used : UpdateResponse(ddf.catalog.operation.UpdateResponse) DeletedMetacard(ddf.catalog.core.versioning.DeletedMetacard) Metacard(ddf.catalog.data.Metacard) UpdateStorageResponse(ddf.catalog.content.operation.UpdateStorageResponse) UpdateStorageRequest(ddf.catalog.content.operation.UpdateStorageRequest) Update(ddf.catalog.operation.Update) Test(org.junit.Test)

Example 78 with UpdateResponse

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

the class HistorianTest method testUpdateStorageResponseSetSkipFlag.

@Test
public void testUpdateStorageResponseSetSkipFlag() throws SourceUnavailableException, IngestException, StorageException, UnsupportedQueryException {
    Map<String, Serializable> storageRequestProperties = new HashMap<>();
    Map<String, Serializable> storageResponseProperties = new HashMap<>();
    // The metacard and updated metacard
    List<Metacard> metacards = getMetacardUpdatePair();
    // Parameters for historian
    UpdateStorageRequest storageRequest = mock(UpdateStorageRequest.class);
    when(storageRequest.getProperties()).thenReturn(storageRequestProperties);
    UpdateStorageResponse storageResponse = mock(UpdateStorageResponse.class);
    when(storageResponse.getProperties()).thenReturn(storageResponseProperties);
    UpdateResponse updateResponse = mock(UpdateResponse.class);
    Update update1 = mock(Update.class);
    when(update1.getOldMetacard()).thenReturn(metacards.get(0));
    when(updateResponse.getUpdatedMetacards()).thenReturn(ImmutableList.of(update1));
    storeMetacard(metacards.get(0));
    // send a request to update the metacard
    updateMetacard(storageRequest, storageResponse, metacards.get(1));
    storageProvider.update(storageRequest);
    mockQuery(metacards.get(1));
    historian.version(storageRequest, storageResponse, updateResponse);
    assertThat(storageRequestProperties, hasEntry(MetacardVersion.SKIP_VERSIONING, true));
    assertThat(storageResponseProperties, hasEntry(MetacardVersion.SKIP_VERSIONING, true));
}
Also used : UpdateResponse(ddf.catalog.operation.UpdateResponse) Serializable(java.io.Serializable) DeletedMetacard(ddf.catalog.core.versioning.DeletedMetacard) Metacard(ddf.catalog.data.Metacard) HashMap(java.util.HashMap) UpdateStorageResponse(ddf.catalog.content.operation.UpdateStorageResponse) UpdateStorageRequest(ddf.catalog.content.operation.UpdateStorageRequest) Update(ddf.catalog.operation.Update) Test(org.junit.Test)

Example 79 with UpdateResponse

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

the class HistorianTest method testUpdateResponse.

@Test
public void testUpdateResponse() throws Exception {
    UpdateResponse updateResponse = createUpdateResponse(null);
    List<Update> updateList = createUpdatedMetacardList();
    when(updateResponse.getUpdatedMetacards()).thenReturn(updateList);
    historian.version(updateResponse);
    ArgumentCaptor<CreateRequest> createRequest = ArgumentCaptor.forClass(CreateRequest.class);
    verify(catalogProvider).create(createRequest.capture());
    Metacard versionedMetacard = createRequest.getValue().getMetacards().get(0);
    assertThat(versionedMetacard.getAttribute(MetacardVersion.VERSION_OF_ID).getValue(), equalTo(METACARD_ID));
}
Also used : UpdateResponse(ddf.catalog.operation.UpdateResponse) DeletedMetacard(ddf.catalog.core.versioning.DeletedMetacard) Metacard(ddf.catalog.data.Metacard) CreateRequest(ddf.catalog.operation.CreateRequest) Update(ddf.catalog.operation.Update) Test(org.junit.Test)

Aggregations

UpdateResponse (ddf.catalog.operation.UpdateResponse)79 Test (org.junit.Test)56 Metacard (ddf.catalog.data.Metacard)47 Update (ddf.catalog.operation.Update)32 UpdateRequest (ddf.catalog.operation.UpdateRequest)31 ArrayList (java.util.ArrayList)31 Serializable (java.io.Serializable)27 HashMap (java.util.HashMap)26 UpdateRequestImpl (ddf.catalog.operation.impl.UpdateRequestImpl)20 CreateResponse (ddf.catalog.operation.CreateResponse)19 List (java.util.List)18 UpdateStorageRequest (ddf.catalog.content.operation.UpdateStorageRequest)15 Result (ddf.catalog.data.Result)14 Map (java.util.Map)14 UpdateResponseImpl (ddf.catalog.operation.impl.UpdateResponseImpl)13 IngestException (ddf.catalog.source.IngestException)13 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)12 DeletedMetacard (ddf.catalog.core.versioning.DeletedMetacard)11 DeleteResponse (ddf.catalog.operation.DeleteResponse)11 QueryImpl (ddf.catalog.operation.impl.QueryImpl)11