This repository contains the backend code for our Quiz Application, Quizopia.
To run the backend server, follow these steps:
- Clone this repository to your local machine:
git clone https://github.com/heikkkk/IDATT2105-Semester-Project-Backend.git
- Ensure you have Java (v17), Maven, MySQL, Flyway, and Docker installed.
- Navigate to the project directory in your terminal.
- Install dependencies and build the project:
mvn clean install
- Start the backend server:
mvn spring-boot:run
Before you can run the application, ensure you have the following software installed on your system:
- Java (v17):The application is built using Java, so you'll need the JDK to compile and run it. Download Java JDK v17
- Maven:Maven is used for dependency management and to build the application. Download Maven
- MySQL:The application uses MySQL as its database. Download MySQL
- Docker:Docker is used for creating containers for the application and database. Download Docker
Before running the Quizopia Backend application, you need to configure it to connect to your MySQL database. This is done by editing the application.yml
file in the src/main/resources
directory.
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://<your-database-url>:<port>/<your-database-name>?allowPublicKeyRetrieval=true
username: <your-database-username>
password: <your-database-password>
Replace <your-database-url>
, <port>
, <your-database-name>
, <your-database-username>
, and <your-database-password>
with your actual MySQL database details.
This step here is necessary to make it easier to configure Flyway to fix migration issues with your database. This is done by editing the pom.xml
file the root
directory.
<profiles>
<profile>
<id>production</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<flyway.url>jdbc:mysql://<your-database-url>:<port>/<your-database-name>?allowPublicKeyRetrieval=true</flyway.url>
<flyway.user><your-database-username></flyway.user>
<flyway.password><your-database-password></flyway.password>
<flyway.locations>classpath:db/migration</flyway.locations>
</properties>
<dependencies>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
</profile>
</profiles>
Replace <your-database-url>
, <port>
, <your-database-name>
, <your-database-username>
, and <your-database-password>
with your actual MySQL database details. This makes it possible to run mvn flyway:repair -P production to fix any migration issues with your test database.
If you also wanna be able to run tests, you need to configure it to connect to a MySQL database that will be used for the tests. This is done by editing the application-test.yml
file in the src/test/resources
directory.
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: ${DB_URL:jdbc:mysql://<your-test-database-url>:<port>/<your-test-database-name>?allowPublicKeyRetrieval=true}
username: ${DB_USERNAME:<your-test-database-username>}
password: ${DB_PASSWORD:<your-test-database-password>}
Replace <your-test-database-url>
, <port>
, <your-test-database-name>
, <your-test-database-username>
, and <your-test-database-password>
with your actual MySQL test database details.
This step here is necessary to make it easier to configure Flyway to fix migration issues with your test database. This is done by editing the pom.xml
file in the root
directory.
<profiles>
<profile>
<id>test</id>
<activation>
<activeByDefault>false</activeByDefault>
</activation>
<properties>
<flyway.url>jdbc:mysql://<your-test-database-url>:<port>/<your-test-database-name>?allowPublicKeyRetrieval=true</flyway.url>
<flyway.user><your-test-database-username></flyway.user>
<flyway.password><your-test-database-password></flyway.password>
<flyway.locations>classpath:db/migration</flyway.locations>
</properties>
<dependencies>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
</profile>
</profiles>
Replace <your-test-database-url>
, <port>
, <your-test-database-name>
, <your-test-database-username>
, and <your-test-database-password>
with your actual MySQL test database details. This makes it possible to run mvn flyway:repair -P test to fix any migration issues with your test database.
Our application automatically runs Flyway migrations when you start the application or run tests. This process applies the necessary SQL scripts to create or update the database schema.
- Install dependencies and build the project (if you haven't already done so):
mvn clean install
- Run all tests against your MySQL test database:
mvn test
- To test a specific method (Optional):
mvn -Dtest=YourTestClass#YourTestMethod test
Replace YourTestClass
with the name of the test class and YourTestMethod
with the name of the method you wanna test.
- To test E2E tests locally up against your MySQL test database (Optional):
mvn -Dtest=YourTestClass#YourTestMethod test
During the development and operation of Quizopia, you may encounter various issues. Below are some of the common problems and their solutions:
Issue: The schema in the database does not match the one locally, leading to inconsistencies and potential application errors.
Solution: Use Flyway's repair feature:
mvn flyway:repair -P production
Similarily, if you are having Migration Faults with the test database:
mvn flyway:repair -P test
Issue: The application fails to connect to the database, indicating a possible misconfiguration.
Solution: Ensure your database is correctly configured. Common misconfigurations include incorrect database URL, port, username, or password. Double-check your configurations.
Tests are run continuously with the Continuous Integration pipeline through Github Actions. The pipeline executes Maven commands to build the application and run tests. There is also another workflow that makes the e2e workflow on our frontend application run: https://github.com/heikkkk/IDATT2105-Semester-Project-Frontend. Run the index.html file found at: /target/site/jacoco/index.html
to view the test coverage.
The Continuous Deployment pipeline automates the deployment of the Quizopia backend application to GitHub Packages whenever changes are pushed to the main branch. The deployment to GitHub Packages allows for seamless distribution and versioning of the application, ensuring that the most current and stable version is always available for deployment and integration.
- Henrik Teksle Sandok
- Jens Christian Aanestad
- Andreas Kluge Svendsrud
- Anders Høvik