diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6b9ee2e..c888b3e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -13,6 +13,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Deprecated
### Security
+## [1.2.1] - 2024-05-10
+
+### Changed
+- Aggiornamento del modello ORM Panache per l'aggiunta di nuovi attributi nella classe di entità `Horse`
+- Aggiornamento dello script SQL per l'inizializzazione del database H2
+- Aggiornamento dei unit e integration test per l'aggiunta di nuovi attributi nella classe di entità `Horse`
## [1.2.0] - 2024-05-10
diff --git a/pom.xml b/pom.xml
index 27d0a8d..134d07b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
4.0.0
it.dontesta.eventbus
eventbus-logging-filter-jaxrs
- 1.2.0
+ 1.2.1
eventbus-logging-filter-jaxrs
Event Bus Logging Filter JAX-RS
diff --git a/src/main/java/it/dontesta/eventbus/orm/panache/entity/Horse.java b/src/main/java/it/dontesta/eventbus/orm/panache/entity/Horse.java
index f2a7276..a4fbe8d 100644
--- a/src/main/java/it/dontesta/eventbus/orm/panache/entity/Horse.java
+++ b/src/main/java/it/dontesta/eventbus/orm/panache/entity/Horse.java
@@ -5,6 +5,7 @@
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.ManyToMany;
+import jakarta.validation.constraints.Pattern;
import java.time.LocalDate;
import java.util.List;
@@ -15,17 +16,34 @@
@Cacheable
public class Horse extends PanacheEntity {
- @Column(length = 60)
+ @Column(length = 60, nullable = false)
public String name;
- @Column(length = 15)
+ @Column(length = 1, nullable = false)
+ @Pattern(regexp = "^[MF]$", message = "The admitted values for the sex attribute are: 'M' or 'F'")
+ public String sex;
+
+ @Column(length = 15, nullable = false)
public String coat;
- @Column(length = 60)
+ @Column(length = 60, nullable = false)
public String breed;
+ @Column(nullable = false)
public LocalDate dateOfBirth;
+ @Column(length = 15)
+ public String registrationNumber;
+
+ @Column(length = 15)
+ public String microchipNumber;
+
+ @Column(length = 15)
+ public String passportNumber;
+
+ @Column(length = 3)
+ public int height;
+
@ManyToMany
public List owners;
}
diff --git a/src/main/resources/load_data.sql b/src/main/resources/load_data.sql
index d4ba25a..bdd8360 100644
--- a/src/main/resources/load_data.sql
+++ b/src/main/resources/load_data.sql
@@ -1,11 +1,21 @@
-- Description: Load data into the database
-- Insert data into the tables Horse
-INSERT INTO horse(id, name, breed, coat, dateOfBirth) VALUES (1, 'Judio XXXV', 'Pura Raza Española - PRE', 'Black', '2012-05-01');
-INSERT INTO horse(id, name, breed, coat, dateOfBirth) VALUES (2, 'Fuego de Cardenas', 'Pura Raza Española - PRE', 'Grey', '2010-03-01');
-INSERT INTO horse(id, name, breed, coat, dateOfBirth) VALUES (3, 'Francisco', 'Puro Sangue Arabo - PSA', 'Grey', '2010-03-01');
-INSERT INTO horse(id, name, breed, coat, dateOfBirth) VALUES (4, 'Shirus', 'Quarab', 'Grey', '2012-05-01');
-INSERT INTO horse(id, name, breed, coat, dateOfBirth) VALUES (5, 'Artemis', 'San Fratellano', 'Black', '2024-05-01');
+INSERT INTO horse (id, name, sex, coat, breed, dateOfBirth, registrationNumber, microchipNumber, passportNumber, height)
+VALUES (1, 'Thunder', 'M', 'Black', 'Quarter Horse', '2015-05-12', 'AQHA123456', '123456789012345', 'PASS123', 150);
+
+INSERT INTO horse (id, name, sex, coat, breed, dateOfBirth, registrationNumber, microchipNumber, passportNumber, height)
+VALUES (2, 'Bella', 'F', 'Bay', 'Thoroughbred', '2018-08-20', 'TB123', '987654321098765', 'PASS456', 160);
+
+INSERT INTO horse (id, name, sex, coat, breed, dateOfBirth, registrationNumber, microchipNumber, passportNumber, height)
+VALUES (3, 'Spirit', 'M', 'Chestnut', 'Arabian', '2017-03-05', 'ARAB567', '543210987654321', 'PASS789', 155);
+
+INSERT INTO horse (id, name, sex, coat, breed, dateOfBirth, registrationNumber, microchipNumber, passportNumber, height)
+VALUES (4, 'Whisper', 'F', 'Grey', 'Andalusian', '2016-10-15', 'AND456', '246813579135790', 'PASS246', 158);
+
+INSERT INTO horse (id, name, sex, coat, breed, dateOfBirth, registrationNumber, microchipNumber, passportNumber, height)
+VALUES (5, 'Blaze', 'M', 'Palomino', 'Paint', '2019-07-25', 'PAINT789', '987654321', 'PASS357', 152);
+
ALTER SEQUENCE Horse_SEQ RESTART WITH 6;
-- Insert data into the tables Owner
diff --git a/src/test/java/it/dontesta/eventbus/orm/panache/repository/HorseRepositoryIntegrationTest.java b/src/test/java/it/dontesta/eventbus/orm/panache/repository/HorseRepositoryIntegrationTest.java
index 5c4444e..046e2a2 100644
--- a/src/test/java/it/dontesta/eventbus/orm/panache/repository/HorseRepositoryIntegrationTest.java
+++ b/src/test/java/it/dontesta/eventbus/orm/panache/repository/HorseRepositoryIntegrationTest.java
@@ -30,7 +30,7 @@ void testCount() {
void testFindById() {
Horse horse = horseRepository.findById(1L);
Assertions.assertNotNull(horse);
- Assertions.assertEquals("Judio XXXV", horse.name);
+ Assertions.assertEquals("Thunder", horse.name);
}
@Test
@@ -45,17 +45,17 @@ void testFindAll() {
void testFindOrderedByName() {
List horses = horseRepository.findOrderedByName();
Assertions.assertFalse(horses.isEmpty());
- Assertions.assertEquals("Artemis", horses.getFirst().name);
+ Assertions.assertEquals("Bella", horses.getFirst().name);
Assertions.assertInstanceOf(LocalDate.class, horses.getFirst().dateOfBirth);
}
@Test
@Order(5)
void testFindByName() {
- Horse horse = horseRepository.find("name", "Francisco").firstResult();
+ Horse horse = horseRepository.find("name", "Thunder").firstResult();
Assertions.assertNotNull(horse);
- Assertions.assertEquals("Francisco", horse.name);
- Assertions.assertEquals("Mario", horse.owners.getFirst().name);
+ Assertions.assertEquals("Thunder", horse.name);
+ Assertions.assertEquals("John", horse.owners.getFirst().name);
}
@Test
@@ -66,6 +66,7 @@ void testCreateHorse() {
horse.name = "Test Horse";
horse.coat = "Bay";
horse.breed = "Arabian";
+ horse.sex = "M";
horse.dateOfBirth = LocalDate.of(2010, 1, 1);
horseRepository.persist(horse);
Assertions.assertNotNull(horse.id);
diff --git a/src/test/java/it/dontesta/eventbus/orm/panache/repository/OwnerRepositoryIntegrationTest.java b/src/test/java/it/dontesta/eventbus/orm/panache/repository/OwnerRepositoryIntegrationTest.java
index 09b63d7..902432a 100644
--- a/src/test/java/it/dontesta/eventbus/orm/panache/repository/OwnerRepositoryIntegrationTest.java
+++ b/src/test/java/it/dontesta/eventbus/orm/panache/repository/OwnerRepositoryIntegrationTest.java
@@ -53,7 +53,7 @@ void testFindByName() {
Assertions.assertNotNull(owner);
Assertions.assertNotNull(owner.horses);
Assertions.assertEquals(3, owner.horses.size());
- Assertions.assertEquals("Judio XXXV", owner.horses.getFirst().name);
+ Assertions.assertEquals("Thunder", owner.horses.getFirst().name);
Assertions.assertEquals("Mario", owner.name);
}
}
diff --git a/src/test/java/it/dontesta/eventbus/ws/resources/endpoint/repository/v1/HorseRepositoryResourcesTest.java b/src/test/java/it/dontesta/eventbus/ws/resources/endpoint/repository/v1/HorseRepositoryResourcesTest.java
index 279d40a..d60f115 100644
--- a/src/test/java/it/dontesta/eventbus/ws/resources/endpoint/repository/v1/HorseRepositoryResourcesTest.java
+++ b/src/test/java/it/dontesta/eventbus/ws/resources/endpoint/repository/v1/HorseRepositoryResourcesTest.java
@@ -32,7 +32,7 @@ void getHorseByIdSuccess() {
.contentType(ContentType.JSON)
.when().get("/api/rest/repository/horse/v1/1")
.then()
- .body("name", is("Judio XXXV"))
+ .body("name", is("Thunder"))
.statusCode(Response.Status.OK.getStatusCode());
}
@@ -66,6 +66,7 @@ void testCreateHorse() {
"name": "Santos XVVI",
"coat": "Gray",
"breed": "Pura Raza Española - PRE",
+ "sex": "M",
"dateOfBirth": "2024-05-01",
"owners": [{"id": 3}]
}