50 lines
1.2 KiB
Java
50 lines
1.2 KiB
Java
package dev.hinterdorfer;
|
|
|
|
import io.quarkus.test.junit.QuarkusTest;
|
|
import jakarta.inject.Inject;
|
|
import jakarta.persistence.EntityManager;
|
|
import jakarta.transaction.Transactional;
|
|
import org.junit.jupiter.api.BeforeEach;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import java.util.Collection;
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
|
|
@QuarkusTest
|
|
public class FlowerPersistanceTest {
|
|
|
|
@Inject
|
|
FlowerPersistance persistence;
|
|
|
|
@Inject
|
|
EntityManager em;
|
|
|
|
@BeforeEach
|
|
@Transactional
|
|
public void setup() {
|
|
// clean table
|
|
em.createQuery("DELETE FROM FlowerEntity").executeUpdate();
|
|
|
|
// insert two flowers programmatically
|
|
em.persist(new FlowerEntity("Red Flower", Color.red));
|
|
em.persist(new FlowerEntity("Blue Flower", Color.blue));
|
|
em.flush();
|
|
}
|
|
|
|
@Test
|
|
public void testFindByColor() {
|
|
Collection<FlowerEntity> reds = persistence.find(Color.red);
|
|
assertEquals(1, reds.size());
|
|
assertTrue(reds.stream().allMatch(f -> f.getColor() == Color.red));
|
|
}
|
|
|
|
@Test
|
|
public void testCount() {
|
|
long c = persistence.count();
|
|
assertEquals(2L, c);
|
|
}
|
|
}
|
|
|