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

Make sure all assertion rules run at least once #1586

Merged
merged 28 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
326fda0
Bubble up exceptions, add context, and let test fail
basiliskus Nov 1, 2024
353c71f
Throw exception when no matching files found and simplify logic
basiliskus Nov 1, 2024
f292122
Fixed failing test
basiliskus Nov 4, 2024
1b16688
Added HapiHL7FileMatcherException custom exception and fixed tests
basiliskus Nov 4, 2024
694e447
Added javadocs
basiliskus Nov 4, 2024
a81a097
WIP: Added AzureBlobOrganizer to reorganize blobs by dated folders
basiliskus Nov 11, 2024
670fcdc
Merge branch 'main' into story/1523/org-azure-container
basiliskus Nov 11, 2024
ade9cda
Added cleanup logic, fixed storage paths and misc cleanup
basiliskus Nov 12, 2024
7fd09f3
Refactored AzureBlobOrganizer to better handle cooying and deleting b…
basiliskus Nov 12, 2024
2c00ae0
Removed non existing metadata and improved how we're checking the blo…
basiliskus Nov 13, 2024
1cb3dbf
Renaming and cleanup
basiliskus Nov 13, 2024
640dd21
Extracted time zone to use the same one everywhere
basiliskus Nov 13, 2024
05847e7
Moved methods to helper class
basiliskus Nov 13, 2024
6a025fa
Changed azure fetch logic to get blobs in expected path for todays date
basiliskus Nov 13, 2024
4a86f7f
Added tests for AzureBlobHelper
basiliskus Nov 13, 2024
1710fae
Renamed sourcePath => sourceName
basiliskus Nov 13, 2024
551d929
Added javadocs
basiliskus Nov 14, 2024
c8ac0a1
Added assertion to ensure all rules ran
basiliskus Nov 14, 2024
0f6b873
Added test coverage
basiliskus Nov 14, 2024
06cb089
Removed UTC timezone comment. Planning to keep using UTC
basiliskus Nov 15, 2024
572529d
Added comment explaining date path formatting
basiliskus Nov 15, 2024
2403364
Merge branch 'story/1523/org-azure-container' into story/1525/assert-…
basiliskus Nov 15, 2024
c7521b7
Added note about blob retention policy
basiliskus Nov 15, 2024
01c870d
Merge branch 'story/1523/org-azure-container' into story/1525/assert-…
basiliskus Nov 15, 2024
cf3b285
Added more context on file org
basiliskus Nov 15, 2024
bf1f723
Merge branch 'story/1523/org-azure-container' into story/1525/assert-…
basiliskus Nov 15, 2024
5530fed
Merge branch 'main' into story/1525/assert-all-assertions-run
basiliskus Nov 15, 2024
fdc062a
Renamed and added comment for clarity
basiliskus Nov 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
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.inject.Inject;

/**
Expand Down Expand Up @@ -58,21 +60,28 @@ public void ensureRulesLoaded() throws RuleLoaderException {
}
}

public void runRules(Message outputMessage, Message inputMessage) {
public List<AssertionRule> getRules() {
return assertionRules;
}

public Set<AssertionRule> runRules(Message outputMessage, Message inputMessage) {
try {
ensureRulesLoaded();
} catch (RuleLoaderException e) {
logger.logError("Failed to load rules definitions", e);
return;
return Set.of();
basiliskus marked this conversation as resolved.
Show resolved Hide resolved
}

HapiHL7Message outputHapiMessage = new HapiHL7Message(outputMessage);
HapiHL7Message inputHapiMessage = new HapiHL7Message(inputMessage);

Set<AssertionRule> runRules = new HashSet<>();
for (AssertionRule rule : assertionRules) {
if (rule.shouldRun(outputHapiMessage)) {
rule.runRule(outputHapiMessage, inputHapiMessage);
runRules.add(rule);
}
}
return runRules;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class AutomatedTest extends Specification {

FileFetcher localFileFetcher = LocalFileFetcher.getInstance()
localFiles = localFileFetcher.fetchFiles()

engine.ensureRulesLoaded()
}

def cleanup() {
Expand All @@ -50,16 +52,19 @@ class AutomatedTest extends Specification {

def "test defined assertions on relevant messages"() {
given:
def rulesToEvaluate = engine.getRules()
def matchedFiles = fileMatcher.matchFiles(azureFiles, localFiles)

when:
for (messagePair in matchedFiles) {
Message inputMessage = messagePair.getKey() as Message
Message outputMessage = messagePair.getValue() as Message
engine.runRules(outputMessage, inputMessage)
def evaluatedRules = engine.runRules(outputMessage, inputMessage)
rulesToEvaluate.removeAll(evaluatedRules)
}

then:
rulesToEvaluate.collect { it.name }.isEmpty() //Check whether all the rules in the assertions file have been run
0 * mockLogger.logError(_ as String, _ as Exception)
0 * mockLogger.logWarning(_ as String)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gov.hhs.cdc.trustedintermediary.rse2e.ruleengine

import ca.uhn.hl7v2.model.Message
import gov.hhs.cdc.trustedintermediary.rse2e.external.hapi.HapiHL7Message
import gov.hhs.cdc.trustedintermediary.ruleengine.RuleLoader
import gov.hhs.cdc.trustedintermediary.ruleengine.RuleLoaderException
import gov.hhs.cdc.trustedintermediary.context.TestApplicationContext
Expand Down Expand Up @@ -37,7 +38,7 @@ class AssertionRuleEngineTest extends Specification {

then:
1 * mockRuleLoader.loadRules(_ as InputStream, _ as TypeReference) >> [mockRule]
ruleEngine.assertionRules.size() == 1
ruleEngine.getRules().size() == 1
}

def "ensureRulesLoaded loads rules only once by default"() {
Expand All @@ -50,7 +51,7 @@ class AssertionRuleEngineTest extends Specification {

then:
1 * mockRuleLoader.loadRules(_ as InputStream, _ as TypeReference) >> [mockRule]
ruleEngine.assertionRules.size() == 1
ruleEngine.getRules().size() == 1
}

def "ensureRulesLoaded loads rules only once on multiple threads"() {
Expand Down Expand Up @@ -101,4 +102,37 @@ class AssertionRuleEngineTest extends Specification {
then:
1 * mockLogger.logError(_ as String, exception)
}

def "runRules returns nothing when there are no rules"() {
when:
def result = ruleEngine.runRules(Mock(Message), Mock(Message))

then:
result.isEmpty()
}

def "runRules returns rules that have been run"() {
given:
def rule = new AssertionRule("testRule", [], [])
mockRuleLoader.loadRules(_ as InputStream, _ as TypeReference) >> [rule]

when:
def result = ruleEngine.runRules(Mock(Message), Mock(Message))

then:
result.size() == 1
result[0] == rule
}

def "runRules doesn't return rules that shouldn't run"() {
given:
def rule = new AssertionRule("testRule", ["false"], [])
mockRuleLoader.loadRules(_ as InputStream, _ as TypeReference) >> [rule]

when:
def result = ruleEngine.runRules(Mock(Message), Mock(Message))

then:
result.isEmpty()
}
}