Skip to content

Commit

Permalink
Merge branch 'main' into bug/clarify-usage-abstractentity-as-datatype
Browse files Browse the repository at this point in the history
  • Loading branch information
Yauhenikapl authored Jan 22, 2024
2 parents 30d9009 + 5c77e72 commit d2e140f
Show file tree
Hide file tree
Showing 13 changed files with 171 additions and 77 deletions.
15 changes: 7 additions & 8 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.
**How: List of performed steps**

**Where**
Indicate the location of the bug (e.g., in which document, section and paragraph you found the bug).
**What: Actual result vs expected result**

**Screenshots**
If applicable, add screenshots to help explain your problem.
**Where: (e.g. component, version, url, your system info)**

**Input (files/screenshots)**

**Additional context**
Add any other context about the problem here.
**Output (files/screenshots)**

**Additional context (e.g. references)**
5 changes: 5 additions & 0 deletions documentation/modules/ROOT/pages/characteristics.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,11 @@ At least one of `samm-c:maxValue` or `samm-c:minValue` must be present in a Leng
| `samm-c:minValue` | The minimum length. Must be given as `xsd:nonNegativeInteger`. | {nok}
|===

IMPORTANT: When using the `samm-c:minValue` parameter in Length Constraint, it is crucial to consider the following:
* Creating a Model with a <<set-characteristic>>/<<sorted-set-characteristic>> based on a finite Base Characteristic (<<boolean-characteristic>> or <<enumeration-characteristic>>)
and adding Length Constraint, the `samm-c:minValue` must not exceed the total number of elements in the Base Characteristic.
Models with such conditions are not recognized as invalid, but no valid payloads can exist for them.

[[regular-expression-constraint]]
=== Regular Expression Constraint
[.element-urn]
Expand Down
13 changes: 10 additions & 3 deletions documentation/modules/appendix/pages/best-practices.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,16 @@ range, while a Property such as `numberOfProducedItems` is not logically limited
[[choosing-a-unit]]
== Choosing a Unit

When trying to refer to a physical unit, please see the
xref:appendix:unitcatalog.adoc[Unit Catalog]. When searching for the unit,
remember that the unit catalog uses British English.
When trying to refer to a physical unit, please see the xref:appendix:unitcatalog.adoc[Unit
Catalog]. When searching for the unit, remember that the unit catalog uses British English, e.g.,
_metre_ instead of _meter_.

TIP: If you're modeling quantities for which both the metric system and the imperial system provide
units, such as meter vs feet, it is always recommended to use the metric system (preferably SI units
like meter or others like kilometer if more common in the domain) – unless there are specific
reasons to create the model differently. In any case it is strongly discouraged to add multiple
Properties in the same scope representing the same value only using different units due to the
inherent complexity.

[[choosing-a-characteristic]]
== Choosing a Characteristic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,18 @@ samm:ConstraintShape
sh:maxCount 0 ;
sh:name "dataType" ;
sh:description "A Constraint may not change the data type of the Characteristic being constrained." ;
] ;
sh:sparql [
a sh:SPARQLConstraint ;
sh:message "Constraint '{$this}' has invalid type samm:Constraint, only subtypes of samm:Constraint may be used." ;
sh:prefixes samm:prefixDeclarations ;
sh:select """
select $this ?message ?code
where {
$this rdf:type samm:Constraint .
bind( 'ERR_WRONG_DATATYPE' as ?code )
}
"""
] .

