From 75a57e540694ae4bf85e57ead9dbc4339555793c Mon Sep 17 00:00:00 2001 From: Simone Lindner Date: Fri, 1 Dec 2023 09:27:28 +0100 Subject: [PATCH] new field timeToLive for endpoints introduced --- CHANGELOG.md | 7 +++ .../discoveryfinder/ApiExceptionHandler.java | 28 +++++++++- .../DiscoveryFinderProperties.java | 5 ++ .../discoveryfinder/model/Endpoint.java | 1 + .../src/main/resources/application-local.yml | 11 ++-- .../db/changelog/db.changelog-v1.yaml | 11 +++- .../static/discovery-finder-openapi.yaml | 20 +++++-- .../AbstractDiscoveryFinderApi.java | 11 ++-- .../DiscoveryFinderApiDelegateTest.java | 52 ++++++++++++++++--- .../DiscoveryFinderApiSecurityTest.java | 8 +-- .../mapper/DiscoveryFinderMapperTest.java | 10 ++-- .../resources/application-onstartuptest.yml | 2 + charts/discoveryfinder/values.yaml | 1 + docs/6-concepts.md | 12 +++-- .../discoveryfinder/test_api.tavern.yaml | 1 + 15 files changed, 143 insertions(+), 37 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ed9c9f..f139975 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## 0.2.6 +### Added +- new timeToLive field added to Endpoints + +## fixed + + ## 0.2.5 ### Added - Introduced versioning of the APIs of the Discovery Finder.First version of this API is 1.0 diff --git a/backend/src/main/java/org/eclipse/tractusx/discoveryfinder/ApiExceptionHandler.java b/backend/src/main/java/org/eclipse/tractusx/discoveryfinder/ApiExceptionHandler.java index 0172c37..0292fbb 100644 --- a/backend/src/main/java/org/eclipse/tractusx/discoveryfinder/ApiExceptionHandler.java +++ b/backend/src/main/java/org/eclipse/tractusx/discoveryfinder/ApiExceptionHandler.java @@ -19,22 +19,47 @@ ********************************************************************************/ package org.eclipse.tractusx.discoveryfinder; +import java.util.List; + +import java.util.Optional; +import java.util.stream.Collectors; + import org.eclipse.tractusx.discoveryfinder.model.Error; import org.eclipse.tractusx.discoveryfinder.model.ErrorResponse; import org.eclipse.tractusx.discoveryfinder.service.EntityNotFoundException; import org.eclipse.tractusx.discoveryfinder.service.ValidationException; import org.springframework.dao.DuplicateKeyException; +import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; +import org.springframework.http.HttpStatusCode; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.context.request.WebRequest; import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; import jakarta.servlet.http.HttpServletRequest; @ControllerAdvice public class ApiExceptionHandler extends ResponseEntityExceptionHandler { - + + @Override + protected ResponseEntity handleMethodArgumentNotValid( final MethodArgumentNotValidException ex, + final HttpHeaders headers, + final HttpStatusCode status, final WebRequest request ) { + + List errors = ex.getBindingResult() + .getFieldErrors() + .stream() + .map( fieldError -> new Error() + .message( Optional.ofNullable( fieldError.getDefaultMessage() ).orElseGet( () -> "null" ) ) + ).collect( Collectors.toList()); + return new ResponseEntity<>( + errors, HttpStatus.BAD_REQUEST ); + } + + @ExceptionHandler( { ValidationException.class } ) public ResponseEntity handleValidationException( final HttpServletRequest request, final ValidationException exception ) { @@ -61,4 +86,5 @@ public ResponseEntity handleDuplicateKeyException( final HttpServ .message( "Entity for the given resourceId already exists." ) .path( request.getRequestURI() ) ), HttpStatus.BAD_REQUEST ); } + } diff --git a/backend/src/main/java/org/eclipse/tractusx/discoveryfinder/DiscoveryFinderProperties.java b/backend/src/main/java/org/eclipse/tractusx/discoveryfinder/DiscoveryFinderProperties.java index 0b7d48d..4f19336 100644 --- a/backend/src/main/java/org/eclipse/tractusx/discoveryfinder/DiscoveryFinderProperties.java +++ b/backend/src/main/java/org/eclipse/tractusx/discoveryfinder/DiscoveryFinderProperties.java @@ -24,6 +24,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.validation.annotation.Validated; +import jakarta.validation.constraints.Max; +import jakarta.validation.constraints.Min; import jakarta.validation.constraints.NotEmpty; import lombok.Data; @@ -51,5 +53,8 @@ public static class InitialEndpoint { private String description; private String documentation; + @Min( value = 1, message = "value must be greater or equal to 1" ) + @Max( value = 31536000, message = "value must be lesser or equal to 31536000") + private Integer timeToLive; } } \ No newline at end of file diff --git a/backend/src/main/java/org/eclipse/tractusx/discoveryfinder/model/Endpoint.java b/backend/src/main/java/org/eclipse/tractusx/discoveryfinder/model/Endpoint.java index bd90814..483b76a 100644 --- a/backend/src/main/java/org/eclipse/tractusx/discoveryfinder/model/Endpoint.java +++ b/backend/src/main/java/org/eclipse/tractusx/discoveryfinder/model/Endpoint.java @@ -38,4 +38,5 @@ public class Endpoint { String endpointAddress; String documentation; UUID resourceId; + Integer timeToLive; } diff --git a/backend/src/main/resources/application-local.yml b/backend/src/main/resources/application-local.yml index fc7b232..de04180 100644 --- a/backend/src/main/resources/application-local.yml +++ b/backend/src/main/resources/application-local.yml @@ -31,11 +31,12 @@ spring: discoveryfinder: publicClientId: discovery-finder-client - # initialEndpoints: - # - type: "EDC" - # endpointAddress: "https://" - # description: "" - # documentation: "" +# initialEndpoints: +# - type: "EDC" +# endpointAddress: "https://" +# description: "ss" +# documentation: "htt" +# timeToLive: 31536000 # Properties develop against a postgres instance # You can start a postgres instance using the docker-compose file located in the backend/postgres/ directory diff --git a/backend/src/main/resources/db/changelog/db.changelog-v1.yaml b/backend/src/main/resources/db/changelog/db.changelog-v1.yaml index 5090438..a53c940 100644 --- a/backend/src/main/resources/db/changelog/db.changelog-v1.yaml +++ b/backend/src/main/resources/db/changelog/db.changelog-v1.yaml @@ -67,4 +67,13 @@ databaseChangeLog: columnNames: resource_id constraintName: endpoint_ak_AK_02 tableName: endpoint - validate: true \ No newline at end of file + validate: true + - changeSet: + id: 29112023-01 + author: slindner + changes: + - addColumn: + tableName: endpoint + columns: + name: time_to_live + type: integer \ No newline at end of file diff --git a/backend/src/main/resources/static/discovery-finder-openapi.yaml b/backend/src/main/resources/static/discovery-finder-openapi.yaml index 986728a..623a4ef 100644 --- a/backend/src/main/resources/static/discovery-finder-openapi.yaml +++ b/backend/src/main/resources/static/discovery-finder-openapi.yaml @@ -132,6 +132,7 @@ components: - type - description - endpointAddress + - timeToLive properties: type: type: string @@ -151,6 +152,10 @@ components: maxLength: 500 resourceId: type: string + timeToLive: + type: integer + minimum: 1 + maximum: 31536000 SearchRequest: title: SearchRequest required: @@ -209,7 +214,8 @@ components: "type": "oen", "description": "Service to discover BPN to a particular OEN", "endpointAddress": "http://...", - "documentation": "http://.../swagger/index.html" + "documentation": "http://.../swagger/index.html", + "timeToLive": 31536000 } discovery-endpoint-result: value: @@ -218,7 +224,8 @@ components: "description": "Service to discover BPN to a particular OEN", "endpointAddress": "http://...", "documentation": "http://.../swagger/index.html", - "resourceId": "ec6f407b-4296-418c-9e4e-fb739fe72a67" + "resourceId": "ec6f407b-4296-418c-9e4e-fb739fe72a67", + "timeToLive": 31536000 } discovey-endpoint-search: value: @@ -234,21 +241,24 @@ components: "description": "Service to discover BPN to a particular OEN", "endpointAddress": "http://...", "documentation": "http://.../swagger/index.html", - "resourceId": "ec6f407b-4296-418c-9e4e-fb739fe72a67" + "resourceId": "ec6f407b-4296-418c-9e4e-fb739fe72a67", + "timeToLive": 31536000 }, { "type": "bpid", "description": "Service to discover BPN to a particular Battery Pass ID", "endpointAddress": "http://...", "documentation": "http://.../swagger/index.html", - "resourceId": "08702529-3714-4c4f-b022-346b9b4fbbe2" + "resourceId": "08702529-3714-4c4f-b022-346b9b4fbbe2", + "timeToLive": 31536000 }, { "type": "bpn", "description": "Service to discover EDC to a particular BPN", "endpointAddress": "http://...", "documentation": "http://.../swagger/index.html", - "resourceId": "316417cd-0fb5-4daf-8dfa-8f68125923f1" + "resourceId": "316417cd-0fb5-4daf-8dfa-8f68125923f1", + "timeToLive": 31536000 } ] } \ No newline at end of file diff --git a/backend/src/test/java/org/eclipse/tractusx/discoveryfinder/AbstractDiscoveryFinderApi.java b/backend/src/test/java/org/eclipse/tractusx/discoveryfinder/AbstractDiscoveryFinderApi.java index 03d0fe1..96f8c45 100644 --- a/backend/src/test/java/org/eclipse/tractusx/discoveryfinder/AbstractDiscoveryFinderApi.java +++ b/backend/src/test/java/org/eclipse/tractusx/discoveryfinder/AbstractDiscoveryFinderApi.java @@ -19,7 +19,7 @@ ********************************************************************************/ package org.eclipse.tractusx.discoveryfinder; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; import org.eclipse.tractusx.discoveryfinder.configuration.TestJwtTokenFactory; import org.eclipse.tractusx.discoveryfinder.repository.EndpointRepository; @@ -37,6 +37,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; +import com.jayway.jsonpath.JsonPath; @SpringBootTest @AutoConfigureMockMvc @@ -72,19 +73,17 @@ protected String performDiscoveryEndpointCreateRequest( String requestToJson ) t .andExpect( status().isCreated() ) .andReturn(); - String sResult = result.getResponse().getContentAsString(); - String resourceID = sResult.substring( sResult.lastIndexOf( ":" ) ); - resourceID = resourceID.replace( "\"}", "" ).replace( ":\"", "" ).trim(); - + String resourceID = JsonPath.read( result.getResponse().getContentAsString(), "$.resourceId" ); return resourceID; } - protected ObjectNode createDiscoveryEndpoint( String type, String endpointAddress, String description, String documentation ) { + protected ObjectNode createDiscoveryEndpoint( String type, String endpointAddress, String description, String documentation, Integer timeToLive ) { ObjectNode requestNode = mapper.createObjectNode(); requestNode.put( "type", type ); requestNode.put( "description", description ); requestNode.put( "endpointAddress", endpointAddress ); requestNode.put( "documentation", documentation ); + requestNode.put("timeToLive", timeToLive); return requestNode; } diff --git a/backend/src/test/java/org/eclipse/tractusx/discoveryfinder/DiscoveryFinderApiDelegateTest.java b/backend/src/test/java/org/eclipse/tractusx/discoveryfinder/DiscoveryFinderApiDelegateTest.java index 6bf021e..1af38e6 100644 --- a/backend/src/test/java/org/eclipse/tractusx/discoveryfinder/DiscoveryFinderApiDelegateTest.java +++ b/backend/src/test/java/org/eclipse/tractusx/discoveryfinder/DiscoveryFinderApiDelegateTest.java @@ -40,7 +40,7 @@ public void cleanUp() { @Test public void givenValidDiscoveryEndpoint_whenSave_thenSaveSucceeds() throws Exception { // given - ObjectNode givenValidPayload = createDiscoveryEndpoint( "oen", "oen-url-1", "description", "http://oen-swagger" ); + ObjectNode givenValidPayload = createDiscoveryEndpoint( "oen", "oen-url-1", "description", "http://oen-swagger",31536000 ); //when -> then mockMvc.perform( @@ -59,7 +59,7 @@ public void givenValidDiscoveryEndpoint_whenSave_thenSaveSucceeds() throws Excep @Test public void givenDuplicateDiscoveryEndpoint_whenSave_thenThrowDuplicateKeyException() throws Exception { // given - ObjectNode givenPayload = createDiscoveryEndpoint( "oen", "oen-url-2", "description", "http://oen-swagger" ); + ObjectNode givenPayload = createDiscoveryEndpoint( "oen", "oen-url-2", "description", "http://oen-swagger", 31536000 ); performDiscoveryEndpointCreateRequest( toJson( givenPayload ) ); ObjectNode duplicatedPayload = givenPayload; @@ -80,7 +80,7 @@ public void givenDuplicateDiscoveryEndpoint_whenSave_thenThrowDuplicateKeyExcept @Test public void givenValidResourceId_whenDelete_thenDeleteSucceeds() throws Exception { // given - ObjectNode givenPayload = createDiscoveryEndpoint( "oen", "oen-url-3", "description", "http://oen-swagger" ); + ObjectNode givenPayload = createDiscoveryEndpoint( "oen", "oen-url-3", "description", "http://oen-swagger", 31536000 ); String givenResourceId = performDiscoveryEndpointCreateRequest( toJson( givenPayload ) ); // when -> then @@ -136,8 +136,8 @@ public void givenInvalidResourceIdFormat_whenDelete_thenThrowValidationException @Test public void givenSearchRequest_whenGetDiscoveryEndpoints_thenReturnResult() throws Exception { // given - ObjectNode givenOenNode1 = createDiscoveryEndpoint( "oen", "oen-url-4", "description", "http://oen-swagger" ); - ObjectNode givenOenNode2 = createDiscoveryEndpoint( "bpId", "bpId-url-1", "description", "http://oen-swagger" ); + ObjectNode givenOenNode1 = createDiscoveryEndpoint( "oen", "oen-url-4", "description", "http://oen-swagger", 31536000 ); + ObjectNode givenOenNode2 = createDiscoveryEndpoint( "bpId", "bpId-url-1", "description", "http://oen-swagger", 31536000 ); performDiscoveryEndpointCreateRequest( toJson( givenOenNode1 ) ); performDiscoveryEndpointCreateRequest( toJson( givenOenNode2 ) ); @@ -164,9 +164,9 @@ public void givenSearchRequest_whenGetDiscoveryEndpoints_thenReturnResult() thro @Test public void givenEmptySearchRequest_whenGetDiscoveryEndpoints_thenReturnAllDiscoveryEndpoints() throws Exception { // given - ObjectNode givenOenNode1 = createDiscoveryEndpoint( "bpId", "bpId-url-2", "description", "http://oen-swagger" ); - ObjectNode givenOenNode2 = createDiscoveryEndpoint( "oen", "oen-url-5", "description", "http://oen-swagger" ); - ObjectNode givenOenNode3 = createDiscoveryEndpoint( "serialId", "serialId-url-1", "description", "http://oen-swagger" ); + ObjectNode givenOenNode1 = createDiscoveryEndpoint( "bpId", "bpId-url-2", "description", "http://oen-swagger", 31536000 ); + ObjectNode givenOenNode2 = createDiscoveryEndpoint( "oen", "oen-url-5", "description", "http://oen-swagger", 31536000 ); + ObjectNode givenOenNode3 = createDiscoveryEndpoint( "serialId", "serialId-url-1", "description", "http://oen-swagger", 31536000 ); performDiscoveryEndpointCreateRequest( toJson( givenOenNode1 ) ); performDiscoveryEndpointCreateRequest( toJson( givenOenNode2 ) ); performDiscoveryEndpointCreateRequest( toJson( givenOenNode3 ) ); @@ -189,4 +189,40 @@ public void givenEmptySearchRequest_whenGetDiscoveryEndpoints_thenReturnAllDisco .andExpect( jsonPath( "$.endpoints[1].type", equalTo( "oen" ) ) ) .andExpect( jsonPath( "$.endpoints[2].type", equalTo( "serialId" ) ) ); } + + @Test + public void givenToBigTimeToLive_whenSave_thenThrowMethodArgumentNotValidException() throws Exception { + //given + ObjectNode givenInvalidTtl = createDiscoveryEndpoint( "bpId", "bpId-url-2", "description", "http://oen-swagger", 31536001 ); + //when -> then + mockMvc.perform( + MockMvcRequestBuilders + .post( DISCOVERY_FINDER_BASE_PATH ) + .accept( MediaType.APPLICATION_JSON ) + .contentType( MediaType.APPLICATION_JSON ) + .content( toJson( givenInvalidTtl ) ) + .with( jwtTokenFactory.allRoles() ) + ) + .andDo( MockMvcResultHandlers.print() ) + .andExpect( status().isBadRequest() ) + .andExpect( jsonPath( "$.[0].message", equalTo( "must be less than or equal to 31536000" ) ) ); + } + + @Test + public void givenToSmallTimeToLive_whenSave_thenThrowMethodArgumentNotValidException() throws Exception { + //given + ObjectNode givenInvalidTtl = createDiscoveryEndpoint( "bpId", "bpId-url-2", "description", "http://oen-swagger", 0 ); + //when -> then + mockMvc.perform( + MockMvcRequestBuilders + .post( DISCOVERY_FINDER_BASE_PATH ) + .accept( MediaType.APPLICATION_JSON ) + .contentType( MediaType.APPLICATION_JSON ) + .content( toJson( givenInvalidTtl ) ) + .with( jwtTokenFactory.allRoles() ) + ) + .andDo( MockMvcResultHandlers.print() ) + .andExpect( status().isBadRequest() ) + .andExpect( jsonPath( "$.[0].message", equalTo( "must be greater than or equal to 1" ) ) ); + } } \ No newline at end of file diff --git a/backend/src/test/java/org/eclipse/tractusx/discoveryfinder/DiscoveryFinderApiSecurityTest.java b/backend/src/test/java/org/eclipse/tractusx/discoveryfinder/DiscoveryFinderApiSecurityTest.java index 3233fba..d7b32d1 100644 --- a/backend/src/test/java/org/eclipse/tractusx/discoveryfinder/DiscoveryFinderApiSecurityTest.java +++ b/backend/src/test/java/org/eclipse/tractusx/discoveryfinder/DiscoveryFinderApiSecurityTest.java @@ -103,7 +103,7 @@ public void givenAuthenticationTokenWithoutViewRole_whenGetDiscoveryEndpoints_th @Test public void givenAuthenticationTokenWithoutAddRole_whenSave_thenReturnForbidden() throws Exception { // given - ObjectNode givenValidPayload = createDiscoveryEndpoint( "oen", "oen-url-sec-0", "description", "http://oen-swagger" ); + ObjectNode givenValidPayload = createDiscoveryEndpoint( "oen", "oen-url-sec-0", "description", "http://oen-swagger", 31536000 ); //when -> then mockMvc.perform( @@ -159,7 +159,7 @@ public void givenAuthenticationTokenWithoutDeleteRole_whenDelete_thenReturnForbi @Test public void givenAuthenticationTokenWithAddRole_whenSave_thenSaveSucceeds() throws Exception { // given - ObjectNode givenValidPayload = createDiscoveryEndpoint( "oen", "oen-url-sec-1", "description", "http://oen-swagger" ); + ObjectNode givenValidPayload = createDiscoveryEndpoint( "oen", "oen-url-sec-1", "description", "http://oen-swagger", 31536000 ); //when -> then mockMvc.perform( @@ -177,7 +177,7 @@ public void givenAuthenticationTokenWithAddRole_whenSave_thenSaveSucceeds() thro @Test public void givenAuthenticationTokenWithDeleteRole_whenDelete_thenDeleteSucceeds() throws Exception { // given - ObjectNode givenPayload = createDiscoveryEndpoint( "oen", "oen-url-sec-2", "description", "http://oen-swagger" ); + ObjectNode givenPayload = createDiscoveryEndpoint( "oen", "oen-url-sec-2", "description", "http://oen-swagger", 31536000 ); String givenResourceId = performDiscoveryEndpointCreateRequest( toJson( givenPayload ) ); // when -> then @@ -195,7 +195,7 @@ public void givenAuthenticationTokenWithDeleteRole_whenDelete_thenDeleteSucceeds @Test public void givenAuthenticationTokenWithViewRole_whenGetDiscoveryEndpoints_thenReturnResult() throws Exception { // given - ObjectNode givenOenNode1 = createDiscoveryEndpoint( "oen", "oen-url-sec-3", "description", "http://oen-swagger" ); + ObjectNode givenOenNode1 = createDiscoveryEndpoint( "oen", "oen-url-sec-3", "description", "http://oen-swagger",31536000 ); performDiscoveryEndpointCreateRequest( toJson( givenOenNode1 ) ); String givenTypes = "{\n\"types\": [\n \"oen\",\n \"bpId\",\n \"bpId\"\n ]\n}"; diff --git a/backend/src/test/java/org/eclipse/tractusx/discoveryfinder/mapper/DiscoveryFinderMapperTest.java b/backend/src/test/java/org/eclipse/tractusx/discoveryfinder/mapper/DiscoveryFinderMapperTest.java index 22878c2..3ab1314 100644 --- a/backend/src/test/java/org/eclipse/tractusx/discoveryfinder/mapper/DiscoveryFinderMapperTest.java +++ b/backend/src/test/java/org/eclipse/tractusx/discoveryfinder/mapper/DiscoveryFinderMapperTest.java @@ -40,7 +40,8 @@ public void fromApiDto() { .type( "oen" ) .endpointAddress( "oen-url-1" ) .description( "description" ) - .documentation( "swagger-oen-1" ); + .documentation( "swagger-oen-1" ) + .timeToLive( 31536000 ); // then Endpoint actual = discoveryFinderMapper.fromApiDto( givenApiDto ); @@ -52,6 +53,7 @@ public void fromApiDto() { Assertions.assertThat( actual.getDescription() ).isEqualTo( givenApiDto.getDescription() ); Assertions.assertThat( actual.getDescription() ).isEqualTo( givenApiDto.getDescription() ); Assertions.assertThat( actual.getResourceId() ).isNotNull(); + Assertions.assertThat( actual.getTimeToLive() ).isEqualTo( givenApiDto.getTimeToLive() ); } @Test @@ -70,7 +72,7 @@ public void toApiDto() { UUID givenResourceID = UUID.randomUUID(); Endpoint givenDto = new Endpoint( - givenUuid, "oen", "description", "oen-url-2", "swagger-oen-1", givenResourceID ); + givenUuid, "oen", "description", "oen-url-2", "swagger-oen-1", givenResourceID, 31536000 ); // when DiscoveryEndpoint actual = discoveryFinderMapper.toApiDto( givenDto ); @@ -81,6 +83,7 @@ public void toApiDto() { Assertions.assertThat( actual.getEndpointAddress() ).isEqualTo( givenDto.getEndpointAddress() ); Assertions.assertThat( actual.getDescription() ).isEqualTo( givenDto.getDescription() ); Assertions.assertThat( actual.getResourceId() ).isEqualTo( givenResourceID.toString() ); + Assertions.assertThat( actual.getTimeToLive() ).isEqualTo( givenDto.getTimeToLive() ); } @Test @@ -90,7 +93,7 @@ public void toDiscoveryEndpointCollectionApiDto() { UUID givenResourceID = UUID.randomUUID(); Endpoint givenDto = new Endpoint( - givenUuid, "oen", "description", "oen-url-2", "swagger-oen-1", givenResourceID ); + givenUuid, "oen", "description", "oen-url-2", "swagger-oen-1", givenResourceID, 31536000 ); EndpointCollectionDto givenEndpointCollectionDto = EndpointCollectionDto.builder().endpoints( List.of( givenDto ) ).build(); // when @@ -103,5 +106,6 @@ public void toDiscoveryEndpointCollectionApiDto() { Assertions.assertThat( actual.getEndpoints().get( 0 ).getEndpointAddress() ).isEqualTo( givenDto.getEndpointAddress() ); Assertions.assertThat( actual.getEndpoints().get( 0 ).getDescription() ).isEqualTo( givenDto.getDescription() ); Assertions.assertThat( actual.getEndpoints().get( 0 ).getResourceId() ).isEqualTo( givenDto.getResourceId().toString() ); + Assertions.assertThat( actual.getEndpoints().get( 0 ).getTimeToLive() ).isEqualTo( givenDto.getTimeToLive() ); } } \ No newline at end of file diff --git a/backend/src/test/resources/application-onstartuptest.yml b/backend/src/test/resources/application-onstartuptest.yml index b5fb3a1..311e538 100644 --- a/backend/src/test/resources/application-onstartuptest.yml +++ b/backend/src/test/resources/application-onstartuptest.yml @@ -34,10 +34,12 @@ discoveryfinder: endpointAddress: "https://edc.instance.de" description: "https://dummy.swaggerui.de" documentation: "swagger ui documentation" + timeToLive: 31536000 - type: "EDC-1" endpointAddress: "https://edc1.instance.de" description: "https://dummy1.swaggerui.de" documentation: "swagger ui documentation" + timeToLive: 1 logging: level: diff --git a/charts/discoveryfinder/values.yaml b/charts/discoveryfinder/values.yaml index 57b6e4e..835ce76 100644 --- a/charts/discoveryfinder/values.yaml +++ b/charts/discoveryfinder/values.yaml @@ -38,6 +38,7 @@ discoveryfinder: # endpointAddress: # description: # documentation: + # timeToLive: idp: issuerUri: https://idp-url publicClientId: idpClientID diff --git a/docs/6-concepts.md b/docs/6-concepts.md index cf9346f..21b02b4 100644 --- a/docs/6-concepts.md +++ b/docs/6-concepts.md @@ -25,7 +25,8 @@ service. "type": "oen", "description": "Service to discover BPN to a particular OEN", "endpointAddress": "http://...", - "documentation": "http://.../swagger/index.html" + "documentation": "http://.../swagger/index.html", + "timeToLive": 31536000 } ``` @@ -37,7 +38,8 @@ service. "description": "Service to discover BPN to a particular OEN", "endpointAddress": "http://...", "documentation": "http://.../swagger/index.html", - "resourceId": "ec6f407b-4296-418c-9e4e-fb739fe72a67" + "resourceId": "ec6f407b-4296-418c-9e4e-fb739fe72a67", + "timeToLive": 31536000 } ``` @@ -71,14 +73,16 @@ service. "description": "Service to discover BPN to a particular OEN", "endpointAddress": "http://...", "documentation": "http://.../swagger/index.html", - "resourceId": "ec6f407b-4296-418c-9e4e-fb739fe72a67" + "resourceId": "ec6f407b-4296-418c-9e4e-fb739fe72a67", + "timeToLive": 31536000 }, { "type": "bpid", "description": "Service to discover BPN to a particular Battery Pass ID", "endpointAddress": "http://...", "documentation": "http://.../swagger/index.html", - "resourceId": "08702529-3714-4c4f-b022-346b9b4fbbe2" + "resourceId": "08702529-3714-4c4f-b022-346b9b4fbbe2", + "timeToLive": 31536000 } ] } diff --git a/e2e-tests/discoveryfinder/test_api.tavern.yaml b/e2e-tests/discoveryfinder/test_api.tavern.yaml index 8c6998b..aa68e2c 100644 --- a/e2e-tests/discoveryfinder/test_api.tavern.yaml +++ b/e2e-tests/discoveryfinder/test_api.tavern.yaml @@ -73,6 +73,7 @@ stages: description: "Service to discover BPN to a particular serialnr" endpointAddress: "https://e2etests.com" documentation: "https://semantics.int.demo.catena-x.net/bpndiscovery/swagger-ui/index.html" + timeToLive: 31536000 response: status_code: 201 headers: