|
| 1 | +package org.eclipse.esmf.metamodel.visitor; |
| 2 | + |
| 3 | +import static org.assertj.core.api.Assertions.assertThat; |
| 4 | + |
| 5 | +import java.io.ByteArrayInputStream; |
| 6 | +import java.io.InputStream; |
| 7 | +import java.nio.charset.StandardCharsets; |
| 8 | +import java.util.HashSet; |
| 9 | +import java.util.Locale; |
| 10 | +import java.util.Set; |
| 11 | + |
| 12 | +import org.apache.jena.rdf.model.Model; |
| 13 | +import org.apache.jena.rdf.model.ModelFactory; |
| 14 | +import org.apache.jena.riot.RDFLanguages; |
| 15 | +import org.eclipse.esmf.aspectmodel.VersionNumber; |
| 16 | +import org.eclipse.esmf.aspectmodel.resolver.services.SammAspectMetaModelResourceResolver; |
| 17 | +import org.eclipse.esmf.aspectmodel.resolver.services.VersionedModel; |
| 18 | +import org.eclipse.esmf.metamodel.Aspect; |
| 19 | +import org.eclipse.esmf.metamodel.loader.AspectModelLoader; |
| 20 | +import org.junit.jupiter.api.Test; |
| 21 | + |
| 22 | +class LanguageCollectorModelVisitorTest { |
| 23 | + |
| 24 | + @Test |
| 25 | + void testLanguageCollector() { |
| 26 | + final VersionedModel versionedModel = model( """ |
| 27 | + @prefix samm: <urn:samm:org.eclipse.esmf.samm:meta-model:2.0.0#> . |
| 28 | + @prefix samm-c: <urn:samm:org.eclipse.esmf.samm:characteristic:2.0.0#> . |
| 29 | + @prefix : <urn:samm:test:0.0.1#> . |
| 30 | + @prefix xsd: <http://www.w3.org/2001/XMLSchema#> . |
| 31 | + |
| 32 | + :Reference a samm:Aspect ; |
| 33 | + samm:preferredName "Reference"@en ; |
| 34 | + samm:description "Beschreibung."@de ; |
| 35 | + samm:properties ( :items ) ; |
| 36 | + samm:operations ( ) . |
| 37 | + |
| 38 | + :items a samm:Property ; |
| 39 | + samm:preferredName "Items"@es ; |
| 40 | + samm:description "Items."@it ; |
| 41 | + samm:characteristic [ |
| 42 | + a samm-c:Set ; |
| 43 | + samm:dataType :AEntity |
| 44 | + ] . |
| 45 | + |
| 46 | + :AEntity a samm:Entity ; |
| 47 | + samm:preferredName "A name"@pt ; |
| 48 | + samm:preferredName "Ein name"@de ; |
| 49 | + samm:properties ( :AProperty ) . |
| 50 | + |
| 51 | + :AProperty a samm:Property ; |
| 52 | + samm:preferredName "Common Property"@en ; |
| 53 | + samm:description "Bon idee"@fr ; |
| 54 | + samm:characteristic :ACharacteristic . |
| 55 | + |
| 56 | + :ACharacteristic a samm-c:Code ; |
| 57 | + samm:dataType xsd:string . |
| 58 | + """ ); |
| 59 | + final Aspect aspect = AspectModelLoader.getSingleAspectUnchecked( versionedModel ); |
| 60 | + final Set<Locale> reachableLocales = new LanguageCollectorModelVisitor().visitAspect( aspect, new HashSet<>() ); |
| 61 | + assertThat( reachableLocales ).containsExactlyInAnyOrder( Locale.ENGLISH, Locale.GERMAN, Locale.ITALIAN, Locale.FRENCH, Locale.forLanguageTag( "es" ), |
| 62 | + Locale.forLanguageTag( "pt" ) ); |
| 63 | + } |
| 64 | + |
| 65 | + private VersionedModel model( final String ttlRepresentation ) { |
| 66 | + final Model model = ModelFactory.createDefaultModel(); |
| 67 | + final InputStream in = new ByteArrayInputStream( ttlRepresentation.getBytes( StandardCharsets.UTF_8 ) ); |
| 68 | + model.read( in, "", RDFLanguages.strLangTurtle ); |
| 69 | + return new SammAspectMetaModelResourceResolver().mergeMetaModelIntoRawModel( model, VersionNumber.parse( "2.0.0" ) ) |
| 70 | + .get(); |
| 71 | + } |
| 72 | +} |
0 commit comments