Skip to content

Commit

Permalink
Merge branch 'main' into chris-volk-patch-2
Browse files Browse the repository at this point in the history
  • Loading branch information
atextor authored Jan 15, 2024
2 parents a7a70d5 + fc343a7 commit 2a2acb9
Show file tree
Hide file tree
Showing 10 changed files with 149 additions and 66 deletions.
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 2a2acb9

Please sign in to comment.