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
Minor update for RULES_FACT meta tests
Rich Turner5ae41d8b4425
diff --git a/manager/server/src/main/java/org/openremote/manager/server/setup/builtin/ManagerDemoSetup.java b/manager/server/src/main/java/org/openremote/manager/server/setup/builtin/ManagerDemoSetup.javaindex 793f4be78..2141c2266 100644--- a/manager/server/src/main/java/org/openremote/manager/server/setup/builtin/ManagerDemoSetup.java+++ b/manager/server/src/main/java/org/openremote/manager/server/setup/builtin/ManagerDemoSetup.java@@ -97,26 +97,26 @@ public class ManagerDemoSetup extends AbstractManagerSetup {smartOffice.setType(BUILDING);Attributes smartOfficeAttributes = new Attributes();smartOfficeAttributes.put(- new Attribute("geoStreet", STRING, Json.create("Torenallee 20"))- .setMeta(new Meta()- .add(createMetaItem(LABEL, Json.create("Street")))- .add(createMetaItem(ABOUT, Json.create("http://project-haystack.org/tag/geoStreet")))- ),- new Attribute("geoPostalCode", AttributeType.INTEGER, Json.create(5617))- .setMeta(new Meta()- .add(createMetaItem(LABEL, Json.create("Postal Code")))- .add(createMetaItem(ABOUT, Json.create("http://project-haystack.org/tag/geoPostalCode")))- ),- new Attribute("geoCity", STRING, Json.create("Eindhoven"))- .setMeta(new Meta()- .add(createMetaItem(LABEL, Json.create("City")))- .add(createMetaItem(ABOUT, Json.create("http://project-haystack.org/tag/geoCity")))- ),- new Attribute("geoCountry", STRING, Json.create("Netherlands"))- .setMeta(new Meta()- .add(createMetaItem(LABEL, Json.create("Country")))- .add(createMetaItem(ABOUT, Json.create("http://project-haystack.org/tag/geoCountry")))- )+ new Attribute("geoStreet", STRING, Json.create("Torenallee 20"))+ .setMeta(new Meta()+ .add(createMetaItem(LABEL, Json.create("Street")))+ .add(createMetaItem(ABOUT, Json.create("http://project-haystack.org/tag/geoStreet")))+ ),+ new Attribute("geoPostalCode", AttributeType.INTEGER, Json.create(5617))+ .setMeta(new Meta()+ .add(createMetaItem(LABEL, Json.create("Postal Code")))+ .add(createMetaItem(ABOUT, Json.create("http://project-haystack.org/tag/geoPostalCode")))+ ),+ new Attribute("geoCity", STRING, Json.create("Eindhoven"))+ .setMeta(new Meta()+ .add(createMetaItem(LABEL, Json.create("City")))+ .add(createMetaItem(ABOUT, Json.create("http://project-haystack.org/tag/geoCity")))+ ),+ new Attribute("geoCountry", STRING, Json.create("Netherlands"))+ .setMeta(new Meta()+ .add(createMetaItem(LABEL, Json.create("Country")))+ .add(createMetaItem(ABOUT, Json.create("http://project-haystack.org/tag/geoCountry")))+ ));smartOffice.setAttributes(smartOfficeAttributes.getJsonObject());smartOffice = assetStorageService.merge(smartOffice);@@ -154,92 +154,92 @@ public class ManagerDemoSetup extends AbstractManagerSetup {thing.setType(AssetType.THING);ThingAttributes thingAttributes = new ThingAttributes(thing);thingAttributes.put(- new Attribute("light1Toggle", BOOLEAN, Json.create(true))- .setMeta(new Meta()- .add(new MetaItem(- AssetMeta.DESCRIPTION,- Json.create("The switch for the light in the living room"))- )- .add(new MetaItem(- AssetMeta.AGENT_LINK,- new AttributeRef(agent.getId(), "simulator123").asJsonValue()- ))- .add(new MetaItem(- SimulatorProtocol.SIMULATOR_ELEMENT, Json.create(SwitchSimulatorElement.ELEMENT_NAME)- ))- ),- new Attribute("light1Dimmer", INTEGER) // No initial value!- .setMeta(new Meta()- .add(new MetaItem(- AssetMeta.DESCRIPTION,- Json.create("The dimmer for the light in the living room"))- )- .add(new MetaItem(- AssetMeta.RANGE_MIN,- Json.create(0))- )- .add(new MetaItem(- AssetMeta.RANGE_MAX,- Json.create(100))- )- .add(new MetaItem(- AssetMeta.AGENT_LINK,- new AttributeRef(agent.getId(), "simulator123").asJsonValue()- ))- .add(new MetaItem(- SimulatorProtocol.SIMULATOR_ELEMENT, Json.create(IntegerSimulatorElement.ELEMENT_NAME_RANGE)- ))- .add(new MetaItem(- SimulatorProtocol.SIMULATOR_REFLECT_ACTUATOR_WRITES, Json.create(true)- ))- ),- new Attribute("light1Color", INTEGER_ARRAY, new ColorRGB(88, 123, 88).asJsonValue())- .setMeta(new Meta()- .add(new MetaItem(- AssetMeta.UNITS,- Json.create(AttributeUnits.COLOR_RGB.toString())- ))- .add(new MetaItem(- AssetMeta.DESCRIPTION,- Json.create("The color of the living room light"))- )- .add(new MetaItem(- AssetMeta.AGENT_LINK,- new AttributeRef(agent.getId(), "simulator123").asJsonValue()- ))- .add(new MetaItem(- SimulatorProtocol.SIMULATOR_ELEMENT, Json.create(ColorSimulatorElement.ELEMENT_NAME)- ))- ),- new Attribute("light1PowerConsumption", DECIMAL, Json.create(12.345))- .setMeta(new Meta()- .add(new MetaItem(- AssetMeta.DESCRIPTION,- Json.create("The total power consumption of the living room light"))- )- .add(new MetaItem(- AssetMeta.READ_ONLY,- Json.create(true))- )- .add(new MetaItem(- AssetMeta.FORMAT,- Json.create("%3d kWh"))- )- .add(new MetaItem(- AssetMeta.UNITS,- Json.create(AttributeUnits.ENERGY_KWH.name()))- )- .add(new MetaItem(- AssetMeta.AGENT_LINK,- new AttributeRef(agent.getId(), "simulator123").asJsonValue()- ))- .add(new MetaItem(- SimulatorProtocol.SIMULATOR_ELEMENT, Json.create(DecimalSimulatorElement.ELEMENT_NAME)- ))- .add(new MetaItem(- AssetMeta.STORE_DATA_POINTS.getName(), Json.create(true)- ))- )+ new Attribute("light1Toggle", BOOLEAN, Json.create(true))+ .setMeta(new Meta()+ .add(new MetaItem(+ AssetMeta.DESCRIPTION,+ Json.create("The switch for the light in the living room"))+ )+ .add(new MetaItem(+ AssetMeta.AGENT_LINK,+ new AttributeRef(agent.getId(), "simulator123").asJsonValue()+ ))+ .add(new MetaItem(+ SimulatorProtocol.SIMULATOR_ELEMENT, Json.create(SwitchSimulatorElement.ELEMENT_NAME)+ ))+ ),+ new Attribute("light1Dimmer", INTEGER) // No initial value!+ .setMeta(new Meta()+ .add(new MetaItem(+ AssetMeta.DESCRIPTION,+ Json.create("The dimmer for the light in the living room"))+ )+ .add(new MetaItem(+ AssetMeta.RANGE_MIN,+ Json.create(0))+ )+ .add(new MetaItem(+ AssetMeta.RANGE_MAX,+ Json.create(100))+ )+ .add(new MetaItem(+ AssetMeta.AGENT_LINK,+ new AttributeRef(agent.getId(), "simulator123").asJsonValue()+ ))+ .add(new MetaItem(+ SimulatorProtocol.SIMULATOR_ELEMENT, Json.create(IntegerSimulatorElement.ELEMENT_NAME_RANGE)+ ))+ .add(new MetaItem(+ SimulatorProtocol.SIMULATOR_REFLECT_ACTUATOR_WRITES, Json.create(true)+ ))+ ),+ new Attribute("light1Color", INTEGER_ARRAY, new ColorRGB(88, 123, 88).asJsonValue())+ .setMeta(new Meta()+ .add(new MetaItem(+ AssetMeta.UNITS,+ Json.create(AttributeUnits.COLOR_RGB.toString())+ ))+ .add(new MetaItem(+ AssetMeta.DESCRIPTION,+ Json.create("The color of the living room light"))+ )+ .add(new MetaItem(+ AssetMeta.AGENT_LINK,+ new AttributeRef(agent.getId(), "simulator123").asJsonValue()+ ))+ .add(new MetaItem(+ SimulatorProtocol.SIMULATOR_ELEMENT, Json.create(ColorSimulatorElement.ELEMENT_NAME)+ ))+ ),+ new Attribute("light1PowerConsumption", DECIMAL, Json.create(12.345))+ .setMeta(new Meta()+ .add(new MetaItem(+ AssetMeta.DESCRIPTION,+ Json.create("The total power consumption of the living room light"))+ )+ .add(new MetaItem(+ AssetMeta.READ_ONLY,+ Json.create(true))+ )+ .add(new MetaItem(+ AssetMeta.FORMAT,+ Json.create("%3d kWh"))+ )+ .add(new MetaItem(+ AssetMeta.UNITS,+ Json.create(AttributeUnits.ENERGY_KWH.name()))+ )+ .add(new MetaItem(+ AssetMeta.AGENT_LINK,+ new AttributeRef(agent.getId(), "simulator123").asJsonValue()+ ))+ .add(new MetaItem(+ SimulatorProtocol.SIMULATOR_ELEMENT, Json.create(DecimalSimulatorElement.ELEMENT_NAME)+ ))+ .add(new MetaItem(+ AssetMeta.STORE_DATA_POINTS.getName(), Json.create(true)+ ))+ ));thing.setAttributes(thingAttributes.getJsonObject());thing = assetStorageService.merge(thing);@@ -284,10 +284,19 @@ public class ManagerDemoSetup extends AbstractManagerSetup {apartment1Livingroom.setType(ROOM);Attributes apartment1LivingroomAttributes = new Attributes();apartment1LivingroomAttributes.put(- new Attribute("demoBoolean", BOOLEAN, Json.create(true)),- new Attribute("demoString", STRING, Json.create("demo")),+ new Attribute("demoBoolean", BOOLEAN, Json.create(true))+ .setMeta(new Meta().add(+ new MetaItem(AssetMeta.RULES_FACT, Json.create(true))+ )),+ new Attribute("demoString", STRING, Json.create("demo"))+ .setMeta(new Meta().add(+ new MetaItem(AssetMeta.RULES_FACT, Json.create(false))+ )),new Attribute("demoInteger", INTEGER, Json.create(0)),new Attribute("demoDecimal", DECIMAL, Json.create(0d))+ .setMeta(new Meta().add(+ new MetaItem(AssetMeta.RULES_FACT, Json.create(true))+ )));apartment1Livingroom.setAttributes(apartment1LivingroomAttributes.getJsonObject());apartment1Livingroom = assetStorageService.merge(apartment1Livingroom);@@ -298,31 +307,31 @@ public class ManagerDemoSetup extends AbstractManagerSetup {apartment1LivingroomThermostat.setType(AssetType.THING);ThingAttributes apartment1LivingroomThermostatAttributes = new ThingAttributes(apartment1LivingroomThermostat);apartment1LivingroomThermostatAttributes.put(- new Attribute("demoBoolean", BOOLEAN, Json.create(true)),- new Attribute("demoString", STRING, Json.create("demo")),- new Attribute("demoInteger", INTEGER, Json.create(0)),- new Attribute("demoDecimal", DECIMAL, Json.create(0d)),- new Attribute("currentTemperature", DECIMAL, Json.create(19.2))- .setMeta(new Meta()- .add(new MetaItem(- AssetMeta.LABEL,- Json.create("Current Temp"))- )- .add(new MetaItem(- AssetMeta.PROTECTED,- Json.create(true))- )- .add(new MetaItem(- AssetMeta.READ_ONLY,- Json.create(true))- )- .add(new MetaItem(- Constants.NAMESPACE + ":foo:bar", Json.create("FOO")- ))- .add(new MetaItem(- "urn:thirdparty:bar", Json.create("BAR")- ))- )+ new Attribute("demoBoolean", BOOLEAN, Json.create(true)),+ new Attribute("demoString", STRING, Json.create("demo")),+ new Attribute("demoInteger", INTEGER, Json.create(0)),+ new Attribute("demoDecimal", DECIMAL, Json.create(0d)),+ new Attribute("currentTemperature", DECIMAL, Json.create(19.2))+ .setMeta(new Meta()+ .add(new MetaItem(+ AssetMeta.LABEL,+ Json.create("Current Temp"))+ )+ .add(new MetaItem(+ AssetMeta.PROTECTED,+ Json.create(true))+ )+ .add(new MetaItem(+ AssetMeta.READ_ONLY,+ Json.create(true))+ )+ .add(new MetaItem(+ Constants.NAMESPACE + ":foo:bar", Json.create("FOO")+ ))+ .add(new MetaItem(+ "urn:thirdparty:bar", Json.create("BAR")+ ))+ ));apartment1LivingroomThermostat.setAttributes(apartment1LivingroomThermostatAttributes.getJsonObject());@@ -381,7 +390,10 @@ public class ManagerDemoSetup extends AbstractManagerSetup {Attributes apartment3LivingroomAttributes = new Attributes();apartment3LivingroomAttributes.put(new Attribute("demoBoolean", BOOLEAN, Json.create(true)),- new Attribute("demoString", STRING, Json.create("demo")),+ new Attribute("demoString", STRING, Json.create("demo"))+ .setMeta(new Meta().add(+ new MetaItem(AssetMeta.RULES_FACT, Json.create(true))+ )),new Attribute("demoInteger", INTEGER, Json.create(0)),new Attribute("demoDecimal", DECIMAL, Json.create(0d)));diff --git a/manager/test/src/test/groovy/org/openremote/test/rules/RulesDeploymentTest.groovy b/manager/test/src/test/groovy/org/openremote/test/rules/RulesDeploymentTest.groovyindex 32abb2ae8..1216adb9f 100644--- a/manager/test/src/test/groovy/org/openremote/test/rules/RulesDeploymentTest.groovy+++ b/manager/test/src/test/groovy/org/openremote/test/rules/RulesDeploymentTest.groovy@@ -20,7 +20,6 @@ import org.openremote.model.AttributeEventimport org.openremote.model.AttributeRefimport org.openremote.model.AttributeStateimport org.openremote.test.ManagerContainerTrait-import spock.lang.Ignoreimport spock.lang.Specificationimport spock.util.concurrent.PollingConditions@@ -209,7 +208,7 @@ class RulesDeploymentTest extends Specification implements ManagerContainerTraitwhen: "the enabled rule definition for customer B is disabled"conditions = new PollingConditions(timeout: 10)- // TODO: If we don't do this then test will fail+ // TODO: Stop instances of rule definitions being passed around as rules deployment nulls the rules propertyrulesDefinition = rulesStorageService.findById(TenantRulesDefinition.class, managerDemoSetup.customerBRulesDefinitionId)rulesDefinition.setEnabled(false)rulesStorageService.merge(rulesDefinition)@@ -380,8 +379,6 @@ class RulesDeploymentTest extends Specification implements ManagerContainerTraitstopContainer(container)}- // TODO: Add RULES_FACT meta to demo data- @Ignoredef "Check firing of rules LHS"() {given: "expected conditions"def conditions = new PollingConditions(timeout: 10)@@ -433,7 +430,7 @@ class RulesDeploymentTest extends Specification implements ManagerContainerTraitattachRuleExecutionLogger(apartment1Engine, apartment1EngineFiredRules)attachRuleExecutionLogger(apartment3Engine, apartment3EngineFiredRules)- and: "an attribute event is pushed into the system"+ and: "an attribute event is pushed into the system for an attribute with RULES_FACT meta set to true"def apartment1LivingRoomDemoBooleanChange = new AttributeEvent(new AttributeState(new AttributeRef(managerDemoSetup.apartment1LivingroomId, "demoBoolean"), Json.create(false)), getClass())@@ -454,12 +451,44 @@ class RulesDeploymentTest extends Specification implements ManagerContainerTraitassert apartment3EngineFiredRules.size() == 0}+ when: "an attribute event is pushed into the system for an attribute with RULES_FACT meta set to false"+ def apartment1LivingRoomDemoStringChange = new AttributeEvent(+ new AttributeState(new AttributeRef(managerDemoSetup.apartment1LivingroomId, "demoString"), Json.create("demo2")), getClass()+ )+ assetProcessingService.updateAttributeValue(apartment1LivingRoomDemoStringChange)++ then: "no rule engines should have fired after a few seconds"+ new PollingConditions(delay: 3, timeout: 5).eventually {+ assert globalEngineFiredRules.size() == 2+ assert masterEngineFiredRules.size() == 0+ assert customerAEngineFiredRules.size() == 2+ assert smartHomeEngineFiredRules.size() == 2+ assert apartment1EngineFiredRules.size() == 2+ assert apartment3EngineFiredRules.size() == 0+ }++ when: "an attribute event is pushed into the system for an attribute with no RULES_FACT meta"+ def apartment1LivingRoomDemoIntegerChange = new AttributeEvent(+ new AttributeState(new AttributeRef(managerDemoSetup.apartment1LivingroomId, "demoInteger"), Json.create(1)), getClass()+ )+ assetProcessingService.updateAttributeValue(apartment1LivingRoomDemoIntegerChange)++ then: "no rule engines should have fired after a few seconds"+ new PollingConditions(delay: 3, timeout: 5).eventually {+ assert globalEngineFiredRules.size() == 2+ assert masterEngineFiredRules.size() == 0+ assert customerAEngineFiredRules.size() == 2+ assert smartHomeEngineFiredRules.size() == 2+ assert apartment1EngineFiredRules.size() == 2+ assert apartment3EngineFiredRules.size() == 0+ }+when: "an old (stale) attribute event is pushed into the system"conditions = new PollingConditions(timeout: 10, initialDelay: 5)assetProcessingService.updateAttributeValue(apartment1LivingRoomDemoBooleanChange)- then: "after a few seconds no rules should have fired on any engines"- conditions.eventually {+ then: "no rule engines should have fired after a few seconds"+ new PollingConditions(delay: 3, timeout: 5).eventually {assert globalEngineFiredRules.size() == 2assert masterEngineFiredRules.size() == 0assert customerAEngineFiredRules.size() == 2@@ -547,10 +576,10 @@ class RulesDeploymentTest extends Specification implements ManagerContainerTrait}when: "an apartment 1 living room attribute event occurs"- def apartment1LivingRoomDemoStringChange = new AttributeEvent(+ def apartment1LivingRoomDemoDecimalChange = new AttributeEvent(new AttributeState(new AttributeRef(managerDemoSetup.apartment1LivingroomId, "demoDecimal"), Json.create(22.5)), getClass())- assetProcessingService.updateAttributeValue(apartment1LivingRoomDemoStringChange)+ assetProcessingService.updateAttributeValue(apartment1LivingRoomDemoDecimalChange)then: "the apartment 1 rule engine should have fired the 'All', 'All changed' and 'Living Room All' rules but apartment 3 shouldn't have fired any"conditions.eventually {