Skip to content

armgit / core

Public Imported from GitHub
0

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

More test improvements

Rich Turner95c1731cd56f
diff --git a/test/src/test/groovy/org/openremote/test/failure/RulesExecutionFailureTest.groovy b/test/src/test/groovy/org/openremote/test/failure/RulesExecutionFailureTest.groovy
index 414cebb7e..534ebdf63 100644
--- a/test/src/test/groovy/org/openremote/test/failure/RulesExecutionFailureTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/failure/RulesExecutionFailureTest.groovy
@@ -11,6 +11,7 @@ import org.openremote.manager.setup.builtin.ManagerDemoSetup
import org.openremote.model.rules.AssetRuleset
import org.openremote.model.rules.Ruleset
import org.openremote.model.rules.RulesetStatus
+import org.openremote.model.rules.TemporaryFact
import org.openremote.model.value.Values
import org.openremote.test.ManagerContainerTrait
import spock.lang.Specification
@@ -21,6 +22,8 @@ class RulesExecutionFailureTest extends Specification implements ManagerContaine
def "Rule condition invalid return"() {
given: "the container environment is started"
+ def expirationMillis = TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS
+ TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS = 500
def conditions = new PollingConditions(timeout: 20, delay: 0.2)
def container = startContainer(defaultConfig(), defaultServices())
def managerDemoSetup = container.getService(SetupService.class).getTaskOfType(ManagerDemoSetup.class)
@@ -47,11 +50,16 @@ class RulesExecutionFailureTest extends Specification implements ManagerContaine
assert apartment2Engine.deployments[ruleset.id].error instanceof IllegalArgumentException
assert apartment2Engine.deployments[ruleset.id].error.message == "Error evaluating condition of rule 'The when condition is illegal, it's returning an Optional instead of a boolean': result is not boolean but Optional.empty"
}
+
+ cleanup: "the static rules time variable is reset"
+ TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS = expirationMillis
}
def "Rule condition throws exception"() {
given: "the container environment is started"
+ def expirationMillis = TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS
+ TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS = 500
def conditions = new PollingConditions(timeout: 20, delay: 0.2)
def container = startContainer(defaultConfig(), defaultServices())
def managerDemoSetup = container.getService(SetupService.class).getTaskOfType(ManagerDemoSetup.class)
@@ -78,11 +86,16 @@ class RulesExecutionFailureTest extends Specification implements ManagerContaine
assert apartment2Engine.getError() instanceof RuntimeException
assert apartment2Engine.getError().message.startsWith("Ruleset deployments have errors, failed compilation: 0, failed execution: 1")
}
+
+ cleanup: "the static rules time variable is reset"
+ TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS = expirationMillis
}
def "Rule action throws exception"() {
given: "the container environment is started"
+ def expirationMillis = TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS
+ TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS = 500
def conditions = new PollingConditions(timeout: 20, delay: 0.2)
def container = startContainer(defaultConfig(), defaultServices())
def managerDemoSetup = container.getService(SetupService.class).getTaskOfType(ManagerDemoSetup.class)
@@ -109,11 +122,16 @@ class RulesExecutionFailureTest extends Specification implements ManagerContaine
assert apartment2Engine.getError() instanceof RuntimeException
assert apartment2Engine.getError().message.startsWith("Ruleset deployments have errors, failed compilation: 0, failed execution: 1")
}
+
+ cleanup: "the static rules time variable is reset"
+ TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS = expirationMillis
}
def "Rule condition loops"() {
given: "the container environment is started"
+ def expirationMillis = TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS
+ TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS = 500
def conditions = new PollingConditions(timeout: 20, delay: 0.2)
def container = startContainer(defaultConfig(), defaultServices())
def managerDemoSetup = container.getService(SetupService.class).getTaskOfType(ManagerDemoSetup.class)
@@ -142,5 +160,8 @@ class RulesExecutionFailureTest extends Specification implements ManagerContaine
assert apartment2Engine.getError().message.startsWith("Ruleset deployments have errors, failed compilation: 0, failed execution: 1")
assert apartment2Engine.facts.triggerCount == 0 // Ensure trigger count is reset after execution
}
+
+ cleanup: "the static rules time variable is reset"
+ TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS = expirationMillis
}
}
diff --git a/test/src/test/groovy/org/openremote/test/protocol/TcpClientTest.groovy b/test/src/test/groovy/org/openremote/test/protocol/TcpClientTest.groovy
index 2b03032e8..0fdeb2502 100644
--- a/test/src/test/groovy/org/openremote/test/protocol/TcpClientTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/protocol/TcpClientTest.groovy
@@ -49,14 +49,14 @@ class TcpClientTest extends Specification implements ManagerContainerTrait {
and: "a simple TCP echo server"
def echoServerPort = findEphemeralPort()
- def echoServer = new TcpStringServer(protocolExecutorService, new InetSocketAddress(echoServerPort), ";", Integer.MAX_VALUE, true)
+ def echoServer = new TcpStringServer(protocolExecutorService, new InetSocketAddress("127.0.0.1", echoServerPort), ";", Integer.MAX_VALUE, true)
echoServer.addMessageConsumer({
message, channel, sender -> echoServer.sendMessage(message)
})
and: "a simple TCP client"
TcpIoClient<String> client = new TcpIoClient<String>(
- "localhost",
+ "127.0.0.1",
echoServerPort,
protocolExecutorService)
client.setEncoderDecoderProvider({
diff --git a/test/src/test/groovy/org/openremote/test/rules/BasicRulesProcessingTest.groovy b/test/src/test/groovy/org/openremote/test/rules/BasicRulesProcessingTest.groovy
index 31e1e526c..f0c143af4 100644
--- a/test/src/test/groovy/org/openremote/test/rules/BasicRulesProcessingTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/rules/BasicRulesProcessingTest.groovy
@@ -1,6 +1,6 @@
package org.openremote.test.rules
-import org.openremote.container.timer.TimerService
+
import org.openremote.manager.asset.AssetProcessingService
import org.openremote.manager.asset.AssetStorageService
import org.openremote.manager.rules.RulesEngine
@@ -11,14 +11,11 @@ import org.openremote.manager.setup.builtin.KeycloakDemoSetup
import org.openremote.manager.setup.builtin.ManagerDemoSetup
import org.openremote.model.asset.Asset
import org.openremote.model.asset.AssetAttribute
-import org.openremote.model.attribute.MetaItemType
import org.openremote.model.asset.AssetType
-import org.openremote.model.attribute.AttributeEvent
-import org.openremote.model.attribute.AttributeValueType
-import org.openremote.model.attribute.Meta
-import org.openremote.model.attribute.MetaItem
+import org.openremote.model.attribute.*
import org.openremote.model.rules.AssetRuleset
import org.openremote.model.rules.Ruleset
+import org.openremote.model.rules.TemporaryFact
import org.openremote.model.rules.TenantRuleset
import org.openremote.model.value.Values
import org.openremote.test.ManagerContainerTrait
@@ -27,8 +24,8 @@ import spock.util.concurrent.PollingConditions
import java.util.concurrent.TimeUnit
-import static org.openremote.model.rules.RulesetStatus.*
import static org.openremote.manager.setup.builtin.ManagerDemoSetup.*
+import static org.openremote.model.rules.RulesetStatus.*
import static org.openremote.test.rules.BasicRulesImport.assertRulesFired
class BasicRulesProcessingTest extends Specification implements ManagerContainerTrait {
@@ -38,6 +35,8 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
def conditions = new PollingConditions(timeout: 10, delay: 0.2)
and: "the container is started"
+ def expirationMillis = TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS
+ TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS = 500
def container = startContainer(defaultConfig(), defaultServices())
def managerDemoSetup = container.getService(SetupService.class).getTaskOfType(ManagerDemoSetup.class)
def keycloakDemoSetup = container.getService(SetupService.class).getTaskOfType(KeycloakDemoSetup.class)
@@ -116,6 +115,9 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
assertRulesFired(smartHomeEngine, 8)
assertRulesFired(smartHomeEngine, ["Living Room All", "Kitchen All", "Kitchen Number Attributes", "Parent Type Residence", "Asset Type Room", "Boolean Attributes", "String attributes", "Number value types"])
}
+
+ cleanup: "the static rules time variable is reset"
+ TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS = expirationMillis
}
def "Handle attribute event with no meta, asset create, update, delete"() {
@@ -123,6 +125,8 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
def conditions = new PollingConditions(timeout: 15, delay: 0.2)
and: "the container is started"
+ def expirationMillis = TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS
+ TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS = 500
def container = startContainer(defaultConfig(), defaultServices())
def managerDemoSetup = container.getService(SetupService.class).getTaskOfType(ManagerDemoSetup.class)
def keycloakDemoSetup = container.getService(SetupService.class).getTaskOfType(KeycloakDemoSetup.class)
@@ -335,6 +339,9 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
assertRulesFired(rulesImport.apartment2Engine, ["All"])
assertRulesFired(rulesImport.apartment3Engine, 0)
}
+
+ cleanup: "the static rules time variable is reset"
+ TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS = expirationMillis
}
def "Stop processing when engine in error state"() {
@@ -342,13 +349,14 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
def conditions = new PollingConditions(timeout: 10, delay: 0.2)
and: "the container is started"
+ def expirationMillis = TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS
+ TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS = 500
def container = startContainer(defaultConfig(), defaultServices())
def managerDemoSetup = container.getService(SetupService.class).getTaskOfType(ManagerDemoSetup.class)
def keycloakDemoSetup = container.getService(SetupService.class).getTaskOfType(KeycloakDemoSetup.class)
def rulesService = container.getService(RulesService.class)
def rulesetStorageService = container.getService(RulesetStorageService.class)
def assetProcessingService = container.getService(AssetProcessingService.class)
- def assetStorageService = container.getService(AssetStorageService.class)
and: "some test rulesets have been imported"
def rulesImport = new BasicRulesImport(rulesetStorageService, keycloakDemoSetup, managerDemoSetup)
@@ -397,5 +405,8 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
assert rulesImport.apartment2Engine.lastFireTimestamp > apartment2LastFireTimestamp
assert rulesImport.apartment3Engine.lastFireTimestamp > apartment3LastFireTimestamp
}
+
+ cleanup: "the static rules time variable is reset"
+ TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS = expirationMillis
}
}
diff --git a/test/src/test/groovy/org/openremote/test/rules/BasicRulesTimedExecutionTest.groovy b/test/src/test/groovy/org/openremote/test/rules/BasicRulesTimedExecutionTest.groovy
index e74405a74..df905ca2c 100644
--- a/test/src/test/groovy/org/openremote/test/rules/BasicRulesTimedExecutionTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/rules/BasicRulesTimedExecutionTest.groovy
@@ -5,6 +5,7 @@ import org.openremote.manager.rules.RulesService
import org.openremote.manager.rules.RulesetStorageService
import org.openremote.model.rules.GlobalRuleset
import org.openremote.model.rules.Ruleset
+import org.openremote.model.rules.TemporaryFact
import org.openremote.test.ManagerContainerTrait
import spock.lang.Ignore
import spock.lang.Specification
@@ -29,6 +30,8 @@ class BasicRulesTimedExecutionTest extends Specification implements ManagerConta
def conditions = new PollingConditions(timeout: 30, delay: 0.2)
and: "the container is started"
+ def expirationMillis = TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS
+ TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS = 500
def container = startContainer(defaultConfig(), defaultServices())
def rulesService = container.getService(RulesService.class)
def rulesetStorageService = container.getService(RulesetStorageService.class)
@@ -61,11 +64,16 @@ class BasicRulesTimedExecutionTest extends Specification implements ManagerConta
assert globalEngineFiredRules.size() > 10
assert globalEngineFiredRules.containsAll(expectedFiredRules)
}
+
+ cleanup: "the static rules time variable is reset"
+ TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS = expirationMillis
}
def "Check firing of timer rules with pseudo clock"() {
given: "the container environment is started"
+ def expirationMillis = TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS
+ TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS = 500
def conditions = new PollingConditions(timeout: 30, delay: 0.2)
def container = startContainer(defaultConfig(), defaultServices())
def rulesService = container.getService(RulesService.class)
@@ -110,5 +118,8 @@ class BasicRulesTimedExecutionTest extends Specification implements ManagerConta
assert globalEngineFiredRules.size() > 1
assert globalEngineFiredRules.containsAll(expectedFiredRules)
}
+
+ cleanup: "the static rules time variable is reset"
+ TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS = expirationMillis
}
}
diff --git a/test/src/test/groovy/org/openremote/test/rules/BasicRulesetResourceTest.groovy b/test/src/test/groovy/org/openremote/test/rules/BasicRulesetResourceTest.groovy
index cc99f918c..daee5e1a2 100644
--- a/test/src/test/groovy/org/openremote/test/rules/BasicRulesetResourceTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/rules/BasicRulesetResourceTest.groovy
@@ -8,6 +8,7 @@ import org.openremote.manager.setup.builtin.ManagerDemoSetup
import org.openremote.model.rules.AssetRuleset
import org.openremote.model.rules.GlobalRuleset
import org.openremote.model.rules.RulesResource
+import org.openremote.model.rules.TemporaryFact
import org.openremote.model.rules.TenantRuleset
import org.openremote.model.value.Values
import org.openremote.test.ManagerContainerTrait
@@ -27,6 +28,8 @@ class BasicRulesetResourceTest extends Specification implements ManagerContainer
def "Access rules as superuser"() {
given: "the server container is started"
def container = startContainer(defaultConfig(), defaultServices())
+ def expirationMillis = TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS
+ TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS = 500
def rulesetStorageService = container.getService(RulesetStorageService.class)
def rulesService = container.getService(RulesService.class)
def keycloakDemoSetup = container.getService(SetupService.class).getTaskOfType(KeycloakDemoSetup.class)
@@ -292,11 +295,16 @@ class BasicRulesetResourceTest extends Specification implements ManagerContainer
assetRuleset.name == "Test asset definition"
assetRuleset.rules == "SomeRulesCode"
assetRuleset.assetId == managerDemoSetup.apartment2Id
+
+ cleanup: "the static rules time variable is reset"
+ TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS = expirationMillis
}
def "Access rules as testuser1"() {
given: "the server container is started"
+ def expirationMillis = TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS
+ TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS = 500
def container = startContainer(defaultConfig(), defaultServices())
def rulesetStorageService = container.getService(RulesetStorageService.class)
def rulesService = container.getService(RulesService.class)
@@ -518,12 +526,17 @@ class BasicRulesetResourceTest extends Specification implements ManagerContainer
then: "access should be forbidden"
ex = thrown()
ex.response.status == 403
+
+ cleanup: "the static rules time variable is reset"
+ TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS = expirationMillis
}
def "Access rules as testuser2"() {
given: "the server container is started"
def container = startContainer(defaultConfig(), defaultServices())
+ def expirationMillis = TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS
+ TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS = 500
def rulesetStorageService = container.getService(RulesetStorageService.class)
def rulesService = container.getService(RulesService.class)
def keycloakDemoSetup = container.getService(SetupService.class).getTaskOfType(KeycloakDemoSetup.class)
@@ -660,12 +673,17 @@ class BasicRulesetResourceTest extends Specification implements ManagerContainer
then: "access should be forbidden"
ex = thrown()
ex.response.status == 403
+
+ cleanup: "the static rules time variable is reset"
+ TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS = expirationMillis
}
def "Access rules as testuser3"() {
given: "the server container is started"
def container = startContainer(defaultConfig(), defaultServices())
+ def expirationMillis = TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS
+ TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS = 500
def rulesetStorageService = container.getService(RulesetStorageService.class)
def rulesService = container.getService(RulesService.class)
def keycloakDemoSetup = container.getService(SetupService.class).getTaskOfType(KeycloakDemoSetup.class)
@@ -872,5 +890,8 @@ class BasicRulesetResourceTest extends Specification implements ManagerContainer
then: "access should be forbidden"
ex = thrown()
ex.response.status == 403
+
+ cleanup: "the static rules time variable is reset"
+ TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS = expirationMillis
}
}
diff --git a/test/src/test/groovy/org/openremote/test/rules/residence/FlowRulesTest.groovy b/test/src/test/groovy/org/openremote/test/rules/residence/FlowRulesTest.groovy
index c9e09055f..50e7386ce 100644
--- a/test/src/test/groovy/org/openremote/test/rules/residence/FlowRulesTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/rules/residence/FlowRulesTest.groovy
@@ -1,13 +1,11 @@
package org.openremote.test.rules.residence
-import org.openremote.container.timer.TimerService
+
import org.openremote.manager.asset.AssetProcessingService
import org.openremote.manager.asset.AssetStorageService
import org.openremote.manager.rules.FlowRulesBuilder
-import org.openremote.manager.rules.RulesEngine
import org.openremote.manager.rules.RulesService
import org.openremote.manager.rules.RulesetStorageService
-import org.openremote.manager.rules.geofence.ORConsoleGeofenceAssetAdapter
import org.openremote.manager.setup.SetupService
import org.openremote.manager.setup.builtin.ManagerDemoSetup
import org.openremote.model.attribute.AttributeEvent
@@ -20,18 +18,17 @@ import org.openremote.test.ManagerContainerTrait
import spock.lang.Specification
import spock.util.concurrent.PollingConditions
-import java.util.concurrent.TimeUnit
-
import static org.openremote.model.rules.RulesetStatus.DEPLOYED
class FlowRulesTest extends Specification implements ManagerContainerTrait {
- private FlowRulesBuilder builder
def "Execute flow rules"() {
given: "expected conditions"
def conditions = new PollingConditions(timeout: 10, delay: 0.2)
and: "the container is started"
+ def expirationMillis = TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS
+ TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS = 500
def container = startContainer(defaultConfig(), defaultServices())
def managerDemoSetup = container.getService(SetupService.class).getTaskOfType(ManagerDemoSetup.class)
def rulesService = container.getService(RulesService.class)
@@ -79,5 +76,8 @@ class FlowRulesTest extends Specification implements ManagerContainerTrait {
getAttribute("targetTemperature").get().getValueAsNumber().get()
assert bedroomTargetTemp.intValue() == (startTemperature.intValue() + 10) : ("it was actually " + bedroomTargetTemp.intValue())//convert to int considering floating point inaccuracy
}
+
+ cleanup: "the static rules time variable is reset"
+ TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS = expirationMillis
}
}
diff --git a/test/src/test/groovy/org/openremote/test/rules/residence/JsonRulesTest.groovy b/test/src/test/groovy/org/openremote/test/rules/residence/JsonRulesTest.groovy
index e917305fc..5cf04564b 100644
--- a/test/src/test/groovy/org/openremote/test/rules/residence/JsonRulesTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/rules/residence/JsonRulesTest.groovy
@@ -63,8 +63,8 @@ class JsonRulesTest extends Specification implements ManagerContainerTrait {
ORConsoleGeofenceAssetAdapter.NOTIFY_ASSETS_DEBOUNCE_MILLIS = 100
and: "the rule firing delay time is set to a small value for testing"
- def originalExpirationMillis = TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS
- TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS = 100
+ def expirationMillis = TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS
+ TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS = 500
and: "the container environment is started with the mock handler"
def conditions = new PollingConditions(timeout: 15, delay: 0.2)
@@ -466,7 +466,7 @@ class JsonRulesTest extends Specification implements ManagerContainerTrait {
RulesEngine.PAUSE_SCHEDULER = originalPause
RulesEngine.UNPAUSE_SCHEDULER = originalUnpause
ORConsoleGeofenceAssetAdapter.NOTIFY_ASSETS_DEBOUNCE_MILLIS = originalDebounceMillis
- TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS = originalExpirationMillis
+ TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS = expirationMillis
notificationService.notificationHandlerMap.put(emailNotificationHandler.getTypeName(), emailNotificationHandler)
notificationService.notificationHandlerMap.put(pushNotificationHandler.getTypeName(), pushNotificationHandler)
}
diff --git a/test/src/test/groovy/org/openremote/test/rules/residence/ResidenceAllLightsOffTest.groovy b/test/src/test/groovy/org/openremote/test/rules/residence/ResidenceAllLightsOffTest.groovy
index 81147649c..5394592fb 100644
--- a/test/src/test/groovy/org/openremote/test/rules/residence/ResidenceAllLightsOffTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/rules/residence/ResidenceAllLightsOffTest.groovy
@@ -10,6 +10,7 @@ import org.openremote.manager.setup.builtin.ManagerDemoSetup
import org.openremote.model.attribute.AttributeEvent
import org.openremote.model.rules.AssetRuleset
import org.openremote.model.rules.Ruleset
+import org.openremote.model.rules.TemporaryFact
import org.openremote.model.value.Values
import org.openremote.test.ManagerContainerTrait
import spock.lang.Specification
@@ -23,6 +24,8 @@ class ResidenceAllLightsOffTest extends Specification implements ManagerContaine
def "Turn all lights off"() {
given: "the container environment is started"
+ def expirationMillis = TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS
+ TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS = 500
def conditions = new PollingConditions(timeout: 10, delay: 0.2)
def container = startContainer(defaultConfig(), defaultServices())
def managerDemoSetup = container.getService(SetupService.class).getTaskOfType(ManagerDemoSetup.class)
@@ -91,5 +94,8 @@ class ResidenceAllLightsOffTest extends Specification implements ManagerContaine
def livingroomAsset = assetStorageService.find(managerDemoSetup.apartment2LivingroomId, true)
assert livingroomAsset.getAttribute("lightSwitch").get().valueAsBoolean.get()
}
+
+ cleanup: "the static rules time variable is reset"
+ TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS = expirationMillis
}
}
diff --git a/test/src/test/groovy/org/openremote/test/rules/residence/ResidenceAutoVentilationTest.groovy b/test/src/test/groovy/org/openremote/test/rules/residence/ResidenceAutoVentilationTest.groovy
index fd9792e86..10130a6e0 100644
--- a/test/src/test/groovy/org/openremote/test/rules/residence/ResidenceAutoVentilationTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/rules/residence/ResidenceAutoVentilationTest.groovy
@@ -11,6 +11,7 @@ import org.openremote.manager.setup.builtin.ManagerDemoSetup
import org.openremote.model.attribute.AttributeEvent
import org.openremote.model.rules.AssetRuleset
import org.openremote.model.rules.Ruleset
+import org.openremote.model.rules.TemporaryFact
import org.openremote.model.value.Values
import org.openremote.test.ManagerContainerTrait
import spock.lang.Specification
@@ -26,6 +27,8 @@ class ResidenceAutoVentilationTest extends Specification implements ManagerConta
def "Auto ventilation with CO2 detection"() {
given: "the container environment is started"
+ def expirationMillis = TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS
+ TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS = 500
def conditions = new PollingConditions(timeout: 20, delay: 0.2)
def container = startContainer(defaultConfig(), defaultServices())
def managerDemoSetup = container.getService(SetupService.class).getTaskOfType(ManagerDemoSetup.class)
@@ -185,6 +188,9 @@ class ResidenceAutoVentilationTest extends Specification implements ManagerConta
def apartment = assetStorageService.find(managerDemoSetup.apartment1Id, true)
assert apartment.getAttribute("ventilationLevel").get().getValueAsNumber().get() == 64d
}
+
+ cleanup: "the static rules time variable is reset"
+ TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS = expirationMillis
}
}
diff --git a/test/src/test/groovy/org/openremote/test/rules/residence/ResidenceNotifyAlarmTriggerTest.groovy b/test/src/test/groovy/org/openremote/test/rules/residence/ResidenceNotifyAlarmTriggerTest.groovy
index ada7901f9..d532de026 100644
--- a/test/src/test/groovy/org/openremote/test/rules/residence/ResidenceNotifyAlarmTriggerTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/rules/residence/ResidenceNotifyAlarmTriggerTest.groovy
@@ -23,6 +23,7 @@ import org.openremote.model.notification.NotificationSendResult
import org.openremote.model.notification.PushNotificationMessage
import org.openremote.model.rules.AssetRuleset
import org.openremote.model.rules.Ruleset
+import org.openremote.model.rules.TemporaryFact
import org.openremote.model.value.ObjectValue
import org.openremote.model.value.Values
import org.openremote.test.ManagerContainerTrait
@@ -47,6 +48,8 @@ class ResidenceNotifyAlarmTriggerTest extends Specification implements ManagerCo
def messages = []
given: "the container environment is started with the mock handler"
+ def expirationMillis = TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS
+ TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS = 500
def conditions = new PollingConditions(timeout: 20, delay: 0.2)
def container = startContainer(defaultConfig(), defaultServices())
def managerDemoSetup = container.getService(SetupService.class).getTaskOfType(ManagerDemoSetup.class)
@@ -232,5 +235,6 @@ class ResidenceNotifyAlarmTriggerTest extends Specification implements ManagerCo
cleanup: "the mock is removed"
notificationService.notificationHandlerMap.put(pushNotificationHandler.getTypeName(), pushNotificationHandler)
+ TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS = expirationMillis
}
}
diff --git a/test/src/test/groovy/org/openremote/test/rules/residence/ResidencePresenceDetectionTest.groovy b/test/src/test/groovy/org/openremote/test/rules/residence/ResidencePresenceDetectionTest.groovy
index 46b9b83bc..268232938 100644
--- a/test/src/test/groovy/org/openremote/test/rules/residence/ResidencePresenceDetectionTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/rules/residence/ResidencePresenceDetectionTest.groovy
@@ -11,6 +11,7 @@ import org.openremote.manager.setup.builtin.ManagerDemoSetup
import org.openremote.model.attribute.AttributeEvent
import org.openremote.model.rules.AssetRuleset
import org.openremote.model.rules.Ruleset
+import org.openremote.model.rules.TemporaryFact
import org.openremote.model.value.Values
import org.openremote.test.ManagerContainerTrait
import spock.lang.Specification
@@ -25,6 +26,8 @@ class ResidencePresenceDetectionTest extends Specification implements ManagerCon
def "Presence detection with motion sensor"() {
given: "the container environment is started"
+ def expirationMillis = TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS
+ TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS = 500
def conditions = new PollingConditions(timeout: 30, delay: 0.2)
def container = startContainer(defaultConfig(), defaultServices())
def managerDemoSetup = container.getService(SetupService.class).getTaskOfType(ManagerDemoSetup.class)
@@ -148,11 +151,16 @@ class ResidencePresenceDetectionTest extends Specification implements ManagerCon
assert !hallway.getAttribute("presenceDetected").get().getValueAsBoolean().get()
assert hallway.getAttribute("lastPresenceDetected").get().getValueAsNumber().get() == expectedLastPresenceDetected
}
+
+ cleanup: "the static rules time variable is reset"
+ TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS = expirationMillis
}
def "Presence detection with motion sensor and confirmation with CO2 level"() {
given: "the container environment is started"
+ def expirationMillis = TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS
+ TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS = 500
def conditions = new PollingConditions(timeout: 20, delay: 0.2)
def container = startContainer(defaultConfig(), defaultServices())
def managerDemoSetup = container.getService(SetupService.class).getTaskOfType(ManagerDemoSetup.class)
@@ -274,6 +282,9 @@ class ResidencePresenceDetectionTest extends Specification implements ManagerCon
assert !roomAsset.getAttribute("presenceDetected").get().getValueAsBoolean().get()
assert roomAsset.getAttribute("lastPresenceDetected").get().getValueAsNumber().get() == expectedLastPresenceDetected
}
+
+ cleanup: "the static rules time variable is reset"
+ TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS = expirationMillis
}
/* TODO Migrate to JS, didn't compile even with Drools
diff --git a/test/src/test/groovy/org/openremote/test/rules/residence/ResidenceSmartSwitchTest.groovy b/test/src/test/groovy/org/openremote/test/rules/residence/ResidenceSmartSwitchTest.groovy
index 5ca9a5582..adef3f28f 100644
--- a/test/src/test/groovy/org/openremote/test/rules/residence/ResidenceSmartSwitchTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/rules/residence/ResidenceSmartSwitchTest.groovy
@@ -10,6 +10,7 @@ import org.openremote.manager.setup.builtin.ManagerDemoSetup
import org.openremote.model.attribute.AttributeEvent
import org.openremote.model.rules.AssetRuleset
import org.openremote.model.rules.Ruleset
+import org.openremote.model.rules.TemporaryFact
import org.openremote.model.value.Values
import org.openremote.test.ManagerContainerTrait
import spock.lang.Specification
@@ -26,6 +27,8 @@ class ResidenceSmartSwitchTest extends Specification implements ManagerContainer
given: "the container environment is started"
def conditions = new PollingConditions(timeout: 10, delay: 0.2)
+ def expirationMillis = TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS
+ TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS = 500
def container = startContainer(defaultConfig(), defaultServices())
def managerDemoSetup = container.getService(SetupService.class).getTaskOfType(ManagerDemoSetup.class)
def rulesService = container.getService(RulesService.class)
@@ -145,12 +148,17 @@ class ResidenceSmartSwitchTest extends Specification implements ManagerContainer
assert !kitchen.getAttribute("smartSwitchStopTimeC").get().getValue().isPresent()
assert !kitchen.getAttribute("smartSwitchEnabledC").get().getValue().isPresent()
}
+
+ cleanup: "the static rules time variable is reset"
+ TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS = expirationMillis
}
def "Set mode ON_AT and begin/end cycle time in past"() {
given: "the container environment is started"
def conditions = new PollingConditions(timeout: 10, delay: 0.2)
+ def expirationMillis = TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS
+ TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS = 500
def container = startContainer(defaultConfig(), defaultServices())
def managerDemoSetup = container.getService(SetupService.class).getTaskOfType(ManagerDemoSetup.class)
def rulesService = container.getService(RulesService.class)
@@ -238,12 +246,17 @@ class ResidenceSmartSwitchTest extends Specification implements ManagerContainer
assert !kitchen.getAttribute("smartSwitchStopTimeC").get().getValue().isPresent()
assert !kitchen.getAttribute("smartSwitchEnabledC").get().getValue().isPresent()
}
+
+ cleanup: "the static rules time variable is reset"
+ TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS = expirationMillis
}
def "Set mode READY_AT and begin/end cycle time in future"() {
given: "the container environment is started"
def conditions = new PollingConditions(timeout: 10, delay: 0.2)
+ def expirationMillis = TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS
+ TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS = 500
def container = startContainer(defaultConfig(), defaultServices())
def managerDemoSetup = container.getService(SetupService.class).getTaskOfType(ManagerDemoSetup.class)
def rulesService = container.getService(RulesService.class)
@@ -355,12 +368,17 @@ class ResidenceSmartSwitchTest extends Specification implements ManagerContainer
assert !kitchen.getAttribute("smartSwitchStopTimeC").get().getValue().isPresent()
assert !kitchen.getAttribute("smartSwitchEnabledC").get().getValue().isPresent()
}
+
+ cleanup: "the static rules time variable is reset"
+ TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS = expirationMillis
}
def "Set mode READY_AT and begin/end cycle time in past"() {
given: "the container environment is started"
def conditions = new PollingConditions(timeout: 10, delay: 0.2)
+ def expirationMillis = TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS
+ TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS = 500
def container = startContainer(defaultConfig(), defaultServices())
def managerDemoSetup = container.getService(SetupService.class).getTaskOfType(ManagerDemoSetup.class)
def rulesService = container.getService(RulesService.class)
@@ -449,12 +467,17 @@ class ResidenceSmartSwitchTest extends Specification implements ManagerContainer
assert !kitchen.getAttribute("smartSwitchStopTimeC").get().getValue().isPresent()
assert !kitchen.getAttribute("smartSwitchEnabledC").get().getValue().isPresent()
}
+
+ cleanup: "the static rules time variable is reset"
+ TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS = expirationMillis
}
def "Set mode READY_AT and insufficient begin/end cycle time"() {
given: "the container environment is started"
def conditions = new PollingConditions(timeout: 10, delay: 0.2)
+ def expirationMillis = TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS
+ TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS = 500
def container = startContainer(defaultConfig(), defaultServices())
def managerDemoSetup = container.getService(SetupService.class).getTaskOfType(ManagerDemoSetup.class)
def rulesService = container.getService(RulesService.class)
@@ -543,6 +566,9 @@ class ResidenceSmartSwitchTest extends Specification implements ManagerContainer
assert !kitchen.getAttribute("smartSwitchStopTimeC").get().getValue().isPresent()
assert !kitchen.getAttribute("smartSwitchEnabledC").get().getValue().isPresent()
}
+
+ cleanup: "the static rules time variable is reset"
+ TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS = expirationMillis
}
}
diff --git a/test/src/test/groovy/org/openremote/test/rules/residence/ResidenceVacationModeTest.groovy b/test/src/test/groovy/org/openremote/test/rules/residence/ResidenceVacationModeTest.groovy
index 30aa7c777..be02ccf71 100644
--- a/test/src/test/groovy/org/openremote/test/rules/residence/ResidenceVacationModeTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/rules/residence/ResidenceVacationModeTest.groovy
@@ -11,6 +11,7 @@ import org.openremote.model.attribute.AttributeEvent
import org.openremote.model.attribute.AttributeExecuteStatus
import org.openremote.model.rules.AssetRuleset
import org.openremote.model.rules.Ruleset
+import org.openremote.model.rules.TemporaryFact
import org.openremote.model.value.Values
import org.openremote.test.ManagerContainerTrait
import spock.lang.Specification
@@ -28,6 +29,8 @@ class ResidenceVacationModeTest extends Specification implements ManagerContaine
given: "the container environment is started"
def conditions = new PollingConditions(timeout: 20, delay: 0.2)
+ def expirationMillis = TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS
+ TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS = 500
def container = startContainer(defaultConfig(), defaultServices())
def managerDemoSetup = container.getService(SetupService.class).getTaskOfType(ManagerDemoSetup.class)
def rulesService = container.getService(RulesService.class)
@@ -123,5 +126,8 @@ class ResidenceVacationModeTest extends Specification implements ManagerContaine
assert asset.getAttribute("nightSceneEnabled" + it.name()).get().getValueAsBoolean().get()
}
}
+
+ cleanup: "the static rules time variable is reset"
+ TemporaryFact.GUARANTEED_MIN_EXPIRATION_MILLIS = expirationMillis
}
}