diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..01276d9 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,38 @@ +name: Spring Boot Build + +on: + pull_request: + branch_protection_rule: + branches: [ dev, main ] + workflow_call: + workflow_dispatch: # Manually run the workflow + +jobs: + gradle-build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up JDK 20.0.1 + uses: actions/setup-java@v1 + with: + java-version: 20.0.1 + + - name: Cache Gradle dependencies + id: gradle-cache + uses: actions/cache@v2 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} + restore-keys: | + gradle-${{ runner.os }}- + + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + - name: Build with Gradle + run: ./gradlew build --stacktrace \ No newline at end of file diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml new file mode 100644 index 0000000..aba8322 --- /dev/null +++ b/.github/workflows/unit-test.yml @@ -0,0 +1,38 @@ +name: Spring Boot Unit Tests + +on: + pull_request: + branch_protection_rule: + branches: [ dev, main ] + workflow_dispatch: # Manually run the workflow + +jobs: + unit-test: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up JDK 20.0.1 + uses: actions/setup-java@v1 + with: + java-version: 20.0.1 + + - name: Grant execute permission for gradlew + run: chmod +x gradlew + + - name: Restore Gradle build caches + id: gradle-cache-restore + uses: actions/cache@v2 + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} + restore-keys: | + gradle-${{ runner.os }}- + + - name: Run Tests + id: run-tests + run: ./gradlew test --stacktrace diff --git a/build.gradle.kts b/build.gradle.kts index b04dd87..59b7d45 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -25,6 +25,9 @@ dependencies { // https://mvnrepository.com/artifact/mysql/mysql-connector-java runtimeOnly("mysql:mysql-connector-java:8.0.33") + // H2 database + runtimeOnly("com.h2database:h2") + // https://mvnrepository.com/artifact/org.hibernate/hibernate-core implementation("org.hibernate:hibernate-core:6.2.9.Final") diff --git a/src/test/java/spring/practice/zentarea/ZenTareaApplicationTests.java b/src/test/java/spring/practice/zentarea/ZenTareaApplicationTests.java index 0f3ff66..6deed7f 100644 --- a/src/test/java/spring/practice/zentarea/ZenTareaApplicationTests.java +++ b/src/test/java/spring/practice/zentarea/ZenTareaApplicationTests.java @@ -1,9 +1,11 @@ package spring.practice.zentarea; -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; +import org.junit.jupiter.api.*; +import org.springframework.boot.test.context.*; +import org.springframework.test.context.*; @SpringBootTest +@TestPropertySource(locations = "classpath:application.properties") class ZenTareaApplicationTests { @Test diff --git a/src/test/resources/application.properties b/src/test/resources/application.properties new file mode 100644 index 0000000..1a0bd50 --- /dev/null +++ b/src/test/resources/application.properties @@ -0,0 +1,13 @@ +spring.datasource.url=jdbc:h2:mem:test;MODE=MySQL; +spring.datasource.driver-class-name=org.h2.Driver +spring.datasource.username= +spring.datasource.password= +# We add the MySQL Dialect so that it understands and generates the query based on MySQL +spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect +spring.h2.console.enabled=true +spring.jpa.defer-datasource-initialization=true +spring.jpa.hibernate.ddl-auto=update +spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl +spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl +spring.jpa.properties.hibernate.format_sql=true +spring.sql.init.mode=always \ No newline at end of file