Skip to content

Commit 6d06e2d

Browse files
authored
Merge pull request #48 from eclipse-aas4j/update-to-rc02-xml
Re-enable XML Unit Tests
2 parents 1a76a01 + 20dafe1 commit 6d06e2d

File tree

55 files changed

+793
-2158
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+793
-2158
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.eclipse.digitaltwin.aas4j.v3.dataformat.core;
17+
18+
import org.eclipse.digitaltwin.aas4j.v3.model.DataSpecificationContent;
19+
import org.eclipse.digitaltwin.aas4j.v3.model.Reference;
20+
21+
/**
22+
* Class representing all information required for a (custom) data specification
23+
*/
24+
public class DataSpecificationInfo {
25+
26+
private final Class<? extends DataSpecificationContent> type;
27+
private final Reference reference;
28+
private final String prefix;
29+
30+
public DataSpecificationInfo(Class<? extends DataSpecificationContent> type, Reference reference, String prefix) {
31+
this.type = type;
32+
this.reference = reference;
33+
this.prefix = prefix;
34+
}
35+
36+
public Class<? extends DataSpecificationContent> getType() {
37+
return type;
38+
}
39+
40+
public Reference getReference() {
41+
return reference;
42+
}
43+
44+
public String getPrefix() {
45+
return prefix;
46+
}
47+
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
* Copyright (c) 2021 Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e. V.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.eclipse.digitaltwin.aas4j.v3.dataformat.core;
17+
18+
import org.eclipse.digitaltwin.aas4j.v3.dataformat.core.util.AasUtils;
19+
import java.util.Arrays;
20+
import java.util.Objects;
21+
import java.util.Optional;
22+
23+
import org.eclipse.digitaltwin.aas4j.v3.model.DataSpecificationContent;
24+
import org.eclipse.digitaltwin.aas4j.v3.model.KeyTypes;
25+
import org.eclipse.digitaltwin.aas4j.v3.model.Reference;
26+
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultKey;
27+
import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultReference;
28+
import java.util.HashSet;
29+
import java.util.Set;
30+
import java.util.function.Predicate;
31+
32+
/**
33+
* This class is used to manage supported data specification templates. Each
34+
* template is identified through a reference and a prefix and provides a
35+
* corresponding Java class.
36+
*/
37+
public class DataSpecificationManager {
38+
39+
public static final String PROP_DATA_SPECIFICATION = "dataSpecification";
40+
// public static final String PROP_DATA_SPECIFICATION_CONTENT = "dataSpecificationContent";
41+
public static final String PROP_DATA_SPECIFICATION_CONTENT = "dataSpecificationIec61360";
42+
43+
44+
private static final Set<DataSpecificationInfo> KNOWN_IMPLEMENTATIONS = new HashSet<>(Arrays.asList(
45+
// new DataSpecificationInfo(DataSpecificationIEC61360.class,
46+
// createGlobalIri(DATA_SPECIFICATION_IEC61360_IRI),
47+
// DATA_SPECIFICATION_IEC61360_PREFIX)
48+
));
49+
50+
/**
51+
* Allows to register an additional data specification template
52+
*
53+
* @param dataSpecification Details of the data specification template to
54+
* register
55+
*/
56+
public static void register(DataSpecificationInfo dataSpecification) {
57+
KNOWN_IMPLEMENTATIONS.add(dataSpecification);
58+
}
59+
60+
private static Reference createGlobalIri(String iri) {
61+
return new DefaultReference.Builder().keys(Arrays.asList(
62+
new DefaultKey.Builder().type(KeyTypes.GLOBAL_REFERENCE).value(iri).build()))
63+
.build();
64+
}
65+
66+
/**
67+
* Returns a DataSpecificationInfo describing the data specification
68+
* template implemented by the given class. If the class is unknown, null is
69+
* returned.
70+
*
71+
* @param implementation type of the implementation class
72+
* @return a DataSpecificationInfo describing the data specification
73+
* template represented by the given class, or null if the implementation
74+
* class does not represent any data specification
75+
*/
76+
public static DataSpecificationInfo getDataSpecification(Class<? extends DataSpecificationContent> implementation) {
77+
DataSpecificationInfo result = getDataSpecification(x -> Objects.equals(x.getType(), implementation));
78+
if (result == null) {
79+
result = getDataSpecification(x -> x.getType().isAssignableFrom(implementation));
80+
}
81+
return result;
82+
}
83+
84+
/**
85+
* Returns a DataSpecificationInfo describing the data specification
86+
* template implemented by the given class. If the class is unknown, null is
87+
* returned.
88+
*
89+
* @param reference Reference associated with the wanted data specficiation
90+
* @return a DataSpecificationInfo describing the data specification
91+
* template represented by the reference, or null if the reference does not
92+
* represent any data specification
93+
*/
94+
public static DataSpecificationInfo getDataSpecification(Reference reference) {
95+
return getDataSpecification(x -> AasUtils.sameAs(x.getReference(), reference));
96+
}
97+
98+
private static DataSpecificationInfo getDataSpecification(Predicate<DataSpecificationInfo> filter) {
99+
Optional<DataSpecificationInfo> exactMatch = KNOWN_IMPLEMENTATIONS.stream()
100+
.filter(filter)
101+
.findFirst();
102+
if (exactMatch.isPresent()) {
103+
return exactMatch.get();
104+
}
105+
return null;
106+
}
107+
}

dataformat-core/src/test/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/core/AASFull.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ public static Submodel createSubmodel3() {
733733
.type(ReferenceTypes.GLOBAL_REFERENCE)
734734
.build())
735735
.build())
736-
.value(new DefaultRange.Builder()
736+
.value(new DefaultRange.Builder() // TODO: a SME-List must only contain one SME-Type, e.g. Property or Range
737737
.idShort("ExampleRange")
738738
.category("PARAMETER")
739739
.description(Arrays.asList(
@@ -751,6 +751,7 @@ public static Submodel createSubmodel3() {
751751
.max("100")
752752
.valueType(DataTypeDefXsd.INT)
753753
.build())
754+
.typeValueListElement(AasSubmodelElements.SUBMODEL_ELEMENT)
754755
.build())
755756
.submodelElements(new DefaultSubmodelElementCollection.Builder()
756757
.idShort("ExampleSubmodelElementCollection")
@@ -949,6 +950,7 @@ public static Submodel createSubmodel4() {
949950
.max(null)
950951
.valueType(DataTypeDefXsd.INT)
951952
.build())
953+
.typeValueListElement(AasSubmodelElements.SUBMODEL_ELEMENT)
952954
.build())
953955
.submodelElements(new DefaultSubmodelElementCollection.Builder()
954956
.idShort("ExampleSubmodelElementCollection")
@@ -1301,6 +1303,7 @@ public static Submodel createSubmodel6() {
13011303
.max("100")
13021304
.valueType(DataTypeDefXsd.INT)
13031305
.build())
1306+
.typeValueListElement(AasSubmodelElements.SUBMODEL_ELEMENT)
13041307
.build())
13051308
.submodelElements(new DefaultSubmodelElementCollection.Builder()
13061309
.idShort("ExampleSubmodelElementCollection")
@@ -1712,6 +1715,7 @@ public static Submodel createSubmodel7() {
17121715
.max(null)
17131716
.valueType(DataTypeDefXsd.INT)
17141717
.build())
1718+
.typeValueListElement(AasSubmodelElements.SUBMODEL_ELEMENT)
17151719
.build())
17161720
.submodelElements(new DefaultSubmodelElementCollection.Builder()
17171721
.idShort("ExampleSubmodelElementCollection")

dataformat-json/src/main/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/json/mixins/ConceptDescriptionMixin.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
public interface ConceptDescriptionMixin {
2323

2424
@JsonProperty("isCaseOf")
25-
public List<Reference> getIsCaseOfs();
25+
public List<Reference> getIsCaseOf();
2626

2727
@JsonProperty("isCaseOf")
28-
public void setIsCaseOfs(List<Reference> isCaseOfs);
28+
public void setIsCaseOfs(List<Reference> isCaseOf);
2929
}

dataformat-json/src/test/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/json/JsonReferableSerializerTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.Collection;
2020

2121
import org.json.JSONException;
22+
import org.junit.Ignore;
2223
import org.junit.Test;
2324
import org.skyscreamer.jsonassert.JSONAssert;
2425
import org.skyscreamer.jsonassert.JSONCompareMode;
@@ -51,6 +52,7 @@ public void testSerializeAASs() throws IOException, SerializationException, JSON
5152
}
5253

5354
@Test
55+
@Ignore("Add test after DataSpecficationPhysicalUnit is supported again")
5456
public void testSerializeConceptDescriptionWithPhysicalUnit() throws IOException, SerializationException, JSONException {
5557
compare(Examples.CONCEPT_DESCRIPTION_DATA_SPECIFICATION_PHYSICAL_UNIT);
5658
}

dataformat-json/src/test/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/json/util/Examples.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -98,28 +98,28 @@ public class Examples {
9898
.value("https://admin-shell.io/DataSpecificationTemplates/DataSpecificationPhysicalUnit/3/0/RC02")
9999
.build())
100100
.build())
101-
.dataSpecificationContent(new DefaultDataSpecificationPhysicalUnit.Builder()
102-
.conversionFactor("1.0")
103-
.eceCode("ece-code")
104-
.eceName("ece-name")
105-
.definition(new DefaultLangString.Builder()
106-
.language("en")
107-
.text("definition-en")
108-
.build())
109-
.definition(new DefaultLangString.Builder()
110-
.language("de")
111-
.text("definition-de")
112-
.build())
113-
.nistName("nist-name")
114-
.dinNotation("din-notation")
115-
.siName("si-name")
116-
.registrationAuthorityId("registration-authority-id")
117-
.siNotation("si-notation")
118-
.sourceOfDefinition("source-of-definition")
119-
.supplier("supplier")
120-
.unitName("unit-name")
121-
.unitSymbol("unit-symbol")
122-
.build())
101+
// .dataSpecificationContent(new DefaultDataSpecificationPhysicalUnit.Builder()
102+
// .conversionFactor("1.0")
103+
// .eceCode("ece-code")
104+
// .eceName("ece-name")
105+
// .definition(new DefaultLangString.Builder()
106+
// .language("en")
107+
// .text("definition-en")
108+
// .build())
109+
// .definition(new DefaultLangString.Builder()
110+
// .language("de")
111+
// .text("definition-de")
112+
// .build())
113+
// .nistName("nist-name")
114+
// .dinNotation("din-notation")
115+
// .siName("si-name")
116+
// .registrationAuthorityId("registration-authority-id")
117+
// .siNotation("si-notation")
118+
// .sourceOfDefinition("source-of-definition")
119+
// .supplier("supplier")
120+
// .unitName("unit-name")
121+
// .unitSymbol("unit-symbol")
122+
// .build())
123123
.build())
124124
.build(),
125125
"ConceptDescription-DataSpecificationPhysicalUnit.json");

