Skip to content

Commit

Permalink
Merge branch 'support/review-orm-model' into develop
Browse files Browse the repository at this point in the history
Aggiornamento model ORM Panache Horse
  • Loading branch information
amusarra committed May 10, 2024
2 parents b39af28 + 2e69613 commit 7268f08
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 16 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>it.dontesta.eventbus</groupId>
<artifactId>eventbus-logging-filter-jaxrs</artifactId>
<version>1.2.0</version>
<version>1.2.1</version>

<name>eventbus-logging-filter-jaxrs</name>
<description>Event Bus Logging Filter JAX-RS</description>
Expand Down
24 changes: 21 additions & 3 deletions src/main/java/it/dontesta/eventbus/orm/panache/entity/Horse.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<Owner> owners;
}
20 changes: 15 additions & 5 deletions src/main/resources/load_data.sql
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -45,17 +45,17 @@ void testFindAll() {
void testFindOrderedByName() {
List<Horse> 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
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down Expand Up @@ -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}]
}
Expand Down

0 comments on commit 7268f08

Please sign in to comment.