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

Commit

Permalink
Adding the IAIS validation shapes
Browse files Browse the repository at this point in the history
  • Loading branch information
sebbader committed Aug 26, 2021
1 parent b6ff0ca commit e35c677
Show file tree
Hide file tree
Showing 13 changed files with 1,087 additions and 33 deletions.
277 changes: 246 additions & 31 deletions validator/src/main/resources/constraint_shapes.ttl

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions validator/src/main/resources/ontology.ttl
Expand Up @@ -1664,6 +1664,7 @@ aas:Extension rdf:type owl:Class ;

### https://admin-shell.io/aas/3/0/RC01/Referable
aas:Referable rdf:type owl:Class ;
rdfs:subClassOf aas:HasExtensions ;
dash:abstract true ;
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 ;
rdfs:label "Referable"^^xsd:string ;
Expand Down
2 changes: 0 additions & 2 deletions validator/src/main/resources/shapes.ttl
Expand Up @@ -1422,9 +1422,7 @@ aas:ReferableShape a sh:NodeShape ;
sh:datatype xsd:string ;
sh:maxCount 1 ;
sh:minCount 1 ;
sh:pattern ".+" ;
sh:message "(Referable.idShort): Exactly one <id>idShort</id> is required."^^xsd:string ;
sh:pattern "^[a-zA-Z]\\w*$"^^xsd:string ;
] ;
.

Expand Down
@@ -0,0 +1,79 @@
/*******************************************************************************
* Copyright (C) 2021 the Eclipse BaSyx Authors
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
******************************************************************************/

package io.adminshell.aas.v3.model.validator;

import io.adminshell.aas.v3.model.AdministrativeInformation;
import io.adminshell.aas.v3.model.Referable;
import io.adminshell.aas.v3.model.Submodel;
import io.adminshell.aas.v3.model.impl.DefaultAdministrativeInformation;
import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

/**
* Tests the following constraint:
* <p>
* <i> idShort of Referables shall only feature letters, digits, underscore ("_");
* starting mandatory with a letter. I.e. [a-zA-Z][a-zA-Z0-9_]+. </i>
* </p>
*
* @author bader, chang
*
*/
public class TestAASd_002 {
@Test
public void idShortWithNotAllowedCharacters() throws ValidationException {
Referable wrongReferable = ConstraintTestHelper.createSubmodel(new ArrayList<>());
wrongReferable.setIdShort("_idShort");

try {
ShaclValidator.getInstance().validate(wrongReferable);
fail();
} catch (ValidationException e) {
assertTrue(e.getMessage().endsWith("starting mandatory with a letter. I.e. [a-zA-Z][a-zA-Z0-9_]+."));
}

wrongReferable.setIdShort("0idShort");
try {
ShaclValidator.getInstance().validate(wrongReferable);
fail();
} catch (ValidationException e) {
assertTrue(e.getMessage().endsWith("starting mandatory with a letter. I.e. [a-zA-Z][a-zA-Z0-9_]+."));
}

wrongReferable.setIdShort("");
try {
ShaclValidator.getInstance().validate(wrongReferable);
fail();
} catch (ValidationException e) {
assertTrue(e.getMessage().endsWith("starting mandatory with a letter. I.e. [a-zA-Z][a-zA-Z0-9_]+."));
}

wrongReferable.setIdShort("%");
try {
ShaclValidator.getInstance().validate(wrongReferable);
fail();
} catch (ValidationException e) {
assertTrue(e.getMessage().endsWith("starting mandatory with a letter. I.e. [a-zA-Z][a-zA-Z0-9_]+."));
}
}

@Test
public void idShortWithAllowedCharacters() throws ValidationException {
Referable referable = ConstraintTestHelper.createSubmodel(new ArrayList<>());
referable.setIdShort("id_Short");
ShaclValidator.getInstance().validate(referable);
}
}
@@ -0,0 +1,44 @@
/*******************************************************************************
* Copyright (C) 2021 the Eclipse BaSyx Authors
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
******************************************************************************/

package io.adminshell.aas.v3.model.validator;

import io.adminshell.aas.v3.model.Referable;
import io.adminshell.aas.v3.model.impl.DefaultSubmodel;
import org.junit.Test;

import java.util.ArrayList;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

/**
* Tests the following constraint:
* <p>
* <i> idShort shall be matched case-insensitive. </i>
* </p>
*
* @author bader, chang
*
*/
public class TestAASd_003 {
@Test
public void idShortMatchCaseInsensitive() throws ValidationException {
DefaultSubmodel smA = (DefaultSubmodel) ConstraintTestHelper.createSubmodel(new ArrayList<>());
smA.setIdShort("idShort");

Referable smB = (DefaultSubmodel) ConstraintTestHelper.createSubmodel(new ArrayList<>());
smB.setIdShort("IDSHORT");

// assertTrue(smA.equals(smB)); // TODO: should be true

}

}
@@ -0,0 +1,75 @@
/*******************************************************************************
* Copyright (C) 2021 the Eclipse BaSyx Authors
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
******************************************************************************/

package io.adminshell.aas.v3.model.validator;

