Skip to content

Commit

Permalink
story: 117304 implement openklant 2.0 (#302)
Browse files Browse the repository at this point in the history
* wip

* wip

* wip

* wip

* improve gradle setup so that docker compose can be used for integration testing on macOS

* * make filtering easier to apply to OpenKlant requests
* fix integration tests not running on check/build
* remove unnecessary Create* dto's

* * separate contactgegevens api from klantinteracties api in OpenKlant Module

* * more gradle test fixes
* expand filtering with page

* * added partijen path test
* refactored some functions and class names

* * wip PartijMutation

* * add initial PartijMutation test

* * add assertions to Partij Mutation test

* * implement updatePartij mutation

* * run ktlint

* * refactor some tests
* introduce initial DigitaleAdres related entities and queries

* * change default loglevels for app to info
* disable sql logging for app
* fix DigitaleAdresType serialization
* add authentication requirement to all openklant queries and mutations
* add delete DigitaleAdres mutation

* * revert splitting autoconfiguration
* change base integration test image

* * add missing queries

* * changed return type of deleteUserDigitaleAdres mutation
* integration tests for DigitaleAdres
* fixed integration test ordering in test classe where it matters
  • Loading branch information
anna-ritense authored Oct 14, 2024
1 parent beb75c1 commit b9d4773
Show file tree
Hide file tree
Showing 67 changed files with 4,279 additions and 28 deletions.
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ dependencies {
implementation(project(":product"))
implementation(project(":form"))
implementation(project(":zgw:taak"))
implementation(project(":zgw:openklant"))
implementation(project(":zgw:zaken-api"))
implementation(project(":zgw:catalogi-api"))
implementation(project(":zgw:documenten-api"))
Expand Down
12 changes: 9 additions & 3 deletions app/src/main/resources/config/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ spring:
jpa:
database-platform: org.hibernate.dialect.PostgreSQLDialect
database: postgresql
show_sql: true
show_sql: false
open-in-view: false
properties:
hibernate:
Expand Down Expand Up @@ -69,9 +69,15 @@ graphql:

logging:
level:
org.springframework.amqp: DEBUG
root: INFO

nl-portal:
config:
openklant:
enabled: true
properties:
klantinteracties-api-url: http://localhost:8007/klantinteracties/api/v1
token: ac045222c9e7cde8120b48735560f9b920bb58cd
zgw:
catalogiapi:
url: http://localhost:8001
Expand Down Expand Up @@ -169,4 +175,4 @@ nl-portal:
shaInKey: de14f0e3-2ff0-45eb-95a6-1cdc35ca7a00
shaOutKey: de14f0e3-2ff0-45eb-95a6-1cdc35ca7a00
failureUrl: http://localhost:3000
successUrl: http://localhost:3000
successUrl: http://localhost:3000
20 changes: 16 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import io.spring.gradle.dependencymanagement.dsl.DependencyManagementExtension
import io.spring.gradle.dependencymanagement.org.codehaus.plexus.interpolation.os.Os.FAMILY_MAC
import org.apache.tools.ant.taskdefs.condition.Os
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile
import java.net.URI
Expand Down Expand Up @@ -122,6 +124,10 @@ subprojects {
freeCompilerArgs.add("-Xjsr305=strict")
freeCompilerArgs.add("-Xemit-jvm-type-annotations")
}
val ktlintFormat: Task? by tasks
if (ktlintFormat != null) {
dependsOn(ktlintFormat)
}
}

println("Enabling Spring Boot Dependency Management in project ${project.name}...")
Expand All @@ -134,10 +140,6 @@ subprojects {
}
}

tasks.withType<Test> {
useJUnitPlatform()
}

