Skip to content

Commit

Permalink
Replace Empty String with Null for Version Handling in Dataset Caching
Browse files Browse the repository at this point in the history
  • Loading branch information
elmiomar committed Oct 18, 2024
1 parent 1e45804 commit f819586
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ public DefaultRPADatasetCacher(RPACachingService rpaCachingService) {
public String cache(String datasetId) throws RequestProcessingException {
String randomId;
try {
randomId = rpaCachingService.cacheAndGenerateRandomId(datasetId, "");
// Replaced "" with null because passing an empty string would break the logic downstream.
// An empty string would match the first version available, while in this scenario,
// when the version is not provided, we want to select the latest version. Passing null achieves this.
randomId = rpaCachingService.cacheAndGenerateRandomId(datasetId, null);
} catch (Exception e) {
this.logCachingException(e);
throw new RequestProcessingException(e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.mockito.junit.MockitoJUnitRunner;

import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.times;
Expand All @@ -30,7 +31,7 @@ public void setUp() {
MockitoAnnotations.initMocks(this);
rpaDatasetCacher = new DefaultRPADatasetCacher(rpaCachingService);
datasetId = "mds2-2909";
version = "";
version = null;
}

@Test
Expand Down Expand Up @@ -65,7 +66,7 @@ public void testCache_invalidDatasetId() throws Exception {
String invalidDatasetId = "ark:/invalid_id";

// Throw an IllegalArgumentException for the invalid datasetId when the cacheAndGenerateRandomId method is called
when(rpaCachingService.cacheAndGenerateRandomId(eq(invalidDatasetId), anyString()))
when(rpaCachingService.cacheAndGenerateRandomId(eq(invalidDatasetId), any()))
.thenThrow(new IllegalArgumentException("Invalid dataset ID format: " + invalidDatasetId));

rpaDatasetCacher.cache(invalidDatasetId);
Expand Down

0 comments on commit f819586

Please sign in to comment.