import io.adminshell.aas.v3.model.Qualifier;
import io.adminshell.aas.v3.model.Referable;
import io.adminshell.aas.v3.model.Reference;
import io.adminshell.aas.v3.model.impl.DefaultQualifier;
import org.junit.Test;

import java.util.ArrayList;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

/**
* Tests the following constraint:
* <p>
* <i> If both, the value and the valueId of a Qualifier are present then the value needs to be identical to the value
* of the referenced coded value in Qualifier/valueId. </i>
* </p>
*
* @author bader, chang
*
*/
public class TestAASd_006 {
@Test
public void missmatchingValueAndValueId() throws ValidationException {

Reference reference = ConstraintTestHelper.createDummyReference();
reference.getKeys().get(0).setValue("http://example.org/someRef");

Qualifier wrongQualifier = new DefaultQualifier.Builder()
.value("http://example.org")
.valueType("string")
.valueId(reference)
.type("REFERENCE")
.build();

try {
ShaclValidator.getInstance().validate(wrongQualifier);
fail();
} catch (ValidationException e) {
assertTrue(e.getMessage().endsWith(
"If both, the value and the valueId of a Qualifier are present then the value needs to be identical " +
"to the value of the referenced coded value in Qualifier/valueId."));
}


}

@Test
public void matchingValueAndValueId() throws ValidationException {
Reference reference = ConstraintTestHelper.createDummyReference();
reference.getKeys().get(0).setValue("http://example.org");

Qualifier qualifier = new DefaultQualifier.Builder()
.value("http://example.org")
.valueType("string")
.valueId(reference)
.type("REFERENCE")
.build();

ShaclValidator.getInstance().validate(qualifier);

}
}
@@ -0,0 +1,74 @@
/*******************************************************************************
* Copyright (C) 2021 the Eclipse BaSyx Authors
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
******************************************************************************/

package io.adminshell.aas.v3.model.validator;

import io.adminshell.aas.v3.model.Property;
import io.adminshell.aas.v3.model.Qualifier;
import io.adminshell.aas.v3.model.Reference;
import io.adminshell.aas.v3.model.impl.DefaultProperty;
import io.adminshell.aas.v3.model.impl.DefaultQualifier;
import org.junit.Test;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

/**
* Tests the following constraint:
* <p>
* <i> If both, the Property/value and the Property/valueId are present then the value of Property/value needs to be
* identical to the value of the referenced coded value in Property/valueId. </i>
* </p>
*
* @author bader, chang
*
*/
public class TestAASd_007 {
@Test
public void missmatchingValueAndValueId() throws ValidationException {

Reference reference = ConstraintTestHelper.createDummyReference();
reference.getKeys().get(0).setValue("http://example.org/someRef");

Property wrongProperty = new DefaultProperty.Builder()
.idShort("idShort")
.value("http://example.org")
.valueType("string")
.valueId(reference)
.build();

try {
ShaclValidator.getInstance().validate(wrongProperty);
fail();
} catch (ValidationException e) {
assertTrue(e.getMessage().endsWith(
"If both, the Property/value and the Property/valueId are present then the value of Property/value " +
"needs to be identical to the value of the referenced coded value in Property/valueId."));
}


}

@Test
public void matchingValueAndValueId() throws ValidationException {
Reference reference = ConstraintTestHelper.createDummyReference();
reference.getKeys().get(0).setValue("http://example.org");

Property property = new DefaultProperty.Builder()
.idShort("idShort")
.value("http://example.org")
.valueType("string")
.valueId(reference)
.build();

ShaclValidator.getInstance().validate(property);

}
}
@@ -0,0 +1,64 @@
/*******************************************************************************
* Copyright (C) 2021 the Eclipse BaSyx Authors
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
******************************************************************************/

package io.adminshell.aas.v3.model.validator;

import io.adminshell.aas.v3.model.ModelingKind;
import io.adminshell.aas.v3.model.Operation;
import io.adminshell.aas.v3.model.Property;
import io.adminshell.aas.v3.model.Reference;
import io.adminshell.aas.v3.model.impl.DefaultOperation;
import io.adminshell.aas.v3.model.impl.DefaultProperty;
import org.junit.Test;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

/**
* Tests the following constraint:
* <p>
* <i> The submodel element value of an operation variable shall be of kind=Template. </i>
* </p>
*
* @author bader, chang
*
*/
public class TestAASd_008 {
@Test
public void wrongKind() throws ValidationException {

Operation wrongOperation = new DefaultOperation.Builder()
.idShort("idShort")
.kind(ModelingKind.INSTANCE)
.build();

try {
ShaclValidator.getInstance().validate(wrongOperation);
fail();
} catch (ValidationException e) {
assertTrue(e.getMessage().endsWith(
"The submodel element value of an operation variable shall be of kind=Template."));
}


}

@Test
public void correctKind() throws ValidationException {

Operation operation = new DefaultOperation.Builder()
.idShort("idShort")
.kind(ModelingKind.TEMPLATE)
.build();

ShaclValidator.getInstance().validate(operation);

}
}

0 comments on commit e35c677

Please sign in to comment.