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

test: add e2e test scenarios #13

Merged
merged 52 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
171c800
test: add e2e test scenarios
tomwwinter Mar 20, 2024
5c8155a
ci: add analyse pipeline for test coverage
tomwwinter Mar 21, 2024
90ab11a
ci: add analyse pipeline for test coverage
tomwwinter Mar 21, 2024
52fd69a
ci: add analyse pipeline for test coverage
tomwwinter Mar 21, 2024
3951ab4
ci: add analyse pipeline for test coverage
tomwwinter Mar 21, 2024
0a36be1
ci: add pr branch build
tomwwinter Mar 21, 2024
47cfc7b
ci: add pr branch build
tomwwinter Mar 21, 2024
df69c13
ci: add pr branch build
tomwwinter Mar 21, 2024
24b897c
ci: add pr branch build
tomwwinter Mar 21, 2024
0520c45
docs: update readme with codeclimate badge
tomwwinter Mar 21, 2024
99e0eb1
fix: update code coverage comment
tomwwinter Mar 21, 2024
b50b742
test: update cucumber tests
tomwwinter Mar 21, 2024
56379bd
test: update cucumber tests
tomwwinter Mar 22, 2024
8333ad0
test: update cucumber tests
tomwwinter Mar 22, 2024
1851fcd
test: update cucumber tests
tomwwinter Mar 22, 2024
2c5ef8a
test: update cucumber tests
tomwwinter Mar 22, 2024
1123367
typo
tomwwinter Apr 8, 2024
bce6d80
Merge branch 'refs/heads/main' into tw/test/add-e2e-scenarios
tomwwinter Apr 8, 2024
adfc005
test: update cucumber tests
tomwwinter Apr 8, 2024
8d3b98d
test: update cucumber tests
tomwwinter Apr 11, 2024
21017a5
ci: add codeclimate coverage action
tomwwinter Apr 11, 2024
78f638e
ci: add codeclimate coverage action
tomwwinter Apr 11, 2024
c396f2a
ci: add codeclimate coverage action
tomwwinter Apr 11, 2024
354ded5
ci: add codeclimate coverage action
tomwwinter Apr 11, 2024
ce1bf47
ci: add codeclimate coverage action
tomwwinter Apr 11, 2024
0f4ede8
ci: add codeclimate coverage action
tomwwinter Apr 11, 2024
1632eb3
ci: add codeclimate coverage action
tomwwinter Apr 11, 2024
f3f1502
ci: add codeclimate coverage action
tomwwinter Apr 11, 2024
d72c639
ci: add codeclimate coverage action
tomwwinter Apr 11, 2024
2418c9d
ci: add codeclimate coverage action
tomwwinter Apr 11, 2024
59a8312
ci: add codeclimate coverage action
tomwwinter Apr 11, 2024
82669d0
ci: add codeclimate coverage action
tomwwinter Apr 11, 2024
ac6b1d0
ci: add codeclimate coverage action
tomwwinter Apr 11, 2024
69b778f
test: add e2e test scenarios
tomwwinter Apr 12, 2024
7e7f3ea
test: add e2e test scenarios
tomwwinter Apr 12, 2024
9491a72
ci: fix docker config access in tests
tomwwinter Apr 12, 2024
6852b40
ci: fix docker config access in tests
tomwwinter Apr 12, 2024
8c995a7
ci: fix docker config access in tests
tomwwinter Apr 12, 2024
a05235b
ci: fix docker config access in tests
tomwwinter Apr 12, 2024
bd2607c
ci: fix docker config access in tests
tomwwinter Apr 12, 2024
3976efe
ci: fix docker config access in tests
tomwwinter Apr 12, 2024
938611c
ci: debug ci script
tomwwinter Apr 15, 2024
e5642b0
ci: disable sqs container
tomwwinter Apr 15, 2024
f192dbb
ci: debug ci
tomwwinter Apr 15, 2024
6ca2cc1
ci: debug ci
tomwwinter Apr 15, 2024
ad71f81
ci: debug ci
tomwwinter Apr 15, 2024
300aebf
ci: debug ci
tomwwinter Apr 15, 2024
76cfd85
ci: debug ci
tomwwinter Apr 15, 2024
dc0ad15
ci: debug ci
tomwwinter Apr 15, 2024
20ee69b
ci: debug ci
tomwwinter Apr 15, 2024
9436603
ci: debug ci
tomwwinter Apr 15, 2024
822a909
fix: prevent crash if initial design document is missing
tomwwinter Apr 15, 2024
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
62 changes: 62 additions & 0 deletions .github/workflows/aam-backend-service-analyse.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: aam-backend-service-analyse

