Skip to content
This repository was archived by the owner on Feb 15, 2024. It is now read-only.

Commit e35c677

Browse files
committed
Adding the IAIS validation shapes
1 parent b6ff0ca commit e35c677

13 files changed

Lines changed: 1087 additions & 33 deletions

File tree

validator/src/main/resources/constraint_shapes.ttl

Lines changed: 246 additions & 31 deletions
Large diffs are not rendered by default.

validator/src/main/resources/ontology.ttl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1664,6 +1664,7 @@ aas:Extension rdf:type owl:Class ;
16641664

16651665
### https://admin-shell.io/aas/3/0/RC01/Referable
16661666
aas:Referable rdf:type owl:Class ;
1667+
rdfs:subClassOf aas:HasExtensions ;
16671668
dash:abstract true ;
16681669
rdfs:comment "An element that is referable by its idShort. This id is not globally unique. This id is unique within the name space of the element."@en ;
16691670
rdfs:label "Referable"^^xsd:string ;

validator/src/main/resources/shapes.ttl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1422,9 +1422,7 @@ aas:ReferableShape a sh:NodeShape ;
14221422
sh:datatype xsd:string ;
14231423
sh:maxCount 1 ;
14241424
sh:minCount 1 ;
1425-
sh:pattern ".+" ;
14261425
sh:message "(Referable.idShort): Exactly one <id>idShort</id> is required."^^xsd:string ;
1427-
sh:pattern "^[a-zA-Z]\\w*$"^^xsd:string ;
14281426
] ;
14291427
.
14301428

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*******************************************************************************
2+
* Copyright (C) 2021 the Eclipse BaSyx Authors
3+
*
4+
* This program and the accompanying materials are made
5+
* available under the terms of the Eclipse Public License 2.0
6+
* which is available at https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
******************************************************************************/
10+
11+
package io.adminshell.aas.v3.model.validator;
12+
13+
import io.adminshell.aas.v3.model.AdministrativeInformation;
14+
import io.adminshell.aas.v3.model.Referable;
15+
import io.adminshell.aas.v3.model.Submodel;
16+
import io.adminshell.aas.v3.model.impl.DefaultAdministrativeInformation;
17+
import org.junit.Test;
18+
19+
import java.util.ArrayList;
20+
import java.util.Arrays;
21+
22+
import static org.junit.Assert.assertTrue;
23+
import static org.junit.Assert.fail;
24+
25+
/**
26+
* Tests the following constraint:
27+
* <p>
28+
* <i> idShort of Referables shall only feature letters, digits, underscore ("_");
29+
* starting mandatory with a letter. I.e. [a-zA-Z][a-zA-Z0-9_]+. </i>
30+
* </p>
31+
*
32+
* @author bader, chang
33+
*
34+
*/
35+
public class TestAASd_002 {
36+
@Test
37+
public void idShortWithNotAllowedCharacters() throws ValidationException {
38+
Referable wrongReferable = ConstraintTestHelper.createSubmodel(new ArrayList<>());
39+
wrongReferable.setIdShort("_idShort");
40+
41+
try {
42+
ShaclValidator.getInstance().validate(wrongReferable);
43+
fail();
44+
} catch (ValidationException e) {
45+
assertTrue(e.getMessage().endsWith("starting mandatory with a letter. I.e. [a-zA-Z][a-zA-Z0-9_]+."));
46+
}
47+
48+
wrongReferable.setIdShort("0idShort");
49+
try {
50+
ShaclValidator.getInstance().validate(wrongReferable);
51+
fail();
52+
} catch (ValidationException e) {
53+
assertTrue(e.getMessage().endsWith("starting mandatory with a letter. I.e. [a-zA-Z][a-zA-Z0-9_]+."));
54+
}
55+
56+
wrongReferable.setIdShort("");
57+
try {
58+
ShaclValidator.getInstance().validate(wrongReferable);
59+
fail();
60+
} catch (ValidationException e) {
61+
assertTrue(e.getMessage().endsWith("starting mandatory with a letter. I.e. [a-zA-Z][a-zA-Z0-9_]+."));
62+
}
63+
64+
wrongReferable.setIdShort("%");
65+
try {
66+
ShaclValidator.getInstance().validate(wrongReferable);
67+
fail();
68+
} catch (ValidationException e) {
69+
assertTrue(e.getMessage().endsWith("starting mandatory with a letter. I.e. [a-zA-Z][a-zA-Z0-9_]+."));
70+
}
71+
}
72+
73+
@Test
74+
public void idShortWithAllowedCharacters() throws ValidationException {
75+
Referable referable = ConstraintTestHelper.createSubmodel(new ArrayList<>());
76+
referable.setIdShort("id_Short");
77+
ShaclValidator.getInstance().validate(referable);
78+
}
79+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*******************************************************************************
2+
* Copyright (C) 2021 the Eclipse BaSyx Authors
3+
*
4+
* This program and the accompanying materials are made
5+
* available under the terms of the Eclipse Public License 2.0
6+
* which is available at https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
******************************************************************************/
10+
11+
package io.adminshell.aas.v3.model.validator;
12+
13+
import io.adminshell.aas.v3.model.Referable;
14+
import io.adminshell.aas.v3.model.impl.DefaultSubmodel;
15+
import org.junit.Test;
16+
17+
import java.util.ArrayList;
18+
19+
import static org.junit.Assert.assertTrue;
20+
import static org.junit.Assert.fail;
21+
22+
/**
23+
* Tests the following constraint:
24+
* <p>
25+
* <i> idShort shall be matched case-insensitive. </i>
26+
* </p>
27+
*
28+
* @author bader, chang
29+
*
30+
*/
31+
public class TestAASd_003 {
32+
@Test
33+
public void idShortMatchCaseInsensitive() throws ValidationException {
34+
DefaultSubmodel smA = (DefaultSubmodel) ConstraintTestHelper.createSubmodel(new ArrayList<>());
35+
smA.setIdShort("idShort");
36+
37+
Referable smB = (DefaultSubmodel) ConstraintTestHelper.createSubmodel(new ArrayList<>());
38+
smB.setIdShort("IDSHORT");
39+
40+
// assertTrue(smA.equals(smB)); // TODO: should be true
41+
42+
}
43+
44+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*******************************************************************************
2+
* Copyright (C) 2021 the Eclipse BaSyx Authors
3+
*
4+
* This program and the accompanying materials are made
5+
* available under the terms of the Eclipse Public License 2.0
6+
* which is available at https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
******************************************************************************/
10+
11+
package io.adminshell.aas.v3.model.validator;
12+
13+
import io.adminshell.aas.v3.model.Qualifier;
14+
import io.adminshell.aas.v3.model.Referable;
15+
import io.adminshell.aas.v3.model.Reference;
16+
import io.adminshell.aas.v3.model.impl.DefaultQualifier;
17+
import org.junit.Test;
18+
19+
import java.util.ArrayList;
20+
21+
import static org.junit.Assert.assertTrue;
22+
import static org.junit.Assert.fail;
23+
24+
/**
25+
* Tests the following constraint:
26+
* <p>
27+
* <i> If both, the value and the valueId of a Qualifier are present then the value needs to be identical to the value
28+
* of the referenced coded value in Qualifier/valueId. </i>
29+
* </p>
30+
*
31+
* @author bader, chang
32+
*
33+
*/
34+
public class TestAASd_006 {
35+
@Test
36+
public void missmatchingValueAndValueId() throws ValidationException {
37+
38+
Reference reference = ConstraintTestHelper.createDummyReference();
39+
reference.getKeys().get(0).setValue("http://example.org/someRef");
40+
41+
Qualifier wrongQualifier = new DefaultQualifier.Builder()
42+
.value("http://example.org")
43+
.valueType("string")
44+
.valueId(reference)
45+
.type("REFERENCE")
46+
.build();
47+
48+
try {
49+
ShaclValidator.getInstance().validate(wrongQualifier);
50+
fail();
51+
} catch (ValidationException e) {
52+
assertTrue(e.getMessage().endsWith(
53+
"If both, the value and the valueId of a Qualifier are present then the value needs to be identical " +
54+
"to the value of the referenced coded value in Qualifier/valueId."));
55+
}
56+
57+
58+
}
59+
60+
@Test
61+
public void matchingValueAndValueId() throws ValidationException {
62+
Reference reference = ConstraintTestHelper.createDummyReference();
63+
reference.getKeys().get(0).setValue("http://example.org");
64+
65+
Qualifier qualifier = new DefaultQualifier.Builder()
66+
.value("http://example.org")
67+
.valueType("string")
68+
.valueId(reference)
69+
.type("REFERENCE")
70+
.build();
71+
72+
ShaclValidator.getInstance().validate(qualifier);
73+
74+
}
75+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*******************************************************************************
2+
* Copyright (C) 2021 the Eclipse BaSyx Authors
3+
*
4+
* This program and the accompanying materials are made
5+
* available under the terms of the Eclipse Public License 2.0
6+
* which is available at https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
******************************************************************************/
10+
11+
package io.adminshell.aas.v3.model.validator;
12+
13+
import io.adminshell.aas.v3.model.Property;
14+
import io.adminshell.aas.v3.model.Qualifier;
15+
import io.adminshell.aas.v3.model.Reference;
16+
import io.adminshell.aas.v3.model.impl.DefaultProperty;
17+
import io.adminshell.aas.v3.model.impl.DefaultQualifier;
18+
import org.junit.Test;
19+
20+
import static org.junit.Assert.assertTrue;
21+
import static org.junit.Assert.fail;
22+
23+
/**
24+
* Tests the following constraint:
25+
* <p>
26+
* <i> If both, the Property/value and the Property/valueId are present then the value of Property/value needs to be
27+
* identical to the value of the referenced coded value in Property/valueId. </i>
28+
* </p>
29+
*
30+
* @author bader, chang
31+
*
32+
*/
33+
public class TestAASd_007 {
34+
@Test
35+
public void missmatchingValueAndValueId() throws ValidationException {
36+
37+
Reference reference = ConstraintTestHelper.createDummyReference();
38+
reference.getKeys().get(0).setValue("http://example.org/someRef");
39+
40+
Property wrongProperty = new DefaultProperty.Builder()
41+
.idShort("idShort")
42+
.value("http://example.org")
43+
.valueType("string")
44+
.valueId(reference)
45+
.build();
46+
47+
try {
48+
ShaclValidator.getInstance().validate(wrongProperty);
49+
fail();
50+
} catch (ValidationException e) {
51+
assertTrue(e.getMessage().endsWith(
52+
"If both, the Property/value and the Property/valueId are present then the value of Property/value " +
53+
"needs to be identical to the value of the referenced coded value in Property/valueId."));
54+
}
55+
56+
57+
}
58+
59+
@Test
60+
public void matchingValueAndValueId() throws ValidationException {
61+
Reference reference = ConstraintTestHelper.createDummyReference();
62+
reference.getKeys().get(0).setValue("http://example.org");
63+
64+
Property property = new DefaultProperty.Builder()
65+
.idShort("idShort")
66+
.value("http://example.org")
67+
.valueType("string")
68+
.valueId(reference)
69+
.build();
70+
71+
ShaclValidator.getInstance().validate(property);
72+
73+
}
74+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*******************************************************************************
2+
* Copyright (C) 2021 the Eclipse BaSyx Authors
3+
*
4+
* This program and the accompanying materials are made
5+
* available under the terms of the Eclipse Public License 2.0
6+
* which is available at https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
******************************************************************************/
10+
11+
package io.adminshell.aas.v3.model.validator;
12+
13+
import io.adminshell.aas.v3.model.ModelingKind;
14+
import io.adminshell.aas.v3.model.Operation;
15+
import io.adminshell.aas.v3.model.Property;
16+
import io.adminshell.aas.v3.model.Reference;
17+
import io.adminshell.aas.v3.model.impl.DefaultOperation;
18+
import io.adminshell.aas.v3.model.impl.DefaultProperty;
19+
import org.junit.Test;
20+
21+
import static org.junit.Assert.assertTrue;
22+
import static org.junit.Assert.fail;
23+
24+
/**
25+
* Tests the following constraint:
26+
* <p>
27+
* <i> The submodel element value of an operation variable shall be of kind=Template. </i>
28+
* </p>
29+
*
30+
* @author bader, chang
31+
*
32+
*/
33+
public class TestAASd_008 {
34+
@Test
35+
public void wrongKind() throws ValidationException {
36+
37+
Operation wrongOperation = new DefaultOperation.Builder()
38+
.idShort("idShort")
39+
.kind(ModelingKind.INSTANCE)
40+
.build();
41+
42+
try {
43+
ShaclValidator.getInstance().validate(wrongOperation);
44+
fail();
45+
} catch (ValidationException e) {
46+
assertTrue(e.getMessage().endsWith(
47+
"The submodel element value of an operation variable shall be of kind=Template."));
48+
}
49+
50+
51+
}
52+
53+
@Test
54+
public void correctKind() throws ValidationException {
55+
56+
Operation operation = new DefaultOperation.Builder()
57+
.idShort("idShort")
58+
.kind(ModelingKind.TEMPLATE)
59+
.build();
60+
61+
ShaclValidator.getInstance().validate(operation);
62+
63+
}
64+
}

0 commit comments

Comments
 (0)