diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1f33738b3eaae1d1942e0d1c0703a297052faa64..cb282f6d42063de00c779dc53ba1f0ecb4d73424 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -14,14 +14,36 @@ default: stages: - build - - test + - tests build: stage: build script: + - echo "We are building your project" - mvn clean install $MAVEN_CLI_OPTS -DskipTests -test: - stage: test +unit_test: + stage: tests script: - - mvn test $MAVEN_CLI_OPTS \ No newline at end of file + - echo "We are testing your project build with unit tests" + - mvn test $MAVEN_CLI_OPTS + artifacts: + expire_in: 10 min + paths: + - "*/target/surefire-reports/*" + reports: + junit: + - "*/target/surefire-reports/*.xml" + +integration_test: + stage: tests + script: + - echo "We are testing your project build with integration tests" + - mvn verify $MAVEN_CLI_OPTS + artifacts: + expire_in: 10 min + paths: + - "*/target/failsafe-reports/*" + reports: + junit: + - "*/target/failsafe-reports/*.xml" diff --git a/README.md b/README.md index 67d0f5b5a416101727fb503a167a922c96c60822..63ebe41cdd12ddfb15957a147d76b4f5f6d327db 100644 --- a/README.md +++ b/README.md @@ -97,6 +97,15 @@ Just note that each module runs on a different port by default, so care where yo These ports can be overridden either in the application.properties file of each module, or by specifying the port manually when running the "mvn" command to run the module. +## Seed and clear DB +DB is at the start of the app seeded with some Data, thus you don't have to do it manually. +For users are available 2 endpoints: + +- /seed - Seed DB with some Data +- /clear - Clear DB whenever during running + +*Note: /seed will always seed DB with the same Data. Keep in mind, If you seed DB after startup, DB will contain the same data twice.* + ## Build and run the app with Docker For purpose of this build and run the installation of Docker/Podman diff --git a/application/openapi.yaml b/application/openapi.yaml index ad0409608d74bee41087e980e18ff58fe5d8b776..b53ae168b2a36251d71568da139505eb53934226 100644 --- a/application/openapi.yaml +++ b/application/openapi.yaml @@ -39,10 +39,12 @@ components: type: string description: Name of the person example: Max + maxLength: 35 surname: type: string description: Surname of the person example: Verstappen + maxLength: 35 birthday: type: string description: Date of birth @@ -64,9 +66,11 @@ components: name: type: string description: Name of the person + maxLength: 35 surname: type: string description: Name of the person + maxLength: 35 birthday: type: string description: Date of birth diff --git a/application/src/main/java/cz/muni/pa165/data/model/Application.java b/application/src/main/java/cz/muni/pa165/data/model/Application.java index c597fbb4ad52e08dc26dc9f9e8b81d55b2533217..578ee814be2e0b1b3992ba684129a0c529561387 100644 --- a/application/src/main/java/cz/muni/pa165/data/model/Application.java +++ b/application/src/main/java/cz/muni/pa165/data/model/Application.java @@ -22,9 +22,11 @@ public class Application implements Serializable { private ApplicationStatusEnum status; @NotEmpty + @Size(max = 35) private String name; @NotEmpty + @Size(max = 35) private String surname; @Past diff --git a/application/src/test/java/cz/muni/pa165/rest/IntegrationTests.java b/application/src/test/java/cz/muni/pa165/ApplicationIT.java similarity index 93% rename from application/src/test/java/cz/muni/pa165/rest/IntegrationTests.java rename to application/src/test/java/cz/muni/pa165/ApplicationIT.java index 624ff7406426fc025bed692a05a9a828c298c91a..ea447845786e1d3b105a1b551683339e63a64526 100644 --- a/application/src/test/java/cz/muni/pa165/rest/IntegrationTests.java +++ b/application/src/test/java/cz/muni/pa165/ApplicationIT.java @@ -1,4 +1,4 @@ -package cz.muni.pa165.rest; +package cz.muni.pa165; import org.junit.jupiter.api.Test; import org.slf4j.Logger; @@ -23,9 +23,9 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. @SpringBootTest @AutoConfigureMockMvc @ActiveProfiles("test") -class IntegrationTests { +class ApplicationIT { - private static final Logger log = LoggerFactory.getLogger(IntegrationTests.class); + private static final Logger log = LoggerFactory.getLogger(ApplicationIT.class); @Autowired private MockMvc mockMvc; diff --git a/core/openapi.yaml b/core/openapi.yaml index 03bf9819526868392e5e44723e99504c801a1b14..0d2b2786ce14a421db580106320e362d256d488b 100644 --- a/core/openapi.yaml +++ b/core/openapi.yaml @@ -47,6 +47,7 @@ components: type: string description: Specific information about component example: lightweight front wing v2 (black) + maxLength: 100 CarComponentCreateDto: type: object properties: @@ -58,6 +59,7 @@ components: information: type: string description: Specific information about component + maxLength: 100 required: - componentType - weight @@ -73,6 +75,7 @@ components: information: type: string description: Specific information about component + maxLength: 100 CarDto: type: object @@ -130,10 +133,12 @@ components: type: string description: Name of the driver example: Max + maxLength: 35 surname: type: string description: Surname of the driver example: Verstappen + maxLength: 35 height: type: integer description: Height in cm @@ -147,6 +152,7 @@ components: type: string description: Nationality of the driver example: Dutch + maxLength: 20 characteristics: type: array description: Set of driver's characteristics @@ -158,12 +164,15 @@ components: name: type: string description: Name of the driver + maxLength: 35 surname: type: string description: Name of the driver + maxLength: 35 nationality: type: string description: nationality of the driver + maxLength: 20 height: type: integer description: Height in cm @@ -178,12 +187,15 @@ components: name: type: string description: Name of the driver + maxLength: 35 surname: type: string description: Name of the driver + maxLength: 35 nationality: type: string description: Nationality of the driver + maxLength: 20 height: type: integer description: Height in cm @@ -220,10 +232,12 @@ components: type: string description: Name of the engineer example: John + maxLength: 35 surname: type: string description: Surname of the engineer example: Doe + maxLength: 35 EngineerCreateDto: type: object title: Engineer @@ -236,10 +250,12 @@ components: type: string description: Name of the engineer example: John + maxLength: 35 surname: type: string description: Surname of the engineer example: Doe + maxLength: 35 DepartmentDto: type: object @@ -259,6 +275,7 @@ components: specialization: type: string example: "Aerodynamics" + maxLength: 100 DepartmentUpdateDto: type: object properties: @@ -266,6 +283,7 @@ components: type: string example: "Aerodynamics" description: New specialization + maxLength: 100 required: - specialization DepartmentCreateDto: @@ -274,6 +292,7 @@ components: specialization: type: string example: "Aerodynamics" + maxLength: 100 required: - specialization Pageable: diff --git a/core/src/main/java/cz/muni/pa165/data/model/Car.java b/core/src/main/java/cz/muni/pa165/data/model/Car.java index cfd36d0e767f35be14f300ccdc7a8271e7e4168e..26bd28b436b3549c42ae944ee8608c6c31f11abc 100644 --- a/core/src/main/java/cz/muni/pa165/data/model/Car.java +++ b/core/src/main/java/cz/muni/pa165/data/model/Car.java @@ -11,7 +11,7 @@ import java.util.Set; @Entity @Table(name = "car") -public class Car extends DomainObject implements Serializable { +public class Car extends DomainObject<Long> implements Serializable { @OneToOne(fetch = FetchType.LAZY) @JoinColumn(name = "driver_id") @Nullable diff --git a/core/src/main/java/cz/muni/pa165/data/model/CarComponent.java b/core/src/main/java/cz/muni/pa165/data/model/CarComponent.java index f5641c0d22840e9cd6737e45d1d9e8ca716fa621..9b63182b9dbb0beb9284918ea42fc30ebc500388 100644 --- a/core/src/main/java/cz/muni/pa165/data/model/CarComponent.java +++ b/core/src/main/java/cz/muni/pa165/data/model/CarComponent.java @@ -6,13 +6,14 @@ import jakarta.annotation.Nullable; import jakarta.persistence.*; import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.Positive; +import jakarta.validation.constraints.Size; import java.io.Serializable; import java.util.Objects; @Entity @Table(name = "car_component") -public class CarComponent extends DomainObject implements Serializable { +public class CarComponent extends DomainObject<Long> implements Serializable { @Column(name = "component_type") @Enumerated(EnumType.STRING) @@ -24,6 +25,7 @@ public class CarComponent extends DomainObject implements Serializable { private Double weight; @NotEmpty + @Size(max = 100) private String information; @ManyToOne(fetch = FetchType.LAZY) diff --git a/core/src/main/java/cz/muni/pa165/data/model/Department.java b/core/src/main/java/cz/muni/pa165/data/model/Department.java index ca27780d3ef0eb0a4a98055a5e5b18a4a43db1c7..43a7be25ad8c4c6543667c61cb9dcca9c080c3ef 100644 --- a/core/src/main/java/cz/muni/pa165/data/model/Department.java +++ b/core/src/main/java/cz/muni/pa165/data/model/Department.java @@ -3,6 +3,7 @@ package cz.muni.pa165.data.model; import jakarta.annotation.Nullable; import jakarta.persistence.*; import jakarta.validation.constraints.NotEmpty; +import jakarta.validation.constraints.Size; import java.io.Serializable; import java.util.Objects; @@ -10,9 +11,10 @@ import java.util.Set; @Entity @Table(name = "department") -public class Department extends DomainObject implements Serializable { +public class Department extends DomainObject<Long> implements Serializable { @NotEmpty + @Size(max = 100) private String specialization; @OneToMany(fetch = FetchType.LAZY, diff --git a/core/src/main/java/cz/muni/pa165/data/model/DomainObject.java b/core/src/main/java/cz/muni/pa165/data/model/DomainObject.java index 1fa12590cf56406a08fb1a554ecef9e94b484014..7071f57d04baa00e3b7fda2e2f2af36deac209c6 100644 --- a/core/src/main/java/cz/muni/pa165/data/model/DomainObject.java +++ b/core/src/main/java/cz/muni/pa165/data/model/DomainObject.java @@ -6,20 +6,22 @@ import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import jakarta.persistence.MappedSuperclass; +import java.io.Serializable; + /** * @author Michal Badin */ @MappedSuperclass -public abstract class DomainObject { +public abstract class DomainObject<PK extends Serializable> implements Serializable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; + private PK id; - public Long getId() { + public PK getId() { return id; } - public void setId(Long id) { + public void setId(PK id) { this.id = id; } } diff --git a/core/src/main/java/cz/muni/pa165/data/model/Driver.java b/core/src/main/java/cz/muni/pa165/data/model/Driver.java index efa7bad06caf0c425cf334b18f929505357dd926..6f8f8e2a9b7bf94b944388e91e9120a36b8a8153 100644 --- a/core/src/main/java/cz/muni/pa165/data/model/Driver.java +++ b/core/src/main/java/cz/muni/pa165/data/model/Driver.java @@ -4,10 +4,7 @@ import cz.muni.pa165.data.enums.CharacteristicsEnum; import jakarta.annotation.Nonnull; import jakarta.annotation.Nullable; import jakarta.persistence.*; -import jakarta.validation.constraints.Max; -import jakarta.validation.constraints.Min; -import jakarta.validation.constraints.NotEmpty; -import jakarta.validation.constraints.Past; +import jakarta.validation.constraints.*; import java.io.Serializable; import java.time.LocalDate; @@ -16,12 +13,14 @@ import java.util.Set; @Entity @Table(name = "driver") -public class Driver extends DomainObject implements Serializable { +public class Driver extends DomainObject<Long> implements Serializable { @NotEmpty + @Size(max = 35) private String name; @NotEmpty + @Size(max = 35) private String surname; @Nullable @@ -34,6 +33,7 @@ public class Driver extends DomainObject implements Serializable { private LocalDate birthday; @NotEmpty + @Size(max = 20) private String nationality; @ElementCollection(targetClass = CharacteristicsEnum.class) diff --git a/core/src/main/java/cz/muni/pa165/data/model/Engineer.java b/core/src/main/java/cz/muni/pa165/data/model/Engineer.java index 7fa3623617173ca276db256d65cde8716efa63c8..1e8e5dbad8c6b3f68ace657aaa60ce16d50dc3cc 100644 --- a/core/src/main/java/cz/muni/pa165/data/model/Engineer.java +++ b/core/src/main/java/cz/muni/pa165/data/model/Engineer.java @@ -3,18 +3,21 @@ package cz.muni.pa165.data.model; import jakarta.annotation.Nullable; import jakarta.persistence.*; import jakarta.validation.constraints.NotEmpty; +import jakarta.validation.constraints.Size; import java.io.Serializable; import java.util.Objects; @Entity @Table(name = "engineer") -public class Engineer extends DomainObject implements Serializable { +public class Engineer extends DomainObject<Long> implements Serializable { @NotEmpty + @Size(max = 35) private String name; @NotEmpty + @Size(max = 35) private String surname; @ManyToOne(fetch = FetchType.LAZY) diff --git a/core/src/main/java/cz/muni/pa165/data/repository/CarRepository.java b/core/src/main/java/cz/muni/pa165/data/repository/CarRepository.java index 9b0400b217d452c01911b581b5107403a12f733a..7d4091c81cab8aa9924b98d0b82242d17d216c63 100644 --- a/core/src/main/java/cz/muni/pa165/data/repository/CarRepository.java +++ b/core/src/main/java/cz/muni/pa165/data/repository/CarRepository.java @@ -10,6 +10,6 @@ import java.util.Optional; @Repository public interface CarRepository extends JpaRepository<Car, Long> { - @Query("SELECT c FROM Car c LEFT JOIN FETCH c.components LEFT JOIN FETCH c.driver WHERE c.id = :id") + @Query("SELECT c FROM Car c LEFT JOIN FETCH c.components cc LEFT JOIN FETCH c.driver d WHERE c.id = :id") Optional<Car> findById(@Param("id") Long id); } diff --git a/core/src/test/java/cz/muni/pa165/IntegrationTests.java b/core/src/test/java/cz/muni/pa165/CoreIT.java similarity index 99% rename from core/src/test/java/cz/muni/pa165/IntegrationTests.java rename to core/src/test/java/cz/muni/pa165/CoreIT.java index 431374b5b7eaf5800a824a659f77d2feb32c82db..aa9991cf066891580d1fa8b00f4ae490195594e4 100644 --- a/core/src/test/java/cz/muni/pa165/IntegrationTests.java +++ b/core/src/test/java/cz/muni/pa165/CoreIT.java @@ -33,9 +33,9 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. @SpringBootTest @AutoConfigureMockMvc @ActiveProfiles("test") -class IntegrationTests { +class CoreIT { - private static final Logger log = LoggerFactory.getLogger(IntegrationTests.class); + private static final Logger log = LoggerFactory.getLogger(CoreIT.class); private final ObjectMapper mapper = new ObjectMapper().registerModule(new JavaTimeModule()); @Autowired diff --git a/notification/src/test/java/cz/muni/pa165/rest/IntegrationTests.java b/notification/src/test/java/cz/muni/pa165/rest/NotificationIT.java similarity index 95% rename from notification/src/test/java/cz/muni/pa165/rest/IntegrationTests.java rename to notification/src/test/java/cz/muni/pa165/rest/NotificationIT.java index f05e0787f0cb302dfa48f455fefe2cfdb97e0cb5..9bb60eb71a5561d8b62b37c747686d0dec765306 100644 --- a/notification/src/test/java/cz/muni/pa165/rest/IntegrationTests.java +++ b/notification/src/test/java/cz/muni/pa165/rest/NotificationIT.java @@ -19,9 +19,9 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. */ @SpringBootTest @AutoConfigureMockMvc -class IntegrationTests { +class NotificationIT { - private static final Logger log = LoggerFactory.getLogger(IntegrationTests.class); + private static final Logger log = LoggerFactory.getLogger(NotificationIT.class); @Autowired private MockMvc mockMvc; diff --git a/visualization/src/test/java/cz/muni/pa165/rest/IntegrationTests.java b/visualization/src/test/java/cz/muni/pa165/rest/VisualizationIT.java similarity index 93% rename from visualization/src/test/java/cz/muni/pa165/rest/IntegrationTests.java rename to visualization/src/test/java/cz/muni/pa165/rest/VisualizationIT.java index 4addd5d6549a4c890c4cffcca28bdd1c32b67fa3..af8bf675cf935e277ea3d59446ceb09ca07165c7 100644 --- a/visualization/src/test/java/cz/muni/pa165/rest/IntegrationTests.java +++ b/visualization/src/test/java/cz/muni/pa165/rest/VisualizationIT.java @@ -19,9 +19,9 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. */ @SpringBootTest @AutoConfigureMockMvc -class IntegrationTests { +class VisualizationIT { - private static final Logger log = LoggerFactory.getLogger(IntegrationTests.class); + private static final Logger log = LoggerFactory.getLogger(VisualizationIT.class); @Autowired private MockMvc mockMvc;