Can I use UUID with DBRider/DBUnit?

50 views Asked by At

I'm trying to test some part of my code in SpringBoot with @DataSet from DBRider/DBUnit, but it seems this tool cannot map value from yml file to UUID in db. Is it possible to use UUID with DBRider?

Entity:

@Entity
@Table(name = "t_reservation")
public class ReservationBE {

    @Id
    @GeneratedValue
    private UUID id;

    @NotNull
    private String name;
}

SQL migration in postgresql:

CREATE EXTENSION "uuid-ossp";

CREATE TABLE t_reservation (
    id uuid DEFAULT uuid_generate_v4() NOT NULL,
    name varchar
);

Dataset I want to use in tests via DBRider:

t_reservation:
  - id: '63a5044a-7f8d-4e0b-9c0b-3e8a28d72c7f'
  - name: 'kowalski'

And finally, my test class:

@SpringBootTest
@DBRider
class ReservationBFTest {

    private final UUID PERSISTED_UUID = UUID.fromString("63a5044a-7f8d-4e0b-9c0b-3e8a28d72c7f");

    @Autowired
    ReservationBF reservationBF;

    @Test
    @DataSet("reservation/boundary/reservations.yml")
    void getReservation() {
        //when
        ReservationDO persistedReservationDO = reservationBF.getReservation(PERSISTED_UUID);

        //then
        assertEquals(persistedReservationDO.getId(), PERSISTED_UUID);
    }

But I'm receiving this error when trying to run test: org.postgresql.util.PSQLException: ERROR: null value in column "id" of relation "t_reservation" violates not-null constraint

Changing UUID to Long fixes the issue, but I really hope that there is some other way so I don't have to abandon UUID

0

There are 0 answers