From 66505127f36f5ddc7cd9ce36dca6bed674855d3d Mon Sep 17 00:00:00 2001 From: Jannis Tsiroyannis Date: Mon, 20 Nov 2023 12:51:02 +0100 Subject: [PATCH] Add CXZ testing framework. --- housekeeping/build.gradle | 12 +++ .../whelk/housekeeping/InquirySender.groovy | 2 +- .../housekeeping/NotificationGenerator.groovy | 2 +- .../housekeeping/NotificationRulesSpec.groovy | 87 +++++++++++++++++++ 4 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 housekeeping/src/test/groovy/whelk/housekeeping/NotificationRulesSpec.groovy diff --git a/housekeeping/build.gradle b/housekeeping/build.gradle index 9239c707df..e879084ae1 100755 --- a/housekeeping/build.gradle +++ b/housekeeping/build.gradle @@ -45,8 +45,20 @@ dependencies { // Cron implementation group: 'it.sauronsoftware.cron4j', name: 'cron4j', version: '2.2.5' + // Testing + testImplementation "org.spockframework:spock-core:${spockVersion}" } +test { + useJUnitPlatform() +} + +test.testLogging { + showStandardStreams = true + exceptionFormat = "full" +} + + gretty { jvmArgs = ['-XX:+UseParallelGC'] systemProperties = ['xl.secret.properties': System.getProperty("xl.secret.properties")] diff --git a/housekeeping/src/main/groovy/whelk/housekeeping/InquirySender.groovy b/housekeeping/src/main/groovy/whelk/housekeeping/InquirySender.groovy index b1803d8318..8087fdfafb 100644 --- a/housekeeping/src/main/groovy/whelk/housekeeping/InquirySender.groovy +++ b/housekeeping/src/main/groovy/whelk/housekeeping/InquirySender.groovy @@ -56,7 +56,7 @@ class InquirySender extends HouseKeeper { connection = whelk.getStorage().getOuterConnection() connection.setAutoCommit(false) try { - String sql = "SELECT modified, data FROM lddb WHERE data#>>'{@graph,1,@type}' IN ('InquiryAction', 'ChangeNotice') AND modified > ?;" + String sql = "SELECT modified, data FROM lddb WHERE deleted = false AND data#>>'{@graph,1,@type}' IN ('InquiryAction', 'ChangeNotice') AND modified > ?;" connection.setAutoCommit(false) statement = connection.prepareStatement(sql) statement.setTimestamp(1, from) diff --git a/housekeeping/src/main/groovy/whelk/housekeeping/NotificationGenerator.groovy b/housekeeping/src/main/groovy/whelk/housekeeping/NotificationGenerator.groovy index cbdea117a5..41414c099a 100644 --- a/housekeeping/src/main/groovy/whelk/housekeeping/NotificationGenerator.groovy +++ b/housekeeping/src/main/groovy/whelk/housekeeping/NotificationGenerator.groovy @@ -63,7 +63,7 @@ class NotificationGenerator extends HouseKeeper { connection.setAutoCommit(false) try { // Fetch all changed IDs within the interval - String sql = "SELECT id, ARRAY_AGG(data#>>'{@graph,0,hasChangeNote}') as changeNotes FROM lddb__versions WHERE collection IN ('bib', 'auth') AND ( modified > ? AND modified <= ? ) group by id;" + String sql = "SELECT id, ARRAY_AGG(data#>>'{@graph,0,hasChangeNote}') as changeNotes FROM lddb__versions WHERE collection IN ('bib', 'auth') AND deleted = false AND ( modified > ? AND modified <= ? ) group by id;" connection.setAutoCommit(false) statement = connection.prepareStatement(sql) statement.setTimestamp(1, from) diff --git a/housekeeping/src/test/groovy/whelk/housekeeping/NotificationRulesSpec.groovy b/housekeeping/src/test/groovy/whelk/housekeeping/NotificationRulesSpec.groovy new file mode 100644 index 0000000000..31aef6572c --- /dev/null +++ b/housekeeping/src/test/groovy/whelk/housekeeping/NotificationRulesSpec.groovy @@ -0,0 +1,87 @@ +package whelk.housekeeping + +import spock.lang.Specification +import whelk.Document + +class NotificationRulesSpec extends Specification { + + def "Change PrimaryContribution familyName"() { + given: + Document framedBefore = new Document([ + "mainEntity" : [ + "instanceOf" : [ + "contribution" : [ + [ + "@type" : "PrimaryContribution", + "agent" : [ + "familyName": "aaa", + "givenName": "bbb", + "lifeSpan": "2022-2023" + ] + ] + ] + ] + ] + ]) + Document framedAfter = new Document([ + "mainEntity" : [ + "instanceOf" : [ + "contribution" : [ + [ + "@type" : "PrimaryContribution", + "agent" : [ + "familyName": "aab", + "givenName": "bbb", + "lifeSpan": "2022-2023" + ] + ] + ] + ] + ] + ]) + Tuple result = NotificationRules.primaryContributionChanged(framedBefore, framedAfter) + + expect: + result[0] == true + } + + def "Change PrimaryContribution givenName"() { + given: + Document framedBefore = new Document([ + "mainEntity" : [ + "instanceOf" : [ + "contribution" : [ + [ + "@type" : "PrimaryContribution", + "agent" : [ + "familyName": "aaa", + "givenName": "bbb", + "lifeSpan": "2022-2023" + ] + ] + ] + ] + ] + ]) + Document framedAfter = new Document([ + "mainEntity" : [ + "instanceOf" : [ + "contribution" : [ + [ + "@type" : "PrimaryContribution", + "agent" : [ + "familyName": "aaa", + "givenName": "bbc", + "lifeSpan": "2022-2023" + ] + ] + ] + ] + ] + ]) + Tuple result = NotificationRules.primaryContributionChanged(framedBefore, framedAfter) + + expect: + result[0] == true + } +} \ No newline at end of file