on:
push:
branches:
- main
paths:
- '.github/workflows/aam-backend-service-analyse.yml'
- 'application/aam-backend-service/**'
pull_request:
types: [ opened, synchronize, reopened, ready_for_review ]

jobs:
test_coverage:
name: Run tests and coverage calculation
runs-on: ubuntu-latest
permissions:
packages: read
defaults:
run:
working-directory: application/aam-backend-service
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Java
uses: actions/setup-java@v4
with:
distribution: 'corretto'
java-version: 17
cache: 'gradle'

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GHCR_PULL_SECRET }}

- name: Run Tests and generate Jacoco Test Report
env:
JACOCO_SOURCE_PATH: application/aam-backend-service/src/main/kotlin
run: |
./gradlew jacocoTestReport --no-daemon

- name: Publish code coverage to code climate
uses: paambaati/[email protected]
env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
JACOCO_SOURCE_PATH: application/aam-backend-service/src/main/kotlin
with:
coverageLocations: application/aam-backend-service/build/reports/jacoco/test/jacocoTestReport.xml:jacoco

- name: Add code coverage to PR
uses: madrapps/[email protected]
with:
paths: application/aam-backend-service/build/reports/jacoco/test/jacocoTestReport.xml
token: ${{ secrets.GITHUB_TOKEN }}
min-coverage-overall: 80
min-coverage-changed-files: 80
title: Code Coverage Analyse
update-comment: true
45 changes: 45 additions & 0 deletions .github/workflows/aam-backend-service-build-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: aam-backend-service-build-pr

on:
pull_request:
paths:
- '.github/workflows/aam-backend-service-build-pr.yml'
- 'application/aam-backend-service/**'
workflow_dispatch:

jobs:
push_pr_build_to_registry:
name: Build aam-backend-service and publish to container registry
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: 'corretto'
java-version: 17
cache: 'gradle'

- name: Build application
working-directory: application/aam-backend-service
run: ./gradlew installDist

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v5
with:
platforms: linux/amd64
context: ./application/aam-backend-service
push: true
tags: ghcr.io/aam-digital/aam-backend-service:pr-${{ github.event.number }}
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
name: aam-backend-service
name: aam-backend-service-build

on:
push:
branches:
- main
- 'tw/feat/query-backend-port'
paths:
- '.github/workflows/aam-backend-service.yml'
- '.github/workflows/aam-backend-service-build.yml'
- 'application/aam-backend-service/**'
workflow_dispatch:

Expand Down
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
# Aam Digital Backend Services
# Aam Digital Services

Collection of aam-digital services and tools

### aam-backend-service

