100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps
Java asset-managementbuildingdashboarddataplatformdevice-managementedge-computingenergyenergy-managementenergy-monitorfleet-managementfleet-telematicsiotiot-applicationiot-platformmodbusmqttmqtt-brokerota-updaterules-enginesmartcity
Updated tests to match user facade lenient behaviour
Rich Turner940fdd4ef488
diff --git a/test/src/test/groovy/org/openremote/test/failure/RulesExecutionFailureTest.groovy b/test/src/test/groovy/org/openremote/test/failure/RulesExecutionFailureTest.groovyindex 619d65d7b..a1b32305e 100644--- a/test/src/test/groovy/org/openremote/test/failure/RulesExecutionFailureTest.groovy+++ b/test/src/test/groovy/org/openremote/test/failure/RulesExecutionFailureTest.groovy@@ -130,87 +130,6 @@ class RulesExecutionFailureTest extends Specification implements ManagerContainestopContainer(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"diff --git a/test/src/test/resources/org/openremote/test/failure/RulesFailureUserQueryTenantException.groovy b/test/src/test/resources/org/openremote/test/failure/RulesFailureUserQueryTenantException.groovydeleted file mode 100644index 80632efd3..000000000--- a/test/src/test/resources/org/openremote/test/failure/RulesFailureUserQueryTenantException.groovy+++ /dev/null@@ -1,42 +0,0 @@-package org.openremote.test.failure--import org.openremote.manager.rules.RulesBuilder-import org.openremote.model.attribute.AttributeRef-import org.openremote.model.notification.Notification-import org.openremote.model.notification.PushNotificationAction-import org.openremote.model.notification.PushNotificationButton-import org.openremote.model.notification.PushNotificationMessage-import org.openremote.model.query.filter.TenantPredicate-import org.openremote.model.rules.Notifications-import org.openremote.model.rules.Users-import org.openremote.model.value.Values--RulesBuilder rules = binding.rules-Users users = binding.users-Notifications notifications = binding.notifications--rules.add()- .name("Notify master user out of scope")- .when(- { facts ->- return !facts.getOptional("fired").isPresent()- })- .then(- { facts ->- facts.put("fired", true)-- def userQuery = users.query()- userQuery.tenantPredicate = new TenantPredicate("master")- def targetUsers = userQuery.getResults()-- Notification notification = new Notification(- "ApartmentAlarm",- new PushNotificationMessage()- .setTitle("False Alarm")- .setBody("This alarm should not be sent"),- new Notification.Targets(Notification.TargetType.USER, targetUsers)- )-- // Send the notification to non existent user- notifications.send(notification)- })