Skip to content

Commit 9e8fc33

Browse files
committed
Update tests and logic
1 parent 0eaeddd commit 9e8fc33

File tree

9 files changed

+38
-52
lines changed

9 files changed

+38
-52
lines changed

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

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@
1414
package org.eclipse.esmf.aspectmodel.loader;
1515

1616
import java.util.ArrayList;
17+
import java.util.Collection;
1718
import java.util.HashMap;
1819
import java.util.LinkedHashSet;
1920
import java.util.List;
2021
import java.util.Map;
2122
import java.util.Optional;
23+
import java.util.Set;
2224
import java.util.function.Function;
2325
import java.util.stream.Collectors;
2426
import java.util.stream.Stream;
@@ -166,31 +168,14 @@ protected Value buildValue( final RDFNode node, final Optional<Resource> charact
166168
if ( node.isResource() ) {
167169
Resource resource = node.asResource();
168170

169-
if ( resource.canAs( RDFList.class ) ) {
170-
RDFList list = resource.as( RDFList.class );
171-
List<Value> values = list.iterator().toList().stream()
172-
.map( rdfNode -> buildValue( rdfNode, characteristicResource, type ) )
173-
.toList();
174-
175-
return new DefaultCollectionValue( values, CollectionValue.CollectionType.SET, type );
176-
}
177-
178-
if ( type.is( Entity.class ) ) {
179-
return buildEntityInstance( resource, (Entity) type );
180-
}
181-
182-
if ( !resource.hasProperty( RDF.type, SammNs.SAMM.Value() ) ) {
183-
return new DefaultScalarValue( buildBaseAttributes( resource ), resource.getURI(), new DefaultScalar( type.toString() ) );
184-
}
185-
186171
if ( resource.hasProperty( RDF.type, SammNs.SAMM.Value() ) ) {
187172
Optional<String> valueOpt = optionalAttributeValue( resource, SammNs.SAMM.value() ).map( Statement::getString );
188173

189174
if ( valueOpt.isEmpty() ) {
190175
throw new AspectLoadingException( "samm:Value must contain a samm:value property" );
191176
}
192177

193-
return new DefaultScalarValue( buildBaseAttributes( resource ), valueOpt.get(), new DefaultScalar( type.toString() ) );
178+
return new DefaultScalarValue( buildBaseAttributes( resource ), valueOpt.get(), new DefaultScalar( type.getUrn() ) );
194179
}
195180
}
196181

core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/serializer/RdfModelCreatorVisitor.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -647,14 +647,10 @@ public ElementModel visitProperty( final Property property, final ModelElement c
647647
model.add( serializeDescriptions( resource, property ) );
648648

649649
property.getExampleValue().ifPresent( exampleValue -> {
650-
if ( exampleValue instanceof Value value ) {
651-
final ElementModel exampleValueElementModel = ( value ).accept( this, property );
652-
model.add( exampleValueElementModel.model() );
653-
exampleValueElementModel.focusElement().ifPresent( exampleValueNode ->
654-
model.add( resource, SammNs.SAMM.exampleValue(), exampleValueNode ) );
655-
} else {
656-
throw new IllegalArgumentException( "exampleValue is not a Value: " + exampleValue.getClass() );
657-
}
650+
final ElementModel exampleValueElementModel = ( exampleValue ).accept( this, property );
651+
model.add( exampleValueElementModel.model() );
652+
exampleValueElementModel.focusElement().ifPresent( exampleValueNode ->
653+
model.add( resource, SammNs.SAMM.exampleValue(), exampleValueNode ) );
658654
} );
659655

660656
property.getCharacteristic().ifPresent( characteristic -> {

core/esmf-aspect-meta-model-java/src/test/java/org/eclipse/esmf/aspectmodel/edit/AspectChangeManagerTest.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import org.eclipse.esmf.metamodel.Property;
4444
import org.eclipse.esmf.metamodel.impl.DefaultNamespace;
4545
import org.eclipse.esmf.metamodel.vocabulary.SammNs;
46+
import org.eclipse.esmf.samm.KnownVersion;
4647
import org.eclipse.esmf.test.TestAspect;
4748
import org.eclipse.esmf.test.TestResources;
4849

@@ -166,15 +167,15 @@ void testCreateFileWithElementDefinition() {
166167
final AspectModelFile aspectModelFile = RawAspectModelFileBuilder.builder()
167168
.sourceLocation( Optional.of( URI.create( "file:///temp/test.ttl" ) ) )
168169
.sourceModel( createModel( """
169-
@prefix samm: <urn:samm:org.eclipse.esmf.samm:meta-model:2.2.0#> .
170+
@prefix samm: <urn:samm:org.eclipse.esmf.samm:meta-model:%s#> .
170171
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
171172
@prefix : <urn:samm:org.eclipse.esmf.test:1.0.0#> .
172173
173174
:Aspect a samm:Aspect ;
174175
samm:description "This is a test description"@en ;
175176
samm:properties ( ) ;
176177
samm:operations ( ) .
177-
"""
178+
""".formatted( KnownVersion.getLatest().toVersionString() )
178179
) )
179180
.build();
180181
final Change addFile = new AddAspectModelFile( aspectModelFile );
@@ -205,15 +206,15 @@ void testCreateFileThenAddElementDefinition() {
205206
new AddAspectModelFile( aspectModelFile ),
206207
new AddElementDefinition( AspectModelUrn.fromUrn( "urn:samm:org.eclipse.esmf.test:1.0.0#Aspect" ),
207208
createModel( """
208-
@prefix samm: <urn:samm:org.eclipse.esmf.samm:meta-model:2.2.0#> .
209+
@prefix samm: <urn:samm:org.eclipse.esmf.samm:meta-model:%s#> .
209210
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
210211
@prefix : <urn:samm:org.eclipse.esmf.test:1.0.0#> .
211212
212213
:Aspect a samm:Aspect ;
213214
samm:description "This is a test description"@en ;
214215
samm:properties ( ) ;
215216
samm:operations ( ) .
216-
""" ), aspectModelFile )
217+
""".formatted( KnownVersion.getLatest().toVersionString() ) ), aspectModelFile )
217218
);
218219

219220
changeManager.applyChange( changes );
@@ -274,15 +275,15 @@ void testMoveElementToExistingFile() {
274275
final AspectModelFile file1 = RawAspectModelFileBuilder.builder()
275276
.sourceLocation( file1Location )
276277
.sourceModel( createModel( """
277-
@prefix samm: <urn:samm:org.eclipse.esmf.samm:meta-model:2.2.0#> .
278+
@prefix samm: <urn:samm:org.eclipse.esmf.samm:meta-model:%s#> .
278279
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
279280
@prefix : <urn:samm:org.eclipse.esmf.test:1.0.0#> .
280281
281282
:Aspect a samm:Aspect ;
282283
samm:description "This is a test description"@en ;
283284
samm:properties ( ) ;
284285
samm:operations ( ) .
285-
"""
286+
""".formatted( KnownVersion.getLatest().toVersionString() )
286287
) )
287288
.build();
288289
final AspectModelFile file2 = RawAspectModelFileBuilder.builder().sourceLocation( file2Location ).build();
@@ -355,15 +356,15 @@ void testMoveElementToOtherNamespaceExistingFile() {
355356
final AspectModelFile file1 = RawAspectModelFileBuilder.builder()
356357
.sourceLocation( file1Location )
357358
.sourceModel( createModel( """
358-
@prefix samm: <urn:samm:org.eclipse.esmf.samm:meta-model:2.2.0#> .
359+
@prefix samm: <urn:samm:org.eclipse.esmf.samm:meta-model:%s#> .
359360
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
360361
@prefix : <urn:samm:org.eclipse.esmf.test:1.0.0#> .
361362
362363
:Aspect a samm:Aspect ;
363364
samm:description "This is a test description"@en ;
364365
samm:properties ( ) ;
365366
samm:operations ( ) .
366-
"""
367+
""".formatted( KnownVersion.getLatest().toVersionString() )
367368
) )
368369
.build();
369370
final AspectModelFile file2 = RawAspectModelFileBuilder.builder().sourceLocation( file2Location ).build();

core/esmf-aspect-meta-model-java/src/test/java/org/eclipse/esmf/aspectmodel/serializer/AspectSerializerTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.eclipse.esmf.aspectmodel.resolver.modelfile.RawAspectModelFileBuilder;
3535
import org.eclipse.esmf.aspectmodel.resolver.services.TurtleLoader;
3636
import org.eclipse.esmf.metamodel.AspectModel;
37+
import org.eclipse.esmf.samm.KnownVersion;
3738
import org.eclipse.esmf.test.TestAspect;
3839
import org.eclipse.esmf.test.TestResources;
3940

@@ -120,30 +121,30 @@ void testWriteAspectModelToFileSystem() {
120121
final AspectModelFile file1 = RawAspectModelFileBuilder.builder()
121122
.sourceLocation( Optional.of( file1Path.toUri() ) )
122123
.sourceModel( createModel( """
123-
@prefix samm: <urn:samm:org.eclipse.esmf.samm:meta-model:2.2.0#> .
124+
@prefix samm: <urn:samm:org.eclipse.esmf.samm:meta-model:%s#> .
124125
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
125126
@prefix : <urn:samm:org.eclipse.esmf.test:1.0.0#> .
126127
127128
:Aspect1 a samm:Aspect ;
128129
samm:description "This is a test description"@en ;
129130
samm:properties ( ) ;
130131
samm:operations ( ) .
131-
"""
132+
""".formatted( KnownVersion.getLatest().toVersionString() )
132133
) )
133134
.build();
134135
final Path file2Path = outputDirectory.resolve( "Aspect2.ttl" );
135136
final AspectModelFile file2 = RawAspectModelFileBuilder.builder()
136137
.sourceLocation( Optional.of( file2Path.toUri() ) )
137138
.sourceModel( createModel( """
138-
@prefix samm: <urn:samm:org.eclipse.esmf.samm:meta-model:2.2.0#> .
139+
@prefix samm: <urn:samm:org.eclipse.esmf.samm:meta-model:%s#> .
139140
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
140141
@prefix : <urn:samm:org.eclipse.esmf.test:1.0.0#> .
141142
142143
:Aspect2 a samm:Aspect ;
143144
samm:description "This is a test description"@en ;
144145
samm:properties ( ) ;
145146
samm:operations ( ) .
146-
"""
147+
""".formatted( KnownVersion.getLatest().toVersionString() )
147148
) )
148149
.build();
149150
final AspectChangeManager changeContext = new AspectChangeManager( aspectModel );

core/esmf-aspect-model-document-generators/src/test/java/org/eclipse/esmf/aspectmodel/generator/json/AspectModelJsonPayloadGeneratorTest.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ static void setup() {
148148
@ParameterizedTest
149149
@EnumSource( value = TestAspect.class, mode = EnumSource.Mode.EXCLUDE, names = {
150150
"MODEL_WITH_BROKEN_CYCLES",
151-
"ASPECT_WITH_MULTIPLE_ENTITIES_SAME_EXTEND"
151+
"ASPECT_WITH_MULTIPLE_ENTITIES_SAME_EXTEND",
152+
"ASPECT_WITH_ANY_VALUE_DECLARATIONS"
152153
} )
153154
void testDeserializationForGeneratedJson( final TestAspect testAspect ) {
154155
final Aspect aspect = TestResources.load( testAspect ).aspect();
@@ -790,13 +791,11 @@ Trait createTraitWithRangeConstraint( final Type dataType, final BoundDefinition
790791
.withUrn( TestModel.TEST_NAMESPACE + "TestConstraint" ).build();
791792
final Optional<ScalarValue> minValue = BoundDefinition.OPEN.equals( boundKind )
792793
? Optional.empty()
793-
:
794-
Optional.of( new DefaultScalarValue( MetaModelBaseAttributes.builder().build(), randomRange.getLeft(),
794+
: Optional.of( new DefaultScalarValue( MetaModelBaseAttributes.builder().build(), randomRange.getLeft(),
795795
new DefaultScalar( dataType.getUrn() ) ) );
796796
final Optional<ScalarValue> maxValue = BoundDefinition.OPEN.equals( boundKind )
797797
? Optional.empty()
798-
:
799-
Optional.of( new DefaultScalarValue( MetaModelBaseAttributes.builder().build(), randomRange.getRight(),
798+
: Optional.of( new DefaultScalarValue( MetaModelBaseAttributes.builder().build(), randomRange.getRight(),
800799
new DefaultScalar( dataType.getUrn() ) ) );
801800
final RangeConstraint rangeConstraint = new DefaultRangeConstraint( constraintAttibutes, minValue, maxValue, boundKind,
802801
getMatchingUpperBound( boundKind ) );

core/esmf-aspect-model-document-generators/src/test/java/org/eclipse/esmf/aspectmodel/generator/jsonschema/AspectModelJsonSchemaGeneratorTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ private void assertPayloadIsValid( final JsonNode schema, final Aspect aspect )
126126
*/
127127
@ParameterizedTest
128128
@EnumSource( value = TestAspect.class, mode = EnumSource.Mode.EXCLUDE, names = {
129-
"MODEL_WITH_BROKEN_CYCLES" // contains cycles, but all of them should be "breakable", need to be investigated
129+
"MODEL_WITH_BROKEN_CYCLES", // contains cycles, but all of them should be "breakable", need to be investigated
130+
"ASPECT_WITH_ANY_VALUE_DECLARATIONS"
130131
} )
131132
void testGeneration( final TestAspect testAspect ) {
132133
final Aspect aspect = TestResources.load( testAspect ).aspect();

core/esmf-aspect-model-java-generator/src/main/java/org/eclipse/esmf/aspectmodel/java/metamodel/StaticMetaModelVisitor.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.eclipse.esmf.aspectmodel.java.ValueExpressionVisitor;
2828
import org.eclipse.esmf.aspectmodel.java.ValueInitializer;
2929
import org.eclipse.esmf.aspectmodel.java.exception.CodeGenerationException;
30+
import org.eclipse.esmf.aspectmodel.loader.MetaModelBaseAttributes;
3031
import org.eclipse.esmf.aspectmodel.visitor.AspectVisitor;
3132
import org.eclipse.esmf.metamodel.AbstractEntity;
3233
import org.eclipse.esmf.metamodel.BoundDefinition;
@@ -111,10 +112,11 @@ public String visitBase( final ModelElement modelElement, final StaticCodeGenera
111112
public String visitScalarValue( final ScalarValue value, final StaticCodeGenerationContext context ) {
112113
context.getCodeGenerationConfig().importTracker().importExplicit( DefaultScalarValue.class );
113114
final ValueExpressionVisitor.Context valueContext = new ValueExpressionVisitor.Context( context.getCodeGenerationConfig(), false );
114-
final String metaModelAttributes = ( !value.getSee().isEmpty() && !value.getPreferredNames().isEmpty() )
115-
? "getMetaModelBaseAttributes( value, context )"
116-
: null;
115+
final String metaModelAttributes = (!value.getSee().isEmpty() && !value.getPreferredNames().isEmpty())
116+
? getMetaModelBaseAttributes( value, context )
117+
: "MetaModelBaseAttributes.builder().build()";
117118
return "new DefaultScalarValue("
119+
// Object value
118120
+ metaModelAttributes + ","
119121
// Object value
120122
+ value.accept( valueExpressionVisitor, valueContext ) + ","

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ private Collection<JavaGenerator> getGenerators( final TestAspect testAspect, fi
122122
@ParameterizedTest
123123
@EnumSource( value = TestAspect.class, mode = EnumSource.Mode.EXCLUDE, names = {
124124
"ASPECT_WITH_USED_AND_UNUSED_ENUMERATION", // No code will be generated for an unused enumeration
125-
"MODEL_WITH_BROKEN_CYCLES" // Contains elements that are not references from the Aspect
125+
"MODEL_WITH_BROKEN_CYCLES", // Contains elements that are not references from the Aspect
126+
"ASPECT_WITH_ANY_VALUE_DECLARATIONS"
126127
} )
127128
void testCodeGeneration( final TestAspect testAspect ) {
128129
assertThatCode( () -> {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -446,9 +446,9 @@ void testCharacteristicInstantiationForEnums() throws IOException {
446446
new DefaultEnumeration(MetaModelBaseAttributes.builder().withUrn(AspectModelUrn.fromUrn(NAMESPACE + "TestEnumeration")).build(), new DefaultScalar("http://www.w3.org/2001/XMLSchema#integer"), new ArrayList<Value>() {
447447
448448
{
449-
add(new DefaultScalarValue(null, new BigInteger("1"), new DefaultScalar("http://www.w3.org/2001/XMLSchema#integer")));
450-
add(new DefaultScalarValue(null, new BigInteger("2"), new DefaultScalar("http://www.w3.org/2001/XMLSchema#integer")));
451-
add(new DefaultScalarValue(null, new BigInteger("3"), new DefaultScalar("http://www.w3.org/2001/XMLSchema#integer")));
449+
add(new DefaultScalarValue(MetaModelBaseAttributes.builder().build(), new BigInteger("1"), new DefaultScalar("http://www.w3.org/2001/XMLSchema#integer")));
450+
add(new DefaultScalarValue(MetaModelBaseAttributes.builder().build(), new BigInteger("2"), new DefaultScalar("http://www.w3.org/2001/XMLSchema#integer")));
451+
add(new DefaultScalarValue(MetaModelBaseAttributes.builder().build(), new BigInteger("3"), new DefaultScalar("http://www.w3.org/2001/XMLSchema#integer")));
452452
}
453453
})""";
454454

@@ -518,7 +518,7 @@ void testCharacteristicInstantiationForPropertyWithExampleValue() throws IOExcep
518518

519519
result.assertMetaModelBaseAttributesForProperties( "MetaAspectWithCollection", expectedBaseAttributes );
520520

521-
final String expectedExampleValue = "Optional.of(new DefaultScalarValue(null, \"Example Value\", new DefaultScalar(\"http://www.w3"
521+
final String expectedExampleValue = "Optional.of(new DefaultScalarValue(MetaModelBaseAttributes.builder().build(), \"Example Value\", new DefaultScalar(\"http://www.w3"
522522
+ ".org/2001/XMLSchema#string\")))";
523523

524524
result.assertConstructorArgumentForProperties(

0 commit comments

Comments
 (0)