Skip to content

Commit

Permalink
test: Jacoco reporting (#84)
Browse files Browse the repository at this point in the history
* test: Jacoco reporting

Implemented jacoco reporting and added intergration tests

WIP

* fix: template config linting

coverage currently sitting at 21%

* test: More coverage

* test: Upload jacoco test results

Added jacoco test results to github actions

* fix: Removed LabelTemplateHelpers

These have been bootstrapped from the mod-agreements templating service and contain funcitons very specific to that use case

* fix: Reimplemented starting values code

Added back in starting values code, refactored into a singe method
  • Loading branch information
Jack-Golding authored Mar 15, 2024
1 parent 0052b1b commit 003ba99
Show file tree
Hide file tree
Showing 17 changed files with 2,133 additions and 354 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ jobs:
- name: Build with Gradle
run: |
./gradlew --refresh-dependencies clean buildImage
./gradlew --refresh-dependencies clean buildImage jacocoTestReport
ls ./build/test-results/integrationTest/*
- name: Stop containers
run: |
Expand All @@ -51,10 +52,14 @@ jobs:
path: |
service/build/test-results/**/*.xml
service/build/spock-reports/*.html
service/build/reports/jacoco/test/**/*.html
service/build/reports/jacoco/test/**/*.csv
service/build/reports/jacoco/test/**/*.xml
- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action@v1
if: always()
with:
files: |
service/build/test-results/**/*.xml
49 changes: 49 additions & 0 deletions service/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ apply plugin: "eclipse"
apply plugin: 'eclipse-wtp'
apply plugin: "idea"
//apply plugin:"war"
apply plugin: 'jacoco'
apply plugin: "org.grails.grails-web"
apply plugin: "org.grails.plugins.views-json"
apply plugin: 'com.bmuschko.docker-remote-api'
Expand Down Expand Up @@ -379,4 +380,52 @@ eclipse {
}
}
}

jacoco {
toolVersion = "0.8.11"
}

test {
jacoco {
// append = false
destinationFile = file("$buildDir/jacoco/integrationTest.exec")
// classDumpFile = file("$buildDir/jacoco/classpathdumps")
}
}

