Skip to content

armgit / core

Public Imported from GitHub
0

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

Cleanup of descriptors and added deserialisation implementations

Rich Turner756e3c2d4303
diff --git a/client/src/main/java/org/openremote/app/client/assets/asset/AssetEditActivity.java b/client/src/main/java/org/openremote/app/client/assets/asset/AssetEditActivity.java
index 4c7566f74..54767a4d3 100644
--- a/client/src/main/java/org/openremote/app/client/assets/asset/AssetEditActivity.java
+++ b/client/src/main/java/org/openremote/app/client/assets/asset/AssetEditActivity.java
@@ -243,7 +243,9 @@ public class AssetEditActivity
attribute = new AssetAttribute();
attribute.setType(attributeValueType);
- attributeValueType.getMetaItemDescriptors().ifPresent(attribute::addMeta);
+ if (attributeValueType.getMetaItemDescriptors() != null) {
+ attribute.addMeta(attributeValueType.getMetaItemDescriptors());
+ }
}
attribute.setName(name);
diff --git a/manager/src/main/java/org/openremote/manager/asset/AssetResourceImpl.java b/manager/src/main/java/org/openremote/manager/asset/AssetResourceImpl.java
index d7f67472a..314e7b9c6 100644
--- a/manager/src/main/java/org/openremote/manager/asset/AssetResourceImpl.java
+++ b/manager/src/main/java/org/openremote/manager/asset/AssetResourceImpl.java
@@ -465,27 +465,30 @@ public class AssetResourceImpl extends ManagerWebResource implements AssetResour
// Add meta items to well known attributes if not present
newAsset.getAttributesStream().forEach(assetAttribute -> {
- Optional<AttributeDescriptor> attributeDescriptor = assetDescriptor.getAttributeDescriptors()
- .flatMap(attributeDescriptors ->
- Arrays.stream(attributeDescriptors)
- .filter(attrDescriptor -> attrDescriptor.getAttributeName().equals(assetAttribute.getNameOrThrow()))
- .findFirst()
- );
-
- attributeDescriptor.ifPresent(defaultAttribute ->
- defaultAttribute.getMetaItemDescriptors().ifPresent(metaItemDescriptors ->
- assetAttribute.addMeta(
- Arrays.stream(metaItemDescriptors).filter(metaItemDescriptor -> !assetAttribute.hasMetaItem(metaItemDescriptor)).map(MetaItem::new).toArray(MetaItem[]::new)
- ))
- );
+ if (assetDescriptor.getAttributeDescriptors() != null) {
+ Arrays.stream(assetDescriptor.getAttributeDescriptors())
+ .filter(attrDescriptor -> attrDescriptor.getAttributeName().equals(assetAttribute.getNameOrThrow()))
+ .findFirst()
+ .ifPresent(defaultAttribute -> {
+ if (defaultAttribute.getMetaItemDescriptors() != null) {
+ assetAttribute.addMeta(
+ Arrays.stream(defaultAttribute.getMetaItemDescriptors())
+ .filter(metaItemDescriptor -> !assetAttribute.hasMetaItem(metaItemDescriptor))
+ .map(MetaItem::new)
+ .toArray(MetaItem[]::new)
+ );
+ }
+ });
+ }
});
// Add attributes for this well known asset if not present
- assetDescriptor.getAttributeDescriptors().ifPresent(attributeDescriptors ->
- newAsset.addAttributes(
- Arrays.stream(attributeDescriptors).filter(attributeDescriptor ->
- !newAsset.hasAttribute(attributeDescriptor.getAttributeName())).map(AssetAttribute::new).toArray(AssetAttribute[]::new)
- ));
+ if (assetDescriptor.getAttributeDescriptors() != null) {
+ newAsset.addAttributes(
+ Arrays.stream(assetDescriptor.getAttributeDescriptors()).filter(attributeDescriptor ->
+ !newAsset.hasAttribute(attributeDescriptor.getAttributeName())).map(AssetAttribute::new).toArray(AssetAttribute[]::new)
+ );
+ }
});
//Check if a well known attribute is added
diff --git a/model/src/main/java/org/openremote/model/asset/Asset.java b/model/src/main/java/org/openremote/model/asset/Asset.java
index a17292901..2c4fc0d92 100644
--- a/model/src/main/java/org/openremote/model/asset/Asset.java
+++ b/model/src/main/java/org/openremote/model/asset/Asset.java
@@ -300,8 +300,9 @@ public class Asset implements IdentifiableEntity {
public Asset(@NotNull String name, @NotNull AssetDescriptor type, Asset parent, String realm) {
this(name, type.getType(), type.getAccessPublicRead(), parent, realm);
- type.getAttributeDescriptors().ifPresent(attributeDescriptors ->
- addAttributes(Arrays.stream(attributeDescriptors).map(AssetAttribute::new).toArray(AssetAttribute[]::new)));
+ if (type.getAttributeDescriptors() != null) {
+ addAttributes(Arrays.stream(type.getAttributeDescriptors()).map(AssetAttribute::new).toArray(AssetAttribute[]::new));
+ }
}
public Asset(@NotNull String name, @NotNull String type, boolean accessPublicRead, Asset parent, String realm) {
diff --git a/model/src/main/java/org/openremote/model/asset/AssetAttribute.java b/model/src/main/java/org/openremote/model/asset/AssetAttribute.java
index 7f40f58bf..7f218ba4b 100644
--- a/model/src/main/java/org/openremote/model/asset/AssetAttribute.java
+++ b/model/src/main/java/org/openremote/model/asset/AssetAttribute.java
@@ -86,9 +86,9 @@ public class AssetAttribute extends Attribute {
}
}
setValue(value, timestamp);
- attributeDescriptor.getMetaItemDescriptors().ifPresent(metaItemDescriptors ->
- addMeta(Arrays.stream(metaItemDescriptors).map(MetaItem::new).toArray(MetaItem[]::new))
- );
+ if (attributeDescriptor.getMetaItemDescriptors() != null) {
+ addMeta(Arrays.stream(attributeDescriptor.getMetaItemDescriptors()).map(MetaItem::new).toArray(MetaItem[]::new));
+ }
}
public AssetAttribute(String name, AttributeValueType type, Value value, long timestamp) {
diff --git a/model/src/main/java/org/openremote/model/asset/AssetDescriptor.java b/model/src/main/java/org/openremote/model/asset/AssetDescriptor.java
index 83b4c1f8d..09b10e476 100644
--- a/model/src/main/java/org/openremote/model/asset/AssetDescriptor.java
+++ b/model/src/main/java/org/openremote/model/asset/AssetDescriptor.java
@@ -21,11 +21,11 @@ package org.openremote.model.asset;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.openremote.model.attribute.AttributeDescriptor;
-import java.util.Optional;
-
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
+@JsonDeserialize(as = AssetDescriptorImpl.class)
public interface AssetDescriptor {
@JsonProperty
@@ -37,5 +37,5 @@ public interface AssetDescriptor {
boolean getAccessPublicRead();
- Optional<AttributeDescriptor[]> getAttributeDescriptors();
+ AttributeDescriptor[] getAttributeDescriptors();
}
diff --git a/model/src/main/java/org/openremote/model/asset/AssetDescriptorImpl.java b/model/src/main/java/org/openremote/model/asset/AssetDescriptorImpl.java
new file mode 100644
index 000000000..b22d64da1
--- /dev/null
+++ b/model/src/main/java/org/openremote/model/asset/AssetDescriptorImpl.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2019, OpenRemote Inc.
+ *
+ * See the CONTRIBUTORS.txt file in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.openremote.model.asset;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import org.openremote.model.attribute.AttributeDescriptor;
+
+public class AssetDescriptorImpl implements AssetDescriptor {
+
+ protected String name;
+ protected String type;
+ protected String icon;
+ protected boolean accessPublicRead;
+ AttributeDescriptor[] attributeDescriptors;
+
+ @JsonCreator
+ public AssetDescriptorImpl(@JsonProperty("name") String name,
+ @JsonProperty("type") String type,
+ @JsonProperty("icon") String icon,
+ @JsonProperty("accessPublicRead") boolean accessPublicRead,
+ @JsonProperty("attributeDescriptors") AttributeDescriptor[] attributeDescriptors) {
+ this.name = name;
+ this.type = type;
+ this.icon = icon;
+ this.accessPublicRead = accessPublicRead;
+ this.attributeDescriptors = attributeDescriptors;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public String getType() {
+ return type;
+ }
+
+ @Override
+ public String getIcon() {
+ return icon;
+ }
+
+ public boolean getAccessPublicRead() {
+ return accessPublicRead;
+ }
+
+ @Override
+ public AttributeDescriptor[] getAttributeDescriptors() {
+ return attributeDescriptors;
+ }
+}
diff --git a/model/src/main/java/org/openremote/model/asset/AssetType.java b/model/src/main/java/org/openremote/model/asset/AssetType.java
index 75c432f10..3926b2f85 100644
--- a/model/src/main/java/org/openremote/model/asset/AssetType.java
+++ b/model/src/main/java/org/openremote/model/asset/AssetType.java
@@ -103,7 +103,7 @@ public enum AssetType implements AssetDescriptor {
}
@Override
- public Optional<AttributeDescriptor[]> getAttributeDescriptors() {
- return Optional.ofNullable(attributeDescriptors);
+ public AttributeDescriptor[] getAttributeDescriptors() {
+ return attributeDescriptors;
}
}
diff --git a/model/src/main/java/org/openremote/model/attribute/AttributeDescriptor.java b/model/src/main/java/org/openremote/model/attribute/AttributeDescriptor.java
index ca1ed256c..db0e3444f 100644
--- a/model/src/main/java/org/openremote/model/attribute/AttributeDescriptor.java
+++ b/model/src/main/java/org/openremote/model/attribute/AttributeDescriptor.java
@@ -20,20 +20,28 @@
package org.openremote.model.attribute;
import com.fasterxml.jackson.annotation.JsonFormat;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.openremote.model.value.Value;
import java.util.Optional;
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
+@JsonDeserialize(as = AttributeDescriptorImpl.class)
public interface AttributeDescriptor {
+ @JsonProperty
String getName();
+ @JsonProperty
String getAttributeName();
+ @JsonProperty
AttributeValueDescriptor getValueDescriptor();
- Optional<MetaItemDescriptor[]> getMetaItemDescriptors();
+ @JsonProperty
+ MetaItemDescriptor[] getMetaItemDescriptors();
+ @JsonProperty
Value getInitialValue();
}
diff --git a/model/src/main/java/org/openremote/model/attribute/AttributeDescriptorImpl.java b/model/src/main/java/org/openremote/model/attribute/AttributeDescriptorImpl.java
new file mode 100644
index 000000000..38d5d4b75
--- /dev/null
+++ b/model/src/main/java/org/openremote/model/attribute/AttributeDescriptorImpl.java
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2019, OpenRemote Inc.
+ *
+ * See the CONTRIBUTORS.txt file in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.openremote.model.attribute;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import org.openremote.model.value.Value;
+
+public class AttributeDescriptorImpl implements AttributeDescriptor {
+
+ protected String name;
+ protected String attributeName;
+ protected AttributeValueDescriptor valueDescriptor;
+ protected MetaItemDescriptor[] metaItemDescriptors;
+ protected Value initialValue;
+
+ @JsonCreator
+ public AttributeDescriptorImpl(@JsonProperty("name") String name,
+ @JsonProperty("attributeName") String attributeName,
+ @JsonProperty("valueDescriptor") AttributeValueDescriptor valueDescriptor,
+ @JsonProperty("metaItemDescriptors") MetaItemDescriptor[] metaItemDescriptors,
+ @JsonProperty("initialValue") Value initialValue) {
+ this.name = name;
+ this.attributeName = attributeName;
+ this.valueDescriptor = valueDescriptor;
+ this.metaItemDescriptors = metaItemDescriptors;
+ this.initialValue = initialValue;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public String getAttributeName() {
+ return attributeName;
+ }
+
+ @Override
+ public AttributeValueDescriptor getValueDescriptor() {
+ return valueDescriptor;
+ }
+
+ @Override
+ public MetaItemDescriptor[] getMetaItemDescriptors() {
+ return metaItemDescriptors;
+ }
+
+ @Override
+ public Value getInitialValue() {
+ return initialValue;
+ }
+}
diff --git a/model/src/main/java/org/openremote/model/attribute/AttributeType.java b/model/src/main/java/org/openremote/model/attribute/AttributeType.java
index df602e70a..b0f670d91 100644
--- a/model/src/main/java/org/openremote/model/attribute/AttributeType.java
+++ b/model/src/main/java/org/openremote/model/attribute/AttributeType.java
@@ -19,7 +19,6 @@
*/
package org.openremote.model.attribute;
-import com.fasterxml.jackson.annotation.JsonProperty;
import org.openremote.model.value.Value;
import org.openremote.model.value.Values;
@@ -70,17 +69,17 @@ public enum AttributeType implements AttributeDescriptor {
final protected String attributeName;
- final protected AttributeValueDescriptor attributeValueDescriptor;
+ final protected AttributeValueDescriptor valueDescriptor;
final protected Value initialValue;
final protected MetaItemDescriptor[] metaItemDescriptors;
- AttributeType(String attributeName, AttributeValueDescriptor attributeValueDescriptor, MetaItemDescriptor... metaItemDescriptors) {
- this(attributeName, attributeValueDescriptor, null, metaItemDescriptors);
+ AttributeType(String attributeName, AttributeValueDescriptor valueDescriptor, MetaItemDescriptor... metaItemDescriptors) {
+ this(attributeName, valueDescriptor, null, metaItemDescriptors);
}
- AttributeType(String attributeName, AttributeValueDescriptor attributeValueDescriptor, Value initialValue, MetaItemDescriptor... metaItemDescriptors) {
+ AttributeType(String attributeName, AttributeValueDescriptor valueDescriptor, Value initialValue, MetaItemDescriptor... metaItemDescriptors) {
this.attributeName = attributeName;
- this.attributeValueDescriptor = attributeValueDescriptor;
+ this.valueDescriptor = valueDescriptor;
this.metaItemDescriptors = metaItemDescriptors;
this.initialValue = initialValue;
}
@@ -109,12 +108,12 @@ public enum AttributeType implements AttributeDescriptor {
@Override
public AttributeValueDescriptor getValueDescriptor() {
- return attributeValueDescriptor;
+ return valueDescriptor;
}
@Override
- public Optional<MetaItemDescriptor[]> getMetaItemDescriptors() {
- return Optional.ofNullable(metaItemDescriptors);
+ public MetaItemDescriptor[] getMetaItemDescriptors() {
+ return metaItemDescriptors;
}
@Override
@@ -123,40 +122,11 @@ public enum AttributeType implements AttributeDescriptor {
}
public AttributeDescriptor withName(String name, MetaItemDescriptor... metaItemDescriptors) {
- return withName(name, null, metaItemDescriptors);
+ return withName(name, initialValue, metaItemDescriptors);
}
public AttributeDescriptor withName(String name, Value initialValue, MetaItemDescriptor... metaItemDescriptors) {
- return new AttributeDescriptor() {
- @Override
- public String getName() {
- return name();
- }
-
- @Override
- @JsonProperty
- public String getAttributeName() {
- return name;
- }
-
- @Override
- @JsonProperty
- public AttributeValueDescriptor getValueDescriptor() {
- return attributeValueDescriptor;
- }
-
- @Override
- @JsonProperty
- public Optional<MetaItemDescriptor[]> getMetaItemDescriptors() {
- return Optional.ofNullable(metaItemDescriptors);
- }
-
- @Override
- @JsonProperty
- public Value getInitialValue() {
- return initialValue;
- }
- };
+ return new AttributeDescriptorImpl(name, attributeName, valueDescriptor, metaItemDescriptors, initialValue);
}
}
diff --git a/model/src/main/java/org/openremote/model/attribute/AttributeValueDescriptor.java b/model/src/main/java/org/openremote/model/attribute/AttributeValueDescriptor.java
index 8e3c7917a..a889d00a8 100644
--- a/model/src/main/java/org/openremote/model/attribute/AttributeValueDescriptor.java
+++ b/model/src/main/java/org/openremote/model/attribute/AttributeValueDescriptor.java
@@ -22,6 +22,7 @@ package org.openremote.model.attribute;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.openremote.model.ValidationFailure;
import org.openremote.model.value.Value;
import org.openremote.model.value.ValueType;
@@ -30,6 +31,7 @@ import java.util.Optional;
import java.util.function.Function;
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
+@JsonDeserialize(as = AttributeValueDescriptorImpl.class)
public interface AttributeValueDescriptor {
@JsonProperty
@@ -39,7 +41,7 @@ public interface AttributeValueDescriptor {
ValueType getValueType();
- Optional<MetaItemDescriptor[]> getMetaItemDescriptors();
+ MetaItemDescriptor[] getMetaItemDescriptors();
@JsonIgnore
Optional<Function<Value, Optional<ValidationFailure>>> getValidator();
diff --git a/model/src/main/java/org/openremote/model/attribute/AttributeValueDescriptorImpl.java b/model/src/main/java/org/openremote/model/attribute/AttributeValueDescriptorImpl.java
new file mode 100644
index 000000000..59b766064
--- /dev/null
+++ b/model/src/main/java/org/openremote/model/attribute/AttributeValueDescriptorImpl.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2019, OpenRemote Inc.
+ *
+ * See the CONTRIBUTORS.txt file in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.openremote.model.attribute;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import org.openremote.model.ValidationFailure;
+import org.openremote.model.value.Value;
+import org.openremote.model.value.ValueType;
+
+import java.util.Optional;
+import java.util.function.Function;
+
+public class AttributeValueDescriptorImpl implements AttributeValueDescriptor {
+
+ protected String name;
+ protected String icon;
+ protected ValueType valueType;
+ protected MetaItemDescriptor[] metaItemDescriptors;
+ @JsonIgnore
+ protected Function<Value, Optional<ValidationFailure>> validator;
+
+ @JsonCreator
+ public AttributeValueDescriptorImpl(@JsonProperty("name") String name,
+ @JsonProperty("icon") String icon,
+ @JsonProperty("valueType") ValueType valueType,
+ @JsonProperty("metaItemDescriptors") MetaItemDescriptor[] metaItemDescriptors) {
+ this(name, icon, valueType, metaItemDescriptors, null);
+ }
+
+ public AttributeValueDescriptorImpl(String name, String icon, ValueType valueType, MetaItemDescriptor[] metaItemDescriptors, Function<Value, Optional<ValidationFailure>> validator) {
+ this.name = name;
+ this.icon = icon;
+ this.valueType = valueType;
+ this.metaItemDescriptors = metaItemDescriptors;
+ this.validator = validator;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public String getIcon() {
+ return icon;
+ }
+
+ @Override
+ public ValueType getValueType() {
+ return valueType;
+ }
+
+ @Override
+ public MetaItemDescriptor[] getMetaItemDescriptors() {
+ return metaItemDescriptors;
+ }
+
+ @Override
+ public Optional<Function<Value, Optional<ValidationFailure>>> getValidator() {
+ return Optional.ofNullable(validator);
+ }
+}
diff --git a/model/src/main/java/org/openremote/model/attribute/AttributeValueType.java b/model/src/main/java/org/openremote/model/attribute/AttributeValueType.java
index b03bdbd2f..8a9237ee4 100644
--- a/model/src/main/java/org/openremote/model/attribute/AttributeValueType.java
+++ b/model/src/main/java/org/openremote/model/attribute/AttributeValueType.java
@@ -232,8 +232,8 @@ public enum AttributeValueType implements AttributeValueDescriptor {
}
@Override
- public Optional<MetaItemDescriptor[]> getMetaItemDescriptors() {
- return Optional.ofNullable(metaItemDescriptors);
+ public MetaItemDescriptor[] getMetaItemDescriptors() {
+ return metaItemDescriptors;
}
@Override
diff --git a/model/src/main/java/org/openremote/model/attribute/MetaItemDescriptor.java b/model/src/main/java/org/openremote/model/attribute/MetaItemDescriptor.java
index 2d778141a..6bb0804a7 100644
--- a/model/src/main/java/org/openremote/model/attribute/MetaItemDescriptor.java
+++ b/model/src/main/java/org/openremote/model/attribute/MetaItemDescriptor.java
@@ -21,6 +21,7 @@ package org.openremote.model.attribute;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.openremote.model.HasUniqueResourceName;
import org.openremote.model.ValidationFailure;
import org.openremote.model.value.Value;
@@ -31,6 +32,7 @@ import java.util.Optional;
import java.util.function.Function;
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
+@JsonDeserialize(as = MetaItemDescriptorImpl.class)
public interface MetaItemDescriptor extends HasUniqueResourceName {
/**
diff --git a/test/src/test/groovy/org/openremote/test/assets/AssetModelResourceTest.groovy b/test/src/test/groovy/org/openremote/test/assets/AssetModelResourceTest.groovy
index 19edda952..cd4a7d3d8 100644
--- a/test/src/test/groovy/org/openremote/test/assets/AssetModelResourceTest.groovy
+++ b/test/src/test/groovy/org/openremote/test/assets/AssetModelResourceTest.groovy
@@ -21,6 +21,7 @@ package org.openremote.test.assets
import org.openremote.container.Container
import org.openremote.model.asset.AssetModelResource
+import org.openremote.model.attribute.AttributeType
import org.openremote.model.value.ValueType
import org.openremote.test.ManagerContainerTrait
import spock.lang.Shared
@@ -61,12 +62,12 @@ class AssetModelResourceTest extends Specification implements ManagerContainerTr
def assetDescriptors = assetModelResource.getAssetDescriptors(null)
- then: "the eight default types should be present"
+ then: "the default asset types should be present"
assetDescriptors.size() == 8
assetDescriptors[0].name == CUSTOM.name
assetDescriptors[1].name == BUILDING.name
- assetDescriptors[1].attributeDescriptors.get().length == 4
- assetDescriptors[1].attributeDescriptors.get()[0].valueDescriptor.name == ValueType.STRING
+ assetDescriptors[1].attributeDescriptors.length == 5
+ assetDescriptors[1].attributeDescriptors.find {it.name == AttributeType.SURFACE_AREA.name}.valueDescriptor.valueType == ValueType.NUMBER
assetDescriptors[2].name == FLOOR.name
assetDescriptors[3].name == RESIDENCE.name
assetDescriptors[4].name == ROOM.name
@@ -78,19 +79,21 @@ class AssetModelResourceTest extends Specification implements ManagerContainerTr
def attributeTypeDescriptors = assetModelResource.getAttributeTypeDescriptors(null)
- then: "the eleven default types should be present"
- attributeTypeDescriptors.size() == 11
- attributeTypeDescriptors[0].attributeName == "consoleName"
- attributeTypeDescriptors[1].attributeName == "consoleVersion"
- attributeTypeDescriptors[2].attributeName == "consolePlatform"
- attributeTypeDescriptors[3].attributeName == "consoleProviders"
- attributeTypeDescriptors[4].attributeName == "email"
- attributeTypeDescriptors[5].attributeName == "city"
- attributeTypeDescriptors[6].attributeName == "country"
- attributeTypeDescriptors[7].attributeName == "postalCode"
- attributeTypeDescriptors[8].attributeName == "street"
- attributeTypeDescriptors[9].attributeName == "location"
- attributeTypeDescriptors[10].attributeName == "surfaceArea"
+ then: "the default types should be present"
+ attributeTypeDescriptors.size() == 13
+ attributeTypeDescriptors.any {it.attributeName == "string"}
+ attributeTypeDescriptors.any {it.attributeName == "number"}
+ attributeTypeDescriptors.any {it.attributeName == "consoleName"}
+ attributeTypeDescriptors.any {it.attributeName == "consoleVersion"}
+ attributeTypeDescriptors.any {it.attributeName == "consolePlatform"}
+ attributeTypeDescriptors.any {it.attributeName == "consoleProviders"}
+ attributeTypeDescriptors.any {it.attributeName == "email"}
+ attributeTypeDescriptors.any {it.attributeName == "city"}
+ attributeTypeDescriptors.any {it.attributeName == "country"}
+ attributeTypeDescriptors.any {it.attributeName == "postalCode"}
+ attributeTypeDescriptors.any {it.attributeName == "street"}
+ attributeTypeDescriptors.any {it.attributeName == "location"}
+ attributeTypeDescriptors.any {it.attributeName == "surfaceArea"}
when: "a request for Attribute value types is made"
@@ -103,7 +106,7 @@ class AssetModelResourceTest extends Specification implements ManagerContainerTr
def metaItemDescriptors = assetModelResource.getMetaItemDescriptors(null)
- then: "the 26 default MetaItem types should be present"
- metaItemDescriptors.size() == 26
+ then: "the default MetaItem types should be present"
+ metaItemDescriptors.size() == 24
}
}