Search in sources :

Example 36 with UpdateResponse

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

the class SolrProviderTest method testUpdateOperationSimple.

/**
     * Testing that if records are properly updated.
     *
     * @throws IngestException
     * @throws UnsupportedQueryException
     */
@Test
public void testUpdateOperationSimple() throws IngestException, UnsupportedQueryException {
    // Single Update
    deleteAllIn(provider);
    MockMetacard metacard = new MockMetacard(Library.getFlagstaffRecord());
    CreateResponse createResponse = create(metacard);
    String id = createResponse.getCreatedMetacards().get(0).getId();
    metacard.setContentTypeName("newContentType");
    UpdateResponse response = update(id, metacard);
    Update update = response.getUpdatedMetacards().get(0);
    Metacard newMetacard = update.getNewMetacard();
    Metacard oldMetacard = update.getOldMetacard();
    assertEquals(1, response.getUpdatedMetacards().size());
    assertEquals("newContentType", newMetacard.getContentTypeName());
    assertEquals(MockMetacard.DEFAULT_TYPE, oldMetacard.getContentTypeName());
}
Also used : UpdateResponse(ddf.catalog.operation.UpdateResponse) Metacard(ddf.catalog.data.Metacard) CreateResponse(ddf.catalog.operation.CreateResponse) Matchers.containsString(org.hamcrest.Matchers.containsString) Update(ddf.catalog.operation.Update) Test(org.junit.Test)

Example 37 with UpdateResponse

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

the class SolrProviderTest method testUpdateEmptyList.

/**
     * Tests empty list in UpdateRequest
     *
     * @throws IngestException
     * @throws UnsupportedQueryException
     */
@Test
public void testUpdateEmptyList() throws IngestException, UnsupportedQueryException {
    deleteAllIn(provider);
    UpdateResponse response = provider.update(new UpdateRequestImpl(new ArrayList<Entry<Serializable, Metacard>>(), Metacard.ID, null));
    assertEquals(0, response.getUpdatedMetacards().size());
}
Also used : UpdateResponse(ddf.catalog.operation.UpdateResponse) Serializable(java.io.Serializable) Metacard(ddf.catalog.data.Metacard) ArrayList(java.util.ArrayList) UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl) Test(org.junit.Test)

Example 38 with UpdateResponse

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

the class TestCswEndpoint method testUpdateTransactionWithConstraint.

@Test
public void testUpdateTransactionWithConstraint() throws CswException, FederationException, IngestException, SourceUnavailableException, UnsupportedQueryException {
    List<Result> results = new ArrayList<>();
    MetacardImpl firstResult = new MetacardImpl();
    firstResult.setId("123");
    firstResult.setTitle("Title one");
    firstResult.setAttribute("subject", "Subject one");
    results.add(new ResultImpl(firstResult));
    MetacardImpl secondResult = new MetacardImpl();
    secondResult.setId("789");
    secondResult.setTitle("Title two");
    secondResult.setAttribute("subject", "Subject two");
    results.add(new ResultImpl(secondResult));
    QueryResponse queryResponse = new QueryResponseImpl(null, results, results.size());
    doReturn(queryResponse).when(catalogFramework).query(any(QueryRequest.class));
    List<Update> updatedMetacards = new ArrayList<>();
    updatedMetacards.add(new UpdateImpl(new MetacardImpl(), new MetacardImpl()));
    updatedMetacards.add(new UpdateImpl(new MetacardImpl(), new MetacardImpl()));
    UpdateResponse updateResponse = new UpdateResponseImpl(null, null, updatedMetacards);
    doReturn(updateResponse).when(catalogFramework).update(any(UpdateRequest.class));
    Map<String, Serializable> recordProperties = new HashMap<>();
    recordProperties.put("title", "foo");
    recordProperties.put("subject", "bar");
    QueryConstraintType constraint = new QueryConstraintType();
    constraint.setCqlText("title = 'fake'");
    UpdateAction updateAction = new UpdateAction(recordProperties, CswConstants.CSW_RECORD, "", constraint, DefaultCswRecordMap.getDefaultCswRecordMap().getPrefixToUriMapping());
    CswTransactionRequest updateRequest = new CswTransactionRequest();
    updateRequest.getUpdateActions().add(updateAction);
    updateRequest.setVersion(CswConstants.VERSION_2_0_2);
    updateRequest.setService(CswConstants.CSW);
    updateRequest.setVerbose(false);
    TransactionResponseType response = csw.transaction(updateRequest);
    assertThat(response, notNullValue());
    TransactionSummaryType summary = response.getTransactionSummary();
    assertThat(summary, notNullValue());
    assertThat(summary.getTotalDeleted().intValue(), is(0));
    assertThat(summary.getTotalInserted().intValue(), is(0));
    assertThat(summary.getTotalUpdated().intValue(), is(2));
    verifyMarshalResponse(response, "net.opengis.cat.csw.v_2_0_2:net.opengis.filter.v_1_1_0:net.opengis.gml.v_3_1_1", cswQnameOutPutSchema);
    ArgumentCaptor<UpdateRequest> updateRequestArgumentCaptor = ArgumentCaptor.forClass(UpdateRequest.class);
    verify(catalogFramework, times(1)).update(updateRequestArgumentCaptor.capture());
    UpdateRequest actualUpdateRequest = updateRequestArgumentCaptor.getValue();
    List<Map.Entry<Serializable, Metacard>> updates = actualUpdateRequest.getUpdates();
    assertThat(updates.size(), is(2));
    Metacard firstUpdate = updates.get(0).getValue();
    assertThat(firstUpdate.getId(), is("123"));
    assertThat(firstUpdate.getTitle(), is("foo"));
    assertThat(firstUpdate.getAttribute("subject").getValue(), is("bar"));
    Metacard secondUpdate = updates.get(1).getValue();
    assertThat(secondUpdate.getId(), is("789"));
    assertThat(secondUpdate.getTitle(), is("foo"));
    assertThat(secondUpdate.getAttribute("subject").getValue(), is("bar"));
}
Also used : UpdateImpl(ddf.catalog.operation.impl.UpdateImpl) Serializable(java.io.Serializable) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ResultImpl(ddf.catalog.data.impl.ResultImpl) Update(ddf.catalog.operation.Update) TransactionSummaryType(net.opengis.cat.csw.v_2_0_2.TransactionSummaryType) QueryConstraintType(net.opengis.cat.csw.v_2_0_2.QueryConstraintType) Result(ddf.catalog.data.Result) TransactionResponseType(net.opengis.cat.csw.v_2_0_2.TransactionResponseType) UpdateResponse(ddf.catalog.operation.UpdateResponse) UpdateResponseImpl(ddf.catalog.operation.impl.UpdateResponseImpl) QueryRequest(ddf.catalog.operation.QueryRequest) UpdateRequest(ddf.catalog.operation.UpdateRequest) UpdateAction(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.UpdateAction) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) Metacard(ddf.catalog.data.Metacard) CswTransactionRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.transaction.CswTransactionRequest) QueryResponse(ddf.catalog.operation.QueryResponse) Test(org.junit.Test)

Example 39 with UpdateResponse

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

the class CatalogMetricsTest method catalogUpdateMetric.

@Test
public void catalogUpdateMetric() throws Exception {
    UpdateRequest request = mock(UpdateRequest.class);
    UpdateResponse response = mock(UpdateResponse.class);
    List<Update> updatedList = mock(List.class);
    when(updatedList.size()).thenReturn(100);
    when(response.getRequest()).thenReturn(request);
    when(response.getUpdatedMetacards()).thenReturn(updatedList);
    underTest.process(response);
    assertThat(underTest.updatedMetacards.getCount(), is(100L));
}
Also used : UpdateResponse(ddf.catalog.operation.UpdateResponse) UpdateRequest(ddf.catalog.operation.UpdateRequest) Update(ddf.catalog.operation.Update) Test(org.junit.Test)

Example 40 with UpdateResponse

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

the class CachingFederationStrategyTest method testProcessUpdateResponseRequestNotLocal.

@Test
public void testProcessUpdateResponseRequestNotLocal() throws Exception {
    Map<String, Serializable> testMap = new HashMap<>();
    testMap.put(Constants.SERVICE_TITLE, MOCK_RESPONSE_TITLE);
    testMap.put(Constants.LOCAL_DESTINATION_KEY, false);
    UpdateResponse response = mock(UpdateResponseImpl.class);
    UpdateRequest request = mock(UpdateRequestImpl.class);
    when(request.hasProperties()).thenReturn(true);
    when(request.getProperties()).thenReturn(testMap);
    when(response.getRequest()).thenReturn(request);
    assertThat(response, is(strategy.process(response)));
}
Also used : UpdateResponse(ddf.catalog.operation.UpdateResponse) Serializable(java.io.Serializable) HashMap(java.util.HashMap) UpdateRequest(ddf.catalog.operation.UpdateRequest) Test(org.junit.Test)

Aggregations

UpdateResponse (ddf.catalog.operation.UpdateResponse)57 Test (org.junit.Test)38 Metacard (ddf.catalog.data.Metacard)36 HashMap (java.util.HashMap)24 UpdateRequest (ddf.catalog.operation.UpdateRequest)22 Serializable (java.io.Serializable)22 ArrayList (java.util.ArrayList)22 Update (ddf.catalog.operation.Update)21 UpdateRequestImpl (ddf.catalog.operation.impl.UpdateRequestImpl)15 List (java.util.List)15 UpdateStorageRequest (ddf.catalog.content.operation.UpdateStorageRequest)14 CreateResponse (ddf.catalog.operation.CreateResponse)13 DeletedMetacard (ddf.catalog.core.versioning.DeletedMetacard)11 Map (java.util.Map)11 ContentItem (ddf.catalog.content.data.ContentItem)10 UpdateStorageResponse (ddf.catalog.content.operation.UpdateStorageResponse)10 Result (ddf.catalog.data.Result)10 IngestException (ddf.catalog.source.IngestException)10 DeleteResponse (ddf.catalog.operation.DeleteResponse)9 UpdateResponseImpl (ddf.catalog.operation.impl.UpdateResponseImpl)9