@@ -870,6 +870,53 @@ protected String getEntityType() {
870870 return ProductSpecification .TYPE_PRODUCT_SPECIFICATION ;
871871 }
872872
873+ @ DisplayName ("ProductSpecificationRelationship validFor should be persisted and retrieved correctly" )
874+ @ Test
875+ public void specRelationshipValidForSerialization () throws Exception {
876+ // create a target spec to reference
877+ ProductSpecificationCreateVO targetSpecCreate = ProductSpecificationCreateVOTestExample .build ()
878+ .atSchemaLocation (null )
879+ .targetProductSchema (null );
880+ HttpResponse <ProductSpecificationVO > targetCreateResponse = callAndCatch (
881+ () -> productSpecificationApiTestClient .createProductSpecification (null , targetSpecCreate ));
882+ assertEquals (HttpStatus .CREATED , targetCreateResponse .getStatus (),
883+ "The target productSpecification should have been created." );
884+ String targetSpecId = targetCreateResponse .body ().getId ();
885+
886+ // build a relationship with a validFor period
887+ TimePeriodVO validFor = new TimePeriodVO ();
888+ Instant start = Instant .ofEpochSecond (1000 );
889+ Instant end = Instant .ofEpochSecond (2000 );
890+ validFor .setStartDateTime (start );
891+ validFor .setEndDateTime (end );
892+
893+ ProductSpecificationRelationshipVO specRel = ProductSpecificationRelationshipVOTestExample .build ()
894+ .atSchemaLocation (null )
895+ .id (targetSpecId )
896+ .href (URI .create (targetSpecId ))
897+ .validFor (validFor );
898+
899+ ProductSpecificationCreateVO specWithRelCreate = ProductSpecificationCreateVOTestExample .build ()
900+ .atSchemaLocation (null )
901+ .targetProductSchema (null )
902+ .productSpecificationRelationship (List .of (specRel ));
903+ HttpResponse <ProductSpecificationVO > createResponse = callAndCatch (
904+ () -> productSpecificationApiTestClient .createProductSpecification (null , specWithRelCreate ));
905+ assertEquals (HttpStatus .CREATED , createResponse .getStatus (),
906+ "The productSpecification with a relationship should have been created." );
907+ String specId = createResponse .body ().getId ();
908+
909+ // retrieve and verify validFor is correctly deserialized (regression for targetClass = TimePeriod.class fix)
910+ HttpResponse <ProductSpecificationVO > retrievalResponse = callAndCatch (
911+ () -> productSpecificationApiTestClient .retrieveProductSpecification (null , specId , null ));
912+ assertEquals (HttpStatus .OK , retrievalResponse .getStatus (), "The spec should have been retrieved." );
913+
914+ List <ProductSpecificationRelationshipVO > relationships = retrievalResponse .body ().getProductSpecificationRelationship ();
915+ assertEquals (1 , relationships .size (), "One relationship should be present." );
916+ assertEquals (validFor , relationships .get (0 ).getValidFor (),
917+ "The validFor of the relationship should have been persisted and retrieved correctly." );
918+ }
919+
873920 @ DisplayName ("Duplicate relationship issue - DOME#83519" )
874921 @ Test
875922 public void duplicateRelationshipIssue () throws Exception {
0 commit comments