Skip to content

Commit

Permalink
feat: make auto_refresh default to true (#1301)
Browse files Browse the repository at this point in the history
  • Loading branch information
paullatzelsperger authored May 14, 2024
1 parent 9307fd8 commit c6b1b31
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
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

0 comments on commit c6b1b31

Please sign in to comment.