[![Maintainability](https://api.codeclimate.com/v1/badges/57213b5887a579196d6d/maintainability)](https://codeclimate.com/github/Aam-Digital/aam-services/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/57213b5887a579196d6d/test_coverage)](https://codeclimate.com/github/Aam-Digital/aam-services/test_coverage)

A modularize Spring Boot application that contains API modules for [Aam Digital's case management platform](https://github.com/Aam-Digital/ndb-core).

## API Modules
#### API Modules

- **Reporting**: Calculate aggregated reports and run queries on all data, accessible for external services for API integrations of systems
38 changes: 38 additions & 0 deletions application/aam-backend-service/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,48 @@ dependencies {

annotationProcessor("org.springframework.boot:spring-boot-configuration-processor")

testImplementation("io.cucumber:cucumber-java:7.14.0")
testImplementation("io.cucumber:cucumber-junit:7.14.0")
testImplementation("io.cucumber:cucumber-spring:7.14.0")
testImplementation("org.junit.vintage:junit-vintage-engine:5.10.2")

testImplementation("org.junit.jupiter:junit-jupiter-engine:5.10.2")
testImplementation("io.projectreactor:reactor-test")

testImplementation("org.testcontainers:junit-jupiter:1.19.7") {
constraints {
testImplementation("org.apache.commons:commons-compress:1.26.1") {
because("previous versions have security issues")
}
}
}
testImplementation("org.testcontainers:rabbitmq:1.19.7")
testImplementation("com.github.dasniko:testcontainers-keycloak:3.3.0") {
constraints {
testImplementation("org.apache.james:apache-mime4j-core:0.8.11") {
because("previous versions have security issues")
}
}
}

testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.springframework.boot:spring-boot-testcontainers")
testImplementation("org.springframework.security:spring-security-test")
}

jacoco {
toolVersion = "0.8.11"
}

tasks.jacocoTestReport {
dependsOn(tasks.test)
reports {
html.required.set(false)
csv.required.set(true)
xml.required.set(true)
}
}

sentry {
// Generates a JVM (Java, Kotlin, etc.) source bundle and uploads your source code to Sentry.
// This enables source context, allowing you to see your source
Expand All @@ -84,4 +121,5 @@ tasks.withType<KotlinCompile> {

tasks.withType<Test> {
useJUnitPlatform()
systemProperty("cucumber.junit-platform.naming-strategy", "long")
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class InternalServerException(
code: String = "INTERNAL_SERVER_ERROR"
) : AamException(message, cause, code)


class ExternalSystemException(
message: String = "",
cause: Throwable? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ sealed class ReportCalculationOutcome {
}

data class ReportCalculation(
@JsonProperty("_id")
val id: String,
val report: DomainReference,
var status: ReportCalculationStatus,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.aamdigital.aambackendservice.reporting.domain

import com.aamdigital.aambackendservice.domain.DomainReference
import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.databind.ObjectMapper
import java.security.MessageDigest

data class ReportData(
@JsonProperty("_id")
val id: String,
val report: DomainReference,
val calculation: DomainReference,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.aamdigital.aambackendservice.reporting.reportcalculation.controller
package com.aamdigital.aambackendservice.reporting.report.controller

import com.aamdigital.aambackendservice.domain.DomainReference
import com.aamdigital.aambackendservice.error.NotFoundException
Expand All @@ -12,12 +12,12 @@ import org.springframework.web.bind.annotation.RestController
import reactor.core.publisher.Mono

@RestController
@RequestMapping("/v1/reporting")
@RequestMapping("/v1/reporting/report")
@Validated
class ReportController(
private val reportingStorage: ReportingStorage,
) {
@GetMapping("/report")
@GetMapping
fun fetchReports(): Mono<List<ReportDto>> {
return reportingStorage.fetchAllReports("sql")
.zipWith(
Expand All @@ -38,7 +38,7 @@ class ReportController(
}
}

@GetMapping("/report/{reportId}")
@GetMapping("/{reportId}")
fun fetchReport(
@PathVariable reportId: String
): Mono<ReportDto> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.aamdigital.aambackendservice.reporting.report.sqs

import com.aamdigital.aambackendservice.couchdb.core.CouchDbStorage
import com.aamdigital.aambackendservice.crypto.core.CryptoService
import com.aamdigital.aambackendservice.domain.EntityAttribute
import com.aamdigital.aambackendservice.domain.EntityConfig
import com.aamdigital.aambackendservice.domain.EntityType
Expand All @@ -11,6 +10,8 @@ import org.springframework.stereotype.Service
import org.springframework.util.LinkedMultiValueMap
import reactor.core.publisher.Mono
import java.security.MessageDigest
import java.util.*
import kotlin.jvm.optionals.getOrNull

data class AppConfigAttribute(
val dataType: String,
Expand Down Expand Up @@ -41,7 +42,7 @@ data class TableName(

data class SqlObject(
val tables: Map<String, TableFields>,
val indexes: List<String>,
val indexes: List<String>?,
val options: SqlOptions,
)

Expand Down Expand Up @@ -72,7 +73,6 @@ data class SqsSchema(
@Service
class SqsSchemaService(
private val couchDbStorage: CouchDbStorage,
private val cryptoService: CryptoService,
) {

companion object {
Expand Down Expand Up @@ -110,13 +110,15 @@ class SqsSchemaService(
queryParams = LinkedMultiValueMap(),
kClass = SqsSchema::class
)
.map { Optional.of(it) }
.onErrorResume { Mono.just(Optional.empty()) }
)
.flatMap {
val entityConfig = it.t1
val currentSqsSchema = it.t2
val currentSqsSchema = it.t2.getOrNull()
val newSqsSchema: SqsSchema = mapToSqsSchema(entityConfig)

if (currentSqsSchema.configVersion == newSqsSchema.configVersion) {
if (currentSqsSchema?.configVersion == newSqsSchema.configVersion) {
return@flatMap Mono.just(Unit)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ import org.springframework.web.bind.annotation.RestController
import reactor.core.publisher.Mono

@RestController
@RequestMapping("/v1/reporting")
@RequestMapping("/v1/reporting/report-calculation")
@Validated
class ReportCalculationController(
private val reportingStorage: ReportingStorage,
private val createReportCalculationUseCase: CreateReportCalculationUseCase
) {
@PostMapping("/report-calculation/report/{reportId}")
@PostMapping("/report/{reportId}")
fun startCalculation(
@PathVariable reportId: String
): Mono<DomainReference> {
Expand All @@ -50,14 +50,14 @@ class ReportCalculationController(
}
}

@GetMapping("/report-calculation/report/{reportId}")
@GetMapping("/report/{reportId}")
fun fetchReportCalculations(
@PathVariable reportId: String
): Mono<List<ReportCalculation>> {
return reportingStorage.fetchCalculations(DomainReference(id = reportId))
}

@GetMapping("/report-calculation/{calculationId}")
@GetMapping("/{calculationId}")
fun fetchReportCalculation(
@PathVariable calculationId: String
): Mono<ReportCalculation> {
Expand All @@ -73,7 +73,7 @@ class ReportCalculationController(
}
}

@GetMapping("/report-calculation/{calculationId}/data")
@GetMapping("/{calculationId}/data")
fun fetchReportCalculationData(
@PathVariable calculationId: String
): Mono<ReportData> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.aamdigital.aambackendservice.reporting.report.storage
package com.aamdigital.aambackendservice.reporting.storage

import com.aamdigital.aambackendservice.couchdb.dto.CouchDbChange
import com.aamdigital.aambackendservice.domain.DomainReference
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.aamdigital.aambackendservice.reporting.report.storage
package com.aamdigital.aambackendservice.reporting.storage

import com.aamdigital.aambackendservice.couchdb.core.CouchDbStorage
import com.aamdigital.aambackendservice.couchdb.core.getQueryParamsAllDocs
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.aamdigital.aambackendservice.reporting.report.storage
package com.aamdigital.aambackendservice.reporting.storage

import com.aamdigital.aambackendservice.couchdb.core.CouchDbStorage
import com.aamdigital.aambackendservice.couchdb.core.getQueryParamsAllDocs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ class SecurityConfiguration {
it.pathMatchers(HttpMethod.GET, "/actuator/**").permitAll()
it.anyExchange().authenticated()
}
.csrf {
it.disable()
}
.exceptionHandling {
it.accessDeniedHandler(customServerAccessDeniedHandler())
it.authenticationEntryPoint(CustomAuthenticationEntryPoint())
Expand All @@ -52,9 +55,7 @@ class SecurityConfiguration {

private class CustomAuthenticationEntryPoint : ServerAuthenticationEntryPoint {
override fun commence(exchange: ServerWebExchange, ex: AuthenticationException): Mono<Void> {
return Mono.fromRunnable {
throw UnauthorizedAccessException("Access Token invalid or missing")
}
throw UnauthorizedAccessException("Access Token invalid or missing")
}
}

Expand Down
Loading
Loading