Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Test Resources plugin #6

Merged
merged 6 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/cypress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: Run the server with Gradle
env:
VITE_BACKEND_URL: /api
MICRONAUT_ENVIRONMENTS: dev,dev-data
MICRONAUT_ENVIRONMENTS: h2,dev,dev-data
run: |
./gradlew app:run &
- name: Cypress run
Expand Down
18 changes: 17 additions & 1 deletion .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,23 @@ jobs:
distribution: 'temurin'
- name: Build with Gradle
env:
MICRONAUT_ENVIRONMENTS: dev,dev-data
MICRONAUT_ENVIRONMENTS: h2,dev,dev-data
uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1
with:
arguments: 'app:build'
- name: Build with Gradle - MySQL Datasource
if: ${{ success() }}
env:
DPM_DATABASE_DEPENDENCY: mysql:mysql-connector-java:8.0.31
DPM_DB_TYPE: mysql
uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1
with:
arguments: 'app:build'
- name: Build with Gradle - PostgreSQL Datasource
if: ${{ success() }}
env:
DPM_DATABASE_DEPENDENCY: org.postgresql:postgresql:42.4.2
DPM_DB_TYPE: postgres
uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1
with:
arguments: 'app:build'
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,11 @@ To connect to a database, the following environment variables must be set for th
* DPM_JDBC_PASSWORD - The database user password.
* DPM_AUTO_SCHEMA_GEN (Options include `none`, `create-only`, `drop`, `create`, `create-drop`, `validate`, and `update` (default value))

Note: In a deployed environment, it is recommended to set the `MICRONAUT_ENVIRONMENTS` environment variable to include
the `prod` value so that the above environments variables are registered. Otherwise, in a local development environment,
please feel free to update datasource configuration either in the application.yml or application-dev.yml files
`app/src/main/resources` directory.

The following describes the options for DPM_AUTO_SCHEMA_GEN environment variable in detail:

* *none** - No action will be performed.
Expand Down
4 changes: 4 additions & 0 deletions app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ The project requires JDK 11 or later to build and run. There is no need to
install the Micronaut framework, or Gradle, or any tools other than the JDK in order to
build and run the app.

As a prerequisite, please set the `MICRONAUT_ENVIRONMENTS` environment variable to `h2,dev`.
This will enable the application to use an in-memory database, namely H2, and sets default values
for local development environments.

From the project root, the app may be run locally using gradle:

./gradlew app:run
Expand Down
11 changes: 8 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ buildscript {
}
plugins {
id("com.github.johnrengelman.shadow") version "7.1.2"
id 'jacoco'
id "com.gorylenko.gradle-git-properties" version "2.3.2"
id("jacoco")
id("com.gorylenko.gradle-git-properties") version "2.3.2"
id("io.micronaut.application") version "3.7.8"
id("io.micronaut.test-resources") version "3.7.8"
}

version = "0.1"
Expand Down Expand Up @@ -73,7 +74,7 @@ dependencies {
}
if (mnEnvs != null) {
def envList = mnEnvs.split(',').each {it.trim()}.collect()
if (envList.contains("dev") || envList.contains("test")) {
if (envList.contains("h2")) {
runtimeOnly("com.h2database:h2")
}
}
Expand All @@ -96,6 +97,10 @@ micronaut {
incremental(true)
annotations("io.unityfoundation.dds.permissions.manager.*")
}
// see https://micronaut-projects.github.io/micronaut-gradle-plugin/latest/#_configuring_the_test_resources_plugin
testResources {
enabled = true
}
}

tasks.withType(JavaCompile) {
Expand Down
19 changes: 19 additions & 0 deletions app/src/main/resources/application-h2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2023 DDS Permissions Manager Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
datasources:
default:
url: jdbc:h2:mem:devDb;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE;IGNORECASE=TRUE
driverClassName: org.h2.Driver
username: sa
password: ''
20 changes: 20 additions & 0 deletions app/src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2023 DDS Permissions Manager Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
datasources:
default:
url: ${DPM_JDBC_URL}
driverClassName: ${DPM_JDBC_DRIVER}
username: ${DPM_JDBC_USER}
password: ${DPM_JDBC_PASSWORD}
db-type: ${DATASOURCES_DEFAULT_DB_TYPE}
5 changes: 1 addition & 4 deletions app/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,7 @@ micronaut:
---
datasources:
default:
url: ${DPM_JDBC_URL:`jdbc:h2:mem:devDb;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE;IGNORECASE=TRUE`}
driverClassName: ${DPM_JDBC_DRIVER:org.h2.Driver}
username: ${DPM_JDBC_USER:sa}
password: ${DPM_JDBC_PASSWORD:""}
db-type: ${DPM_DB_TYPE}
jpa:
default:
entity-scan:
Expand Down
14 changes: 14 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2023 DDS Permissions Manager Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
micronautVersion=3.8.9
Loading