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

feat: make auto_refresh default to true #1301

Merged
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 @@ -67,7 +67,7 @@ public interface EdrCacheApi {

@Operation(description = "Gets the EDR data address with the given transfer process ID",
parameters = { @Parameter(name = "transferProcessId", description = "The ID of the transferprocess for which the EDR should be fetched", required = true),
@Parameter(name = "auto_refresh", description = "Whether the access token that is stored on the EDR should be checked for expiry, and renewed if necessary. Default is true")
@Parameter(name = "auto_refresh", description = "Whether the access token that is stored on the EDR should be checked for expiry, and renewed if necessary. Default is true.")
},
responses = {
@ApiResponse(responseCode = "200", description = "The data address",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import jakarta.json.JsonObject;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.DELETE;
import jakarta.ws.rs.DefaultValue;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
Expand Down Expand Up @@ -139,7 +140,7 @@ public JsonArray requestEdrEntries(JsonObject querySpecJson) {
@GET
@Path("{transferProcessId}/dataaddress")
@Override
public JsonObject getEdrEntryDataAddress(@PathParam("transferProcessId") String transferProcessId, @QueryParam("auto_refresh") boolean autoRefresh) {
public JsonObject getEdrEntryDataAddress(@PathParam("transferProcessId") String transferProcessId, @DefaultValue("true") @QueryParam("auto_refresh") boolean autoRefresh) {
var mode = autoRefresh ? AUTO_REFRESH : NO_REFRESH;
var dataAddress = edrService.resolveByTransferProcess(transferProcessId, mode)
.orElseThrow(exceptionMapper(EndpointDataReferenceEntry.class, transferProcessId));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ void getEdrEntryDataAddress() {

var dataAddressType = "type";
var dataAddress = DataAddress.Builder.newInstance().type(dataAddressType).build();
when(edrService.resolveByTransferProcess("transferProcessId", NO_REFRESH))
when(edrService.resolveByTransferProcess("transferProcessId", AUTO_REFRESH))
.thenReturn(ServiceResult.success(dataAddress));

when(transformerRegistry.transform(isA(DataAddress.class), eq(JsonObject.class)))
Expand All @@ -176,13 +176,13 @@ void getEdrEntryDataAddress() {
.contentType(JSON)
.body("'%s'".formatted(DataAddress.EDC_DATA_ADDRESS_TYPE_PROPERTY), equalTo(dataAddressType));

verify(edrService).resolveByTransferProcess("transferProcessId", NO_REFRESH);
verify(edrService).resolveByTransferProcess("transferProcessId", AUTO_REFRESH);
verify(transformerRegistry).transform(isA(DataAddress.class), eq(JsonObject.class));
verifyNoMoreInteractions(transformerRegistry);
}

@Test
void getEdrEntryDataAddress_withAutorefresh() {
void getEdrEntryDataAddress_withExplicitAutoRefreshTrue() {

var dataAddressType = "type";
var dataAddress = DataAddress.Builder.newInstance().type(dataAddressType).build();
Expand All @@ -206,11 +206,36 @@ void getEdrEntryDataAddress_withAutorefresh() {
verifyNoMoreInteractions(transformerRegistry);
}

@Test
void getEdrEntryDataAddress_withExplicitAutoRefreshFalse() {

var dataAddressType = "type";
var dataAddress = DataAddress.Builder.newInstance().type(dataAddressType).build();
when(edrService.resolveByTransferProcess("transferProcessId", NO_REFRESH))
.thenReturn(ServiceResult.success(dataAddress));

when(transformerRegistry.transform(isA(DataAddress.class), eq(JsonObject.class)))
.thenReturn(Result.success(createDataAddress(dataAddressType).build()));

baseRequest()
.contentType(JSON)
.get("/v2/edrs/transferProcessId/dataaddress?auto_refresh=false")
.then()
.log().ifError()
.statusCode(200)
.contentType(JSON)
.body("'%s'".formatted(DataAddress.EDC_DATA_ADDRESS_TYPE_PROPERTY), equalTo(dataAddressType));

verify(edrService).resolveByTransferProcess("transferProcessId", NO_REFRESH);
verify(transformerRegistry).transform(isA(DataAddress.class), eq(JsonObject.class));
verifyNoMoreInteractions(transformerRegistry);
}


@Test
void getEdrEntryDataAddress_whenNotFound() {

when(edrService.resolveByTransferProcess("transferProcessId", NO_REFRESH))
when(edrService.resolveByTransferProcess("transferProcessId", AUTO_REFRESH))
.thenReturn(ServiceResult.notFound("notFound"));


Expand All @@ -222,7 +247,7 @@ void getEdrEntryDataAddress_whenNotFound() {
.statusCode(404)
.contentType(JSON);

verify(edrService).resolveByTransferProcess("transferProcessId", NO_REFRESH);
verify(edrService).resolveByTransferProcess("transferProcessId", AUTO_REFRESH);
verifyNoMoreInteractions(transformerRegistry);
}

Expand Down
Loading