Skip to content
Snippets Groups Projects
Commit e254d811 authored by MZhu9's avatar MZhu9
Browse files

correct shallow copy bug

parent 535c51c8
No related branches found
No related tags found
1 merge request!628resolve the bug of "/reindex/record API returns 500 when there is no not-found records"
Pipeline #215170 failed
......@@ -147,8 +147,9 @@ public class StorageServiceImpl implements StorageService {
}
try {
Records records = this.objectMapper.readValue(response.getBody(), Records.class);
ids.removeAll(records.getRecords().stream().map(Records.Entity::getId).collect(Collectors.toList()));
records.setNotFound(ids);
List<String> notFoundRecordIds = new ArrayList<>(ids);
notFoundRecordIds.removeAll(records.getRecords().stream().map(Records.Entity::getId).collect(Collectors.toList()));
records.setNotFound(notFoundRecordIds);
return records;
} catch (JsonProcessingException e) {
throw new AppException(RequestStatus.INVALID_RECORD, "Invalid request", "Successful Storage service response with wrong json", e);
......
......@@ -190,6 +190,43 @@ public class StorageServiceImplTest {
@Test
public void should_returnStorageRecords_givenRecordIds_getValidStorageRecordsTest() throws URISyntaxException {
String validDataFromStorage = "{\"records\":[{\"id\":\"tenant1:doc:1dbf528e0e0549cab7a08f29fbfc8465\", \"version\":1, \"kind\":\"tenant:test:test:1.0.0\"}," +
"{\"id\":\"tenant1:doc:15e790a69beb4d789b1f979e2af2e813\", \"version\":1, \"kind\":\"tenant:test:test:1.0.0\"}]}";
HttpResponse httpResponse = mock(HttpResponse.class);
when(httpResponse.getBody()).thenReturn(validDataFromStorage);
when(configurationProperties.getStorageQueryRecordHost()).thenReturn("storageUrl");
when(this.httpClientHandler.sendRequest(any(), any())).thenReturn(httpResponse);
List<String> idsCopy = new ArrayList<>();
idsCopy.addAll(ids);
Records storageRecords = this.sut.getStorageRecords(idsCopy);
assertEquals(2, storageRecords.getRecords().size());
assertEquals(0, storageRecords.getNotFound().size());
}
@Test
public void should_returnStorageRecords_givenRecordIds_allFound_getValidStorageRecordsTest() throws URISyntaxException {
String validDataFromStorage = "{\"records\":[]}";
HttpResponse httpResponse = mock(HttpResponse.class);
when(httpResponse.getBody()).thenReturn(validDataFromStorage);
when(configurationProperties.getStorageQueryRecordHost()).thenReturn("storageUrl");
when(this.httpClientHandler.sendRequest(any(), any())).thenReturn(httpResponse);
List<String> idsCopy = new ArrayList<>();
idsCopy.addAll(ids);
Records storageRecords = this.sut.getStorageRecords(idsCopy);
assertEquals(0, storageRecords.getRecords().size());
assertEquals(2, storageRecords.getNotFound().size());
}
@Test
public void should_returnStorageRecords_givenRecordIds_noneFound_getValidStorageRecordsTest() throws URISyntaxException {
String validDataFromStorage = "{\"records\":[{\"id\":\"tenant1:doc:1dbf528e0e0549cab7a08f29fbfc8465\", \"version\":1, \"kind\":\"tenant:test:test:1.0.0\"}]}";
HttpResponse httpResponse = mock(HttpResponse.class);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment