Skip to content

armgit / core

Public Imported from GitHub
0

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

Added scene test attributes

Christian Bauerf6dde6a09a7e
diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesBrowser.java b/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesBrowser.java
index da51132b1..23ba94740 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesBrowser.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesBrowser.java
@@ -214,6 +214,7 @@ public abstract class AttributesBrowser
FormGroup formGroup = new FormGroup();
FormLabel formLabel = new FormLabel(environment.getMessages().showLiveUpdates());
+ formLabel.addStyleName("larger");
formGroup.addFormLabel(formLabel);
FormField formField = new FormField();
diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesEditor.java b/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesEditor.java
index b1381599d..4c3d75f42 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesEditor.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesEditor.java
@@ -71,6 +71,7 @@ public class AttributesEditor
protected FormLabel createAttributeLabel(AssetAttribute attribute) {
FormLabel formLabel = new FormLabel(TextUtil.ellipsize(getAttributeLabel(attribute), 30));
+ formLabel.setIcon("edit");
formLabel.addStyleName("larger");
return formLabel;
}
@@ -158,6 +159,7 @@ public class AttributesEditor
FormGroup formGroup = new FormGroup();
FormLabel label = new FormLabel(environment.getMessages().newAttribute());
+ label.setIcon("plus-square");
label.addStyleName("larger");
formGroup.addFormLabel(label);
diff --git a/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesView.java b/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesView.java
index 3887dc288..038e22bcf 100644
--- a/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesView.java
+++ b/manager/client/src/main/java/org/openremote/manager/client/assets/attributes/AttributesView.java
@@ -19,6 +19,7 @@
*/
package org.openremote.manager.client.assets.attributes;
+import com.google.gwt.dom.client.Style;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.InsertPanel;
@@ -67,13 +68,14 @@ public abstract class AttributesView<
public interface AttributeEditor extends IsWidget {
}
- public static class TimestampLabel extends FormOutputText {
+ public static class TimestampLabel extends FlowPanel {
- static protected DateTimeFormat dateTimeFormat = DateTimeFormat.getFormat(Constants.DEFAULT_DATETIME_FORMAT);
+ static protected DateTimeFormat dateFormat = DateTimeFormat.getFormat(Constants.DEFAULT_DATE_FORMAT);
+ static protected DateTimeFormat timeFormat = DateTimeFormat.getFormat(Constants.DEFAULT_TIME_FORMAT);
public TimestampLabel(Long timestamp) {
addStyleName("flex");
- getElement().getStyle().setFontSize(0.8, com.google.gwt.dom.client.Style.Unit.EM);
+ getElement().getStyle().setFontSize(9, com.google.gwt.dom.client.Style.Unit.PX);
getElement().getStyle().setTextAlign(com.google.gwt.dom.client.Style.TextAlign.RIGHT);
if (timestamp != null) {
setTimestamp(timestamp);
@@ -81,7 +83,11 @@ public abstract class AttributesView<
}
public void setTimestamp(long timestamp) {
- setText(timestamp > 0 ? dateTimeFormat.format(new Date(timestamp)) : "");
+ clear();
+ if (timestamp > 0) {
+ add(new FormOutputText(dateFormat.format(new Date(timestamp))));
+ add(new FormOutputText(timeFormat.format(new Date(timestamp))));
+ }
}
}
@@ -188,7 +194,9 @@ public abstract class AttributesView<
}
protected FormLabel createAttributeLabel(AssetAttribute attribute) {
- return new FormLabel(TextUtil.ellipsize(getAttributeLabel(attribute), 100));
+ FormLabel formLabel = new FormLabel(TextUtil.ellipsize(getAttributeLabel(attribute), 100));
+ formLabel.addStyleName("larger");
+ return formLabel;
}
protected String getAttributeLabel(AssetAttribute attribute) {
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.java
index 7161ae3f3..ba6d5b3af 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
@@ -53,10 +53,10 @@ import static org.openremote.model.asset.agent.ProtocolConfiguration.initProtoco
public class ManagerDemoSetup extends AbstractManagerSetup {
- // Update these numbers whenever you change a RULE_STATE flag in test data
- public static final int DEMO_RULE_STATES_APARTMENT_1 = 8;
- public static final int DEMO_RULE_STATES_APARTMENT_2 = 4;
- public static final int DEMO_RULE_STATES_APARTMENT_3 = 2;
+ // Update these numbers whenever you change a RULE_STATE flag in test data
+ public static final int DEMO_RULE_STATES_APARTMENT_1 = 37;
+ public static final int DEMO_RULE_STATES_APARTMENT_2 = 3;
+ public static final int DEMO_RULE_STATES_APARTMENT_3 = 0;
public static final int DEMO_RULE_STATES_SMART_HOME = DEMO_RULE_STATES_APARTMENT_1 + DEMO_RULE_STATES_APARTMENT_2 + DEMO_RULE_STATES_APARTMENT_3;
public static final int DEMO_RULE_STATES_CUSTOMER_A = DEMO_RULE_STATES_SMART_HOME;
public static final int DEMO_RULE_STATES_GLOBAL = DEMO_RULE_STATES_CUSTOMER_A;
@@ -261,7 +261,8 @@ public class ManagerDemoSetup extends AbstractManagerSetup {
thing = assetStorageService.find(thingId, true);
ZonedDateTime now = LocalDateTime.now().atZone(ZoneId.systemDefault());
- AssetAttribute light1PowerConsumptionAttribute = thing.getAttribute("light1PowerConsumption").get();
+ AssetAttribute light1PowerConsumptionAttribute =
+ thing.getAttribute("light1PowerConsumption").orElseThrow(IllegalStateException::new);
assetDatapointService.accept(new AssetState(thing, light1PowerConsumptionAttribute));
@@ -350,39 +351,259 @@ public class ManagerDemoSetup extends AbstractManagerSetup {
apartment1.setLocation(geometryFactory.createPoint(new Coordinate(5.470945, 51.438000)));
apartment1.setType(RESIDENCE);
List<AssetAttribute> apartment1Attributes = Arrays.asList(
- new AssetAttribute("allLightsOffSwitch", AttributeType.BOOLEAN, Json.create(true))
+ new AssetAttribute("vacationDays", AttributeType.INTEGER, Json.createNull())
.setMeta(
new Meta().add(
- new MetaItem(AssetMeta.LABEL, Json.create("All Lights Off Switch"))
+ new MetaItem(AssetMeta.LABEL, Json.create("Vacation Days"))
).add(
- new MetaItem(AssetMeta.DESCRIPTION, Json.create("When triggered, turns all lights in the apartment off"))
+ new MetaItem(AssetMeta.DESCRIPTION, Json.create("Enable vacation mode for given days"))
).add(
- new MetaItem(AssetMeta.RULE_EVENT, Json.create(true))
+ new MetaItem(AssetMeta.RULE_STATE, Json.create(true))
+ )
+ ),
+ new AssetAttribute("automaticSceneSchedule", AttributeType.BOOLEAN, Json.create(false))
+ .setMeta(
+ new Meta().add(
+ new MetaItem(AssetMeta.LABEL, Json.create("Automatic scene schedule"))
).add(
- new MetaItem(AssetMeta.RULE_EVENT_EXPIRES, Json.create("10s"))
+ new MetaItem(AssetMeta.DESCRIPTION, Json.create("Predict presence and automatically adjust scene execution"))
+ ).add(
+ new MetaItem(AssetMeta.RULE_STATE, Json.create(true))
)
),
- new AssetAttribute("vacationDays", AttributeType.INTEGER, Json.createNull())
+ new AssetAttribute("lastExecutedScene", AttributeType.STRING, Json.create("HOME"))
.setMeta(
new Meta().add(
- new MetaItem(AssetMeta.LABEL, Json.create("Vacation Days"))
+ new MetaItem(AssetMeta.LABEL, Json.create("Last executed scene"))
).add(
- new MetaItem(AssetMeta.DESCRIPTION, Json.create("Enable vacation mode for given days"))
+ new MetaItem(AssetMeta.RULE_STATE, Json.create(true))
+ )
+ ),
+ new AssetAttribute("homeSceneMonday", AttributeType.STRING, Json.create("06:45:00"))
+ .setMeta(
+ new Meta().add(
+ new MetaItem(AssetMeta.LABEL, Json.create("Waking up on Monday"))
).add(
new MetaItem(AssetMeta.RULE_STATE, Json.create(true))
)
),
- new AssetAttribute( "lastScene", AttributeType.STRING, Json.create("NIGHT"))
+ new AssetAttribute("awaySceneMonday", AttributeType.STRING, Json.create("08:00:00"))
.setMeta(
new Meta().add(
- new MetaItem(AssetMeta.LABEL, Json.create("Current scene"))
+ new MetaItem(AssetMeta.LABEL, Json.create("Going to work on Monday"))
).add(
- new MetaItem(AssetMeta.DESCRIPTION, Json.create("The scene which is currently active"))
+ new MetaItem(AssetMeta.RULE_STATE, Json.create(true))
+ )
+ ),
+ new AssetAttribute("eveningSceneMonday", AttributeType.STRING, Json.create("17:30:00"))
+ .setMeta(
+ new Meta().add(
+ new MetaItem(AssetMeta.LABEL, Json.create("Back from work on Monday"))
+ ).add(
+ new MetaItem(AssetMeta.RULE_STATE, Json.create(true))
+ )
+ ),
+ new AssetAttribute("nightSceneMonday", AttributeType.STRING, Json.create("22:00:00"))
+ .setMeta(
+ new Meta().add(
+ new MetaItem(AssetMeta.LABEL, Json.create("Going to bed on Monday"))
+ ).add(
+ new MetaItem(AssetMeta.RULE_STATE, Json.create(true))
+ )
+ ),
+ new AssetAttribute("homeSceneTuesday", AttributeType.STRING, Json.create("06:45:00"))
+ .setMeta(
+ new Meta().add(
+ new MetaItem(AssetMeta.LABEL, Json.create("Waking up on Tuesday"))
+ ).add(
+ new MetaItem(AssetMeta.RULE_STATE, Json.create(true))
+ )
+ ),
+ new AssetAttribute("awaySceneTuesday", AttributeType.STRING, Json.create("08:00:00"))
+ .setMeta(
+ new Meta().add(
+ new MetaItem(AssetMeta.LABEL, Json.create("Going to work on Tuesday"))
+ ).add(
+ new MetaItem(AssetMeta.RULE_STATE, Json.create(true))
+ )
+ ),
+ new AssetAttribute("eveningSceneTuesday", AttributeType.STRING, Json.create("17:30:00"))
+ .setMeta(
+ new Meta().add(
+ new MetaItem(AssetMeta.LABEL, Json.create("Back from work on Tuesday"))
+ ).add(
+ new MetaItem(AssetMeta.RULE_STATE, Json.create(true))
+ )
+ ),
+ new AssetAttribute("nightSceneTuesday", AttributeType.STRING, Json.create("22:00:00"))
+ .setMeta(
+ new Meta().add(
+ new MetaItem(AssetMeta.LABEL, Json.create("Going to bed on Tuesday"))
+ ).add(
+ new MetaItem(AssetMeta.RULE_STATE, Json.create(true))
+ )
+ ),
+ new AssetAttribute("homeSceneWednesday", AttributeType.STRING, Json.create("06:45:00"))
+ .setMeta(
+ new Meta().add(
+ new MetaItem(AssetMeta.LABEL, Json.create("Waking up on Wednesday"))
+ ).add(
+ new MetaItem(AssetMeta.RULE_STATE, Json.create(true))
+ )
+ ),
+ new AssetAttribute("awaySceneWednesday", AttributeType.STRING, Json.create("08:00:00"))
+ .setMeta(
+ new Meta().add(
+ new MetaItem(AssetMeta.LABEL, Json.create("Going to work on Wednesday"))
+ ).add(
+ new MetaItem(AssetMeta.RULE_STATE, Json.create(true))
+ )
+ ),
+ new AssetAttribute("eveningSceneWednesday", AttributeType.STRING, Json.create("17:30:00"))
+ .setMeta(
+ new Meta().add(
+ new MetaItem(AssetMeta.LABEL, Json.create("Back from work on Wednesday"))
+ ).add(
+ new MetaItem(AssetMeta.RULE_STATE, Json.create(true))
+ )
+ ),
+ new AssetAttribute("nightSceneWednesday", AttributeType.STRING, Json.create("22:00:00"))
+ .setMeta(
+ new Meta().add(
+ new MetaItem(AssetMeta.LABEL, Json.create("Going to bed on Wednesday"))
+ ).add(
+ new MetaItem(AssetMeta.RULE_STATE, Json.create(true))
+ )
+ ),
+ new AssetAttribute("homeSceneThursday", AttributeType.STRING, Json.create("06:45:00"))
+ .setMeta(
+ new Meta().add(
+ new MetaItem(AssetMeta.LABEL, Json.create("Waking up on Thursday"))
+ ).add(
+ new MetaItem(AssetMeta.RULE_STATE, Json.create(true))
+ )
+ ),
+ new AssetAttribute("awaySceneThursday", AttributeType.STRING, Json.create("08:00:00"))
+ .setMeta(
+ new Meta().add(
+ new MetaItem(AssetMeta.LABEL, Json.create("Going to work on Thursday"))
+ ).add(
+ new MetaItem(AssetMeta.RULE_STATE, Json.create(true))
+ )
+ ),
+ new AssetAttribute("eveningSceneThursday", AttributeType.STRING, Json.create("17:30:00"))
+ .setMeta(
+ new Meta().add(
+ new MetaItem(AssetMeta.LABEL, Json.create("Back from work on Thursday"))
+ ).add(
+ new MetaItem(AssetMeta.RULE_STATE, Json.create(true))
+ )
+ ),
+ new AssetAttribute("nightSceneThursday", AttributeType.STRING, Json.create("22:00:00"))
+ .setMeta(
+ new Meta().add(
+ new MetaItem(AssetMeta.LABEL, Json.create("Going to bed on Thursday"))
+ ).add(
+ new MetaItem(AssetMeta.RULE_STATE, Json.create(true))
+ )
+ ),
+ new AssetAttribute("homeSceneFriday", AttributeType.STRING, Json.create("06:45:00"))
+ .setMeta(
+ new Meta().add(
+ new MetaItem(AssetMeta.LABEL, Json.create("Waking up on Friday"))
+ ).add(
+ new MetaItem(AssetMeta.RULE_STATE, Json.create(true))
+ )
+ ),
+ new AssetAttribute("awaySceneFriday", AttributeType.STRING, Json.create("08:00:00"))
+ .setMeta(
+ new Meta().add(
+ new MetaItem(AssetMeta.LABEL, Json.create("Going to work on Friday"))
+ ).add(
+ new MetaItem(AssetMeta.RULE_STATE, Json.create(true))
+ )
+ ),
+ new AssetAttribute("eveningSceneFriday", AttributeType.STRING, Json.create("16:00:00"))
+ .setMeta(
+ new Meta().add(
+ new MetaItem(AssetMeta.LABEL, Json.create("Back from work on Friday"))
+ ).add(
+ new MetaItem(AssetMeta.RULE_STATE, Json.create(true))
+ )
+ ),
+ new AssetAttribute("nightSceneFriday", AttributeType.STRING, Json.create("23:00:00"))
+ .setMeta(
+ new Meta().add(
+ new MetaItem(AssetMeta.LABEL, Json.create("Going to bed on Friday"))
+ ).add(
+ new MetaItem(AssetMeta.RULE_STATE, Json.create(true))
+ )
+ ),
+ new AssetAttribute("homeSceneSaturday", AttributeType.STRING, Json.create("07:30:00"))
+ .setMeta(
+ new Meta().add(
+ new MetaItem(AssetMeta.LABEL, Json.create("Waking up on Saturday"))
+ ).add(
+ new MetaItem(AssetMeta.RULE_STATE, Json.create(true))
+ )
+ ),
+ new AssetAttribute("awaySceneSaturday", AttributeType.STRING, Json.createNull())
+ .setMeta(
+ new Meta().add(
+ new MetaItem(AssetMeta.LABEL, Json.create("Going to work on Saturday"))
+ ).add(
+ new MetaItem(AssetMeta.RULE_STATE, Json.create(true))
+ )
+ ),
+ new AssetAttribute("eveningSceneSaturday", AttributeType.STRING, Json.create("18:00:00"))
+ .setMeta(
+ new Meta().add(
+ new MetaItem(AssetMeta.LABEL, Json.create("Back from work on Saturday"))
+ ).add(
+ new MetaItem(AssetMeta.RULE_STATE, Json.create(true))
+ )
+ ),
+ new AssetAttribute("nightSceneSaturday", AttributeType.STRING, Json.create("23:00:00"))
+ .setMeta(
+ new Meta().add(
+ new MetaItem(AssetMeta.LABEL, Json.create("Going to bed on Saturday"))
+ ).add(
+ new MetaItem(AssetMeta.RULE_STATE, Json.create(true))
+ )
+ ),
+ new AssetAttribute("homeSceneSunday", AttributeType.STRING, Json.create("08:00:00"))
+ .setMeta(
+ new Meta().add(
+ new MetaItem(AssetMeta.LABEL, Json.create("Waking up on Sunday"))
+ ).add(
+ new MetaItem(AssetMeta.RULE_STATE, Json.create(true))
+ )
+ ),
+ new AssetAttribute("awaySceneSunday", AttributeType.STRING, Json.createNull())
+ .setMeta(
+ new Meta().add(
+ new MetaItem(AssetMeta.LABEL, Json.create("Going to work on Sunday"))
+ ).add(
+ new MetaItem(AssetMeta.RULE_STATE, Json.create(true))
+ )
+ ),
+ new AssetAttribute("eveningSceneSunday", AttributeType.STRING, Json.create("18:00:00"))
+ .setMeta(
+ new Meta().add(
+ new MetaItem(AssetMeta.LABEL, Json.create("Back from work on Sunday"))
+ ).add(
+ new MetaItem(AssetMeta.RULE_STATE, Json.create(true))
+ )
+ ),
+ new AssetAttribute("nightSceneSunday", AttributeType.STRING, Json.create("22:00:00"))
+ .setMeta(
+ new Meta().add(
+ new MetaItem(AssetMeta.LABEL, Json.create("Going to bed on Sunday"))
).add(
new MetaItem(AssetMeta.RULE_STATE, Json.create(true))
)
)
- );
+ );
apartment1.setAttributeList(apartment1Attributes);
apartment1 = assetStorageService.merge(apartment1);
apartment1Id = apartment1.getId();
@@ -392,13 +613,13 @@ public class ManagerDemoSetup extends AbstractManagerSetup {
apartment1Livingroom.setLocation(geometryFactory.createPoint(new Coordinate(5.470945, 51.438000)));
apartment1Livingroom.setType(ROOM);
List<AssetAttribute> apartment1LivingroomAttributes = Arrays.asList(
- new AssetAttribute("motionSensor", AttributeType.BOOLEAN, Json.create(false))
+ new AssetAttribute("motionCounter", AttributeType.INTEGER, Json.create(0))
.setMeta(
new Meta().add(
- new MetaItem(AssetMeta.LABEL, Json.create("Motion Sensor"))
+ new MetaItem(AssetMeta.LABEL, Json.create("Motion Counter"))
).add(
new MetaItem(AssetMeta.DESCRIPTION, Json.create(
- "PIR sensor that sends 'true' when motion is sensed"
+ "Sensor that increments a counter when motion is sensed"
))
).add(
new MetaItem(AssetMeta.RULE_STATE, Json.create(true))
@@ -430,26 +651,12 @@ public class ManagerDemoSetup extends AbstractManagerSetup {
new MetaItem(AssetMeta.RULE_STATE, Json.create(true))
)
),
- new AssetAttribute("lightSwitch", AttributeType.BOOLEAN, Json.create(true))
- .setMeta(
- new Meta().add(
- new MetaItem(AssetMeta.LABEL, Json.create("Light Switch"))
- ).add(
- new MetaItem(AssetMeta.RULE_STATE, Json.create(true))
- )
- ),
- new AssetAttribute("windowOpen", AttributeType.BOOLEAN, Json.create(false))
- .setMeta(
- new Meta().add(
- new MetaItem(AssetMeta.LABEL, Json.create("Window Open"))
- )
- ),
new AssetAttribute("co2Level", AttributeType.DECIMAL, Json.create(450))
.setMeta(
new Meta().add(
new MetaItem(AssetMeta.LABEL, Json.create("CO2 Level"))
).add(
- new MetaItem(AssetMeta.RULE_STATE, Json.create(false))
+ new MetaItem(AssetMeta.RULE_STATE, Json.create(true))
)
)
);
@@ -521,14 +728,16 @@ public class ManagerDemoSetup extends AbstractManagerSetup {
apartment2.setLocation(geometryFactory.createPoint(new Coordinate(5.470945, 51.438000)));
apartment2.setType(RESIDENCE);
List<AssetAttribute> apartment2Attributes = Collections.singletonList(
- new AssetAttribute("allLightsOffSwitch", AttributeType.BOOLEAN, Json.create(false))
+ new AssetAttribute("allLightsOffSwitch", AttributeType.BOOLEAN, Json.create(true))
.setMeta(
new Meta().add(
new MetaItem(AssetMeta.LABEL, Json.create("All Lights Off Switch"))
).add(
new MetaItem(AssetMeta.DESCRIPTION, Json.create("When triggered, turns all lights in the apartment off"))
).add(
- new MetaItem(AssetMeta.RULE_STATE, Json.create(true))
+ new MetaItem(AssetMeta.RULE_EVENT, Json.create(true))
+ ).add(
+ new MetaItem(AssetMeta.RULE_EVENT_EXPIRES, Json.create("10s"))
)
)
);
@@ -541,13 +750,13 @@ public class ManagerDemoSetup extends AbstractManagerSetup {
apartment2Livingroom.setLocation(geometryFactory.createPoint(new Coordinate(5.470945, 51.438000)));
apartment2Livingroom.setType(ROOM);
List<AssetAttribute> apartment2LivingroomAttributes = Arrays.asList(
- new AssetAttribute("motionCounter", AttributeType.INTEGER, Json.create(0))
+ new AssetAttribute("motionSensor", AttributeType.BOOLEAN, Json.create(false))
.setMeta(
new Meta().add(
- new MetaItem(AssetMeta.LABEL, Json.create("Motion Counter"))
+ new MetaItem(AssetMeta.LABEL, Json.create("Motion Sensor"))
).add(
new MetaItem(AssetMeta.DESCRIPTION, Json.create(
- "Sensor that increments a counter when motion is sensed"
+ "PIR sensor that sends 'true' when motion is sensed"
))
).add(
new MetaItem(AssetMeta.RULE_STATE, Json.create(true))
@@ -602,19 +811,6 @@ public class ManagerDemoSetup extends AbstractManagerSetup {
apartment3.setName("Apartment 3");
apartment3.setLocation(geometryFactory.createPoint(new Coordinate(5.470945, 51.438000)));
apartment3.setType(RESIDENCE);
- List<AssetAttribute> apartment3Attributes = Collections.singletonList(
- new AssetAttribute("allLightsOffSwitch", AttributeType.BOOLEAN, Json.create(false))
- .setMeta(
- new Meta().add(
- new MetaItem(AssetMeta.LABEL, Json.create("All Lights Off Switch"))
- ).add(
- new MetaItem(AssetMeta.DESCRIPTION, Json.create("When triggered, turns all lights in the apartment off"))
- ).add(
- new MetaItem(AssetMeta.RULE_STATE, Json.create(true))
- )
- )
- );
- apartment3.setAttributeList(apartment3Attributes);
apartment3 = assetStorageService.merge(apartment3);
apartment3Id = apartment3.getId();
@@ -622,35 +818,6 @@ public class ManagerDemoSetup extends AbstractManagerSetup {
apartment3Livingroom.setName("Livingroom");
apartment3Livingroom.setLocation(geometryFactory.createPoint(new Coordinate(5.470945, 51.438000)));
apartment3Livingroom.setType(ROOM);
- List<AssetAttribute> apartment3LivingroomAttributes = Arrays.asList(
- new AssetAttribute("presenceDetected", AttributeType.BOOLEAN, Json.create(false))
- .setMeta(
- new Meta().add(
- new MetaItem(AssetMeta.LABEL, Json.create("Presence Detected"))
- ).add(
- new MetaItem(AssetMeta.DESCRIPTION, Json.create(
- "Someone is currently present in the room"
- ))
- ).add(
- new MetaItem(AssetMeta.RULE_STATE, Json.create(true))
- )
- ),
- new AssetAttribute("lightSwitch", AttributeType.BOOLEAN, Json.create(true))
- .setMeta(
- new Meta().add(
- new MetaItem(AssetMeta.LABEL, Json.create("Light Switch"))
- ).add(
- new MetaItem(AssetMeta.RULE_STATE, Json.create(false))
- )
- ),
- new AssetAttribute("windowOpen", AttributeType.BOOLEAN, Json.create(false))
- .setMeta(
- new Meta().add(
- new MetaItem(AssetMeta.LABEL, Json.create("Window Open"))
- )
- )
- );
- apartment3Livingroom.setAttributeList(apartment3LivingroomAttributes);
apartment3Livingroom = assetStorageService.merge(apartment3Livingroom);
apartment3LivingroomId = apartment3Livingroom.getId();
diff --git a/manager/server/src/main/java/org/openremote/manager/server/setup/builtin/RulesDemoSetup.java b/manager/server/src/main/java/org/openremote/manager/server/setup/builtin/RulesDemoSetup.java
index f700d09d5..8b95791d4 100644
--- a/manager/server/src/main/java/org/openremote/manager/server/setup/builtin/RulesDemoSetup.java
+++ b/manager/server/src/main/java/org/openremote/manager/server/setup/builtin/RulesDemoSetup.java
@@ -50,28 +50,30 @@ public class RulesDemoSetup extends AbstractManagerSetup {
// ################################ Rules demo data ###################################
- // See ApartmentActionsTest.groovy
- try (InputStream inputStream = RulesDemoSetup.class.getResourceAsStream("/demo/rules/DemoApartmentAllLightsOff.drl")) {
+ // Apartment 1
+ try (InputStream inputStream = RulesDemoSetup.class.getResourceAsStream("/demo/rules/DemoApartmentPresenceDetectionCounter.drl")) {
String rules = IOUtils.toString(inputStream, Charset.forName("utf-8"));
- Ruleset ruleset = new TenantRuleset("Demo Apartment - All Lights Off", keycloakDemoSetup.customerATenant.getId(), rules);
+ Ruleset ruleset = new AssetRuleset("Demo Apartment - Presence Detection with motion counter", managerDemoSetup.apartment1Id, rules);
apartmentActionsRulesetId = rulesetStorageService.merge(ruleset).getId();
}
try (InputStream inputStream = RulesDemoSetup.class.getResourceAsStream("/demo/rules/DemoApartmentVacationMode.drl")) {
String rules = IOUtils.toString(inputStream, Charset.forName("utf-8"));
- Ruleset ruleset = new TenantRuleset("Demo Apartment - Vacation Mode", keycloakDemoSetup.customerATenant.getId(), rules);
+ Ruleset ruleset = new AssetRuleset("Demo Apartment - Vacation Mode", managerDemoSetup.apartment1Id, rules);
apartmentActionsRulesetId = rulesetStorageService.merge(ruleset).getId();
}
- // See ApartmentPresenceDetectionTest.groovy, these are conflicting rules and therefore we need two different apartments
+ // Apartment 2
try (InputStream inputStream = RulesDemoSetup.class.getResourceAsStream("/demo/rules/DemoApartmentPresenceDetectionPIR.drl")) {
String rules = IOUtils.toString(inputStream, Charset.forName("utf-8"));
- Ruleset ruleset = new AssetRuleset("Demo Apartment - Presence Detection with motion PIR", managerDemoSetup.apartment1Id, rules);
+ Ruleset ruleset = new AssetRuleset("Demo Apartment - Presence Detection with motion PIR", managerDemoSetup.apartment2Id, rules);
apartmentActionsRulesetId = rulesetStorageService.merge(ruleset).getId();
}
- try (InputStream inputStream = RulesDemoSetup.class.getResourceAsStream("/demo/rules/DemoApartmentPresenceDetectionCounter.drl")) {
+ try (InputStream inputStream = RulesDemoSetup.class.getResourceAsStream("/demo/rules/DemoApartmentAllLightsOff.drl")) {
String rules = IOUtils.toString(inputStream, Charset.forName("utf-8"));
- Ruleset ruleset = new AssetRuleset("Demo Apartment - Presence Detection with motion counter", managerDemoSetup.apartment2Id, rules);
+ Ruleset ruleset = new AssetRuleset("Demo Apartment - All Lights Off", managerDemoSetup.apartment2Id, rules);
apartmentActionsRulesetId = rulesetStorageService.merge(ruleset).getId();
}
+
+
}
}
diff --git a/manager/server/src/main/resources/demo/rules/DemoApartmentVacationMode.drl b/manager/server/src/main/resources/demo/rules/DemoApartmentVacationMode.drl
index e1d941278..b8072c7f6 100644
--- a/manager/server/src/main/resources/demo/rules/DemoApartmentVacationMode.drl
+++ b/manager/server/src/main/resources/demo/rules/DemoApartmentVacationMode.drl
@@ -16,21 +16,4 @@ when
then
// Decrement the vacation days by one
assets.dispatch( new AttributeEvent($ref, Json.create($val- 1)) );
-end
-
-rule "Set state to AWAY when on holidays"
-when
- $a: AssetState(attributeName == "vacationDays", value.asNumber() > 0 )
- AssetState(attributeName == "lastScene", $ref: attributeRef, value.asString() != "AWAY")
-then
- assets.dispatch( new AttributeEvent($ref, Json.create("AWAY")) );
-end
-
-rule "Set state to HOME when not on holidays"
-timer(int: 7h) // At morning
-when
- $a: AssetState(attributeName == "vacationDays", value.asNumber() == 0 )
- AssetState(attributeName == "lastScene", $ref: attributeRef, value.asString() != "HOME")
-then
- assets.dispatch( new AttributeEvent($ref, Json.create("HOME")) );
end
\ No newline at end of file
diff --git a/manager/test/src/test/groovy/org/openremote/test/assets/AssetProcessingTest.groovy b/manager/test/src/test/groovy/org/openremote/test/assets/AssetProcessingTest.groovy
index 8aa3376bf..607f297e1 100644
--- a/manager/test/src/test/groovy/org/openremote/test/assets/AssetProcessingTest.groovy
+++ b/manager/test/src/test/groovy/org/openremote/test/assets/AssetProcessingTest.groovy
@@ -94,22 +94,7 @@ class AssetProcessingTest extends Specification implements ManagerContainerTrait
assetProcessingService.processors.add(0, mockStartConsumer)
assetProcessingService.processors.add(mockEndConsumer)
- // The conditions here depend on how we handle the initial insert of facts into the rule engines
- expect: "the demo rule engine should start and trigger the 'Switch room lights off when apartment ALL LIGHTS OFF switch is off' rule and cause attribute events to go through the system"
- conditions.eventually {
- def customerAEngine = rulesService.tenantDeployments.get(keycloakDemoSetup.customerATenant.id)
- assert customerAEngine != null
- assert customerAEngine.isRunning()
- assert customerAEngine.rulesets.size() == 2
- assert updatesPassedStartOfProcessingChain.size() == 0
- assert updatesReachedEndOfProcessingChain.size() == 0
- }
-
- when: "the processing chain counters are reset"
- updatesPassedStartOfProcessingChain.clear()
- updatesReachedEndOfProcessingChain.clear()
-
- and: "a mock agent that uses the mock protocol is created"
+ when: "a mock agent that uses the mock protocol is created"
def mockAgent = new ServerAsset()
mockAgent.setName("Mock Agent")
mockAgent.setType(AssetType.AGENT)
diff --git a/manager/test/src/test/groovy/org/openremote/test/rules/ApartmentActionsTest.groovy b/manager/test/src/test/groovy/org/openremote/test/rules/ApartmentActionsTest.groovy
deleted file mode 100644
index e3341ccd5..000000000
--- a/manager/test/src/test/groovy/org/openremote/test/rules/ApartmentActionsTest.groovy
+++ /dev/null
@@ -1,162 +0,0 @@
-package org.openremote.test.rules
-
-import elemental.json.Json
-import org.openremote.manager.server.asset.AssetProcessingService
-import org.openremote.manager.server.asset.AssetStorageService
-import org.openremote.manager.server.rules.RulesEngine
-import org.openremote.manager.server.rules.RulesService
-import org.openremote.manager.server.setup.SetupService
-import org.openremote.manager.server.setup.builtin.KeycloakDemoSetup
-import org.openremote.manager.server.setup.builtin.ManagerDemoSetup
-import org.openremote.model.AttributeEvent
-import org.openremote.test.ManagerContainerTrait
-import spock.lang.Specification
-import spock.util.concurrent.PollingConditions
-
-import static java.util.concurrent.TimeUnit.*
-import static org.openremote.manager.server.setup.builtin.ManagerDemoSetup.DEMO_RULE_STATES_CUSTOMER_A
-
-class ApartmentActionsTest extends Specification implements ManagerContainerTrait {
-
- def "All Lights Off"() {
-
- given: "the container environment is started"
- def conditions = new PollingConditions(timeout: 10, delay: 1)
- def serverPort = findEphemeralPort()
- def container = startContainerWithPseudoClock(defaultConfig(serverPort), 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 assetProcessingService = container.getService(AssetProcessingService.class)
- def assetStorageService = container.getService(AssetStorageService.class)
- RulesEngine customerAEngine
-
- expect: "the rule engines to become available and be running"
- conditions.eventually {
- customerAEngine = rulesService.tenantDeployments.get(keycloakDemoSetup.customerATenant.id)
- assert customerAEngine != null
- assert customerAEngine.isRunning()
- }
-
- and: "the demo attributes marked with RULE_STATE = true meta should be inserted into the engines"
- conditions.eventually {
- assert rulesService.assetStates.size() == DEMO_RULE_STATES_CUSTOMER_A
- assert customerAEngine.assetStates.size() == DEMO_RULE_STATES_CUSTOMER_A
- assert customerAEngine.knowledgeSession.factCount == DEMO_RULE_STATES_CUSTOMER_A
- }
-
- and: "the room lights in an apartment to be on"
- def livingRoomAsset = assetStorageService.find(managerDemoSetup.apartment1LivingroomId, true)
- assert livingRoomAsset.getAttribute("lightSwitch").get().valueAsBoolean
-
- when: "the ALL LIGHTS OFF push-button is pressed for an apartment"
- setPseudoClocksToRealTime(container, customerAEngine)
- def apartment1AllLightsOffChange = new AttributeEvent(
- managerDemoSetup.apartment1Id, "allLightsOffSwitch", Json.create(true), getClockTimeOf(container)
- )
- assetProcessingService.sendAttributeEvent(apartment1AllLightsOffChange)
-
- then: "the room lights in the apartment should be off"
- conditions.eventually {
- assert customerAEngine.knowledgeSession.factCount == DEMO_RULE_STATES_CUSTOMER_A + 1
- livingRoomAsset = assetStorageService.find(managerDemoSetup.apartment1LivingroomId, true)
- assert !livingRoomAsset.getAttribute("lightSwitch").get().valueAsBoolean
- }
-
- when: "time advanced"
- advancePseudoClocks(15, SECONDS, container, customerAEngine)
-
- then: "event expired"
- conditions.eventually {
- assert customerAEngine.knowledgeSession.factCount == DEMO_RULE_STATES_CUSTOMER_A
- }
-
- cleanup: "stop the container"
- stopContainer(container)
- }
-
- def "Vacation Mode"() {
-
- given: "the container environment is started"
- def conditions = new PollingConditions(timeout: 15, delay: 1)
- def serverPort = findEphemeralPort()
- def container = startContainerWithPseudoClock(defaultConfig(serverPort), 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 assetProcessingService = container.getService(AssetProcessingService.class)
- def assetStorageService = container.getService(AssetStorageService.class)
- RulesEngine customerAEngine
-
- expect: "the rule engines to become available and be running"
- conditions.eventually {
- customerAEngine = rulesService.tenantDeployments.get(keycloakDemoSetup.customerATenant.id)
- assert customerAEngine != null
- assert customerAEngine.isRunning()
- }
-
- and: "the demo attributes marked with RULE_STATE = true meta should be inserted into the engines"
- conditions.eventually {
- assert rulesService.assetStates.size() == DEMO_RULE_STATES_CUSTOMER_A
- assert customerAEngine.assetStates.size() == DEMO_RULE_STATES_CUSTOMER_A
- assert customerAEngine.knowledgeSession.factCount == DEMO_RULE_STATES_CUSTOMER_A
- }
-
- when: "the vacation days are set to 5"
- setPseudoClocksToRealTime(container, customerAEngine)
- assetProcessingService.sendAttributeEvent(new AttributeEvent(
- managerDemoSetup.apartment1Id, "vacationDays", Json.create(5), getClockTimeOf(container)
- ))
-
- then: "that value should be stored"
- conditions.eventually {
- def asset = assetStorageService.find(managerDemoSetup.apartment1Id, true)
- assert asset.getAttribute("vacationDays").get().valueAsInteger == 5
- assert asset.getAttribute("lastScene").get().valueAsString == "AWAY"
- }
-
- when: "time advanced to the next day, which should trigger the cron rule"
- advancePseudoClocks(24, HOURS, container, customerAEngine)
-
- then: "the vacation days should be decremented"
- conditions.eventually {
- def asset = assetStorageService.find(managerDemoSetup.apartment1Id, true)
- assert asset.getAttribute("vacationDays").get().valueAsInteger == 4
- assert asset.getAttribute("lastScene").get().valueAsString == "AWAY"
- }
-
- when: "time advanced again (to test that the rule only fires once per day)"
- advancePseudoClocks(10, SECONDS, container, customerAEngine)
-
- then: "the vacation days should NOT be decremented"
- new PollingConditions(initialDelay: 2).eventually {
- def asset = assetStorageService.find(managerDemoSetup.apartment1Id, true)
- assert asset.getAttribute("vacationDays").get().valueAsInteger == 4
- assert asset.getAttribute("lastScene").get().valueAsString == "AWAY"
- }
-
- expect: "the remaining vacation days to be decremented with each passing day"
- int remainingDays = 4
- while (remainingDays > 0) {
-
- remainingDays--
-
- advancePseudoClocks(1, DAYS, container, customerAEngine)
- conditions.eventually {
- def asset = assetStorageService.find(managerDemoSetup.apartment1Id, true)
- assert asset.getAttribute("vacationDays").get().valueAsInteger == remainingDays
- assert asset.getAttribute("lastScene").get().valueAsString == "AWAY"
- }
- }
-
- and: "after some more time to switch to HOME status"
- advancePseudoClocks(8, HOURS, container, customerAEngine)
- conditions.eventually {
- def asset = assetStorageService.find(managerDemoSetup.apartment1Id, true)
- assert asset.getAttribute("lastScene").get().valueAsString == "HOME"
- }
-
- cleanup: "the server should be stopped"
- stopContainer(container)
- }
-}
diff --git a/manager/test/src/test/groovy/org/openremote/test/rules/BasicRulesDeploymentTest.groovy b/manager/test/src/test/groovy/org/openremote/test/rules/BasicRulesDeploymentTest.groovy
index 88f339e37..baf324367 100644
--- a/manager/test/src/test/groovy/org/openremote/test/rules/BasicRulesDeploymentTest.groovy
+++ b/manager/test/src/test/groovy/org/openremote/test/rules/BasicRulesDeploymentTest.groovy
@@ -151,15 +151,15 @@ class BasicRulesDeploymentTest extends Specification implements ManagerContainer
assert customerBEngine.allRulesets[0].deploymentStatus == DeploymentStatus.DEPLOYED
}
- when: "the asset rule definition for apartment 1 is deleted"
- rulesetStorageService.delete(AssetRuleset.class, rulesImport.apartment1RulesetId)
+ when: "the asset rule definition for apartment 2 is deleted"
+ rulesetStorageService.delete(AssetRuleset.class, rulesImport.apartment2RulesetId)
then: "the apartment rules engine should be removed"
conditions.eventually {
assert rulesService.assetDeployments.size() == 1
- def apartment1Engine = rulesService.assetDeployments.get(managerDemoSetup.apartment1Id)
+ def apartment2Engine = rulesService.assetDeployments.get(managerDemoSetup.apartment2Id)
def apartment3Engine = rulesService.assetDeployments.get(managerDemoSetup.apartment3Id)
- assert apartment1Engine == null
+ assert apartment2Engine == null
assert apartment3Engine != null
assert apartment3Engine.isRunning()
}
diff --git a/manager/test/src/test/groovy/org/openremote/test/rules/BasicRulesImport.groovy b/manager/test/src/test/groovy/org/openremote/test/rules/BasicRulesImport.groovy
index 191659610..1f98b3298 100644
--- a/manager/test/src/test/groovy/org/openremote/test/rules/BasicRulesImport.groovy
+++ b/manager/test/src/test/groovy/org/openremote/test/rules/BasicRulesImport.groovy
@@ -13,13 +13,20 @@ import org.openremote.manager.shared.rules.TenantRuleset
class BasicRulesImport {
- Long customerBRulesetId
- Long apartment1RulesetId
+ final Long globalRulesetId
+ final Long globalRuleset2Id
+ final Long masterRulesetId
+ final Long customerARulesetId
+ final Long customerBRulesetId
+ final Long apartment1RulesetId
+ final Long apartment2RulesetId
+ final Long apartment3RulesetId
RulesEngine globalEngine
RulesEngine masterEngine
RulesEngine customerAEngine
RulesEngine apartment1Engine
+ RulesEngine apartment2Engine
RulesEngine apartment3Engine
BasicRulesImport(RulesetStorageService rulesetStorageService,
@@ -30,28 +37,28 @@ class BasicRulesImport {
"Some global demo rules",
getClass().getResource("/org/openremote/test/rules/BasicMatchAllAssetStates.drl").text
)
- rulesetStorageService.merge(ruleset)
+ globalRulesetId = rulesetStorageService.merge(ruleset).id
ruleset = new GlobalRuleset(
"Other global demo rules with a long name that should fill up space in UI",
getClass().getResource("/org/openremote/test/rules/BasicMatchAllAssetStates.drl").text
)
ruleset.setEnabled(false)
- rulesetStorageService.merge(ruleset)
+ globalRuleset2Id = rulesetStorageService.merge(ruleset).id
ruleset = new TenantRuleset(
"Some master tenant demo rules",
keycloakDemoSetup.masterTenant.id,
getClass().getResource("/org/openremote/test/rules/BasicMatchAllAssetStates.drl").text
)
- rulesetStorageService.merge(ruleset)
+ masterRulesetId = rulesetStorageService.merge(ruleset).id
ruleset = new TenantRuleset(
"Some customerA tenant demo rules",
keycloakDemoSetup.customerATenant.id,
getClass().getResource("/org/openremote/test/rules/BasicMatchAllAssetStates.drl").text
)
- rulesetStorageService.merge(ruleset)
+ customerARulesetId = rulesetStorageService.merge(ruleset).id
ruleset = new TenantRuleset(
"Some customerB tenant demo rules",
@@ -66,6 +73,7 @@ class BasicRulesImport {
managerDemoSetup.apartment1Id,
getClass().getResource("/org/openremote/test/rules/BasicMatchAllAssetStates.drl").text
)
+ ruleset.setEnabled(false)
apartment1RulesetId = rulesetStorageService.merge(ruleset).id
ruleset = new AssetRuleset(
@@ -73,15 +81,14 @@ class BasicRulesImport {
managerDemoSetup.apartment2Id,
getClass().getResource("/org/openremote/test/rules/BasicMatchAllAssetStates.drl").text
)
- ruleset.setEnabled(false)
- rulesetStorageService.merge(ruleset)
+ apartment2RulesetId = rulesetStorageService.merge(ruleset).id
ruleset = new AssetRuleset(
"Some apartment 3 demo rules",
managerDemoSetup.apartment3Id,
getClass().getResource("/org/openremote/test/rules/BasicMatchAllAssetStates.drl").text
)
- rulesetStorageService.merge(ruleset)
+ apartment3RulesetId = rulesetStorageService.merge(ruleset).id
}
boolean assertEnginesReady(RulesService rulesService,
@@ -115,13 +122,15 @@ class BasicRulesImport {
assert rulesService.assetDeployments.size() == 2
apartment1Engine = rulesService.assetDeployments.get(managerDemoSetup.apartment1Id)
+ apartment2Engine = rulesService.assetDeployments.get(managerDemoSetup.apartment2Id)
apartment3Engine = rulesService.assetDeployments.get(managerDemoSetup.apartment3Id)
- assert apartment1Engine != null
- assert apartment1Engine.isRunning()
- assert apartment1Engine.allRulesets.length == 1
- assert apartment1Engine.allRulesets[0].enabled
- assert apartment1Engine.allRulesets[0].name == "Some apartment 1 demo rules"
- assert apartment1Engine.allRulesets[0].deploymentStatus == DeploymentStatus.DEPLOYED
+ assert apartment1Engine == null
+ assert apartment2Engine != null
+ assert apartment2Engine.isRunning()
+ assert apartment2Engine.allRulesets.length == 1
+ assert apartment2Engine.allRulesets[0].enabled
+ assert apartment2Engine.allRulesets[0].name == "Some apartment 2 demo rules"
+ assert apartment2Engine.allRulesets[0].deploymentStatus == DeploymentStatus.DEPLOYED
assert apartment3Engine != null
assert apartment3Engine.isRunning()
assert apartment3Engine.allRulesets.length == 1
diff --git a/manager/test/src/test/groovy/org/openremote/test/rules/BasicRulesProcessingTest.groovy b/manager/test/src/test/groovy/org/openremote/test/rules/BasicRulesProcessingTest.groovy
index fb85bfacf..f1488f5f9 100644
--- a/manager/test/src/test/groovy/org/openremote/test/rules/BasicRulesProcessingTest.groovy
+++ b/manager/test/src/test/groovy/org/openremote/test/rules/BasicRulesProcessingTest.groovy
@@ -33,7 +33,6 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
List<String> masterEngineFiredRules = []
List<String> customerAEngineFiredRules = []
List<String> smartHomeEngineFiredRules = []
- List<String> apartment1EngineFiredRules = []
List<String> apartment2EngineFiredRules = []
List<String> apartment3EngineFiredRules = []
@@ -41,7 +40,6 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
globalEngineFiredRules.clear()
customerAEngineFiredRules.clear()
smartHomeEngineFiredRules.clear()
- apartment1EngineFiredRules.clear()
apartment2EngineFiredRules.clear()
apartment3EngineFiredRules.clear()
}
@@ -51,14 +49,13 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
assert masterEngineFiredRules.size() == 0
assert customerAEngineFiredRules.size() == 0
assert smartHomeEngineFiredRules.size() == 0
- assert apartment1EngineFiredRules.size() == 0
assert apartment2EngineFiredRules.size() == 0
assert apartment3EngineFiredRules.size() == 0
}
- def "Check firing of rules"() {
+ def "Check scoped firing of rules"() {
given: "expected conditions"
- def conditions = new PollingConditions(timeout: 10, delay: 0.5)
+ def conditions = new PollingConditions(timeout: 10, initialDelay: 0.5, delay: 0.5)
and: "the container is started"
def serverPort = findEphemeralPort()
@@ -68,7 +65,6 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
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)
@@ -84,7 +80,7 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
assert rulesImport.globalEngine.assetStates.size() == DEMO_RULE_STATES_GLOBAL
assert rulesImport.masterEngine.assetStates.size() == 0
assert rulesImport.customerAEngine.assetStates.size() == DEMO_RULE_STATES_CUSTOMER_A
- assert rulesImport.apartment1Engine.assetStates.size() == DEMO_RULE_STATES_APARTMENT_1
+ assert rulesImport.apartment2Engine.assetStates.size() == DEMO_RULE_STATES_APARTMENT_2
assert rulesImport.apartment3Engine.assetStates.size() == DEMO_RULE_STATES_APARTMENT_3
}
@@ -92,14 +88,14 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
attachRuleExecutionLogger(rulesImport.globalEngine, globalEngineFiredRules)
attachRuleExecutionLogger(rulesImport.masterEngine, masterEngineFiredRules)
attachRuleExecutionLogger(rulesImport.customerAEngine, customerAEngineFiredRules)
- attachRuleExecutionLogger(rulesImport.apartment1Engine, apartment1EngineFiredRules)
+ attachRuleExecutionLogger(rulesImport.apartment2Engine, apartment2EngineFiredRules)
attachRuleExecutionLogger(rulesImport.apartment3Engine, apartment3EngineFiredRules)
and: "an attribute event is pushed into the system for an attribute with RULE_STATE meta set to true"
- def apartment1LivingRoomPresenceDetectedChange = new AttributeEvent(
- managerDemoSetup.apartment1LivingroomId, "presenceDetected", Json.create(true)
+ def apartment2LivingRoomPresenceDetectedChange = new AttributeEvent(
+ managerDemoSetup.apartment2LivingroomId, "presenceDetected", Json.create(true)
)
- assetProcessingService.sendAttributeEvent(apartment1LivingRoomPresenceDetectedChange)
+ assetProcessingService.sendAttributeEvent(apartment2LivingRoomPresenceDetectedChange)
then: "the rule engines in scope should fire the 'All' and 'All changed' rules"
conditions.eventually {
@@ -110,44 +106,44 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
assert customerAEngineFiredRules.size() == 2
assert customerAEngineFiredRules.containsAll(expectedFiredRules)
assert smartHomeEngineFiredRules.size() == 0
- assert apartment1EngineFiredRules.size() == 2
- assert apartment1EngineFiredRules.containsAll(expectedFiredRules)
+ assert apartment2EngineFiredRules.size() == 2
+ assert apartment2EngineFiredRules.containsAll(expectedFiredRules)
assert apartment3EngineFiredRules.size() == 0
}
when: "an attribute event is pushed into the system for an attribute with RULE_STATE meta set to false"
resetRuleExecutionLoggers()
- def apartment1LivingRoomCO2Change = new AttributeEvent(
- managerDemoSetup.apartment1LivingroomId, "co2Level", Json.create(500)
+ def apartment2LivingroomLightSwitchChange = new AttributeEvent(
+ managerDemoSetup.apartment2LivingroomId, "lightSwitch", Json.create(false)
)
- assetProcessingService.sendAttributeEvent(apartment1LivingRoomCO2Change)
+ assetProcessingService.sendAttributeEvent(apartment2LivingroomLightSwitchChange)
then: "no rule engines should have fired after a few seconds"
new PollingConditions(initialDelay: 3).eventually assertNoRulesFired
when: "an attribute event is pushed into the system for an attribute with no RULE_STATE meta"
resetRuleExecutionLoggers()
- def apartment1LivingRoomWindowOpenChange = new AttributeEvent(
- managerDemoSetup.apartment1LivingroomId, "windowOpen", Json.create(true)
+ def apartment2LivingRoomWindowOpenChange = new AttributeEvent(
+ managerDemoSetup.apartment2LivingroomId, "windowOpen", Json.create(true)
)
- assetProcessingService.sendAttributeEvent(apartment1LivingRoomWindowOpenChange)
+ assetProcessingService.sendAttributeEvent(apartment2LivingRoomWindowOpenChange)
then: "no rule engines should have fired after a few seconds"
new PollingConditions(initialDelay: 3).eventually assertNoRulesFired
when: "an old (stale) attribute event is pushed into the system"
resetRuleExecutionLoggers()
- assetProcessingService.sendAttributeEvent(apartment1LivingRoomPresenceDetectedChange)
+ assetProcessingService.sendAttributeEvent(apartment2LivingRoomPresenceDetectedChange)
then: "no rule engines should have fired after a few seconds"
new PollingConditions(initialDelay: 3).eventually assertNoRulesFired
when: "an attribute event with the same value as current value is pushed into the system"
resetRuleExecutionLoggers()
- apartment1LivingRoomPresenceDetectedChange = new AttributeEvent(
- managerDemoSetup.apartment1LivingroomId, "presenceDetected", Json.create(true)
+ apartment2LivingRoomPresenceDetectedChange = new AttributeEvent(
+ managerDemoSetup.apartment2LivingroomId, "presenceDetected", Json.create(true)
)
- assetProcessingService.sendAttributeEvent(apartment1LivingRoomPresenceDetectedChange)
+ assetProcessingService.sendAttributeEvent(apartment2LivingRoomPresenceDetectedChange)
then: "the rule engines in scope should fire the 'All' rule but not the 'All changed' rule"
conditions.eventually {
@@ -157,8 +153,8 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
assert customerAEngineFiredRules.size() == 1
assert customerAEngineFiredRules[0] == "All"
assert smartHomeEngineFiredRules.size() == 0
- assert apartment1EngineFiredRules.size() == 1
- assert apartment1EngineFiredRules[0] == "All"
+ assert apartment2EngineFiredRules.size() == 1
+ assert apartment2EngineFiredRules[0] == "All"
assert apartment3EngineFiredRules.size() == 0
}
@@ -177,22 +173,23 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
smartHomeEngine = rulesService.assetDeployments.get(managerDemoSetup.smartHomeId)
assert smartHomeEngine != null
assert smartHomeEngine.isRunning()
- assert smartHomeEngine.assetStates.size() == DEMO_RULE_STATES_SMART_HOME
assert smartHomeEngine.allRulesets.length == 1
assert smartHomeEngine.allRulesets[0].enabled
assert smartHomeEngine.allRulesets[0].name == "Some smart home asset rules"
assert smartHomeEngine.allRulesets[0].deploymentStatus == DeploymentStatus.DEPLOYED
+ assert smartHomeEngine.assetStates.size() == DEMO_RULE_STATES_SMART_HOME
+ assert smartHomeEngine.knowledgeSession.factCount == DEMO_RULE_STATES_SMART_HOME
}
when: "the engine counters are reset and the smart home engine logger is attached"
resetRuleExecutionLoggers()
attachRuleExecutionLogger(smartHomeEngine, smartHomeEngineFiredRules)
- and: "an apartment 3 living room attribute event occurs"
- def apartment3LivingRoomPresenceDetectedChange = new AttributeEvent(
- managerDemoSetup.apartment3LivingroomId, "presenceDetected", Json.create(true)
+ and: "an attribute event occurs"
+ apartment2LivingRoomPresenceDetectedChange = new AttributeEvent(
+ managerDemoSetup.apartment2LivingroomId, "presenceDetected", Json.create(false)
)
- assetProcessingService.sendAttributeEvent(apartment3LivingRoomPresenceDetectedChange)
+ assetProcessingService.sendAttributeEvent(apartment2LivingRoomPresenceDetectedChange)
then: "the engines in scope should have fired the matched rules"
conditions.eventually {
@@ -202,35 +199,8 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
assert customerAEngineFiredRules.containsAll(["All", "All changed"])
assert smartHomeEngineFiredRules.size() == 5
assert smartHomeEngineFiredRules.containsAll(["Living Room All", "Current Asset Update", "Parent Type Residence", "Asset Type Room", "Boolean Attributes"])
- assert apartment3EngineFiredRules.size() == 2
- assert apartment3EngineFiredRules.containsAll(["All", "All changed"])
- assert apartment1EngineFiredRules.size() == 0
- }
-
- when: "an apartment 1 living room thermostat attribute event occurs"
- resetRuleExecutionLoggers()
- def apartment1LivingRoomComfortTemperatureChange = new AttributeEvent(
- managerDemoSetup.apartment1LivingroomThermostatId, "comfortTemperature", Json.create(22.5)
- )
- assetProcessingService.sendAttributeEvent(apartment1LivingRoomComfortTemperatureChange)
-
- then: "the engines in scope should have fired the matched rules"
- conditions.eventually {
- assert globalEngineFiredRules.size() == 2
- assert globalEngineFiredRules.containsAll(["All", "All changed"])
- assert customerAEngineFiredRules.size() == 2
- assert customerAEngineFiredRules.containsAll(["All", "All changed"])
- assert smartHomeEngineFiredRules.size() == 5
- assert smartHomeEngineFiredRules.containsAll(
- [
- "Living Room Thermostat",
- "Living Room Comfort Temperature",
- "Living Room as Parent",
- "JSON Number value types",
- "Current Asset Update"
- ])
- assert apartment1EngineFiredRules.size() == 2
- assert apartment1EngineFiredRules.containsAll(["All", "All changed"])
+ assert apartment2EngineFiredRules.size() == 2
+ assert apartment2EngineFiredRules.containsAll(["All", "All changed"])
assert apartment3EngineFiredRules.size() == 0
}
@@ -240,7 +210,7 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
def "Handle asset create, update, delete"() {
given: "expected conditions"
- def conditions = new PollingConditions(timeout: 10, delay: 0.5)
+ def conditions = new PollingConditions(timeout: 10, initialDelay: 0.5, delay: 0.5)
and: "the container is started"
def serverPort = findEphemeralPort()
@@ -249,7 +219,6 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
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"
@@ -264,13 +233,13 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
attachRuleExecutionLogger(rulesImport.globalEngine, globalEngineFiredRules)
attachRuleExecutionLogger(rulesImport.masterEngine, masterEngineFiredRules)
attachRuleExecutionLogger(rulesImport.customerAEngine, customerAEngineFiredRules)
- attachRuleExecutionLogger(rulesImport.apartment1Engine, apartment1EngineFiredRules)
+ attachRuleExecutionLogger(rulesImport.apartment2Engine, apartment2EngineFiredRules)
attachRuleExecutionLogger(rulesImport.apartment3Engine, apartment3EngineFiredRules)
- and: "a Kitchen room asset is inserted into apartment 1 that contains a RULE_STATE = true meta flag"
+ and: "a Kitchen room asset is inserted into apartment that contains a RULE_STATE = true meta flag"
resetRuleExecutionLoggers()
- def apartment1 = assetStorageService.find(managerDemoSetup.apartment1Id)
- def asset = new ServerAsset(apartment1)
+ def apartment2 = assetStorageService.find(managerDemoSetup.apartment2Id)
+ def asset = new ServerAsset(apartment2)
asset.setRealmId(keycloakDemoSetup.customerATenant.getId())
asset.setType(AssetType.ROOM)
asset.setName("Kitchen")
@@ -289,7 +258,7 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
assert rulesImport.globalEngine.assetStates.size() == DEMO_RULE_STATES_GLOBAL + 1
assert rulesImport.masterEngine.assetStates.size() == 0
assert rulesImport.customerAEngine.assetStates.size() == DEMO_RULE_STATES_CUSTOMER_A + 1
- assert rulesImport.apartment1Engine.assetStates.size() == DEMO_RULE_STATES_APARTMENT_1 + 1
+ assert rulesImport.apartment2Engine.assetStates.size() == DEMO_RULE_STATES_APARTMENT_2 + 1
assert rulesImport.apartment3Engine.assetStates.size() == DEMO_RULE_STATES_APARTMENT_3
def expectedFiredRules = ["All", "All changed"]
assert globalEngineFiredRules.size() == 2
@@ -298,8 +267,8 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
assert customerAEngineFiredRules.size() == 2
assert customerAEngineFiredRules.containsAll(expectedFiredRules)
assert smartHomeEngineFiredRules.size() == 0
- assert apartment1EngineFiredRules.size() == 2
- assert apartment1EngineFiredRules.containsAll(expectedFiredRules)
+ assert apartment2EngineFiredRules.size() == 2
+ assert apartment2EngineFiredRules.containsAll(expectedFiredRules)
assert apartment3EngineFiredRules.size() == 0
}
@@ -322,12 +291,12 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
assert rulesImport.globalEngine.assetStates.size() == DEMO_RULE_STATES_GLOBAL + 1
assert rulesImport.masterEngine.assetStates.size() == 0
assert rulesImport.customerAEngine.assetStates.size() == DEMO_RULE_STATES_CUSTOMER_A + 1
- assert rulesImport.apartment1Engine.assetStates.size() == DEMO_RULE_STATES_APARTMENT_1 + 1
+ assert rulesImport.apartment2Engine.assetStates.size() == DEMO_RULE_STATES_APARTMENT_2 + 1
assert rulesImport.apartment3Engine.assetStates.size() == DEMO_RULE_STATES_APARTMENT_3
assert globalEngineFiredRules.size() == 0
assert customerAEngineFiredRules.size() == 0
assert smartHomeEngineFiredRules.size() == 0
- assert apartment1EngineFiredRules.size() == 0
+ assert apartment2EngineFiredRules.size() == 0
assert apartment3EngineFiredRules.size() == 0
}
@@ -349,12 +318,12 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
assert rulesImport.globalEngine.assetStates.size() == DEMO_RULE_STATES_GLOBAL
assert rulesImport.masterEngine.assetStates.size() == 0
assert rulesImport.customerAEngine.assetStates.size() == DEMO_RULE_STATES_CUSTOMER_A
- assert rulesImport.apartment1Engine.assetStates.size() == DEMO_RULE_STATES_APARTMENT_1
+ assert rulesImport.apartment2Engine.assetStates.size() == DEMO_RULE_STATES_APARTMENT_2
assert rulesImport.apartment3Engine.assetStates.size() == DEMO_RULE_STATES_APARTMENT_3
assert globalEngineFiredRules.size() == 0
assert customerAEngineFiredRules.size() == 0
assert smartHomeEngineFiredRules.size() == 0
- assert apartment1EngineFiredRules.size() == 0
+ assert apartment2EngineFiredRules.size() == 0
assert apartment3EngineFiredRules.size() == 0
}
@@ -381,7 +350,7 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
assert rulesImport.globalEngine.assetStates.size() == DEMO_RULE_STATES_GLOBAL + 2
assert rulesImport.masterEngine.assetStates.size() == 0
assert rulesImport.customerAEngine.assetStates.size() == DEMO_RULE_STATES_CUSTOMER_A + 2
- assert rulesImport.apartment1Engine.assetStates.size() == DEMO_RULE_STATES_APARTMENT_1 + 2
+ assert rulesImport.apartment2Engine.assetStates.size() == DEMO_RULE_STATES_APARTMENT_2 + 2
assert rulesImport.apartment3Engine.assetStates.size() == DEMO_RULE_STATES_APARTMENT_3
def expectedFiredRules = ["All", "All changed"]
assert globalEngineFiredRules.size() == 4
@@ -390,8 +359,8 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
assert customerAEngineFiredRules.size() == 4
assert customerAEngineFiredRules.containsAll(expectedFiredRules)
assert smartHomeEngineFiredRules.size() == 0
- assert apartment1EngineFiredRules.size() == 4
- assert apartment1EngineFiredRules.containsAll(expectedFiredRules)
+ assert apartment2EngineFiredRules.size() == 4
+ assert apartment2EngineFiredRules.containsAll(expectedFiredRules)
assert apartment3EngineFiredRules.size() == 0
}
@@ -405,12 +374,12 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
assert rulesImport.globalEngine.assetStates.size() == DEMO_RULE_STATES_GLOBAL
assert rulesImport.masterEngine.assetStates.size() == 0
assert rulesImport.customerAEngine.assetStates.size() == DEMO_RULE_STATES_CUSTOMER_A
- assert rulesImport.apartment1Engine.assetStates.size() == DEMO_RULE_STATES_APARTMENT_1
+ assert rulesImport.apartment2Engine.assetStates.size() == DEMO_RULE_STATES_APARTMENT_2
assert rulesImport.apartment3Engine.assetStates.size() == DEMO_RULE_STATES_APARTMENT_3
assert globalEngineFiredRules.size() == 0
assert customerAEngineFiredRules.size() == 0
assert smartHomeEngineFiredRules.size() == 0
- assert apartment1EngineFiredRules.size() == 0
+ assert apartment2EngineFiredRules.size() == 0
assert apartment3EngineFiredRules.size() == 0
}
@@ -444,7 +413,7 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
attachRuleExecutionLogger(rulesImport.globalEngine, globalEngineFiredRules)
attachRuleExecutionLogger(rulesImport.masterEngine, masterEngineFiredRules)
attachRuleExecutionLogger(rulesImport.customerAEngine, customerAEngineFiredRules)
- attachRuleExecutionLogger(rulesImport.apartment1Engine, apartment1EngineFiredRules)
+ attachRuleExecutionLogger(rulesImport.apartment2Engine, apartment2EngineFiredRules)
attachRuleExecutionLogger(rulesImport.apartment3Engine, apartment3EngineFiredRules)
and: "a broken RHS rule is loaded into the customerA engine"
@@ -469,16 +438,16 @@ class BasicRulesProcessingTest extends Specification implements ManagerContainer
assert rulesImport.customerAEngine.allRulesets[1].deploymentStatus == DeploymentStatus.FAILED
}
- when: "an apartment 1 living room thermostat attribute event occurs"
- def apartment1LivingRoomComfortTemperatureChange = new AttributeEvent(
- managerDemoSetup.apartment1LivingroomThermostatId, "comfortTemperature", Json.create(20.3)
+ when: "an attribute event occurs"
+ def apartment2LivingRoomPresenceDetectedChange = new AttributeEvent(
+ managerDemoSetup.apartment2LivingroomId, "presenceDetected", Json.create(true)
)
- assetProcessingService.sendAttributeEvent(apartment1LivingRoomComfortTemperatureChange)
+ assetProcessingService.sendAttributeEvent(apartment2LivingRoomPresenceDetectedChange)
then: "the broken rules engine should prevent a database update"
new PollingConditions(initialDelay: 3).eventually {
- def asset = assetStorageService.find(managerDemoSetup.apartment1LivingroomThermostatId, true)
- assert asset.getAttribute("comfortTemperature").get().getValue() == Json.createNull()
+ def asset = assetStorageService.find(managerDemoSetup.apartment2LivingroomId, true)
+ assert !asset.getAttribute("presenceDetected").get().getValueAsBoolean()
}
cleanup: "the server should be stopped"
diff --git a/manager/test/src/test/groovy/org/openremote/test/rules/BasicRulesetResourceTest.groovy b/manager/test/src/test/groovy/org/openremote/test/rules/BasicRulesetResourceTest.groovy
index a413864c5..593174a4b 100644
--- a/manager/test/src/test/groovy/org/openremote/test/rules/BasicRulesetResourceTest.groovy
+++ b/manager/test/src/test/groovy/org/openremote/test/rules/BasicRulesetResourceTest.groovy
@@ -77,11 +77,11 @@ class BasicRulesetResourceTest extends Specification implements ManagerContainer
ruleDefinitions[0].enabled
when: "some asset rules are retrieved"
- ruleDefinitions = rulesetResource.getAssetRulesets(null, managerDemoSetup.apartment1Id)
+ ruleDefinitions = rulesetResource.getAssetRulesets(null, managerDemoSetup.apartment2Id)
then: "result should match"
ruleDefinitions.length == 1
- ruleDefinitions[0].name == "Some apartment 1 demo rules"
+ ruleDefinitions[0].name == "Some apartment 2 demo rules"
/* ############################################## WRITE ####################################### */
@@ -272,9 +272,9 @@ class BasicRulesetResourceTest extends Specification implements ManagerContainer
ex.response.status == 404
when: "an asset ruleset is created in a non-authenticated realm"
- assetRuleset = new AssetRuleset("Test asset definition", managerDemoSetup.apartment1Id, "ThisShouldBeDRL")
+ assetRuleset = new AssetRuleset("Test asset definition", managerDemoSetup.apartment2Id, "ThisShouldBeDRL")
rulesetResource.createAssetRuleset(null, assetRuleset)
- rulesetId = rulesetResource.getAssetRulesets(null, managerDemoSetup.apartment1Id)[1].id
+ rulesetId = rulesetResource.getAssetRulesets(null, managerDemoSetup.apartment2Id)[1].id
assetRuleset = rulesetResource.getAssetRuleset(null, rulesetId)
lastModified = assetRuleset.lastModified
@@ -285,7 +285,7 @@ class BasicRulesetResourceTest extends Specification implements ManagerContainer
lastModified.time < System.currentTimeMillis()
assetRuleset.name == "Test asset definition"
assetRuleset.rules == "ThisShouldBeDRL"
- assetRuleset.assetId == managerDemoSetup.apartment1Id
+ assetRuleset.assetId == managerDemoSetup.apartment2Id
cleanup: "the server should be stopped"
stopContainer(container)
@@ -345,7 +345,7 @@ class BasicRulesetResourceTest extends Specification implements ManagerContainer
ex.response.status == 403
when: "some asset rules in a non-authenticated realm are retrieved"
- rulesetResource.getAssetRulesets(null, managerDemoSetup.apartment1Id)
+ rulesetResource.getAssetRulesets(null, managerDemoSetup.apartment2Id)
then: "access should be forbidden"
ex = thrown()
@@ -510,7 +510,7 @@ class BasicRulesetResourceTest extends Specification implements ManagerContainer
ex.response.status == 404
when: "an asset ruleset is created in a non-authenticated realm"
- assetRuleset = new AssetRuleset("Test asset definition", managerDemoSetup.apartment1Id, "ThisShouldBeDRL")
+ assetRuleset = new AssetRuleset("Test asset definition", managerDemoSetup.apartment2Id, "ThisShouldBeDRL")
rulesetResource.createAssetRuleset(null, assetRuleset)
then: "access should be forbidden"
@@ -575,7 +575,7 @@ class BasicRulesetResourceTest extends Specification implements ManagerContainer
ex.response.status == 403
when: "some asset rules in the authenticated realm are retrieved"
- rulesetResource.getAssetRulesets(null, managerDemoSetup.apartment1Id)
+ rulesetResource.getAssetRulesets(null, managerDemoSetup.apartment2Id)
then: "access should be forbidden"
ex = thrown()
@@ -723,14 +723,7 @@ class BasicRulesetResourceTest extends Specification implements ManagerContainer
ex.response.status == 403
when: "some asset rules of a protected assigned asset are retrieved"
- def ruleDefinitions = rulesetResource.getAssetRulesets(null, managerDemoSetup.apartment1Id)
-
- then: "result should match"
- ruleDefinitions.length == 1
- ruleDefinitions[0].name == "Some apartment 1 demo rules"
-
- when: "some asset rules of a protected assigned asset are retrieved"
- ruleDefinitions = rulesetResource.getAssetRulesets(null, managerDemoSetup.apartment2Id)
+ def ruleDefinitions = rulesetResource.getAssetRulesets(null, managerDemoSetup.apartment2Id)
then: "result should match"
ruleDefinitions.length == 1
@@ -799,9 +792,9 @@ class BasicRulesetResourceTest extends Specification implements ManagerContainer
ex.response.status == 403
when: "an asset ruleset is created in the authenticated realm"
- def assetRuleset = new AssetRuleset("Test asset definition", managerDemoSetup.apartment1Id, "ThisShouldBeDRL")
+ def assetRuleset = new AssetRuleset("Test asset definition", managerDemoSetup.apartment2Id, "ThisShouldBeDRL")
rulesetResource.createAssetRuleset(null, assetRuleset)
- def rulesetId = rulesetResource.getAssetRulesets(null, managerDemoSetup.apartment1Id)[1].id
+ def rulesetId = rulesetResource.getAssetRulesets(null, managerDemoSetup.apartment2Id)[1].id
assetRuleset = rulesetResource.getAssetRuleset(null, rulesetId)
def lastModified = assetRuleset.lastModified
@@ -812,7 +805,7 @@ class BasicRulesetResourceTest extends Specification implements ManagerContainer
lastModified.time < System.currentTimeMillis()
assetRuleset.name == "Test asset definition"
assetRuleset.rules == "ThisShouldBeDRL"
- assetRuleset.assetId == managerDemoSetup.apartment1Id
+ assetRuleset.assetId == managerDemoSetup.apartment2Id
when: "an asset ruleset is updated"
assetRuleset.name = "Renamed test asset definition"
@@ -827,7 +820,7 @@ class BasicRulesetResourceTest extends Specification implements ManagerContainer
lastModified.time < System.currentTimeMillis()
assetRuleset.name == "Renamed test asset definition"
assetRuleset.rules == "ThisShouldBeDRLAsWell"
- assetRuleset.assetId == managerDemoSetup.apartment1Id
+ assetRuleset.assetId == managerDemoSetup.apartment2Id
when: "an asset ruleset is updated with a changed asset ID"
assetRuleset.assetId = managerDemoSetup.apartment3Id
@@ -846,7 +839,7 @@ class BasicRulesetResourceTest extends Specification implements ManagerContainer
ex.response.status == 400
when: "an asset ruleset is updated with an invalid id"
- assetRuleset.assetId = managerDemoSetup.apartment1Id
+ assetRuleset.assetId = managerDemoSetup.apartment2Id
assetRuleset.id = 1234567890l
rulesetResource.updateAssetRuleset(null, rulesetId, assetRuleset)
diff --git a/manager/test/src/test/groovy/org/openremote/test/rules/apartment/ApartmentAllLightsOffTest.groovy b/manager/test/src/test/groovy/org/openremote/test/rules/apartment/ApartmentAllLightsOffTest.groovy
new file mode 100644
index 000000000..26c475f2c
--- /dev/null
+++ b/manager/test/src/test/groovy/org/openremote/test/rules/apartment/ApartmentAllLightsOffTest.groovy
@@ -0,0 +1,75 @@
+package org.openremote.test.rules.apartment
+
+import elemental.json.Json
+import org.openremote.manager.server.asset.AssetProcessingService
+import org.openremote.manager.server.asset.AssetStorageService
+import org.openremote.manager.server.rules.RulesEngine
+import org.openremote.manager.server.rules.RulesService
+import org.openremote.manager.server.setup.SetupService
+import org.openremote.manager.server.setup.builtin.KeycloakDemoSetup
+import org.openremote.manager.server.setup.builtin.ManagerDemoSetup
+import org.openremote.model.AttributeEvent
+import org.openremote.test.ManagerContainerTrait
+import spock.lang.Specification
+import spock.util.concurrent.PollingConditions
+
+import static java.util.concurrent.TimeUnit.SECONDS
+import static org.openremote.manager.server.setup.builtin.ManagerDemoSetup.DEMO_RULE_STATES_APARTMENT_2
+
+class ApartmentAllLightsOffTest extends Specification implements ManagerContainerTrait {
+
+ def "Turn all lights off"() {
+
+ given: "the container environment is started"
+ def conditions = new PollingConditions(timeout: 10, delay: 1)
+ def serverPort = findEphemeralPort()
+ def container = startContainerWithPseudoClock(defaultConfig(serverPort), defaultServices())
+ def managerDemoSetup = container.getService(SetupService.class).getTaskOfType(ManagerDemoSetup.class)
+ def rulesService = container.getService(RulesService.class)
+ def assetProcessingService = container.getService(AssetProcessingService.class)
+ def assetStorageService = container.getService(AssetStorageService.class)
+ RulesEngine apartment2Engine
+
+ expect: "the rule engines to become available and be running"
+ conditions.eventually {
+ apartment2Engine = rulesService.assetDeployments.get(managerDemoSetup.apartment2Id)
+ assert apartment2Engine != null
+ assert apartment2Engine.isRunning()
+ }
+
+ and: "the demo attributes marked with RULE_STATE = true meta should be inserted into the engines"
+ conditions.eventually {
+ assert apartment2Engine.assetStates.size() == DEMO_RULE_STATES_APARTMENT_2
+ assert apartment2Engine.knowledgeSession.factCount == DEMO_RULE_STATES_APARTMENT_2
+ }
+
+ and: "the room lights in an apartment to be on"
+ def livingRoomAsset = assetStorageService.find(managerDemoSetup.apartment2LivingroomId, true)
+ assert livingRoomAsset.getAttribute("lightSwitch").get().valueAsBoolean
+
+ when: "the ALL LIGHTS OFF push-button is pressed for an apartment"
+ setPseudoClocksToRealTime(container, apartment2Engine)
+ def lightsOffEvent = new AttributeEvent(
+ managerDemoSetup.apartment2Id, "allLightsOffSwitch", Json.create(true), getClockTimeOf(container)
+ )
+ assetProcessingService.sendAttributeEvent(lightsOffEvent)
+
+ then: "the room lights in the apartment should be off"
+ conditions.eventually {
+ assert apartment2Engine.knowledgeSession.factCount == DEMO_RULE_STATES_APARTMENT_2 + 1
+ livingRoomAsset = assetStorageService.find(managerDemoSetup.apartment2LivingroomId, true)
+ assert !livingRoomAsset.getAttribute("lightSwitch").get().valueAsBoolean
+ }
+
+ when: "time advanced"
+ advancePseudoClocks(15, SECONDS, container, apartment2Engine)
+
+ then: "event expired"
+ conditions.eventually {
+ assert apartment2Engine.knowledgeSession.factCount == DEMO_RULE_STATES_APARTMENT_2
+ }
+
+ cleanup: "stop the container"
+ stopContainer(container)
+ }
+}
diff --git a/manager/test/src/test/groovy/org/openremote/test/rules/ApartmentPresenceDetectionTest.groovy b/manager/test/src/test/groovy/org/openremote/test/rules/apartment/ApartmentPresenceDetectionTest.groovy
similarity index 96%
rename from manager/test/src/test/groovy/org/openremote/test/rules/ApartmentPresenceDetectionTest.groovy
rename to manager/test/src/test/groovy/org/openremote/test/rules/apartment/ApartmentPresenceDetectionTest.groovy
index a04cd8d7f..bfbee19c0 100644
--- a/manager/test/src/test/groovy/org/openremote/test/rules/ApartmentPresenceDetectionTest.groovy
+++ b/manager/test/src/test/groovy/org/openremote/test/rules/apartment/ApartmentPresenceDetectionTest.groovy
@@ -1,4 +1,4 @@
-package org.openremote.test.rules
+package org.openremote.test.rules.apartment
import elemental.json.Json
import elemental.json.JsonType
@@ -20,7 +20,7 @@ import static org.openremote.manager.server.setup.builtin.ManagerDemoSetup.DEMO_
class ApartmentPresenceDetectionTest extends Specification implements ManagerContainerTrait {
- def "Detect presence with motion sensor"() {
+ def "Detect presence with motion counter"() {
given: "the container environment is started"
def conditions = new PollingConditions(timeout: 10, delay: 1)
@@ -51,17 +51,17 @@ class ApartmentPresenceDetectionTest extends Specification implements ManagerCon
insertedAssetEvents << assetEvent
}
- and: "several motion sensor events are triggered in the room, but not enough for presence detection"
+ and: "several motion counter increments occur in the room, but not enough for presence detection"
insertedAssetEvents = []
setPseudoClocksToRealTime(container, apartment1Engine)
// Send 5 triggers each 3 minutes apart
for (i in 1..5) {
- def motionSensorTrigger = new AttributeEvent(
- managerDemoSetup.apartment1LivingroomId, "motionSensor", Json.create(true), getClockTimeOf(apartment1Engine)
+ def motionCounterIncrement = new AttributeEvent(
+ managerDemoSetup.apartment1LivingroomId, "motionCounter", Json.create(i), getClockTimeOf(apartment1Engine)
)
- assetProcessingService.sendAttributeEvent(motionSensorTrigger)
+ assetProcessingService.sendAttributeEvent(motionCounterIncrement)
new PollingConditions(timeout: 3, initialDelay: 0.2, delay: 0.2).eventually {
- assert insertedAssetEvents.any() { it.matches(motionSensorTrigger) }
+ assert insertedAssetEvents.any() { it.matches(motionCounterIncrement) }
}
advancePseudoClocks(3, MINUTES, container, apartment1Engine)
}
@@ -81,18 +81,18 @@ class ApartmentPresenceDetectionTest extends Specification implements ManagerCon
assert apartment1Engine.knowledgeSession.factCount == DEMO_RULE_STATES_APARTMENT_1
}
- when: "several motion sensor events are triggered in the room, fast enough for presence detection"
+ when: "several motion counter increments occur in the room, fast enough for presence detection"
insertedAssetEvents = []
double expectedLastPresenceTimestamp = 0
- // Send 5 triggers each 1 minute apart
+ // Send 5 increments each 1 minute apart
for (i in 1..5) {
- def motionSensorTrigger = new AttributeEvent(
- managerDemoSetup.apartment1LivingroomId, "motionSensor", Json.create(true), getClockTimeOf(apartment1Engine)
+ def motionCounterIncrement = new AttributeEvent(
+ managerDemoSetup.apartment1LivingroomId, "motionCounter", Json.create(i), getClockTimeOf(apartment1Engine)
)
- expectedLastPresenceTimestamp = motionSensorTrigger.timestamp
- assetProcessingService.sendAttributeEvent(motionSensorTrigger)
+ expectedLastPresenceTimestamp = motionCounterIncrement.timestamp
+ assetProcessingService.sendAttributeEvent(motionCounterIncrement)
new PollingConditions(timeout: 3, initialDelay: 0.2, delay: 0.2).eventually {
- assert insertedAssetEvents.any() { it.matches(motionSensorTrigger) }
+ assert insertedAssetEvents.any() { it.matches(motionCounterIncrement) }
}
advancePseudoClocks(1, MINUTES, container, apartment1Engine)
}
@@ -104,17 +104,17 @@ class ApartmentPresenceDetectionTest extends Specification implements ManagerCon
assert asset.getAttribute("lastPresenceDetected").get().value.asNumber() == expectedLastPresenceTimestamp
}
- when: "time moves on and we keep triggering the motion sensor in short intervals "
+ when: "time moves on and we keep incrementing the motion counter in short intervals "
insertedAssetEvents = []
- // Send 20 triggers each 90 seconds apart
+ // Send 20 increments each 90 seconds apart
for (i in 1..20) {
- def motionSensorTrigger = new AttributeEvent(
- managerDemoSetup.apartment1LivingroomId, "motionSensor", Json.create(true), getClockTimeOf(apartment1Engine)
+ def motionCounterIncrement = new AttributeEvent(
+ managerDemoSetup.apartment1LivingroomId, "motionCounter", Json.create(i), getClockTimeOf(apartment1Engine)
)
- expectedLastPresenceTimestamp = motionSensorTrigger.timestamp
- assetProcessingService.sendAttributeEvent(motionSensorTrigger)
+ expectedLastPresenceTimestamp = motionCounterIncrement.timestamp
+ assetProcessingService.sendAttributeEvent(motionCounterIncrement)
new PollingConditions(timeout: 3, initialDelay: 0.2, delay: 0.2).eventually {
- assert insertedAssetEvents.any() { it.matches(motionSensorTrigger) }
+ assert insertedAssetEvents.any() { it.matches(motionCounterIncrement) }
}
advancePseudoClocks(90, SECONDS, container, apartment1Engine)
}
@@ -148,7 +148,7 @@ class ApartmentPresenceDetectionTest extends Specification implements ManagerCon
stopContainer(container)
}
- def "Detect presence with motion counter"() {
+ def "Detect presence with motion sensor"() {
given: "the container environment is started"
def conditions = new PollingConditions(timeout: 10, delay: 1)
@@ -179,24 +179,24 @@ class ApartmentPresenceDetectionTest extends Specification implements ManagerCon
insertedAssetEvents << assetEvent
}
- and: "several motion counter increments occur in the room, but not enough for presence detection"
+ and: "several motion sensor events are triggered in the room, but not enough for presence detection"
insertedAssetEvents = []
setPseudoClocksToRealTime(container, apartment2Engine)
// Send 5 triggers each 3 minutes apart
for (i in 1..5) {
- def motionCounterIncrement = new AttributeEvent(
- managerDemoSetup.apartment2LivingroomId, "motionCounter", Json.create(i), getClockTimeOf(apartment2Engine)
+ def motionSensorTrigger = new AttributeEvent(
+ managerDemoSetup.apartment2LivingroomId, "motionSensor", Json.create(true), getClockTimeOf(apartment2Engine)
)
- assetProcessingService.sendAttributeEvent(motionCounterIncrement)
+ assetProcessingService.sendAttributeEvent(motionSensorTrigger)
new PollingConditions(timeout: 3, initialDelay: 0.2, delay: 0.2).eventually {
- assert insertedAssetEvents.any() { it.matches(motionCounterIncrement) }
+ assert insertedAssetEvents.any() { it.matches(motionSensorTrigger) }
}
advancePseudoClocks(3, MINUTES, container, apartment2Engine)
}
then: "presence should not be detected"
new PollingConditions(initialDelay: 3).eventually {
- def asset = assetStorageService.find(managerDemoSetup.apartment1LivingroomId, true)
+ def asset = assetStorageService.find(managerDemoSetup.apartment2LivingroomId, true)
assert !asset.getAttribute("presenceDetected").get().valueAsBoolean
assert asset.getAttribute("lastPresenceDetected").get().value.getType() == JsonType.NULL
}
@@ -209,18 +209,18 @@ class ApartmentPresenceDetectionTest extends Specification implements ManagerCon
assert apartment2Engine.knowledgeSession.factCount == DEMO_RULE_STATES_APARTMENT_2
}
- when: "several motion counter increments occur in the room, fast enough for presence detection"
+ when: "several motion sensor events are triggered in the room, fast enough for presence detection"
insertedAssetEvents = []
double expectedLastPresenceTimestamp = 0
- // Send 5 increments each 1 minute apart
+ // Send 5 triggers each 1 minute apart
for (i in 1..5) {
- def motionCounterIncrement = new AttributeEvent(
- managerDemoSetup.apartment2LivingroomId, "motionCounter", Json.create(i), getClockTimeOf(apartment2Engine)
+ def motionSensorTrigger = new AttributeEvent(
+ managerDemoSetup.apartment2LivingroomId, "motionSensor", Json.create(true), getClockTimeOf(apartment2Engine)
)
- expectedLastPresenceTimestamp = motionCounterIncrement.timestamp
- assetProcessingService.sendAttributeEvent(motionCounterIncrement)
+ expectedLastPresenceTimestamp = motionSensorTrigger.timestamp
+ assetProcessingService.sendAttributeEvent(motionSensorTrigger)
new PollingConditions(timeout: 3, initialDelay: 0.2, delay: 0.2).eventually {
- assert insertedAssetEvents.any() { it.matches(motionCounterIncrement) }
+ assert insertedAssetEvents.any() { it.matches(motionSensorTrigger) }
}
advancePseudoClocks(1, MINUTES, container, apartment2Engine)
}
@@ -232,17 +232,17 @@ class ApartmentPresenceDetectionTest extends Specification implements ManagerCon
assert asset.getAttribute("lastPresenceDetected").get().value.asNumber() == expectedLastPresenceTimestamp
}
- when: "time moves on and we keep incrementing the motion counter in short intervals "
+ when: "time moves on and we keep triggering the motion sensor in short intervals "
insertedAssetEvents = []
- // Send 20 increments each 90 seconds apart
+ // Send 20 triggers each 90 seconds apart
for (i in 1..20) {
- def motionCounterIncrement = new AttributeEvent(
- managerDemoSetup.apartment2LivingroomId, "motionCounter", Json.create(i), getClockTimeOf(apartment2Engine)
+ def motionSensorTrigger = new AttributeEvent(
+ managerDemoSetup.apartment2LivingroomId, "motionSensor", Json.create(true), getClockTimeOf(apartment2Engine)
)
- expectedLastPresenceTimestamp = motionCounterIncrement.timestamp
- assetProcessingService.sendAttributeEvent(motionCounterIncrement)
+ expectedLastPresenceTimestamp = motionSensorTrigger.timestamp
+ assetProcessingService.sendAttributeEvent(motionSensorTrigger)
new PollingConditions(timeout: 3, initialDelay: 0.2, delay: 0.2).eventually {
- assert insertedAssetEvents.any() { it.matches(motionCounterIncrement) }
+ assert insertedAssetEvents.any() { it.matches(motionSensorTrigger) }
}
advancePseudoClocks(90, SECONDS, container, apartment2Engine)
}
diff --git a/manager/test/src/test/groovy/org/openremote/test/rules/apartment/ApartmentVacationModeTest.groovy b/manager/test/src/test/groovy/org/openremote/test/rules/apartment/ApartmentVacationModeTest.groovy
new file mode 100644
index 000000000..2987a0277
--- /dev/null
+++ b/manager/test/src/test/groovy/org/openremote/test/rules/apartment/ApartmentVacationModeTest.groovy
@@ -0,0 +1,91 @@
+package org.openremote.test.rules.apartment
+
+import elemental.json.Json
+import org.openremote.manager.server.asset.AssetProcessingService
+import org.openremote.manager.server.asset.AssetStorageService
+import org.openremote.manager.server.rules.RulesEngine
+import org.openremote.manager.server.rules.RulesService
+import org.openremote.manager.server.setup.SetupService
+import org.openremote.manager.server.setup.builtin.ManagerDemoSetup
+import org.openremote.model.AttributeEvent
+import org.openremote.test.ManagerContainerTrait
+import spock.lang.Specification
+import spock.util.concurrent.PollingConditions
+
+import static java.util.concurrent.TimeUnit.*
+import static org.openremote.manager.server.setup.builtin.ManagerDemoSetup.DEMO_RULE_STATES_APARTMENT_1
+
+class ApartmentVacationModeTest extends Specification implements ManagerContainerTrait {
+
+ def "Decrement vacation days at midnight"() {
+
+ given: "the container environment is started"
+ def conditions = new PollingConditions(timeout: 15, delay: 1)
+ def serverPort = findEphemeralPort()
+ def container = startContainerWithPseudoClock(defaultConfig(serverPort), defaultServices())
+ def managerDemoSetup = container.getService(SetupService.class).getTaskOfType(ManagerDemoSetup.class)
+ def rulesService = container.getService(RulesService.class)
+ def assetProcessingService = container.getService(AssetProcessingService.class)
+ def assetStorageService = container.getService(AssetStorageService.class)
+ RulesEngine apartment1Engine
+
+ expect: "the rule engines to become available and be running"
+ conditions.eventually {
+ apartment1Engine = rulesService.assetDeployments.get(managerDemoSetup.apartment1Id)
+ assert apartment1Engine != null
+ assert apartment1Engine.isRunning()
+ }
+
+ and: "the demo attributes marked with RULE_STATE = true meta should be inserted into the engines"
+ conditions.eventually {
+ assert apartment1Engine.assetStates.size() == DEMO_RULE_STATES_APARTMENT_1
+ assert apartment1Engine.knowledgeSession.factCount == DEMO_RULE_STATES_APARTMENT_1
+ }
+
+ when: "the vacation days are set to 5"
+ setPseudoClocksToRealTime(container, apartment1Engine)
+ assetProcessingService.sendAttributeEvent(new AttributeEvent(
+ managerDemoSetup.apartment1Id, "vacationDays", Json.create(5), getClockTimeOf(container)
+ ))
+
+ then: "that value should be stored"
+ conditions.eventually {
+ def asset = assetStorageService.find(managerDemoSetup.apartment1Id, true)
+ assert asset.getAttribute("vacationDays").get().valueAsInteger == 5
+ }
+
+ when: "time advanced to the next day, which should trigger the cron rule"
+ advancePseudoClocks(24, HOURS, container, apartment1Engine)
+
+ then: "the vacation days should be decremented"
+ conditions.eventually {
+ def asset = assetStorageService.find(managerDemoSetup.apartment1Id, true)
+ assert asset.getAttribute("vacationDays").get().valueAsInteger == 4
+ }
+
+ when: "time advanced again (to test that the rule only fires once per day)"
+ advancePseudoClocks(10, SECONDS, container, apartment1Engine)
+
+ then: "the vacation days should NOT be decremented"
+ new PollingConditions(initialDelay: 2).eventually {
+ def asset = assetStorageService.find(managerDemoSetup.apartment1Id, true)
+ assert asset.getAttribute("vacationDays").get().valueAsInteger == 4
+ }
+
+ expect: "the remaining vacation days to be decremented with each passing day"
+ int remainingDays = 4
+ while (remainingDays > 0) {
+
+ remainingDays--
+
+ advancePseudoClocks(1, DAYS, container, apartment1Engine)
+ conditions.eventually {
+ def asset = assetStorageService.find(managerDemoSetup.apartment1Id, true)
+ assert asset.getAttribute("vacationDays").get().valueAsInteger == remainingDays
+ }
+ }
+
+ cleanup: "the server should be stopped"
+ stopContainer(container)
+ }
+}
diff --git a/model/src/main/java/org/openremote/model/Constants.java b/model/src/main/java/org/openremote/model/Constants.java
index e2ebbf76a..ee70f7219 100644
--- a/model/src/main/java/org/openremote/model/Constants.java
+++ b/model/src/main/java/org/openremote/model/Constants.java
@@ -36,5 +36,7 @@ public interface Constants {
String ASSET_NAMESPACE = NAMESPACE + ":asset";
String ASSET_META_NAMESPACE = ASSET_NAMESPACE + ":meta";
String DEFAULT_DATETIME_FORMAT ="dd. MMM yyyy HH:mm:ss zzz";
+ String DEFAULT_DATE_FORMAT ="dd. MMM yyyy";
+ String DEFAULT_TIME_FORMAT ="HH:mm:ss";
}