// Use ./gradlew clean build jacocoTestReport
jacocoTestReport {
// See https://github.com/grails/grails-core/issues/11318
// executionData test, integrationTest
executionData(files tasks.withType(Test)*.jacoco*.destinationFile.findAll { it.exists() })
// executionData = files tasks.withType(Test)*.jacoco*.destinationFile.findAll { it.exists() } tasks.withType(IntegrationTest)*.jacoco*.destinationFile.findAll { it.exists() }

println("execution data : ${executionData}");
reports {
xml.enabled true
html.enabled true
csv.enabled true
}
afterEvaluate {
classDirectories.setFrom(files(classDirectories.files.collect {
fileTree(dir: it,
exclude: ['**/Application**',
'**/BootStrap**',
'**/**gson**',
'**/**closure**',
'**/UrlMappings**',
'org/olf/recurrence/**',
'org/olf/omission/**',
'org/olf/combination/**',
'org/olf/internalPiece/**',
'org/olf/templateConfig/**',
]).filter({file ->
file.name.contains('Controller') ||
file.name.contains('Service') ||
file.name.contains('LabelTemplate')
})
}))
}
dependsOn test, integrationTest
}
}
22 changes: 0 additions & 22 deletions service/grails-app/controllers/org/olf/LocaleController.groovy

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,45 +27,36 @@ class PredictedPieceSetController extends OkapiTenantAwareController<PredictedPi
super(PredictedPieceSet)
}
PieceGenerationService pieceGenerationService
// This takes in a JSON shape and outputs predicted pieces without saving domain objects
def generatePredictedPiecesTransient() {
JSONObject data = request.JSON

SerialRuleset ruleset = new SerialRuleset(data)

// Starting values will be refactored soon so this is a placeholder to ensure they are passed through presently
private SerialRuleset handleStartingValues(SerialRuleset ruleset, JSONObject data){
if(ruleset?.templateConfig?.rules?.size()){
for(int i=0;i<ruleset?.templateConfig?.rules?.size();i++){
if(ruleset?.templateConfig?.rules[i]?.ruleType?.templateMetadataRuleFormat?.value == 'enumeration_numeric'){
for(int j=0;j<ruleset?.templateConfig?.rules[i]?.ruleType?.ruleFormat?.levels?.size();j++){
if(data?.templateConfig?.rules?.getAt(i)?.ruleType?.ruleFormat?.levels?.getAt(j)?.startingValue){
ruleset?.templateConfig?.rules[i]?.ruleType?.ruleFormat?.levels[j]?.startingValue = Integer.parseInt(data?.templateConfig?.rules[i]?.ruleType?.ruleFormat?.levels[j]?.startingValue)
for(int i=0;i<ruleset?.templateConfig?.rules?.size();i++){
if(ruleset?.templateConfig?.rules[i]?.ruleType?.templateMetadataRuleFormat?.value == 'enumeration_numeric'){
for(int j=0;j<ruleset?.templateConfig?.rules[i]?.ruleType?.ruleFormat?.levels?.size();j++){
if(data?.templateConfig?.rules?.getAt(i)?.ruleType?.ruleFormat?.levels?.getAt(j)?.startingValue){
ruleset?.templateConfig?.rules[i]?.ruleType?.ruleFormat?.levels[j]?.startingValue = Integer.parseInt(data?.templateConfig?.rules[i]?.ruleType?.ruleFormat?.levels[j]?.startingValue)
}
}
}
}
}
}
return ruleset
}
// This takes in a JSON shape and outputs predicted pieces without saving domain objects
def generatePredictedPiecesTransient() {
JSONObject data = request.JSON
SerialRuleset ruleset = new SerialRuleset(data)

ArrayList<InternalPiece> result = pieceGenerationService.createPiecesTransient(ruleset, LocalDate.parse(data.startDate))
ArrayList<InternalPiece> result = pieceGenerationService.createPiecesTransient(handleStartingValues(ruleset, data), LocalDate.parse(data.startDate))
respond result
}

def generatePredictedPieces() {
JSONObject data = request.JSON
SerialRuleset ruleset = SerialRuleset.get(data?.id)

if(ruleset?.templateConfig?.rules?.size()){
for(int i=0;i<ruleset?.templateConfig?.rules?.size();i++){
if(ruleset?.templateConfig?.rules[i]?.ruleType?.templateMetadataRuleFormat?.value == 'enumeration_numeric'){
for(int j=0;j<ruleset?.templateConfig?.rules[i]?.ruleType?.ruleFormat?.levels?.size();j++){
if(data?.templateConfig?.rules?.getAt(i)?.ruleType?.ruleFormat?.levels?.getAt(j)?.startingValue){
ruleset?.templateConfig?.rules[i]?.ruleType?.ruleFormat?.levels[j]?.startingValue = Integer.parseInt(data?.templateConfig?.rules[i]?.ruleType?.ruleFormat?.levels[j]?.startingValue)
}
}
}
}
}

ArrayList<InternalPiece> ips = pieceGenerationService.createPiecesTransient(ruleset, LocalDate.parse(data.startDate))
ArrayList<InternalPiece> ips = pieceGenerationService.createPiecesTransient(handleStartingValues(ruleset, data), LocalDate.parse(data.startDate))

PredictedPieceSet pps = new PredictedPieceSet([
ruleset: ruleset,
Expand Down
23 changes: 0 additions & 23 deletions service/grails-app/controllers/org/olf/RefdataController.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,6 @@ class RefdataController extends OkapiTenantAwareController<RefdataCategory> {
super(RefdataCategory)
}

def delete() {
def instance = queryForResource(params.id)

// Not found.
if (instance == null) {
RefdataCategory.withTransaction { t ->
t.setRollbackOnly()
}
notFound()
return
}

// Return invalid method if the status is disallowed
if (instance.internal == true) {
render status: HttpStatus.METHOD_NOT_ALLOWED.value()
return
}

deleteResource instance

render status: HttpStatus.NO_CONTENT
}

def lookup (String domain, String property) {
def c = DomainUtils.resolveDomainClass(domain)?.javaClass
def cat = c ? GrailsDomainRefdataHelpers.getCategoryString(c, property) : null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ public class PieceGenerationService {
}
break;
// We dont think default case will be hit, but here for safety
// As of version 1.0.0 the default case cannot be hit and therefore cannot be tested
// Its being kept here as a for potential future combinations work
default:
Set<InternalRecurrencePiece> superCombinedPieces = [currentPiece]
parentCombinationPieces.each { pcp ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ public class PieceLabellingService {
return value.toString() // No escaping. Return as is.
}
})
.registerHelpers(StringHelpers)
.registerHelpers(LabelTemplateHelpers))
.registerHelpers(StringHelpers))


// This needs to take in an individual piece and ooutput a String label
Expand Down
Loading

0 comments on commit 003ba99

Please sign in to comment.