Mam stworzoną klasę OfferEntity
@Entity
@Table(name = "Offer")
@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
class OfferEntity {
@Id
@GeneratedValue(generator = "UUID")
@GenericGenerator(
name = "UUID",
strategy = "org.hibernate.id.UUIDGenerator"
)
@Type(type = "uuid-char")
private UUID offerId;
@Type(type = "uuid-char")
private UUID ownerId;
private LocalDateTime startDate;
private LocalDateTime endDate;
@ElementCollection
private Set<UUID> requestSet;
// rest of fields
- Chce przetestować dodanie elementu dodawanie elementu do zbioru.
- Nie wiem jak zapisać stan bazy danych jako .xml po dodaniu elementu do zbioru. W bazie danych tabela "Offer" nie będie posiadała kolumny request_set, ORM stworzy raczej trzy tabele jena to będzie offer, druga będzie zawierała UUID ze zbioru, a trzecia będzie kojarzyła ofertę z numerami UUID zapytań. Nie wiem jak mogę mogę zapisać oczekiwany stan bazy danych w .xml by ją przetestować.
Test
@DatabaseSetup("classpath:offer/query/created-offer.xml")
@ExpectedDatabase( value = "classpath:offer/create/expected-request-added.xml",
assertionMode = DatabaseAssertionMode.NON_STRICT)
@DatabaseTearDown("classpath:clear-all.xml")
def "should add request to offer"() {
given:
AddRequestToOfferRequest addRequestToOfferRequest = getAddRequestToOffer();
when:
HttpHeaders headers = new HttpHeaders();
HttpEntity<AddRequestToOfferRequest> request = new HttpEntity<>(addRequestToOfferRequest, headers)
URI uri = new URI(String.format(ADD_REQUEST_TO_OFFER_PATH, port))
ResponseEntity response = restTemplate.postForEntity(uri, request, String.class)
then:
noExceptionThrown()
response.getStatusCode() == HttpStatus.OK
}
classpath:offer/query/created-offer.xml
<?xml version="1.0" encoding="UTF-8"?>
<dataset>
<Offer offer_id="893a767b-3d02-4a10-b8d5-e36287451111"
owner_id="893a767b-3d02-4a10-b8d5-e36287451112"
start_date="2021-03-08 13:00:00"
end_date="2021-03-08 13:45:00"
state="NEW_OFFER"/>
</dataset>
Poproszę o podpowiedzi jak mogę stworzyć expected-request-added.xml? Dziękuje.