Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Empty String with Null for Version Handling in Dataset Caching #114

Open
wants to merge 1 commit into
base: integration
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading