Skip to content

Commit 1bd2d41

Browse files
authored
fix time serialization (#127)
* fix time serialization * added test - fix time serialization
1 parent 7d07dea commit 1bd2d41

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

product-catalog/src/test/java/org/fiware/tmforum/productcatalog/ProductSpecificationApiIT.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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 {

product-shared-models/src/main/java/org/fiware/tmforum/product/ProductSpecificationRelationship.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class ProductSpecificationRelationship extends RefEntity {
2929
@Getter(onMethod = @__({
3030
@AttributeGetter(value = AttributeType.PROPERTY, targetName = "validFor", embedProperty = true)}))
3131
@Setter(onMethod = @__({
32-
@AttributeSetter(value = AttributeType.PROPERTY, targetName = "validFor", fromProperties = true)}))
32+
@AttributeSetter(value = AttributeType.PROPERTY, targetName = "validFor", fromProperties = true, targetClass = TimePeriod.class)}))
3333
private TimePeriod validFor;
3434

3535
public ProductSpecificationRelationship(@JsonProperty("id") String id) {

0 commit comments

Comments
 (0)