publishing {
repositories {
maven {
Expand Down Expand Up @@ -208,6 +210,16 @@ subprojects {
sign(publishing.publications["default"])
}
}

apply(from = "${rootProject.projectDir}/gradle/testing.gradle.kts")

if (Os.isFamily(FAMILY_MAC)) {
println("Configure docker compose for macOs")
dockerCompose {
executable = "/usr/local/bin/docker-compose"
dockerExecutable = "/usr/local/bin/docker"
}
}
}

tasks.register<HtmlDependencyReportTask>("htmlDependencyReport")
Expand Down
11 changes: 2 additions & 9 deletions case/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import io.spring.gradle.dependencymanagement.org.codehaus.plexus.interpolation.os.Os.FAMILY_MAC
import org.apache.tools.ant.taskdefs.condition.Os

/*
* Copyright 2015-2023 Ritense BV, the Netherlands.
*
Expand All @@ -21,12 +18,8 @@ plugins {
}

dockerCompose {
if (Os.isFamily(FAMILY_MAC)) {
executable = "/usr/local/bin/docker-compose"
dockerExecutable = "/usr/local/bin/docker"
}
projectNamePrefix = "case"
isRequiredBy(tasks.getByName("test"))
setProjectName("$name-test")
isRequiredBy(tasks.getByName("integrationTest"))
useComposeFiles.addAll("../docker-resources/docker-compose-base-test.yml", "docker-compose-override.yml")
}

Expand Down
3 changes: 1 addition & 2 deletions docker-resources/docker-compose-base-test.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
version: '3.9'
services:
db:
image: "postgres"
image: postgres:15
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=test
Expand Down
5 changes: 5 additions & 0 deletions docker-resources/imports/openklant-2/database/init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

echo ">>>> Starting Open Klant data import script <<<<"

sh /docker-entrypoint-initdb.d/sql/fill-data-on-startup.sh &
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
INSERT INTO public.token_tokenauth (id, token, contact_person, email, organization, last_modified, created, application, administration) VALUES (1, 'ac045222c9e7cde8120b48735560f9b920bb58cd', 'Admin', '[email protected]', '', '2024-09-06 07:26:53.703312 +00:00', '2024-09-06 07:26:53.703384 +00:00', '', '');
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

echo ">>>> Waiting until Open Klant has initialized the database <<<<"
while true
do
initiated=$(psql -U openklant -d openklant -t -A -c "SELECT EXISTS (SELECT table_name FROM information_schema.tables WHERE table_name = 'accounts_user');")
if [ "t" = "${initiated}" ]
then
echo "Running database setup scripts"
for file in /docker-entrypoint-initdb.d/sql/*.sql
do
echo "Running $file"
psql -U openklant -d openklant -f $file
done
break
else
echo "Open Klanten is not initiated yet"
sleep 5
fi
done
21 changes: 21 additions & 0 deletions docker-resources/imports/openklant-2/init/init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

# Apply database migrations
>&2 echo "Apply database migrations"
python src/manage.py migrate

exists=$(echo "from django.contrib.auth import get_user_model; User = get_user_model(); print(User.objects.filter(username='admin').exists())" | python src/manage.py shell)
if [ "False" = "${exists}" ]
then
echo "Creating user 'admin'"
python src/manage.py createsuperuser --username=admin [email protected] --noinput
else
echo "User 'admin' already exists"
fi
echo "Setting 'admin' password."
echo "from django.contrib.auth import get_user_model; User = get_user_model(); user = User.objects.get(username='admin'); user.set_password('admin'); user.save()" | python src/manage.py shell
echo "Loading fixtures"
python src/manage.py loaddata klantinteracties contactgegevens
echo "Finished setup"

sh /start.sh
11 changes: 2 additions & 9 deletions form/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import io.spring.gradle.dependencymanagement.org.codehaus.plexus.interpolation.os.Os.FAMILY_MAC
import org.apache.tools.ant.taskdefs.condition.Os

/*
* Copyright 2015-2023 Ritense BV, the Netherlands.
*
Expand All @@ -21,12 +18,8 @@ plugins {
}

dockerCompose {
if (Os.isFamily(FAMILY_MAC)) {
executable = "/usr/local/bin/docker-compose"
dockerExecutable = "/usr/local/bin/docker"
}
projectNamePrefix = "form"
isRequiredBy(tasks.getByName("test"))
setProjectName("$name-test")
isRequiredBy(tasks.getByName("integrationTest"))
useComposeFiles.addAll("../docker-resources/docker-compose-base-test.yml", "docker-compose-override.yml")
}

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ dokkaVersion=1.9.20

org.gradle.jvmargs=-Xmx6g -XX:MaxMetaspaceSize=2048m
org.gradle.workers.max=10
version=1.4.21-SNAPSHOT
version=1.4.21-SNAPSHOT
37 changes: 37 additions & 0 deletions gradle/testing.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2015-2024 Ritense BV, the Netherlands.
*
* Licensed under EUPL, Version 1.2 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
*
* 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.
*/

tasks.register<Test>("integrationTest") {
group = "verification"
description =
"""
Composes docker containers and runs Tests tagged with "integration".
NB! Project root must contain a docker compose file with the following name: docker-compose-override.yml
""".trimIndent()
useJUnitPlatform {
includeTags("integration")
}
}

tasks.named<Test>("test") {
useJUnitPlatform {
excludeTags("integration")
}
}

tasks.named("check") {
dependsOn(tasks.getByName("integrationTest"))
}
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,5 @@ include(
"zgw:taak",
"zgw:zaken-api",
"zgw:objectenapi",
"zgw:openklant",
)
50 changes: 50 additions & 0 deletions zgw/openklant/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import org.springframework.boot.gradle.tasks.bundling.BootJar

/*
* Copyright (c) 2024 Ritense BV, the Netherlands.
*
* Licensed under EUPL, Version 1.2 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
*
* 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.
*/
plugins {
kotlin("jvm")
}

val isLib = true

dockerCompose {
setProjectName("$name-test")
isRequiredBy(tasks.getByName("integrationTest"))
useComposeFiles.addAll("../../docker-resources/docker-compose-base-test.yml", "docker-compose-override.yml")
}

dependencies {
api(project(":graphql"))
api(project(":portal-authentication"))
api(project(":zgw:common-ground-authentication"))

testImplementation(project(":zgw:common-ground-authentication-test"))
testImplementation(TestDependencies.postgresql)
testImplementation("org.springframework.boot", "spring-boot-starter-test")
testImplementation("org.springframework.security", "spring-security-test")
testImplementation(TestDependencies.kotlinCoroutines)
testImplementation(TestDependencies.mockitoKotlin)
testImplementation(TestDependencies.okHttpMockWebserver)
testImplementation(TestDependencies.okHttp)
}

val jar: Jar by tasks
val bootJar: BootJar by tasks
bootJar.enabled = false
jar.enabled = true

apply(from = "gradle/publishing.gradle.kts")
43 changes: 43 additions & 0 deletions zgw/openklant/docker-compose-override.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
services:

# openklant 2
openklant-2:
image: maykinmedia/open-klant:2.1.0
container_name: openklant-2-test
ports:
- "9007:8000"
depends_on:
- openklant-2-db
- redis
environment:
- DJANGO_SETTINGS_MODULE=openklant.conf.docker
- IS_HTTPS=no
- DB_NAME=openklant
- DB_USER=openklant
- DB_PASSWORD=openklant
- DB_HOST=openklant-2-db
- ALLOWED_HOSTS=*
- CACHE_DEFAULT=redis-test:6379/0
- CACHE_AXES=redis-test:6379/0
- SUBPATH=${SUBPATH:-/}
- SECRET_KEY=${SECRET_KEY:-django-insecure-f8s@b*ds4t84-q_2#c0j0506@!l2q6r5_pq5e!vm^_9c*#^66b}
- CELERY_BROKER_URL=redis://redis-test:6379/0
- CELERY_RESULT_BACKEND=redis://redis-test:6379/0
- DISABLE_2FA=true
volumes:
- ./imports/openklant-2/init:/app/init
command: sh /app/init/init.sh

openklant-2-db:
image: postgres:15
container_name: openklant-2-db-test
environment:
- POSTGRES_USER=openklant
- POSTGRES_PASSWORD=openklant
- POSTGRES_DB=openklant
volumes:
- ./imports/openklant-2/database:/docker-entrypoint-initdb.d/

redis:
image: redis:6.2.6
container_name: redis-test
17 changes: 17 additions & 0 deletions zgw/openklant/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#
# Copyright (c) 2024 Ritense BV, the Netherlands.
#
# Licensed under EUPL, Version 1.2 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
#
# 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.
#

isLib = true
Loading

0 comments on commit b9d4773

Please sign in to comment.