dataformat-xml/pom.xml

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,4 @@
5858
<scope>test</scope>
5959
</dependency>
6060
</dependencies>
61-
62-
<!-- TODO: Remove this part when the XML tests have been fixed! -->
63-
<build>
64-
<plugins>
65-
<plugin>
66-
<groupId>org.apache.maven.plugins</groupId>
67-
<artifactId>maven-surefire-plugin</artifactId>
68-
<version>2.22.2</version>
69-
<configuration>
70-
<skipTests>true</skipTests>
71-
</configuration>
72-
</plugin>
73-
</plugins>
74-
</build>
7561
</project>

dataformat-xml/src/main/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/xml/AasXmlNamespaceContext.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,13 @@ public class AasXmlNamespaceContext {
2424
public static final String AAS_PREFERRED_PREFIX = "aas";
2525
public static final String AAS_URI = "https://admin-shell.io/aas/3/0/RC02";
2626

27-
public static final String ABAC_PREFERRED_PREFIX = "abac";
28-
public static final String ABAC_URI = "http://www.admin-shell.io/aas/abac/3/0";
29-
30-
public static final String COMMON_PREFERRED_PREFIX = "aas_common";
31-
public static final String COMMON_URI = "http://www.admin-shell.io/aas_common/3/0";
32-
33-
public static final String IEC61360_PREFERRED_PREFIX = "IEC61360";
34-
public static final String IEC61360_URI = "http://www.admin-shell.io/IEC61360/3/0";
35-
3627
public static final String XSI_PREFERRED_PREFIX = "xsi";
3728
public static final String XSI_URI = "http://www.w3.org/2001/XMLSchema-instance";
3829

3930
public static final Map<String, String> PREFERRED_PREFIX_CONTEXT = new HashMap<>();
4031

4132
static {
4233
PREFERRED_PREFIX_CONTEXT.put(AAS_PREFERRED_PREFIX, AAS_URI);
43-
PREFERRED_PREFIX_CONTEXT.put(ABAC_PREFERRED_PREFIX, ABAC_URI);
44-
PREFERRED_PREFIX_CONTEXT.put(COMMON_PREFERRED_PREFIX, COMMON_URI);
45-
PREFERRED_PREFIX_CONTEXT.put(IEC61360_PREFERRED_PREFIX, IEC61360_URI);
4634
PREFERRED_PREFIX_CONTEXT.put(XSI_PREFERRED_PREFIX, XSI_URI);
4735
}
4836

dataformat-xml/src/main/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/xml/SubmodelElementManager.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public class SubmodelElementManager {
4343
CLASS_TO_NAME.put(DefaultOperationVariable.class, "operationVariable");
4444
CLASS_TO_NAME.put(DefaultLangString.class, "langString");
4545
CLASS_TO_NAME.put(DefaultSubmodelElementCollection.class, "submodelElementCollection");
46+
CLASS_TO_NAME.put(DefaultSubmodelElementList.class, "submodelElementList");
4647
NAME_TO_CLASS = CLASS_TO_NAME.entrySet().stream().collect(Collectors.toMap(x -> x.getValue(), x -> x.getKey()));
4748
}
4849

dataformat-xml/src/main/java/org/eclipse/digitaltwin/aas4j/v3/dataformat/xml/XmlDataformatAnnotationIntrospector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public String[] findSerializationPropertyOrder(AnnotatedClass ac) {
5959
String[] order = super.findSerializationPropertyOrder(ac);
6060
if (order == null) {
6161
order = new String[] {
62-
"extensions", "idShort", "displayNames", "category", "descriptions", "administration", "identification", "kind", "semanticId",
62+
"extensions", "idShort", "displayName", "category", "description", "administration", "identification", "kind", "semanticId",
6363
"qualifiers", "embeddedDataSpecification", "dataSpecifications", "isCaseOf", "security", "derivedFrom", "submodels", "assetInformation", "views", "externalSubjectId", "key", "allowDuplicates", "ordered", "valueId", "value",
6464
"max", "min", "type", "valueType", "mimeType", "first", "second", "annotations", "revision", "version", "defaultThumbnail", "globalAssetId", "externalAssetId", "entityType", "statements", "assetKind", "billOfMaterials",
6565
"specificAssetIds", "observed", "inoutputVariables", "inputVariables", "outputVariables", "submodelElements", "containedElements"

0 commit comments

Comments
 (0)