Skip to content

Commit

Permalink
test: add e2e test scenarios (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomwwinter authored Apr 15, 2024
1 parent fa57c06 commit 77b7574
Show file tree
Hide file tree
Showing 36 changed files with 3,343 additions and 42 deletions.
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](./docs/modules/reporting.md)**: 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

0 comments on commit 77b7574

Please sign in to comment.