From e337c02ea4ddf040d6eb4d0d438f33c91c1e5f28 Mon Sep 17 00:00:00 2001 From: efilchenko Date: Fri, 12 Sep 2025 18:14:37 +0300 Subject: [PATCH 1/3] fix unordered aspect after files load --- .../aspectmodel/loader/AspectModelLoader.java | 19 +++++++----- .../loader/AspectModelLoaderTest.java | 23 +++++++++++--- .../org/eclipse/esmf/test/TestResources.java | 10 ++++++- .../eclipse/esmf/test/OrderingTestAspect.java | 25 ++++++++++++++++ .../eclipse/esmf/test/TestOrderingModel.java | 25 ++++++++++++++++ .../1.0.0/Aspect.ttl | 30 +++++++++++++++++++ .../1.0.0/Aspect.ttl | 23 ++++++++++++++ 7 files changed, 142 insertions(+), 13 deletions(-) create mode 100644 core/esmf-test-aspect-models/src/main/java/org/eclipse/esmf/test/OrderingTestAspect.java create mode 100644 core/esmf-test-aspect-models/src/main/java/org/eclipse/esmf/test/TestOrderingModel.java create mode 100644 core/esmf-test-aspect-models/src/main/resources/valid/org.eclipse.esmf.test.ordering.dependency/1.0.0/Aspect.ttl create mode 100644 core/esmf-test-aspect-models/src/main/resources/valid/org.eclipse.esmf.test.ordering/1.0.0/Aspect.ttl diff --git a/core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/loader/AspectModelLoader.java b/core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/loader/AspectModelLoader.java index 827966d15..40925b0c1 100644 --- a/core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/loader/AspectModelLoader.java +++ b/core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/loader/AspectModelLoader.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Robert Bosch Manufacturing Solutions GmbH + * Copyright (c) 2025 Robert Bosch Manufacturing Solutions GmbH * * See the AUTHORS file(s) distributed with this work for additional * information regarding authorship. @@ -17,6 +17,7 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; +import java.net.JarURLConnection; import java.net.URI; import java.nio.file.Path; import java.util.ArrayDeque; @@ -25,6 +26,7 @@ import java.util.Deque; import java.util.HashMap; import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Optional; @@ -121,7 +123,7 @@ public AspectModelLoader( final ResolutionStrategy resolutionStrategy ) { */ public AspectModelLoader( final List resolutionStrategies ) { TurtleLoader.init(); - if ( resolutionStrategies.size() == 1 ) { + if ( 1 == resolutionStrategies.size() ) { resolutionStrategy = resolutionStrategies.get( 0 ); } else if ( resolutionStrategies.isEmpty() ) { resolutionStrategy = DEFAULT_STRATEGY.get(); @@ -416,7 +418,7 @@ public AspectModel loadNamespacePackage( final byte[] binaryContent, final URI l * {@code https://example.com/package.zip}, the files in the package will have a location URI such as * {@code jar:file:/some/path/package.zip!/com.example.namespace/1.0.0/AspectModel.ttl} or * {@code jar:https://example.com/package.zip!/com.example.namespace/1.0.0/AspectModel.ttl}, respectively, as described in - * the JavaDoc for {@link java.net.JarURLConnection}. + * the JavaDoc for {@link JarURLConnection}. * * @param location the source location * @param inputStream the input stream to load the ZIP content from @@ -453,7 +455,7 @@ private record LoaderContext( Deque unresolvedFiles ) { private LoaderContext() { - this( new HashSet<>(), new HashSet<>(), new HashSet<>(), new ArrayDeque<>(), new ArrayDeque<>() ); + this( new HashSet<>(), new LinkedHashSet<>(), new HashSet<>(), new ArrayDeque<>(), new ArrayDeque<>() ); } } @@ -473,7 +475,8 @@ private String replaceLegacyBammUrn( final String urn ) { private boolean containsType( final Model model, final String urn ) { if ( model.contains( model.createResource( urn ), RDF.type, (RDFNode) null ) ) { return true; - } else if ( urn.startsWith( AspectModelUrn.PROTOCOL_AND_NAMESPACE_PREFIX ) ) { + } + if ( urn.startsWith( AspectModelUrn.PROTOCOL_AND_NAMESPACE_PREFIX ) ) { // when deriving a URN from file (via "fileToUrn" method - mainly in samm-cli scenarios), // we assume new "samm" format, but could actually have been the old "bamm" return model.contains( model.createResource( toLegacyBammUrn( urn ) ), RDF.type, (RDFNode) null ); @@ -495,7 +498,7 @@ private Optional applyResolutionStrategy( final String urn ) { try { final AspectModelUrn aspectModelUrn = AspectModelUrn.fromUrn( replaceLegacyBammUrn( urn ) ); - if ( aspectModelUrn.getElementType() != ElementType.NONE ) { + if ( ElementType.NONE != aspectModelUrn.getElementType() ) { return Optional.empty(); } final AspectModelFile resolutionResult = resolutionStrategy.apply( aspectModelUrn, this ); @@ -674,7 +677,7 @@ public AspectModel loadAspectModelFiles( final Collection input .findFirst() .ifPresent( aspect -> mergedModel.setNsPrefix( "", aspect.urn().getUrnPrefix() ) ); for ( final AspectModelFile file : files ) { - if ( file.aspects().size() > 1 ) { + if ( 1 < file.aspects().size() ) { throw new AspectLoadingException( "Aspect Model file " + file.humanReadableLocation() + " contains " + file.aspects().size() + " aspects, but may only contain one." ); @@ -709,7 +712,7 @@ private void setNamespaces( final Collection files, final Colle MetaModelBaseAttributes namespaceDefinition = null; AspectModelFile fileContainingNamespaceDefinition = null; final List elementsForUrn = elementsGroupedByNamespaceUrn.get( namespaceUrn ); - if ( elementsForUrn != null ) { + if ( null != elementsForUrn ) { for ( final ModelElement element : elementsForUrn ) { final AspectModelFile elementFile = element.getSourceFile(); if ( elementFile.sourceModel().contains( null, RDF.type, SammNs.SAMM.Namespace() ) ) { diff --git a/core/esmf-aspect-meta-model-java/src/test/java/org/eclipse/esmf/aspectmodel/loader/AspectModelLoaderTest.java b/core/esmf-aspect-meta-model-java/src/test/java/org/eclipse/esmf/aspectmodel/loader/AspectModelLoaderTest.java index 4edce3456..9e4b4c5e2 100644 --- a/core/esmf-aspect-meta-model-java/src/test/java/org/eclipse/esmf/aspectmodel/loader/AspectModelLoaderTest.java +++ b/core/esmf-aspect-meta-model-java/src/test/java/org/eclipse/esmf/aspectmodel/loader/AspectModelLoaderTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Robert Bosch Manufacturing Solutions GmbH + * Copyright (c) 2025 Robert Bosch Manufacturing Solutions GmbH * * See the AUTHORS file(s) distributed with this work for additional * information regarding authorship. @@ -20,6 +20,7 @@ import java.net.URI; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Optional; import java.util.function.Function; import java.util.stream.Collectors; @@ -34,16 +35,19 @@ import org.eclipse.esmf.metamodel.ComplexType; import org.eclipse.esmf.metamodel.ModelElement; import org.eclipse.esmf.test.InvalidTestAspect; +import org.eclipse.esmf.test.OrderingTestAspect; import org.eclipse.esmf.test.TestAspect; import org.eclipse.esmf.test.TestResources; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.RepeatedTest; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.EnumSource; class AspectModelLoaderTest { @ParameterizedTest - @EnumSource( value = TestAspect.class ) + @EnumSource( TestAspect.class ) void testLoadAspectModelsSourceFilesArePresent( final TestAspect testAspect ) { final AspectModel aspectModel = TestResources.load( testAspect ); for ( final ModelElement element : aspectModel.elements() ) { @@ -90,11 +94,11 @@ void testOfAbstractEntityCyclomaticCreation() { assertThat( entities ).extracting( "AbstractTestEntity" ).isInstanceOf( AbstractEntity.class ); final AbstractEntity abstractEntity = (AbstractEntity) entities.get( "AbstractTestEntity" ); assertThat( entities ).extracting( "testEntityOne" ).isInstanceOfSatisfying( ComplexType.class, type -> { - org.assertj.core.api.Assertions.assertThat( type ).extracting( ComplexType::getExtends ).extracting( Optional::get ) + Assertions.assertThat( type ).extracting( ComplexType::getExtends ).extracting( Optional::get ) .isSameAs( abstractEntity ); } ); assertThat( entities ).extracting( "testEntityTwo" ).isInstanceOfSatisfying( ComplexType.class, type -> - org.assertj.core.api.Assertions.assertThat( type ).extracting( ComplexType::getExtends ).extracting( Optional::get ) + Assertions.assertThat( type ).extracting( ComplexType::getExtends ).extracting( Optional::get ) .isSameAs( abstractEntity ) ); } @@ -129,4 +133,15 @@ void testLoadMultipleFilesWithOverlappingRdfStatements() { assertThat( exception ).hasMessageContaining( "Duplicate definition" ); } ); } + + @RepeatedTest( 10 ) + void testAspectUploadOrdering() { + final OrderingTestAspect aspectName = OrderingTestAspect.ASPECT; + final AspectModel aspectModel = TestResources.load( aspectName ); + assertThat( aspectModel ).aspects() + .filteredOn( aspect -> Objects.equals( aspectName.getName(), aspect.getName() ) ) + .first() + .satisfies( + aspect -> assertThat( aspect.urn().toString() ).isEqualTo( "urn:samm:org.eclipse.esmf.test.ordering:1.0.0#Aspect" ) ); + } } \ No newline at end of file diff --git a/core/esmf-aspect-meta-model-java/src/test/java/org/eclipse/esmf/test/TestResources.java b/core/esmf-aspect-meta-model-java/src/test/java/org/eclipse/esmf/test/TestResources.java index ec35ae9df..75456bfc7 100644 --- a/core/esmf-aspect-meta-model-java/src/test/java/org/eclipse/esmf/test/TestResources.java +++ b/core/esmf-aspect-meta-model-java/src/test/java/org/eclipse/esmf/test/TestResources.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Robert Bosch Manufacturing Solutions GmbH + * Copyright (c) 2025 Robert Bosch Manufacturing Solutions GmbH * * See the AUTHORS file(s) distributed with this work for additional * information regarding authorship. @@ -41,6 +41,14 @@ public static AspectModel load( final TestModel model ) { return new AspectModelLoader( testModelsResolutionStrategy ).load( inputStream, URI.create( "testmodel:" + path ) ); } + public static AspectModel load( final OrderingTestAspect model ) { + final String path = String.format( "valid/%s/%s/%s.ttl", model.getUrn().getNamespaceMainPart(), model.getUrn().getVersion(), + model.getName() ); + final InputStream inputStream = TestResources.class.getClassLoader().getResourceAsStream( path ); + final ResolutionStrategy testModelsResolutionStrategy = new ClasspathStrategy( "valid" ); + return new AspectModelLoader( testModelsResolutionStrategy ).load( inputStream, URI.create( "testmodel:" + path ) ); + } + public static AspectModel load( final InvalidTestAspect model ) { final KnownVersion metaModelVersion = KnownVersion.getLatest(); final String path = String.format( "invalid/%s/%s/%s.ttl", model.getUrn().getNamespaceMainPart(), model.getUrn().getVersion(), diff --git a/core/esmf-test-aspect-models/src/main/java/org/eclipse/esmf/test/OrderingTestAspect.java b/core/esmf-test-aspect-models/src/main/java/org/eclipse/esmf/test/OrderingTestAspect.java new file mode 100644 index 000000000..eeba66e92 --- /dev/null +++ b/core/esmf-test-aspect-models/src/main/java/org/eclipse/esmf/test/OrderingTestAspect.java @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 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.test; + +import org.apache.commons.text.CaseUtils; + +public enum OrderingTestAspect implements TestOrderingModel { + ASPECT; + + @Override + public String getName() { + return CaseUtils.toCamelCase( toString().toLowerCase(), true, '_' ); + } +} diff --git a/core/esmf-test-aspect-models/src/main/java/org/eclipse/esmf/test/TestOrderingModel.java b/core/esmf-test-aspect-models/src/main/java/org/eclipse/esmf/test/TestOrderingModel.java new file mode 100644 index 000000000..2506e95c5 --- /dev/null +++ b/core/esmf-test-aspect-models/src/main/java/org/eclipse/esmf/test/TestOrderingModel.java @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 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.test; + +import org.eclipse.esmf.aspectmodel.urn.AspectModelUrn; + +public interface TestOrderingModel extends TestModel { + String TEST_NAMESPACE = "urn:samm:org.eclipse.esmf.test.ordering:1.0.0#"; + + @Override + default AspectModelUrn getUrn() { + return AspectModelUrn.fromUrn( TEST_NAMESPACE + getName() ); + } +} diff --git a/core/esmf-test-aspect-models/src/main/resources/valid/org.eclipse.esmf.test.ordering.dependency/1.0.0/Aspect.ttl b/core/esmf-test-aspect-models/src/main/resources/valid/org.eclipse.esmf.test.ordering.dependency/1.0.0/Aspect.ttl new file mode 100644 index 000000000..e6022b99b --- /dev/null +++ b/core/esmf-test-aspect-models/src/main/resources/valid/org.eclipse.esmf.test.ordering.dependency/1.0.0/Aspect.ttl @@ -0,0 +1,30 @@ +# Copyright (c) 2025 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 samm: . +@prefix samm-c: . +@prefix xsd: . + +@prefix : . + +:Aspect a samm:Aspect ; + samm:description "Test dependency aspect "@en ; + samm:properties ( :test ) ; + samm:operations ( ) ; + samm:events ( ) . + +:test a samm:Property ; + samm:name "test property" ; + samm:characteristic :TestCharacteristic . + +:TestCharacteristic a samm:Characteristic ; + samm:preferredName "Test Characteristic"@en ; + samm:dataType xsd:short . diff --git a/core/esmf-test-aspect-models/src/main/resources/valid/org.eclipse.esmf.test.ordering/1.0.0/Aspect.ttl b/core/esmf-test-aspect-models/src/main/resources/valid/org.eclipse.esmf.test.ordering/1.0.0/Aspect.ttl new file mode 100644 index 000000000..a0fd3f464 --- /dev/null +++ b/core/esmf-test-aspect-models/src/main/resources/valid/org.eclipse.esmf.test.ordering/1.0.0/Aspect.ttl @@ -0,0 +1,23 @@ +# Copyright (c) 2025 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 samm: . +@prefix ref: . + +@prefix : . + +:Aspect a samm:Aspect ; + samm:preferredName "Test Aspect"@en ; + samm:description "This is a test description"@en ; + samm:properties ( + ref:test + ) ; + samm:operations ( ) . From d80eb5d2b415e02f3de51e80c28827d3c93b560b Mon Sep 17 00:00:00 2001 From: efilchenko Date: Tue, 16 Sep 2025 23:07:38 +0300 Subject: [PATCH 2/3] add test --- .../java/org/eclipse/esmf/SammCliTest.java | 92 +++++++++++++------ 1 file changed, 62 insertions(+), 30 deletions(-) diff --git a/tools/samm-cli/src/test/java/org/eclipse/esmf/SammCliTest.java b/tools/samm-cli/src/test/java/org/eclipse/esmf/SammCliTest.java index 913e895a3..9faf43d1b 100644 --- a/tools/samm-cli/src/test/java/org/eclipse/esmf/SammCliTest.java +++ b/tools/samm-cli/src/test/java/org/eclipse/esmf/SammCliTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Robert Bosch Manufacturing Solutions GmbH + * Copyright (c) 2025 Robert Bosch Manufacturing Solutions GmbH * * See the AUTHORS file(s) distributed with this work for additional * information regarding authorship. @@ -38,6 +38,7 @@ import org.eclipse.esmf.aspectmodel.validation.InvalidSyntaxViolation; import org.eclipse.esmf.samm.KnownVersion; import org.eclipse.esmf.test.InvalidTestAspect; +import org.eclipse.esmf.test.OrderingTestAspect; import org.eclipse.esmf.test.TestAspect; import org.eclipse.esmf.test.TestModel; import org.eclipse.esmf.test.TestSharedModel; @@ -49,6 +50,7 @@ import org.apache.tika.mime.MediaType; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.RepeatedTest; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; import org.junit.jupiter.api.condition.DisabledOnOs; @@ -72,7 +74,7 @@ class SammCliTest { private final String defaultInputUrn = testModel.getUrn().toString(); private final String defaultModelsRoot = inputFile( testModel ).toPath().getParent().getParent().getParent().toFile().getAbsolutePath(); - Path outputDirectory = null; + Path outputDirectory; @BeforeEach void beforeEach() throws IOException { @@ -87,7 +89,7 @@ void beforeEach() throws IOException { @AfterEach void afterEach() { - if ( outputDirectory != null ) { + if ( null != outputDirectory ) { final File outputDir = outputDirectory.toFile(); if ( outputDir.exists() && outputDir.isDirectory() ) { // Recursively delete temporary directory @@ -138,7 +140,7 @@ void testWrongArgs() { @Test void testNonExistingFile() { - final ExecutionResult result = sammCli.apply( "--disable-color", "aspect", defaultInputFile + "x", "validate" ); + final ExecutionResult result = sammCli.apply( "--disable-color", "aspect", defaultInputFile + 'x', "validate" ); assertThat( result.stdout() ).isEmpty(); assertThat( result.stderr() ).contains( "File not found" ); assertThat( result.stderr() ).doesNotContain( "CommandException" ); @@ -146,7 +148,7 @@ void testNonExistingFile() { @Test void testNonExistingFileWithDebugLogLevel() { - final ExecutionResult result = sammCli.apply( "--disable-color", "aspect", defaultInputFile + "x", "validate", "-vvv" ); + final ExecutionResult result = sammCli.apply( "--disable-color", "aspect", defaultInputFile + 'x', "validate", "-vvv" ); assertThat( result.stdout() ).isEmpty(); assertThat( result.stderr() ).contains( "File not found" ); assertThat( result.stderr() ).contains( "CommandException" ); @@ -306,7 +308,7 @@ void testAspectValidateValidModelAllTestFiles( final TestModel aspect ) { @Test void testAspectValidateWithRelativePath() { final File workingDirectory = new File( defaultInputFile ).getParentFile(); - final String relativeFileName = "." + File.separator + new File( defaultInputFile ).getName(); + final String relativeFileName = '.' + File.separator + new File( defaultInputFile ).getName(); final ExecutionResult result = sammCli.apply( List.of( "--disable-color", "aspect", relativeFileName, "validate" ), Optional.empty(), workingDirectory ); @@ -471,6 +473,17 @@ void testAspectToAasJsonToStdoutAllTestFiles( final TestModel aspect ) { assertThat( contentType( result.stdoutRaw() ) ).isEqualTo( MediaType.text( "plain" ) ); } + @RepeatedTest( 10 ) + void testAspectToAasJsonToStdoutContentAspectUploadOrdering() { + final String input = inputFile( OrderingTestAspect.ASPECT ).getAbsolutePath(); + final ExecutionResult result = sammCli.runAndExpectSuccess( "--disable-color", "aspect", input, "to", "aas", "--format", + "xml" ); + assertThat( result.stderr() ).isEmpty(); + assertThat( result.stdout() ) + .contains( "urn:samm:org.eclipse.esmf.test.ordering:1.0.0#Aspect" ) + .doesNotContain( "urn:samm:org.eclipse.esmf.test.ordering.dependency:1.0.0#Aspect" ); + } + @Test void testAasToAspectModel() { // First create the AAS XML file we want to read @@ -495,7 +508,7 @@ void testAasToAspectModel() { assertThat( directory ).isDirectoryContaining( file -> file.getName().equals( expectedAspectModelFileName ) ); final File sourceFile = directory.toPath().resolve( expectedAspectModelFileName ).toFile(); - assertThat( sourceFile ).content().contains( ":" + testModel.getName() + " a samm:Aspect" ); + assertThat( sourceFile ).content().contains( ':' + testModel.getName() + " a samm:Aspect" ); } @Test @@ -535,7 +548,7 @@ void testAasToAspectModelWithSelectedSubmodels() { assertThat( directory ).isDirectoryContaining( file -> file.getName().equals( expectedAspectModelFileName ) ); final File sourceFile = directory.toPath().resolve( expectedAspectModelFileName ).toFile(); - assertThat( sourceFile ).content().contains( ":" + testModel.getName() + " a samm:Aspect" ); + assertThat( sourceFile ).content().contains( ':' + testModel.getName() + " a samm:Aspect" ); } @Test @@ -582,6 +595,16 @@ void testAspectToHtmlWithCustomCss() { assertThat( result.stderr() ).isEmpty(); } + @RepeatedTest( 10 ) + void testAspectToHtmlToStdoutContentAspectUploadOrdering() { + final String input = inputFile( OrderingTestAspect.ASPECT ).getAbsolutePath(); + final ExecutionResult result = sammCli.runAndExpectSuccess( "--disable-color", "aspect", input, "to", "html" ); + assertThat( result.stderr() ).isEmpty(); + assertThat( result.stdout() ) + .contains( "
urn:samm:org.eclipse.esmf.test.ordering:1.0.0#Aspect
" ) + .doesNotContain( "
urn:samm:org.eclipse.esmf.test.ordering.dependency:1.0.0#Aspect
" ); + } + @Test void testAspectToJavaWithDefaultPackageName() { final File outputDir = outputDirectory.toFile(); @@ -594,7 +617,7 @@ void testAspectToJavaWithDefaultPackageName() { final File directory = Paths.get( outputDir.getAbsolutePath(), "org", "eclipse", "esmf", "test" ).toFile(); assertThat( directory ).exists(); assertThat( directory ).isDirectoryContaining( - file -> file.getName().equals( "AspectWithEntity.java" ) || file.getName().equals( "TestEntity.java" ) ); + file -> "AspectWithEntity.java".equals( file.getName() ) || "TestEntity.java".equals( file.getName() ) ); final File sourceFile = directory.toPath().resolve( "AspectWithEntity.java" ).toFile(); assertThat( sourceFile ).content().contains( "@JsonCreator" ); @@ -612,7 +635,7 @@ void testAspectToJavaWithCustomPackageName() { final File directory = Paths.get( outputDir.getAbsolutePath(), "com", "example", "foo" ).toFile(); assertThat( directory ).exists(); assertThat( directory ).isDirectoryContaining( - file -> file.getName().equals( "AspectWithEntity.java" ) || file.getName().equals( "TestEntity.java" ) ); + file -> "AspectWithEntity.java".equals( file.getName() ) || "TestEntity.java".equals( file.getName() ) ); } @Test @@ -626,7 +649,7 @@ void testAspectToJavaWithoutJacksonAnnotations() { final File directory = Paths.get( outputDir.getAbsolutePath(), "org", "eclipse", "esmf", "test" ).toFile(); assertThat( directory ).exists(); assertThat( directory ).isDirectoryContaining( - file -> file.getName().equals( "AspectWithEntity.java" ) || file.getName().equals( "TestEntity.java" ) ); + file -> "AspectWithEntity.java".equals( file.getName() ) || "TestEntity.java".equals( file.getName() ) ); final File sourceFile = directory.toPath().resolve( "AspectWithEntity.java" ).toFile(); assertThat( sourceFile ).content().doesNotContain( "@JsonCreator" ); @@ -644,7 +667,7 @@ void testAspectToJavaWithDefaultPackageNameWithCustomResolver() { final File directory = Paths.get( outputDir.getAbsolutePath(), "org", "eclipse", "esmf", "test" ).toFile(); assertThat( directory ).exists(); assertThat( directory ).isDirectoryContaining( - file -> file.getName().equals( "AspectWithEntity.java" ) || file.getName().equals( "TestEntity.java" ) ); + file -> "AspectWithEntity.java".equals( file.getName() ) || "TestEntity.java".equals( file.getName() ) ); final File sourceFile = directory.toPath().resolve( "AspectWithEntity.java" ).toFile(); assertThat( sourceFile ).content().contains( "@JsonCreator" ); @@ -666,7 +689,7 @@ void testAspectToJavaWithCustomFileHeader() { final File directory = Paths.get( outputDir.getAbsolutePath(), "org", "eclipse", "esmf", "test" ).toFile(); assertThat( directory ).exists(); assertThat( directory ).isDirectoryContaining( - file -> file.getName().equals( "AspectWithEntity.java" ) || file.getName().equals( "TestEntity.java" ) ); + file -> "AspectWithEntity.java".equals( file.getName() ) || "TestEntity.java".equals( file.getName() ) ); final String expectedCopyright = String.format( "Copyright (c) %s Test Inc. All rights reserved", LocalDate.now().getYear() ); final File sourceFile = directory.toPath().resolve( "AspectWithEntity.java" ).toFile(); @@ -694,7 +717,7 @@ void testAspectToJavaWithSetters() { final File directory = Paths.get( outputDir.getAbsolutePath(), "org", "eclipse", "esmf", "test" ).toFile(); assertThat( directory ).exists(); assertThat( directory ).isDirectoryContaining( - file -> file.getName().equals( "AspectWithEntity.java" ) || file.getName().equals( "TestEntity.java" ) ); + file -> "AspectWithEntity.java".equals( file.getName() ) || "TestEntity.java".equals( file.getName() ) ); final File sourceFile = directory.toPath().resolve( "AspectWithEntity.java" ).toFile(); assertThat( sourceFile ).content().contains( "public void setTestProperty(final TestEntity testProperty)" ); @@ -712,7 +735,7 @@ void testAspectToJavaWithFluentSetters() { final File directory = Paths.get( outputDir.getAbsolutePath(), "org", "eclipse", "esmf", "test" ).toFile(); assertThat( directory ).exists(); assertThat( directory ).isDirectoryContaining( - file -> file.getName().equals( "AspectWithEntity.java" ) || file.getName().equals( "TestEntity.java" ) ); + file -> "AspectWithEntity.java".equals( file.getName() ) || "TestEntity.java".equals( file.getName() ) ); final File sourceFile = directory.toPath().resolve( "AspectWithEntity.java" ).toFile(); assertThat( sourceFile ).content().contains( "public AspectWithEntity setTestProperty(final TestEntity testProperty)" ); @@ -730,7 +753,7 @@ void testAspectToJavaWithFluentCompactSetters() { final File directory = Paths.get( outputDir.getAbsolutePath(), "org", "eclipse", "esmf", "test" ).toFile(); assertThat( directory ).exists(); assertThat( directory ).isDirectoryContaining( - file -> file.getName().equals( "AspectWithEntity.java" ) || file.getName().equals( "TestEntity.java" ) ); + file -> "AspectWithEntity.java".equals( file.getName() ) || "TestEntity.java".equals( file.getName() ) ); final File sourceFile = directory.toPath().resolve( "AspectWithEntity.java" ).toFile(); assertThat( sourceFile ).content().contains( "public AspectWithEntity testProperty(final TestEntity testProperty)" ); @@ -747,7 +770,7 @@ void testAspectToJavaStaticWithDefaultPackageName() { final File directory = Paths.get( outputDir.getAbsolutePath(), "org", "eclipse", "esmf", "test" ).toFile(); assertThat( directory ).exists(); assertThat( directory ).isDirectoryContaining( - file -> file.getName().equals( "MetaAspectWithEntity.java" ) || file.getName().equals( "MetaTestEntity.java" ) ); + file -> "MetaAspectWithEntity.java".equals( file.getName() ) || "MetaTestEntity.java".equals( file.getName() ) ); final File sourceFile = directory.toPath().resolve( "MetaAspectWithEntity.java" ).toFile(); assertThat( sourceFile ).content().contains( "package org.eclipse.esmf.test;" ); @@ -765,7 +788,7 @@ void testAspectToJavaStaticWithCustomPackageName() { final File directory = Paths.get( outputDir.getAbsolutePath(), "com", "example", "foo" ).toFile(); assertThat( directory ).exists(); assertThat( directory ).isDirectoryContaining( - file -> file.getName().equals( "MetaAspectWithEntity.java" ) || file.getName().equals( "MetaTestEntity.java" ) ); + file -> "MetaAspectWithEntity.java".equals( file.getName() ) || "MetaTestEntity.java".equals( file.getName() ) ); final File sourceFile = directory.toPath().resolve( "MetaAspectWithEntity.java" ).toFile(); assertThat( sourceFile ).content().contains( "package com.example.foo;" ); @@ -783,7 +806,7 @@ void testAspectToJavaStaticWithDefaultPackageNameWithCustomResolver() { final File directory = Paths.get( outputDir.getAbsolutePath(), "org", "eclipse", "esmf", "test" ).toFile(); assertThat( directory ).exists(); assertThat( directory ).isDirectoryContaining( - file -> file.getName().equals( "MetaAspectWithEntity.java" ) || file.getName().equals( "MetaTestEntity.java" ) ); + file -> "MetaAspectWithEntity.java".equals( file.getName() ) || "MetaTestEntity.java".equals( file.getName() ) ); final File sourceFile = directory.toPath().resolve( "MetaAspectWithEntity.java" ).toFile(); assertThat( sourceFile ).content().contains( "package org.eclipse.esmf.test;" ); @@ -804,7 +827,7 @@ void testAspectToJavaStaticWithCustomFileHeader() { final File directory = Paths.get( outputDir.getAbsolutePath(), "org", "eclipse", "esmf", "test" ).toFile(); assertThat( directory ).exists(); assertThat( directory ).isDirectoryContaining( - file -> file.getName().equals( "MetaAspectWithEntity.java" ) || file.getName().equals( "MetaTestEntity.java" ) ); + file -> "MetaAspectWithEntity.java".equals( file.getName() ) || "MetaTestEntity.java".equals( file.getName() ) ); final File sourceFile = directory.toPath().resolve( "MetaAspectWithEntity.java" ).toFile(); final String expectedCopyright = String.format( "Copyright (c) %s Test Inc. All rights reserved", LocalDate.now().getYear() ); @@ -1630,7 +1653,7 @@ void testPackageExportForAspectFromUrn() { /** * Returns the File object for a test namespace package file */ - private File inputFile( final String filename ) { + private static File inputFile( final String filename ) { final String resourcePath = String.format( "%s/../../core/esmf-test-aspect-models/src/main/resources/packages/%s", System.getProperty( "user.dir" ), filename ); try { @@ -1643,11 +1666,20 @@ private File inputFile( final String filename ) { /** * Returns the File object for a test model file */ - private File inputFile( final TestModel testModel ) { + private static File inputFile( final TestModel testModel ) { final boolean isValid = !(testModel instanceof InvalidTestAspect); - final String resourcePath = String.format( - "%s/../../core/esmf-test-aspect-models/src/main/resources/%s/org.eclipse.esmf.test/1.0.0/%s.ttl", - System.getProperty( "user.dir" ), isValid ? "valid" : "invalid", testModel.getName() ); + final boolean isOrdering = testModel instanceof OrderingTestAspect; + + final String resourcePath; + if ( isOrdering ) { + resourcePath = String.format( + "%s/../../core/esmf-test-aspect-models/src/main/resources/valid/org.eclipse.esmf.test.ordering/1.0.0/%s.ttl", + System.getProperty( "user.dir" ), testModel.getName() ); + } else { + resourcePath = String.format( + "%s/../../core/esmf-test-aspect-models/src/main/resources/%s/org.eclipse.esmf.test/1.0.0/%s.ttl", + System.getProperty( "user.dir" ), isValid ? "valid" : "invalid", testModel.getName() ); + } try { return new File( resourcePath ).getCanonicalFile(); @@ -1663,7 +1695,7 @@ private File outputFile( final String filename ) { return outputDirectory.toAbsolutePath().resolve( filename ).toFile(); } - private void writeToFile( final File file, final String content ) { + private static void writeToFile( final File file, final String content ) { try { final BufferedWriter writer = new BufferedWriter( new FileWriter( file ) ); writer.write( content ); @@ -1673,7 +1705,7 @@ private void writeToFile( final File file, final String content ) { } } - private MediaType contentType( final byte[] input ) { + private MediaType contentType( final byte... input ) { try { return new TikaConfig().getDetector().detect( new BufferedInputStream( new ByteArrayInputStream( input ) ), new Metadata() ); } catch ( final IOException | TikaException exception ) { @@ -1681,7 +1713,7 @@ private MediaType contentType( final byte[] input ) { } } - private MediaType contentType( final File file ) { + private static MediaType contentType( final File file ) { try { return new TikaConfig().getDetector().detect( new BufferedInputStream( new FileInputStream( file ) ), new Metadata() ); } catch ( final IOException | TikaException exception ) { @@ -1689,7 +1721,7 @@ private MediaType contentType( final File file ) { } } - private String resolverCommand() { + private static String resolverCommand() { // Note that the following code must not use .class/.getClass()/.getClassLoader() but only operate on the file system level, // since otherwise it will break when running the test suite from the maven build (where tests are run from the jar and resources // are not resolved to the file system but to the jar) @@ -1699,7 +1731,7 @@ private String resolverCommand() { ? ".bat" : ".sh") ).getCanonicalPath(); final String modelsRoot = new File( System.getProperty( "user.dir" ) + "/target/classes/valid" ).getCanonicalPath(); final String metaModelVersion = KnownVersion.getLatest().toString().toLowerCase(); - return resolverScript + " " + modelsRoot + " " + metaModelVersion; + return resolverScript + ' ' + modelsRoot + ' ' + metaModelVersion; } catch ( final IOException exception ) { throw new RuntimeException( exception ); } From cab1215a4968bb66bdb81ec4268c3deae9e87080 Mon Sep 17 00:00:00 2001 From: efilchenko Date: Fri, 19 Sep 2025 13:37:15 +0300 Subject: [PATCH 3/3] delete deprecated property --- .../org.eclipse.esmf.test.ordering.dependency/1.0.0/Aspect.ttl | 1 - 1 file changed, 1 deletion(-) diff --git a/core/esmf-test-aspect-models/src/main/resources/valid/org.eclipse.esmf.test.ordering.dependency/1.0.0/Aspect.ttl b/core/esmf-test-aspect-models/src/main/resources/valid/org.eclipse.esmf.test.ordering.dependency/1.0.0/Aspect.ttl index e6022b99b..bf424d97e 100644 --- a/core/esmf-test-aspect-models/src/main/resources/valid/org.eclipse.esmf.test.ordering.dependency/1.0.0/Aspect.ttl +++ b/core/esmf-test-aspect-models/src/main/resources/valid/org.eclipse.esmf.test.ordering.dependency/1.0.0/Aspect.ttl @@ -22,7 +22,6 @@ samm:events ( ) . :test a samm:Property ; - samm:name "test property" ; samm:characteristic :TestCharacteristic . :TestCharacteristic a samm:Characteristic ;