Skip to content

Commit 0c75e8c

Browse files
committed
Add test
1 parent fc2e78f commit 0c75e8c

File tree

7 files changed

+122
-25
lines changed

7 files changed

+122
-25
lines changed

core/esmf-aspect-meta-model-java/src/test/java/org/eclipse/esmf/metamodel/UnitGenerationTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121

2222
import org.junit.jupiter.api.Test;
2323

24-
public class UnitGenerationTest {
24+
class UnitGenerationTest {
2525
@Test
26-
public void testUnitFromName() {
26+
void testUnitFromName() {
2727
final Optional<Unit> optionalUnit = Units.fromName( "degreeCelsius" );
2828
final Unit unit = optionalUnit.get();
2929
assertThat( unit )
@@ -33,19 +33,19 @@ public void testUnitFromName() {
3333
}
3434

3535
@Test
36-
public void testUnitWithoutReferenceUnit() {
36+
void testUnitWithoutReferenceUnit() {
3737
final Unit ampere = Units.fromName( "ampere" ).get();
3838
assertThat( ampere ).hasNoReferenceUnit();
3939
}
4040

4141
@Test
42-
public void testUnitFromcode() {
42+
void testUnitFromcode() {
4343
final Unit unit = Units.fromCode( "A97" ).get();
4444
assertThat( unit ).isEqualTo( Units.fromName( "hectopascal" ).get() );
4545
}
4646

4747
@Test
48-
public void testUnitFromSymbol() {
48+
void testUnitFromSymbol() {
4949
// Unit with unique symbol
5050
assertThat( Units.fromSymbol( "kg" ) ).containsExactly( Units.fromName( "kilogram" ).get() );
5151

@@ -54,7 +54,7 @@ public void testUnitFromSymbol() {
5454
}
5555

5656
@Test
57-
public void testUnitsWithQuantityKind() {
57+
void testUnitsWithQuantityKind() {
5858
final Set<Unit> units = Units.unitsWithQuantityKind( QuantityKinds.DISTANCE );
5959
assertThat( units ).containsAnyOf( Units.fromName( "nanometre" ).get(), Units.fromName( "metre" ).get(),
6060
Units.fromName( "kilometre" ).get(), Units.fromName( "foot" ).get(), Units.fromName( "lightYear" ).get() );
@@ -63,12 +63,12 @@ public void testUnitsWithQuantityKind() {
6363
}
6464

6565
@Test
66-
public void testGeneratedQuantityKinds() {
66+
void testGeneratedQuantityKinds() {
6767
assertThat( QuantityKinds.values().length ).isGreaterThanOrEqualTo( 80 );
6868
}
6969

7070
@Test
71-
public void testQuantityKindFromName() {
71+
void testQuantityKindFromName() {
7272
final QuantityKind quantityKind = QuantityKinds.fromName( "distance" ).get();
7373
assertThat( quantityKind ).hasName( "distance" ).hasLabel( "distance" );
7474
}

core/esmf-aspect-model-java-generator/src/test/java/org/eclipse/esmf/aspectmodel/java/AspectModelJavaGeneratorTest.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.util.Optional;
3030
import java.util.Set;
3131
import java.util.regex.Pattern;
32+
3233
import javax.xml.datatype.Duration;
3334
import javax.xml.datatype.XMLGregorianCalendar;
3435

@@ -63,7 +64,7 @@
6364
import org.junit.jupiter.params.ParameterizedTest;
6465
import org.junit.jupiter.params.provider.EnumSource;
6566

66-
public class AspectModelJavaGeneratorTest {
67+
class AspectModelJavaGeneratorTest {
6768
private Collection<JavaGenerator> getGenerators( final TestAspect testAspect, final JavaCodeGenerationConfig config ) {
6869
final Aspect aspect = TestResources.load( testAspect ).aspect();
6970
return List.of( new AspectModelJavaGenerator( aspect, config ) );
@@ -240,6 +241,26 @@ void testGenerateAspectModelWithOptionalProperties() throws IOException {
240241
assertConstructor( result, "AspectWithOptionalProperties", expectedFieldsForAspectClass );
241242
}
242243

244+
@Test
245+
void testGenerateAspectWithOptionalPropertyAndEntityWithSeparateFiles() throws IOException {
246+
final ImmutableMap<String, Object> expectedFieldsForAspectClass = ImmutableMap.<String, Object> builder()
247+
.put( "productionPeriod", "Optional<ProductionPeriodEntity>" )
248+
.build();
249+
250+
final TestAspect aspect = TestAspect.ASPECT_WITH_OPTIONAL_PROPERTIES_AND_ENTITY_WITH_SEPARATE_FILES;
251+
final GenerationResult result = TestContext.generateAspectCode().apply( getGenerators( aspect ) );
252+
253+
result.assertNumberOfFiles( 2 );
254+
result.assertFields( "AspectWithOptionalPropertiesAndEntityWithSeparateFiles", expectedFieldsForAspectClass, new HashMap<>() );
255+
assertConstructor( result, "AspectWithOptionalPropertiesAndEntityWithSeparateFiles", expectedFieldsForAspectClass );
256+
257+
CompilationUnit unit = result.compilationUnits.get( "ProductionPeriodEntity" );
258+
ConstructorDeclaration constructor = unit.findFirst( ConstructorDeclaration.class )
259+
.orElseThrow( () -> new AssertionError( "Constructor not found in ProductionPeriodEntity" ) );
260+
String constructorBody = constructor.getBody().toString();
261+
assertThat( constructorBody ).contains( "Optional.of(_datatypeFactory.newXMLGregorianCalendarDate(" );
262+
}
263+
243264
@Test
244265
void testGenerateAspectModelWithCurie() throws IOException {
245266
final ImmutableMap<String, Object> expectedFieldsForAspectClass = ImmutableMap.<String, Object> builder()

core/esmf-aspect-model-java-generator/src/test/java/org/eclipse/esmf/aspectmodel/java/AspectModelJavaUtilTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import org.junit.jupiter.params.provider.Arguments;
3030
import org.junit.jupiter.params.provider.MethodSource;
3131

32-
public class AspectModelJavaUtilTest extends PropertyBasedTest {
32+
class AspectModelJavaUtilTest extends PropertyBasedTest {
3333
private boolean isValidJavaIdentifier( final String value ) {
3434
if ( value == null || value.isEmpty() ) {
3535
return false;
@@ -45,7 +45,7 @@ private boolean isValidJavaIdentifier( final String value ) {
4545
}
4646

4747
@Property
48-
public boolean generatedEnumKeysAreValidJavaIdentifiers( @ForAll( "anyValidTypeValuePair" ) final Tuple.Tuple2<Type, Value> tuple ) {
48+
boolean generatedEnumKeysAreValidJavaIdentifiers( @ForAll( "anyValidTypeValuePair" ) final Tuple.Tuple2<Type, Value> tuple ) {
4949
final String result = AspectModelJavaUtil.generateEnumKey( tuple.get2() );
5050
return isValidJavaIdentifier( result );
5151
}

core/esmf-aspect-model-java-generator/src/test/java/org/eclipse/esmf/aspectmodel/java/JavaCodeGenerationConfigurationTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@
2222

2323
import org.junit.jupiter.api.Test;
2424

25-
public class JavaCodeGenerationConfigurationTest {
25+
class JavaCodeGenerationConfigurationTest {
2626
final String currentWorkingDirectory = System.getProperty( "user.dir" );
2727
private final File templateLibFile = Path.of( currentWorkingDirectory, "/templates", "/test-macro-lib.vm" ).toFile();
2828
private final File emptyTemplateLibFile = Path.of( "" ).toFile();
2929
private final File nonExistingTemplateLibPath = Path.of( "/templates", "/non-existing.vm" ).toFile();
3030

3131
@Test
32-
public void testValidTemplateLibConfig() {
32+
void testValidTemplateLibConfig() {
3333
assertThatCode( () ->
3434
JavaCodeGenerationConfigBuilder.builder()
3535
.enableJacksonAnnotations( true )
@@ -54,7 +54,7 @@ public void testValidTemplateLibConfig() {
5454
}
5555

5656
@Test
57-
public void testTemplateLibConfigMissingFile() {
57+
void testTemplateLibConfigMissingFile() {
5858
assertThatCode( () ->
5959
JavaCodeGenerationConfigBuilder.builder()
6060
.enableJacksonAnnotations( true )
@@ -67,7 +67,7 @@ public void testTemplateLibConfigMissingFile() {
6767
}
6868

6969
@Test
70-
public void testTemplateLibConfigNonExistingFile() {
70+
void testTemplateLibConfigNonExistingFile() {
7171
assertThatCode( () ->
7272
JavaCodeGenerationConfigBuilder.builder()
7373
.enableJacksonAnnotations( true )

core/esmf-aspect-model-java-generator/src/test/java/org/eclipse/esmf/aspectmodel/java/StaticMetaModelBaseAttributesTest.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import com.google.common.collect.ImmutableSet;
2323
import org.junit.jupiter.api.Test;
2424

25-
public class StaticMetaModelBaseAttributesTest extends StaticMetaModelGeneratorTest {
25+
class StaticMetaModelBaseAttributesTest extends StaticMetaModelGeneratorTest {
2626

2727
@Test
2828
void testMetaModelBaseAttributesOfGeneratedProperty() throws IOException {
@@ -40,7 +40,7 @@ void testMetaModelBaseAttributesOfGeneratedProperty() throws IOException {
4040
}
4141

4242
@Test
43-
public void testMetaModelBaseAttributesOfGeneratedPropertyWithAllAttributes() throws IOException {
43+
void testMetaModelBaseAttributesOfGeneratedPropertyWithAllAttributes() throws IOException {
4444
final TestAspect aspect = TestAspect.ASPECT_WITH_PROPERTY_WITH_ALL_BASE_ATTRIBUTES;
4545
final StaticClassGenerationResult result = TestContext.generateStaticAspectCode().apply( getGenerators( aspect ) );
4646
result.assertNumberOfFiles( 2 );
@@ -60,7 +60,7 @@ public void testMetaModelBaseAttributesOfGeneratedPropertyWithAllAttributes() th
6060
}
6161

6262
@Test
63-
public void testMetaModelBaseAttributesOfGeneratedPropertyWithPreferredNames() throws IOException {
63+
void testMetaModelBaseAttributesOfGeneratedPropertyWithPreferredNames() throws IOException {
6464
final TestAspect aspect = TestAspect.ASPECT_WITH_PROPERTY_WITH_PREFERRED_NAMES;
6565
final StaticClassGenerationResult result = TestContext.generateStaticAspectCode().apply( getGenerators( aspect ) );
6666
result.assertNumberOfFiles( 2 );
@@ -76,7 +76,7 @@ public void testMetaModelBaseAttributesOfGeneratedPropertyWithPreferredNames() t
7676
}
7777

7878
@Test
79-
public void testMetaModelBaseAttributesOfGeneratedPropertyWithDescriptions() throws IOException {
79+
void testMetaModelBaseAttributesOfGeneratedPropertyWithDescriptions() throws IOException {
8080
final TestAspect aspect = TestAspect.ASPECT_WITH_PROPERTY_WITH_DESCRIPTIONS;
8181
final StaticClassGenerationResult result = TestContext.generateStaticAspectCode()
8282
.apply( getGenerators( aspect ) );
@@ -93,7 +93,7 @@ public void testMetaModelBaseAttributesOfGeneratedPropertyWithDescriptions() thr
9393
}
9494

9595
@Test
96-
public void testMetaModelBaseAttributesOfGeneratedPropertyWithSee() throws IOException {
96+
void testMetaModelBaseAttributesOfGeneratedPropertyWithSee() throws IOException {
9797
final TestAspect aspect = TestAspect.ASPECT_WITH_PROPERTY_WITH_SEE;
9898
final StaticClassGenerationResult result = TestContext.generateStaticAspectCode()
9999
.apply( getGenerators( aspect ) );
@@ -110,7 +110,7 @@ public void testMetaModelBaseAttributesOfGeneratedPropertyWithSee() throws IOExc
110110
}
111111

112112
@Test
113-
public void testGeneratedMetaModelContainsRequiredMethods() throws IOException {
113+
void testGeneratedMetaModelContainsRequiredMethods() throws IOException {
114114
final TestAspect aspect = TestAspect.ASPECT_WITH_BOOLEAN;
115115
final StaticClassGenerationResult result = TestContext.generateStaticAspectCode()
116116
.apply( getGenerators( aspect ) );
@@ -132,7 +132,7 @@ public void testGeneratedMetaModelContainsRequiredMethods() throws IOException {
132132
}
133133

134134
@Test
135-
public void testGeneratedMetaModelContainsOptionalMethods() throws IOException {
135+
void testGeneratedMetaModelContainsOptionalMethods() throws IOException {
136136
final TestAspect aspect = TestAspect.ASPECT_WITH_ALL_BASE_ATTRIBUTES;
137137
final StaticClassGenerationResult result = TestContext.generateStaticAspectCode()
138138
.apply( getGenerators( aspect ) );
@@ -173,7 +173,7 @@ public void testGeneratedMetaModelContainsOptionalMethods() throws IOException {
173173
}
174174

175175
@Test
176-
public void testGeneratedMetaModelContainsGetPreferredNamesMethod() throws IOException {
176+
void testGeneratedMetaModelContainsGetPreferredNamesMethod() throws IOException {
177177
final TestAspect aspect = TestAspect.ASPECT_WITH_PREFERRED_NAMES;
178178
final StaticClassGenerationResult result = TestContext.generateStaticAspectCode()
179179
.apply( getGenerators( aspect ) );
@@ -204,7 +204,7 @@ public void testGeneratedMetaModelContainsGetPreferredNamesMethod() throws IOExc
204204
}
205205

206206
@Test
207-
public void testGeneratedMetaModelContainsGetDescriptionsMethod() throws IOException {
207+
void testGeneratedMetaModelContainsGetDescriptionsMethod() throws IOException {
208208
final TestAspect aspect = TestAspect.ASPECT_WITH_DESCRIPTIONS;
209209
final StaticClassGenerationResult result = TestContext.generateStaticAspectCode()
210210
.apply( getGenerators( aspect ) );
@@ -235,7 +235,7 @@ public void testGeneratedMetaModelContainsGetDescriptionsMethod() throws IOExcep
235235
}
236236

237237
@Test
238-
public void testGeneratedMetaModelContainsGetSeeMethod() throws IOException {
238+
void testGeneratedMetaModelContainsGetSeeMethod() throws IOException {
239239
final TestAspect aspect = TestAspect.ASPECT_WITH_PROPERTY_WITH_SEE;
240240
final StaticClassGenerationResult result = TestContext.generateStaticAspectCode()
241241
.apply( getGenerators( aspect ) );

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ public enum TestAspect implements TestModel {
143143
ASPECT_WITH_OPERATION_WITH_SEE_ATTRIBUTE,
144144
ASPECT_WITH_OPTIONAL_PROPERTIES,
145145
ASPECT_WITH_OPTIONAL_PROPERTIES_WITH_ENTITY,
146+
ASPECT_WITH_OPTIONAL_PROPERTIES_AND_ENTITY_WITH_SEPARATE_FILES,
146147
ASPECT_WITH_OPTIONAL_PROPERTY,
147148
ASPECT_WITH_OPTIONAL_PROPERTY_AND_CONSTRAINT,
148149
ASPECT_WITH_OPTIONAL_PROPERTY_WITH_PAYLOAD_NAME,
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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:1.0.0#> .
13+
@prefix samm: <urn:samm:org.eclipse.esmf.samm:meta-model:2.2.0#> .
14+
@prefix samm-c: <urn:samm:org.eclipse.esmf.samm:characteristic:2.2.0#> .
15+
@prefix samm-e: <urn:samm:org.eclipse.esmf.samm:entity:2.2.0#> .
16+
@prefix unit: <urn:samm:org.eclipse.esmf.samm:unit:2.2.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+
:AspectWithOptionalPropertiesAndEntityWithSeparateFiles a samm:Aspect ;
22+
samm:preferredName "Minimal Vehicle Type Aspect"@en ;
23+
samm:description "Simplified aspect containing only ProductionPeriodEntity as an optional property."@en ;
24+
samm:properties ( [ samm:property :productionPeriod; samm:optional true ] ) ;
25+
samm:operations ( ) ;
26+
samm:events ( ) .
27+
28+
:productionPeriod a samm:Property ;
29+
samm:preferredName "Production Period"@en ;
30+
samm:description "The production period of this vehicle type."@en ;
31+
samm:characteristic :ProductionPeriodCharacteristic .
32+
33+
:ProductionPeriodCharacteristic a samm-c:SingleEntity ;
34+
samm:preferredName "Production Period Characteristic"@en ;
35+
samm:dataType :ProductionPeriodEntity .
36+
37+
:ProductionPeriodEntity a samm:Entity ;
38+
samm:preferredName "Production Period Entity"@en ;
39+
samm:properties ( :productionPeriodFrom :productionPeriodTo ) .
40+
41+
:productionPeriodFrom a samm:Property ;
42+
samm:description "The start of production for this vehicle type."@en ;
43+
samm:characteristic :YearAndOptionalMonthTrait ;
44+
samm:exampleValue "2016-07" .
45+
46+
:productionPeriodTo a samm:Property ;
47+
samm:description "The end of production for this vehicle type."@en ;
48+
samm:characteristic :YearAndOptionalMonthTrait ;
49+
samm:exampleValue "2018" .
50+
51+
:YearAndOptionalMonthTrait a samm-c:Trait ;
52+
samm-c:baseCharacteristic :YearAndOptionalMonth ;
53+
samm-c:constraint :YearAndOptionalMonthRegex .
54+
55+
:YearAndOptionalMonth a samm-c:StructuredValue ;
56+
samm:preferredName "Year with Optional Month"@en ;
57+
samm:dataType xsd:string ;
58+
samm-c:deconstructionRule "^([0-9]{4})(?:-(0[1-9]|1[0-2]))?" ;
59+
samm-c:elements ( "^" :year "-" :month "$" ) .
60+
61+
:YearAndOptionalMonthRegex a samm-c:RegularExpressionConstraint ;
62+
samm:value "^([0-9]{4})(?:-(0[1-9]|1[0-2]))?" .
63+
64+
:year a samm:Property ;
65+
samm:characteristic :YearCharacteristic .
66+
67+
:month a samm:Property ;
68+
samm:optional true ;
69+
samm:characteristic :MonthCharacteristic .
70+
71+
:YearCharacteristic a samm:Characteristic ;
72+
samm:dataType xsd:gYear .
73+
74+
:MonthCharacteristic a samm:Characteristic ;
75+
samm:dataType xsd:gMonth .

0 commit comments

Comments
 (0)