@Test public void retrieveMultipleObjectsFromStorage_addressesInStorage_returnsAddresses() { GetHistoryAddressesRequest getHistoryAddressesRequest = AddressTestUtils.generateGetHistoryAddressesRequest( null, null, addressDataInStorage1, addressDataInStorage2); when(getHistoryAddressesRequestCrypto.verifySignature(getHistoryAddressesRequest)).thenReturn(true); mockGetMultiObjectsFromDb(true, ElasticSearchData.ADDRESSES, generateInStorageList(Boolean.TRUE, Boolean.TRUE), addressDataInStorage1, addressDataInStorage2); mockGetMultiObjectsFromDb(false, ElasticSearchData.ADDRESSES, generateInStorageList(Boolean.TRUE, Boolean.TRUE), addressDataInStorage1, addressDataInStorage2); ResponseEntity<IResponse> actualResponse = addressStorageService.retrieveMultipleObjectsFromStorage(getHistoryAddressesRequest); ResponseEntity<IResponse> expectedResponse = generateExpectedResponse(generateInStorageList(Boolean.TRUE, Boolean.TRUE), addressDataInStorage1, addressDataInStorage2); checkResponseEquality(expectedResponse, actualResponse); }
public ResponseEntity<IResponse> retrieveMultipleObjectsFromStorage(GetHistoryAddressesRequest getHistoryAddressesRequest) { try { if (!getHistoryAddressesRequestCrypto.verifySignature(getHistoryAddressesRequest)) { return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(new SerializableResponse(INVALID_SIGNATURE, STATUS_ERROR)); } Map<Hash, AddressData> hashToAddressDataMap = new HashMap<>(); super.retrieveMultipleObjectsFromStorage(getHistoryAddressesRequest.getAddressHashes()).forEach((hash, addressString) -> hashToAddressDataMap.put(hash, addressString != null ? jacksonSerializer.deserialize(addressString) : null)); GetHistoryAddressesResponse getHistoryAddressesResponse = new GetHistoryAddressesResponse(hashToAddressDataMap); getHistoryAddressesResponseCrypto.signMessage(getHistoryAddressesResponse); return ResponseEntity.ok(getHistoryAddressesResponse); } catch (Exception e) { return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new SerializableResponse(e.getMessage(), STATUS_ERROR)); } }
AddressStorageService extends EntityStorageService { public ResponseEntity<IResponse> retrieveMultipleObjectsFromStorage(GetHistoryAddressesRequest getHistoryAddressesRequest) { try { if (!getHistoryAddressesRequestCrypto.verifySignature(getHistoryAddressesRequest)) { return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(new SerializableResponse(INVALID_SIGNATURE, STATUS_ERROR)); } Map<Hash, AddressData> hashToAddressDataMap = new HashMap<>(); super.retrieveMultipleObjectsFromStorage(getHistoryAddressesRequest.getAddressHashes()).forEach((hash, addressString) -> hashToAddressDataMap.put(hash, addressString != null ? jacksonSerializer.deserialize(addressString) : null)); GetHistoryAddressesResponse getHistoryAddressesResponse = new GetHistoryAddressesResponse(hashToAddressDataMap); getHistoryAddressesResponseCrypto.signMessage(getHistoryAddressesResponse); return ResponseEntity.ok(getHistoryAddressesResponse); } catch (Exception e) { return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new SerializableResponse(e.getMessage(), STATUS_ERROR)); } } }
AddressStorageService extends EntityStorageService { public ResponseEntity<IResponse> retrieveMultipleObjectsFromStorage(GetHistoryAddressesRequest getHistoryAddressesRequest) { try { if (!getHistoryAddressesRequestCrypto.verifySignature(getHistoryAddressesRequest)) { return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(new SerializableResponse(INVALID_SIGNATURE, STATUS_ERROR)); } Map<Hash, AddressData> hashToAddressDataMap = new HashMap<>(); super.retrieveMultipleObjectsFromStorage(getHistoryAddressesRequest.getAddressHashes()).forEach((hash, addressString) -> hashToAddressDataMap.put(hash, addressString != null ? jacksonSerializer.deserialize(addressString) : null)); GetHistoryAddressesResponse getHistoryAddressesResponse = new GetHistoryAddressesResponse(hashToAddressDataMap); getHistoryAddressesResponseCrypto.signMessage(getHistoryAddressesResponse); return ResponseEntity.ok(getHistoryAddressesResponse); } catch (Exception e) { return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new SerializableResponse(e.getMessage(), STATUS_ERROR)); } }  }
AddressStorageService extends EntityStorageService { public ResponseEntity<IResponse> retrieveMultipleObjectsFromStorage(GetHistoryAddressesRequest getHistoryAddressesRequest) { try { if (!getHistoryAddressesRequestCrypto.verifySignature(getHistoryAddressesRequest)) { return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(new SerializableResponse(INVALID_SIGNATURE, STATUS_ERROR)); } Map<Hash, AddressData> hashToAddressDataMap = new HashMap<>(); super.retrieveMultipleObjectsFromStorage(getHistoryAddressesRequest.getAddressHashes()).forEach((hash, addressString) -> hashToAddressDataMap.put(hash, addressString != null ? jacksonSerializer.deserialize(addressString) : null)); GetHistoryAddressesResponse getHistoryAddressesResponse = new GetHistoryAddressesResponse(hashToAddressDataMap); getHistoryAddressesResponseCrypto.signMessage(getHistoryAddressesResponse); return ResponseEntity.ok(getHistoryAddressesResponse); } catch (Exception e) { return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new SerializableResponse(e.getMessage(), STATUS_ERROR)); } }  @PostConstruct void init(); ResponseEntity<IResponse> retrieveMultipleObjectsFromStorage(GetHistoryAddressesRequest getHistoryAddressesRequest); boolean validateObjectDataIntegrity(Hash addressHash, String addressAsJson); Map<Hash, AddressData> getObjectsMapFromJsonMap(Map<Hash, String> responsesMap); }
AddressStorageService extends EntityStorageService { public ResponseEntity<IResponse> retrieveMultipleObjectsFromStorage(GetHistoryAddressesRequest getHistoryAddressesRequest) { try { if (!getHistoryAddressesRequestCrypto.verifySignature(getHistoryAddressesRequest)) { return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(new SerializableResponse(INVALID_SIGNATURE, STATUS_ERROR)); } Map<Hash, AddressData> hashToAddressDataMap = new HashMap<>(); super.retrieveMultipleObjectsFromStorage(getHistoryAddressesRequest.getAddressHashes()).forEach((hash, addressString) -> hashToAddressDataMap.put(hash, addressString != null ? jacksonSerializer.deserialize(addressString) : null)); GetHistoryAddressesResponse getHistoryAddressesResponse = new GetHistoryAddressesResponse(hashToAddressDataMap); getHistoryAddressesResponseCrypto.signMessage(getHistoryAddressesResponse); return ResponseEntity.ok(getHistoryAddressesResponse); } catch (Exception e) { return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new SerializableResponse(e.getMessage(), STATUS_ERROR)); } }  @PostConstruct void init(); ResponseEntity<IResponse> retrieveMultipleObjectsFromStorage(GetHistoryAddressesRequest getHistoryAddressesRequest); boolean validateObjectDataIntegrity(Hash addressHash, String addressAsJson); Map<Hash, AddressData> getObjectsMapFromJsonMap(Map<Hash, String> responsesMap);  }