Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

Improve test reliability

Rich Turnere8f095d38df1
diff --git a/test/src/test/groovy/org/openremote/test/console/ConsoleTest.groovy b/test/src/test/groovy/org/openremote/test/console/ConsoleTest.groovy
index 02e265d71..7ff33e76c 100644
--- a/test/src/test/groovy/org/openremote/test/console/ConsoleTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/console/ConsoleTest.groovy
@@ -2,6 +2,7 @@ package org.openremote.test.console
import com.fasterxml.jackson.databind.node.ObjectNode
import com.google.firebase.messaging.Message
+import org.openremote.container.timer.TimerService
import org.openremote.container.util.UniqueIdentifierGenerator
import org.openremote.manager.asset.AssetStorageService
import org.openremote.manager.notification.NotificationService
@@ -66,6 +67,7 @@ class ConsoleTest extends Specification implements ManagerContainerTrait {
def pushNotificationHandler = container.getService(PushNotificationHandler.class)
def notificationService = container.getService(NotificationService.class)
def assetStorageService = container.getService(AssetStorageService.class)
+ def timerService = container.getService(TimerService.class)
def keycloakTestSetup = container.getService(SetupService.class).getTaskOfType(KeycloakTestSetup.class)
def managerTestSetup = container.getService(SetupService.class).getTaskOfType(ManagerTestSetup.class)
def rulesService = container.getService(RulesService.class)
@@ -74,8 +76,11 @@ class ConsoleTest extends Specification implements ManagerContainerTrait {
and: "a mock push notification handler is injected"
PushNotificationHandler mockPushNotificationHandler = Spy(pushNotificationHandler)
mockPushNotificationHandler.isValid() >> true
- mockPushNotificationHandler.sendMessage(_ as Long, _ as Notification.Source, _ as String, _ as Notification.Target, _ as AbstractNotificationMessage) >> {
- id, source, sourceId, target, message ->
+ mockPushNotificationHandler.sendMessage(_ as Long, _ as Notification.Source, _ as String, _ as Notification.Target, _ as PushNotificationMessage) >> {
+ Long id, Notification.Source source, String sourceId, Notification.Target target, PushNotificationMessage message ->
+
+ message.title = target.id // Makes it easier to test/debug
+ message.body = timerService.getCurrentTimeMillis() // Makes it easier to test/debug
notificationIds << id
targetTypes << target.type
targetIds << target.id
@@ -409,7 +414,6 @@ class ConsoleTest extends Specification implements ManagerContainerTrait {
assert !tenantBuildingEngine.facts.getOptional("welcomeHome_${testUser3Console2.id}").isPresent()
}
-
when: "time advances"
advancePseudoClock(1, TimeUnit.SECONDS, container)
@@ -493,7 +497,11 @@ class ConsoleTest extends Specification implements ManagerContainerTrait {
assert geofences.size() == 0
}
- when: "a new ruleset is deployed on the console parent asset with multiple location predicate rules (including a duplicate and a rectangular predicate)"
+ when: "the notifications are cleared"
+ notificationIds.clear()
+ messages.clear()
+
+ and: "a new ruleset is deployed on the console parent asset with multiple location predicate rules (including a duplicate and a rectangular predicate)"
def newRuleset = new AssetRuleset(
testUser3Console1.parentId,
"Console test location predicates",
@@ -516,9 +524,9 @@ class ConsoleTest extends Specification implements ManagerContainerTrait {
then: "a push notification should have been sent to the two remaining consoles telling them to refresh their geofences"
conditions.eventually {
- assert notificationIds.size() == 4
- assert ((PushNotificationMessage) messages[2]).data.get("action").asText() == "GEOFENCE_REFRESH"
- assert ((PushNotificationMessage) messages[3]).data.get("action").asText() == "GEOFENCE_REFRESH"
+ assert notificationIds.size() == 2
+ assert ((PushNotificationMessage) messages[0]).data.get("action").asText() == "GEOFENCE_REFRESH"
+ assert ((PushNotificationMessage) messages[1]).data.get("action").asText() == "GEOFENCE_REFRESH"
}
then: "the geofences of testUser3Console1 should contain the welcome home geofence and new radial geofence (but not the rectangular and duplicate predicates)"
@@ -546,16 +554,22 @@ class ConsoleTest extends Specification implements ManagerContainerTrait {
assert geofence2.url == getWriteAttributeUrl(new AttributeRef(testUser3Console1.id, Asset.LOCATION.name))
}
- when: "an existing ruleset containing a radial location predicate is updated"
+ when: "the notifications are cleared"
+ notificationIds.clear()
+ messages.clear()
+
+ and: "an existing ruleset containing a radial location predicate is updated"
newRuleset.rules = getClass().getResource("/org/openremote/test/rules/BasicLocationPredicates2.groovy").text
newRuleset = rulesetStorageService.merge(newRuleset)
newLocationPredicate = new RadialGeofencePredicate(150, 10, 40)
- then: "a push notification should have been sent to the two remaining consoles telling them to refresh their geofences"
+ then: "a push notification should have been sent to the two remaining consoles telling them to refresh their geofences (from the tenant engine and asset engine)"
conditions.eventually {
- assert notificationIds.size() == 6
- assert ((PushNotificationMessage) messages[4]).data.get("action").asText() == "GEOFENCE_REFRESH"
- assert ((PushNotificationMessage) messages[5]).data.get("action").asText() == "GEOFENCE_REFRESH"
+ assert messages.stream()
+ .filter({ it instanceof PushNotificationMessage })
+ .filter({
+ ((PushNotificationMessage) it).data.get("action").asText() == "GEOFENCE_REFRESH"
+ }).count() == 4
}
then: "the geofences of testUser3Console1 should still contain two geofences but the location of the second should have been updated"
@@ -583,13 +597,13 @@ class ConsoleTest extends Specification implements ManagerContainerTrait {
assert geofence2.url == getWriteAttributeUrl(new AttributeRef(testUser3Console1.id, Asset.LOCATION.name))
}
- when: "a location predicate ruleset is removed"
- rulesetStorageService.delete(AssetRuleset.class, newRuleset.id)
-
- and: "previous notification messages are cleared"
+ when: "previous notification messages are cleared"
notificationIds.clear()
messages.clear()
+ and: "a location predicate ruleset is removed"
+ rulesetStorageService.delete(AssetRuleset.class, newRuleset.id)
+
then: "only the welcome home geofence should remain"
conditions.eventually {
geofences = authenticatedRulesResource.getAssetGeofences(null, testUser3Console1.id)
@@ -609,8 +623,7 @@ class ConsoleTest extends Specification implements ManagerContainerTrait {
.filter({ it instanceof PushNotificationMessage })
.filter({
((PushNotificationMessage) it).data.get("action").asText() == "GEOFENCE_REFRESH"
- })
- .count() == 2
+ }).count() == 2
}
when: "previous notification messages are cleared"
diff --git a/test/src/test/groovy/org/openremote/test/gateway/GatewayTest.groovy b/test/src/test/groovy/org/openremote/test/gateway/GatewayTest.groovy
index 02b50fe62..a4aeda143 100644
--- a/test/src/test/groovy/org/openremote/test/gateway/GatewayTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/gateway/GatewayTest.groovy
@@ -729,7 +729,7 @@ class GatewayTest extends Specification implements ManagerContainerTrait {
def "Verify gateway client service"() {
given: "the container environment is started with the spy gateway client service"
- def conditions = new PollingConditions(timeout: 10, delay: 0.2)
+ def conditions = new PollingConditions(timeout: 15, delay: 0.2)
def services = Lists.newArrayList(defaultServices())
def container = startContainer(defaultConfig(), services)
def assetProcessingService = container.getService(AssetProcessingService.class)