samm:OperationShape
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ protected static Stream<KnownVersion> versionsUpToIncluding1_0_0() {
final String messageInvalidLangString = "Value must be a valid literal of type langString";
final String messageDuplicateProperty = "Property may only have 1 value, but found 2";
final String messageMissingDatatype = "No datatype is defined on the Characteristic instance '{$this}'.";

final String messageHasToUseSubClass = "Constraint '{$this}' has invalid type samm:Constraint, only subtypes of samm:Constraint may be used.";
final String messageInvalidEntryEntityPropertyList =
"Element '{?value}' in the Entity's '{$this}' properties list must be a property - either directly or " +
"via a reference to a property with an attribute samm:optional \"true\"^^xsd:boolean and/or samm:payloadName or "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,65 +20,16 @@

public class ConstraintShapeTest extends AbstractShapeTest {
@ParameterizedTest
@MethodSource( value = "allVersions" )
public void testConstraintValidationExpectSuccess( final KnownVersion metaModelVersion ) {
checkValidity( "constraint-shape", "TestConstraint", metaModelVersion );
}

@ParameterizedTest
@MethodSource( value = "allVersions" )
public void testEmptyPropertiesExpectFailure2( final KnownVersion metaModelVersion ) {
final SammUrns sammUrns = new SammUrns( metaModelVersion );

final String constraintName = "TestConstraintWithEmptyProperties";
final String constraintId = testNamespacePrefix + constraintName;
final SemanticError resultForPreferredName = new SemanticError( messageEmptyProperty,
constraintId, sammUrns.preferredNameUrn, violationUrn, "@en" );
final SemanticError resultForDescription = new SemanticError( messageEmptyProperty,
constraintId, sammUrns.descriptionUrn, violationUrn, "@en" );
expectSemanticValidationErrors( "constraint-shape", constraintName,
metaModelVersion, resultForPreferredName, resultForDescription );
}

@ParameterizedTest
@MethodSource( value = "allVersions" )
public void testLanguageStringNotUniqueExpectFailure( final KnownVersion metaModelVersion ) {
final SammUrns sammUrns = new SammUrns( metaModelVersion );
@MethodSource( value = "versionsStartingWith2_2_0")
public void testConstraintWithoutProperties ( final KnownVersion metaModelVersion) {

final String constraintName = "TestConstraintNonUniqueLangStrings";
final String constraintName = "TestConstraintWithoutProperties";
final String constraintId = testNamespacePrefix + constraintName;
final SemanticError resultForPreferredName = new SemanticError( messageLangNotUnique,
constraintId, sammUrns.preferredNameUrn, violationUrn, "" );
final SemanticError resultForDescription = new SemanticError( messageLangNotUnique,
constraintId, sammUrns.descriptionUrn, violationUrn, "" );
expectSemanticValidationErrors( "constraint-shape", constraintName, metaModelVersion, resultForPreferredName,
resultForDescription );
}

@ParameterizedTest
@MethodSource( value = "allVersions" )
public void testInvalidLanguageStringsExpectFailure( final KnownVersion metaModelVersion ) {
final SammUrns sammUrns = new SammUrns( metaModelVersion );

final String constraintName = "TestConstraintWithInvalidLangStrings";
final String constraintId = testNamespacePrefix + constraintName;
final SemanticError resultForPreferredName = new SemanticError(
messageInvalidLangString, constraintId, sammUrns.preferredNameUrn, violationUrn, "Test Constraint" );
final SemanticError resultForDescription = new SemanticError(
messageInvalidLangString, constraintId, sammUrns.descriptionUrn, violationUrn, "TestConstraint" );
expectSemanticValidationErrors( "constraint-shape", constraintName,
metaModelVersion, resultForPreferredName, resultForDescription );
}
final String value = testNamespacePrefix + constraintName;

@ParameterizedTest
@MethodSource( value = "allVersions" )
public void testConstraintDefinesDataTypeExpectFailure( final KnownVersion metaModelVersion ) {
final SammUrns sammUrns = new SammUrns( metaModelVersion );
final SemanticError resultForEmptyConstraint = new SemanticError( messageHasToUseSubClass,
constraintId, "", violationUrn, value);

final String constraintName = "TestConstraintWithDataType";
final String constraintId = testNamespacePrefix + constraintName;
final SemanticError resultForDataType = new SemanticError( messageMoreThanZeroValues, constraintId,
sammUrns.datatypeUrn, violationUrn, "" );
expectSemanticValidationErrors( "constraint-shape", constraintName, metaModelVersion, resultForDataType );
expectSemanticValidationErrors( "constraint-shape", constraintName, metaModelVersion, resultForEmptyConstraint );
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH
*
* See the AUTHORS file(s) distributed with this work for additional
* information regarding authorship.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* SPDX-License-Identifier: MPL-2.0
*/

package org.eclipse.esmf.samm;

import org.eclipse.esmf.samm.validation.SemanticError;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

/**
* Moved tests from the 'constraint-shape' to 'constraint-subclass-core' directory for improved code organization.
* The 'constraint-subclass-core' directory now specifically accommodates tests related to the base functionality implemented in one of the subclasses (LengthConstraint) of the parent class (Constraint).
* From version 2.2.0.
*/

public class ConstraintSubClassCoreTest extends AbstractShapeTest {
@ParameterizedTest
@MethodSource( value = "versionsStartingWith2_2_0" )
public void testConstraintValidationExpectSuccess( final KnownVersion metaModelVersion ) {
checkValidity( "constraint-subclass-core", "TestConstraint", metaModelVersion );
}

@ParameterizedTest
@MethodSource( value = "versionsStartingWith2_2_0" )
public void testLanguageStringNotUniqueExpectFailure( final KnownVersion metaModelVersion ) {
final SammUrns sammUrns = new SammUrns( metaModelVersion );

final String constraintName = "TestConstraintNonUniqueLangStrings";
final String constraintId = testNamespacePrefix + constraintName;
final SemanticError resultForPreferredName = new SemanticError( messageLangNotUnique,
constraintId, sammUrns.preferredNameUrn, violationUrn, "" );
final SemanticError resultForDescription = new SemanticError( messageLangNotUnique,
constraintId, sammUrns.descriptionUrn, violationUrn, "" );
expectSemanticValidationErrors( "constraint-subclass-core", constraintName, metaModelVersion, resultForPreferredName,
resultForDescription );
}

@ParameterizedTest
@MethodSource( value = "versionsStartingWith2_2_0" )
public void testConstraintDefinesDataTypeExpectFailure( final KnownVersion metaModelVersion ) {
final SammUrns sammUrns = new SammUrns( metaModelVersion );

final String constraintName = "TestConstraintWithDataType";
final String constraintId = testNamespacePrefix + constraintName;
final SemanticError resultForDataType = new SemanticError( messageMoreThanZeroValues, constraintId,
sammUrns.datatypeUrn, violationUrn, "" );
expectSemanticValidationErrors( "constraint-subclass-core", constraintName, metaModelVersion, resultForDataType );
}

@ParameterizedTest
@MethodSource( value = "versionsStartingWith2_2_0" )
public void testEmptyPropertiesExpectFailure2( final KnownVersion metaModelVersion ) {
final SammUrns sammUrns = new SammUrns( metaModelVersion );

final String constraintName = "TestConstraintWithEmptyProperties";
final String constraintId = testNamespacePrefix + constraintName;
final SemanticError resultForPreferredName = new SemanticError( messageEmptyProperty,
constraintId, sammUrns.preferredNameUrn, violationUrn, "@en" );
final SemanticError resultForDescription = new SemanticError( messageEmptyProperty,
constraintId, sammUrns.descriptionUrn, violationUrn, "@en" );
expectSemanticValidationErrors( "constraint-subclass-core", constraintName,
metaModelVersion, resultForPreferredName, resultForDescription );
}

@ParameterizedTest
@MethodSource( value = "versionsStartingWith2_2_0" )
public void testInvalidLanguageStringsExpectFailure( final KnownVersion metaModelVersion ) {
final SammUrns sammUrns = new SammUrns( metaModelVersion );

final String constraintName = "TestConstraintWithInvalidLangStrings";
final String constraintId = testNamespacePrefix + constraintName;
final SemanticError resultForPreferredName = new SemanticError(
messageInvalidLangString, constraintId, sammUrns.preferredNameUrn, violationUrn, "Test Constraint" );
final SemanticError resultForDescription = new SemanticError(
messageInvalidLangString, constraintId, sammUrns.descriptionUrn, violationUrn, "TestConstraint" );
expectSemanticValidationErrors( "constraint-subclass-core", constraintName,
metaModelVersion, resultForPreferredName, resultForDescription );
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#
# Copyright (c) 2024 Robert Bosch Manufacturing Solutions GmbH
#
# See the AUTHORS file(s) distributed with this work for additional
# information regarding authorship.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
#
# SPDX-License-Identifier: MPL-2.0
#
@prefix : <urn:samm:org.eclipse.esmf.samm.test:1.0.0#> .
@prefix samm: <urn:samm:org.eclipse.esmf.samm:meta-model:2.2.0#> .
@prefix samm-c: <urn:samm:org.eclipse.esmf.samm:characteristic:2.2.0#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

:TestConstraintWithoutProperties a samm:Constraint.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
@prefix samm-c: <urn:samm:org.eclipse.esmf.samm:characteristic:2.2.0#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

:TestConstraint a samm:Constraint ;
:TestConstraint a samm-c:LengthConstraint ;
samm:preferredName "Test Constraint"@en ;
samm:description "TestConstraint"@en .
samm:description "TestConstraint"@en ;
samm-c:minValue "5"^^xsd:nonNegativeInteger ;
samm-c:maxValue "10"^^xsd:nonNegativeInteger .
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
@prefix samm-c: <urn:samm:org.eclipse.esmf.samm:characteristic:2.2.0#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

:TestConstraintNonUniqueLangStrings a samm:Constraint ;
:TestConstraintNonUniqueLangStrings a samm-c:LengthConstraint ;
samm:preferredName "Test Constraint"@en ;
samm:preferredName "Test Einschränkung"@en ;
samm:description "TestConstraint"@en ;
samm:description "Test Einschränkung"@en .
samm:description "Test Einschränkung"@en ;
samm-c:minValue "5"^^xsd:nonNegativeInteger ;
samm-c:maxValue "10"^^xsd:nonNegativeInteger .
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@
@prefix samm-c: <urn:samm:org.eclipse.esmf.samm:characteristic:2.2.0#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

:TestConstraintWithDataType a samm:Constraint ;
samm:dataType xsd:float .
:TestConstraintWithDataType a samm-c:LengthConstraint ;
samm:dataType xsd:float ;
samm-c:minValue "5"^^xsd:nonNegativeInteger ;
samm-c:maxValue "10"^^xsd:nonNegativeInteger .
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
@prefix samm-c: <urn:samm:org.eclipse.esmf.samm:characteristic:2.2.0#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

:TestConstraintWithEmptyProperties a samm:Constraint ;
:TestConstraintWithEmptyProperties a samm-c:LengthConstraint ;
samm:preferredName ""@en ;
samm:description ""@en .
samm:description ""@en ;
samm-c:minValue "5"^^xsd:nonNegativeInteger ;
samm-c:maxValue "10"^^xsd:nonNegativeInteger .
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
@prefix samm-c: <urn:samm:org.eclipse.esmf.samm:characteristic:2.2.0#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

:TestConstraintWithInvalidLangStrings a samm:Constraint ;
:TestConstraintWithInvalidLangStrings a samm-c:LengthConstraint ;
samm:preferredName "Test Constraint" ;
samm:description "TestConstraint" .
samm:description "TestConstraint" ;
samm-c:minValue "5"^^xsd:nonNegativeInteger ;
samm-c:maxValue "10"^^xsd:nonNegativeInteger .

0 comments on commit d2e140f

Please sign in to comment.