Skip to content

Commit c2d60eb

Browse files
committed
Fix tests
1 parent 87400cb commit c2d60eb

File tree

7 files changed

+79
-152
lines changed

7 files changed

+79
-152
lines changed

core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/loader/AspectModelLoader.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
import org.eclipse.esmf.aspectmodel.resolver.ModelSource;
4646
import org.eclipse.esmf.aspectmodel.resolver.ResolutionStrategy;
4747
import org.eclipse.esmf.aspectmodel.resolver.ResolutionStrategySupport;
48-
import org.eclipse.esmf.aspectmodel.resolver.exceptions.InvalidCountOfAspectsException;
4948
import org.eclipse.esmf.aspectmodel.resolver.exceptions.ModelResolutionException;
5049
import org.eclipse.esmf.aspectmodel.resolver.fs.FlatModelsRoot;
5150
import org.eclipse.esmf.aspectmodel.resolver.modelfile.DefaultAspectModelFile;
@@ -483,10 +482,9 @@ public AspectModel loadAspectModelFiles( final Collection<AspectModelFile> input
483482
.ifPresent( aspect -> mergedModel.setNsPrefix( "", aspect.urn().getUrnPrefix() ) );
484483
for ( AspectModelFile file : files ) {
485484
if ( file.aspects().size() > 1 ) {
486-
throw new InvalidCountOfAspectsException(
487-
"Invalid number of aspects for " + file
488-
+ ". Total aspects: " + file.aspects().size()
489-
);
485+
throw new AspectLoadingException(
486+
"Aspect model file " + file.sourceLocation().map( location -> location + " " ).orElse( "" ) + "contains " + file.aspects()
487+
.size() + " aspects, but may only contain one." );
490488
}
491489
}
492490
return new DefaultAspectModel( files, mergedModel, elements );

core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/resolver/exceptions/InvalidCountOfAspectsException.java

Lines changed: 0 additions & 7 deletions
This file was deleted.

core/esmf-aspect-meta-model-java/src/test/java/org/eclipse/esmf/aspectmodel/resolver/AspectModelResolverTest.java

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,22 @@
1919
import static org.assertj.core.api.Assertions.assertThatThrownBy;
2020

2121
import java.io.File;
22+
import java.io.InputStream;
23+
import java.net.URI;
2224
import java.net.URISyntaxException;
25+
import java.util.Optional;
2326

27+
import org.eclipse.esmf.aspectmodel.AspectLoadingException;
2428
import org.eclipse.esmf.aspectmodel.loader.AspectModelLoader;
25-
import org.eclipse.esmf.aspectmodel.resolver.exceptions.InvalidCountOfAspectsException;
2629
import org.eclipse.esmf.aspectmodel.resolver.exceptions.ModelResolutionException;
2730
import org.eclipse.esmf.aspectmodel.urn.AspectModelUrn;
2831
import org.eclipse.esmf.metamodel.AspectModel;
2932
import org.eclipse.esmf.metamodel.vocabulary.SammNs;
3033
import org.eclipse.esmf.samm.KnownVersion;
34+
import org.eclipse.esmf.test.InvalidTestAspect;
35+
import org.eclipse.esmf.test.TestAspect;
3136
import org.eclipse.esmf.test.TestModel;
37+
import org.eclipse.esmf.test.TestResources;
3238

3339
import org.apache.jena.rdf.model.Resource;
3440
import org.apache.jena.vocabulary.RDF;
@@ -187,36 +193,13 @@ void testResolutionMissingModelElementExpectFailure() throws Throwable {
187193
}
188194

189195
@Test
190-
void getExceptionWhileLoadingModelWithTwoAspects() throws URISyntaxException {
191-
final File aspectModelsRootDirectory = new File(
192-
AspectModelResolverTest.class.getClassLoader().getResource( KnownVersion.getLatest().toString().toLowerCase() )
193-
.toURI().getPath() );
194-
195-
final ResolutionStrategy urnStrategy = new FileSystemStrategy( aspectModelsRootDirectory.toPath() );
196-
197-
final AspectModelUrn testUrn = AspectModelUrn.fromUrn( "urn:samm:io.catenax.shared.uuid:2.0.0#Uuid2" );
198-
196+
void getExceptionWhileLoadingModelWithTwoAspects() {
199197
assertThatThrownBy( () -> {
200-
final AspectModel result = new AspectModelLoader( urnStrategy ).load( testUrn );
201-
} )
202-
.isInstanceOf( InvalidCountOfAspectsException.class )
203-
.hasMessageContaining( "/io.catenax.shared.uuid/2.0.0/invalid_uudi_aspect_contains_two_aspects.ttl. Total aspects: 2" );
204-
}
205-
206-
@Test
207-
void getExceptionWhileLoadingModelWithTwoAspectsInSharedFiles() throws URISyntaxException {
208-
final File aspectModelsRootDirectory = new File(
209-
AspectModelResolverTest.class.getClassLoader().getResource( KnownVersion.getLatest().toString().toLowerCase() )
210-
.toURI().getPath() );
211-
212-
final ResolutionStrategy urnStrategy = new FileSystemStrategy( aspectModelsRootDirectory.toPath() );
213-
214-
final AspectModelUrn testUrn = AspectModelUrn.fromUrn( "urn:samm:io.catenax.shared.uuid:2.0.0#Uuid" );
215-
216-
assertThatThrownBy( () -> {
217-
final AspectModel result = new AspectModelLoader( urnStrategy ).load( testUrn );
198+
TestResources.load( InvalidTestAspect.INVALID_UUID_ASPECT_WITH_TWO_ASPECTS );
218199
} )
219-
.isInstanceOf( InvalidCountOfAspectsException.class )
220-
.hasMessageContaining( "/io.catenax.shared.uuid/2.0.0/invalid_uudi_aspect_contains_two_aspects.ttl. Total aspects: 2" );
200+
.isInstanceOf( AspectLoadingException.class )
201+
.hasMessageContaining(
202+
"Aspect model file testmodel:invalid/org.eclipse.esmf.test/1.0.0/InvalidUuidAspectWithTwoAspects.ttl contains 2 "
203+
+ "aspects, but may only contain one." );
221204
}
222205
}

core/esmf-aspect-meta-model-java/src/test/resources/samm_2_1_0/io.catenax.shared.uuid/2.0.0/invalid_uudi_aspect_contains_two_aspects.ttl

Lines changed: 0 additions & 75 deletions
This file was deleted.

core/esmf-aspect-meta-model-java/src/test/resources/samm_2_1_0/io.catenax.shared.uuid/2.0.0/valid_uudi_aspect.ttl

Lines changed: 0 additions & 34 deletions
This file was deleted.

core/esmf-test-aspect-models/src/main/java/org/eclipse/esmf/test/InvalidTestAspect.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ public enum InvalidTestAspect implements TestModel {
2929
INVALID_PREFERRED_NAME_DATATYPE,
3030
INVALID_CHARACTERISTIC_DATATYPE,
3131
RANGE_CONSTRAINT_WITH_WRONG_TYPE,
32-
MODEL_WITH_CYCLES;
32+
MODEL_WITH_CYCLES,
33+
34+
INVALID_UUID_ASPECT_WITH_TWO_ASPECTS;
3335

3436
@Override
3537
public String getName() {
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Copyright (c) 2025 Robert Bosch Manufacturing Solutions GmbH
2+
#
3+
# See the AUTHORS file(s) distributed with this work for additional
4+
# information regarding authorship.
5+
#
6+
# This Source Code Form is subject to the terms of the Mozilla Public
7+
# License, v. 2.0. If a copy of the MPL was not distributed with this
8+
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
9+
#
10+
# SPDX-License-Identifier: MPL-2.0
11+
12+
@prefix : <urn:samm:org.eclipse.esmf.test:2.0.0#>.
13+
@prefix samm: <urn:samm:org.eclipse.esmf.samm:meta-model:2.1.0#>.
14+
@prefix samm-c: <urn:samm:org.eclipse.esmf.samm:characteristic:2.1.0#>.
15+
@prefix samm-e: <urn:samm:org.eclipse.esmf.samm:entity:2.1.0#>.
16+
@prefix unit: <urn:samm:org.eclipse.esmf.samm:unit:2.1.0#>.
17+
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
18+
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
19+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
20+
21+
:Uuid2 a samm:Aspect;
22+
samm:preferredName "Shared Aspect for UUIDs v4"@en;
23+
samm:properties (:uuidV4Property);
24+
samm:operations ();
25+
samm:events ().
26+
:uuidV4Property a samm:Property;
27+
samm:preferredName "UUID v4 Property"@en;
28+
samm:characteristic :UuidV4Trait;
29+
samm:exampleValue "urn:uuid:48878d48-6f1d-47f5-8ded-a441d0d879df".
30+
:UuidV4Trait a samm-c:Trait;
31+
samm:preferredName "Trait for UUIDs v4"@en;
32+
samm-c:baseCharacteristic :Uuidv4Characteristic;
33+
samm-c:constraint :Uuidv4RegularExpression.
34+
:Uuidv4Characteristic a samm:Characteristic;
35+
samm:preferredName "UUID v4"@en;
36+
samm:dataType xsd:string.
37+
:Uuidv4RegularExpression a samm-c:RegularExpressionConstraint;
38+
samm:preferredName "UUID v4 Regular Expression"@en;
39+
samm:value "(^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$)|(^urn:uuid:[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$)".
40+
41+
:Uuid3 a samm:Aspect;
42+
samm:preferredName "Shared Aspect for UUIDs v4"@en;
43+
samm:properties (:uuidV4Property3);
44+
samm:operations ();
45+
samm:events ().
46+
:uuidV4Property3 a samm:Property;
47+
samm:preferredName "UUID v4 Property"@en;
48+
samm:characteristic :UuidV4Trait3;
49+
samm:exampleValue "urn:uuid:48878d48-6f1d-47f5-8ded-a441d0d879df".
50+
:UuidV4Trait3 a samm-c:Trait;
51+
samm:preferredName "Trait for UUIDs v4"@en;
52+
samm-c:baseCharacteristic :Uuidv4Characteristic3;
53+
samm-c:constraint :Uuidv4RegularExpression3.
54+
:Uuidv4Characteristic3 a samm:Characteristic;
55+
samm:preferredName "UUID v4"@en;
56+
samm:dataType xsd:string.
57+
:Uuidv4RegularExpression3 a samm-c:RegularExpressionConstraint;
58+
samm:preferredName "UUID v4 Regular Expression"@en;
59+
samm:value "(^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$)|(^urn:uuid:[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$)".
60+

0 commit comments

Comments
 (0)