Skip to content
Open
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
@@ -1,6 +1,6 @@
package org.fiware.tmforum.common.domain;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonGetter;
import io.github.wistefan.mapping.annotations.AttributeGetter;
import io.github.wistefan.mapping.annotations.AttributeSetter;
import io.github.wistefan.mapping.annotations.AttributeType;
Expand Down Expand Up @@ -46,7 +46,8 @@ protected RefEntity(URI id) {
}

@Override
@JsonGetter("id")
public URI getEntityId() {
return getId();
return this.id;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@

import org.fiware.tmforum.common.validation.ReferencedEntity;

import com.fasterxml.jackson.annotation.JsonGetter;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@EqualsAndHashCode
public class ReferenceValue implements ReferencedEntity {

private URI id;
Expand All @@ -22,6 +25,7 @@ public List<String> getReferencedTypes() {
}

@Override
@JsonGetter("id")
public URI getEntityId() {
return this.id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.fiware.tmforum.common.mapping.BaseMapper;
import org.fiware.tmforum.common.mapping.IdHelper;
import org.fiware.tmforum.product.Characteristic;
import org.fiware.tmforum.product.ProductOffering;
import org.fiware.tmforum.product.ProductSpecificationCharacteristicValueUse;
import org.fiware.tmforum.productordering.domain.*;
import org.fiware.tmforum.resource.Note;
Expand Down Expand Up @@ -96,6 +97,8 @@ public abstract class TMForumMapper extends BaseMapper {
@Mapping(target = "value", source = "tmfValue")
public abstract CharacteristicVO map(Characteristic characteristic);

public abstract ProductOffering map(ProductOfferingRefVO productOfferingRefVO);

public URL map(String value) {
if (value == null) {
return null;
Expand Down Expand Up @@ -128,5 +131,3 @@ public String mapFromURI(URI value) {
return value.toString();
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.fiware.tmforum.common.domain.Entity;
import org.fiware.tmforum.common.domain.ReferenceValue;
import org.fiware.tmforum.product.ProductOfferingQualificationItemRef;
import org.fiware.tmforum.product.ProductOfferingRefValue;
import org.fiware.tmforum.product.ProductOfferingRef;
import org.fiware.tmforum.product.ProductRefOrValue;

import java.util.List;
Expand All @@ -22,7 +22,7 @@ public class ProductOrderItem extends Entity {
private List<OrderPrice> itemTotalPrice;
private List<ReferenceValue> payment;
private ProductRefOrValue product;
private ProductOfferingRefValue productOffering;
private ProductOfferingRef productOffering;
private ProductOfferingQualificationItemRef productOfferingQualificationItem;
private List<ProductOrderItem> productOrderItem;
private List<OrderItemRelationship> productOrderItemRelationship;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.fiware.tmforum.productordering;

import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.wistefan.mapping.JavaObjectMapper;
import io.micronaut.http.HttpResponse;
import io.micronaut.http.HttpStatus;
import io.micronaut.test.annotation.MockBean;
Expand All @@ -17,6 +18,7 @@
import org.fiware.tmforum.productordering.domain.ProductOrder;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
Expand All @@ -32,6 +34,8 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.fiware.ngsi.model.EntityVO;
import org.fiware.tmforum.product.ProductOffering;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Matchers.any;
Expand All @@ -45,9 +49,13 @@ public class ProductOrderingApiIT extends AbstractApiIT implements ProductOrderA

private String message;
private String fieldsParameter;
private final EntitiesApiClient entitiesApiClient;
private final JavaObjectMapper javaObjectMapper;
private final TMForumMapper tmForumMapper;
private ProductOrderCreateVO productCreateVO;
private ProductOrderUpdateVO productUpdateVO;
private ProductOrderVO expectedProduct;
private final TestSetupTracker setupTracker;

private Clock clock = mock(Clock.class);

Expand All @@ -68,11 +76,36 @@ public TMForumEventHandler eventHandler() {

public ProductOrderingApiIT(ProductOrderApiTestClient productOrderApiTestClient,
EntitiesApiClient entitiesApiClient,
ObjectMapper objectMapper, GeneralProperties generalProperties) {
JavaObjectMapper javaObjectMapper,
TMForumMapper tmForumMapper,
ObjectMapper objectMapper,
GeneralProperties generalProperties,
TestSetupTracker setupTracker) {
super(entitiesApiClient, objectMapper, generalProperties);
this.productOrderApiTestClient = productOrderApiTestClient;
this.entitiesApiClient = entitiesApiClient;
this.javaObjectMapper = javaObjectMapper;
this.tmForumMapper = tmForumMapper;
this.setupTracker = setupTracker;
}

public void createProductOffering(ProductOffering productOfferingVO) {
EntityVO entityVO = javaObjectMapper.toEntityVO(productOfferingVO);
entitiesApiClient.createEntity(entityVO, null).block();
}

public void setup() {
createProductOffering(tmForumMapper.map(ProductOfferingRefVOTestExample.build().atSchemaLocation(null).id("test")));
}

@BeforeEach
public void conditionalSetup() {
if (!setupTracker.isSetupDone()) {
setup();
setupTracker.markSetupDone();
}
}

@ParameterizedTest
@MethodSource("provideValidProducts")
public void createProductOrder201(String message, ProductOrderCreateVO productCreateVO,
Expand All @@ -81,6 +114,7 @@ public void createProductOrder201(String message, ProductOrderCreateVO productCr
this.message = message;
this.productCreateVO = productCreateVO;
this.expectedProduct = expectedProduct;

createProductOrder201();
}

Expand All @@ -91,7 +125,7 @@ public void createProductOrder201() throws Exception {
when(clock.instant()).thenReturn(now);

HttpResponse<ProductOrderVO> productVOHttpResponse = callAndCatch(
() -> productOrderApiTestClient.createProductOrder(null, productCreateVO));
() -> productOrderApiTestClient.createProductOrder(null, productCreateVO));
assertEquals(HttpStatus.CREATED, productVOHttpResponse.getStatus(), message);
String rfId = productVOHttpResponse.body().getId();
expectedProduct.setId(rfId);
Expand Down Expand Up @@ -235,6 +269,25 @@ private static Stream<Arguments> provideValidProducts() {
.productOrderItem(List.of(productOrderItemVO))
.billingAccount(null)));

ProductOrderItemVO productOrderItemOfferingVO = ProductOrderItemVOTestExample.build().atSchemaLocation(null)
.action(OrderItemActionTypeVO.ADD)
.id("urn:order-item")
.appointment(null)
.billingAccount(null)
.product(null)
.productOffering(ProductOfferingRefVOTestExample.build().atSchemaLocation(null).id("urn:ngsi-ld:product-offering:test"))
.productOfferingQualificationItem(null)
.quoteItem(null);

testEntries.add(
Arguments.of("A product order with an order item with product offering should have been created.",
ProductOrderCreateVOTestExample.build().atSchemaLocation(null)
.productOrderItem(List.of(productOrderItemOfferingVO))
.billingAccount(null),
ProductOrderVOTestExample.build().atSchemaLocation(null)
.productOrderItem(List.of(productOrderItemOfferingVO))
.billingAccount(null)));

CharacteristicVO characteristicVO = CharacteristicVOTestExample.build().atSchemaLocation(null)
.name("Characteristic Name")
.value("Value");
Expand Down Expand Up @@ -1550,4 +1603,3 @@ protected String getEntityType() {
return ProductOrder.TYPE_PRODUCT_ORDER;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.fiware.tmforum.productordering;

import jakarta.inject.Singleton;

/**
* Allows to run a setup function only once in a multi-thread testing scenario
*/

@Singleton
public class TestSetupTracker {
private boolean setupDone = false;

public synchronized boolean isSetupDone() {
return setupDone;
}

public synchronized void markSetupDone() {
this.setupDone = true;
}

public synchronized void reset() {
this.setupDone = false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
import java.util.List;

import org.fiware.tmforum.common.domain.ReferenceValue;
import io.github.wistefan.mapping.annotations.MappingEnabled;
import lombok.EqualsAndHashCode;

@EqualsAndHashCode(callSuper = true)
@MappingEnabled(entityType = ProductOffering.TYPE_PRODUCT_OFFERING)
public class ProductOfferingRefValue extends ReferenceValue {

@Override
public List<String> getReferencedTypes() {
// Jackson throws Unsupported Operation exeception in this list
return new ArrayList<>(List.of("product-offering"));
return new ArrayList<>(List.of(ProductOffering.TYPE_PRODUCT_OFFERING));
}
}
Loading