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 52d9e5391..b1040815f 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 @@ -26,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; @@ -454,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<>() ); } } 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..bf424d97e --- /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,29 @@ +# 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: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 ( ) . 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 ); }