Permalink
Browse files

Updated tests to match user facade lenient behaviour

  • Loading branch information...
richturner committed Nov 14, 2018
1 parent 6197686 commit ba455ef4c393721ad49bff278987b5a44ba850fc
@@ -130,87 +130,6 @@ class RulesExecutionFailureTest extends Specification implements ManagerContaine
stopContainer(container)
}
def "Rule action calls users facade with out of scope query"() {
ArrayList<String> notificationIds = []
ArrayList<Notification.TargetType> targetTypes = []
ArrayList<String> targetIds = []
ArrayList<AbstractNotificationMessage> messages = []
given: "a mock push notification handler"
PushNotificationHandler mockPushNotificationHandler = Spy(PushNotificationHandler) {
isValid() >> true
// Assume sent to FCM
sendMessage(*_) >> {
id, targetType, targetId, message ->
notificationIds << id
targetTypes << targetType
targetIds << targetId
messages << message
return NotificationSendResult.success()
}
}
and: "the container environment is started with the mock handler"
def conditions = new PollingConditions(timeout: 20, delay: 1)
def serverPort = findEphemeralPort()
def services = defaultServices()
((NotificationService)services.find {it instanceof NotificationService}).notificationHandlerMap.put("push", mockPushNotificationHandler)
def container = startContainerWithPseudoClock(defaultConfig(serverPort), services)
def keycloakDemoSetup = container.getService(SetupService.class).getTaskOfType(KeycloakDemoSetup.class)
def managerDemoSetup = container.getService(SetupService.class).getTaskOfType(ManagerDemoSetup.class)
def rulesService = container.getService(RulesService.class)
def rulesetStorageService = container.getService(RulesetStorageService.class)
and: "some rules"
Ruleset ruleset = new AssetRuleset(
"Failure Ruleset",
managerDemoSetup.apartment2Id,
getClass().getResource("/org/openremote/test/failure/RulesFailureUserQueryTenantException.groovy").text,
Ruleset.Lang.GROOVY
)
ruleset = rulesetStorageService.merge(ruleset)
expect: "the rule engine to become available and be in an error state"
conditions.eventually {
def apartment2Engine = rulesService.assetEngines.get(managerDemoSetup.apartment2Id)
assert apartment2Engine != null
assert apartment2Engine.deployments[ruleset.id].status == RulesetStatus.EXECUTION_ERROR
assert apartment2Engine.deployments[ruleset.id].error instanceof RuntimeException
assert apartment2Engine.deployments[ruleset.id].error.message ==
"Error executing action of rule 'Notify master user out of scope': Overriding query restriction is not allowed in this rules scope"
assert apartment2Engine.isError()
assert apartment2Engine.getError() instanceof RuntimeException
assert apartment2Engine.getError().message.startsWith("Ruleset deployments have errors, failed compilation: 0, failed execution: 1")
}
when: "the same rules are deployed in a tenant ruleset"
ruleset = new TenantRuleset(
"Failure Ruleset",
keycloakDemoSetup.customerATenant.id,
getClass().getResource("/org/openremote/test/failure/RulesFailureUserQueryTenantException.groovy").text,
Ruleset.Lang.GROOVY
)
ruleset = rulesetStorageService.merge(ruleset)
then: "the rule engine to become available and be in an error state"
conditions.eventually {
def customerAEngine = rulesService.tenantEngines.get(keycloakDemoSetup.customerATenant.id)
assert customerAEngine != null
assert customerAEngine.deployments[ruleset.id].status == RulesetStatus.EXECUTION_ERROR
assert customerAEngine.deployments[ruleset.id].error instanceof RuntimeException
assert customerAEngine.deployments[ruleset.id].error.message ==
"Error executing action of rule 'Notify master user out of scope': Overriding query restriction is not allowed in this rules scope"
assert customerAEngine.isError()
assert customerAEngine.getError() instanceof RuntimeException
assert customerAEngine.getError().message.startsWith("Ruleset deployments have errors, failed compilation: 0, failed execution: 1")
}
cleanup: "stop the container"
stopContainer(container)
}
def "Rule condition loops"() {
given: "the container environment is started"

This file was deleted.

Oops, something went wrong.

0 comments on commit ba455ef

Please sign in to comment.