This repository has been archived by the owner on Feb 15, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
1,087 additions
and
33 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
validator/src/test/java/io/adminshell/aas/v3/model/validator/TestAASd_002.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
validator/src/test/java/io/adminshell/aas/v3/model/validator/TestAASd_003.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
||
} | ||
|
||
} |
75 changes: 75 additions & 0 deletions
75
validator/src/test/java/io/adminshell/aas/v3/model/validator/TestAASd_006.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
|
||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
validator/src/test/java/io/adminshell/aas/v3/model/validator/TestAASd_007.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
|
||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
validator/src/test/java/io/adminshell/aas/v3/model/validator/TestAASd_008.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
|
||
} | ||
} |
Oops, something went wrong.