|
13 | 13 |
|
14 | 14 | package org.eclipse.esmf.aspectmodel.java;
|
15 | 15 |
|
16 |
| -import static org.assertj.core.api.Assertions.assertThat; |
17 |
| -import static org.assertj.core.api.Assertions.assertThatCode; |
| 16 | +import static org.assertj.core.api.Assertions.*; |
18 | 17 |
|
19 | 18 | import java.io.File;
|
20 | 19 | import java.io.IOException;
|
|
36 | 35 | import org.eclipse.esmf.aspectmodel.resolver.services.DataType;
|
37 | 36 | import org.eclipse.esmf.aspectmodel.resolver.services.VersionedModel;
|
38 | 37 | import org.eclipse.esmf.aspectmodel.urn.AspectModelUrn;
|
| 38 | +import org.eclipse.esmf.metamodel.Aspect; |
| 39 | +import org.eclipse.esmf.metamodel.datatypes.LangString; |
| 40 | +import org.eclipse.esmf.metamodel.loader.AspectModelLoader; |
| 41 | +import org.eclipse.esmf.samm.KnownVersion; |
| 42 | +import org.eclipse.esmf.test.MetaModelVersions; |
| 43 | +import org.eclipse.esmf.test.TestAspect; |
| 44 | +import org.eclipse.esmf.test.TestResources; |
39 | 45 | import org.junit.jupiter.api.BeforeAll;
|
40 | 46 | import org.junit.jupiter.params.ParameterizedTest;
|
41 | 47 | import org.junit.jupiter.params.provider.EnumSource;
|
|
53 | 59 | import com.google.common.collect.ImmutableSet;
|
54 | 60 | import com.google.common.reflect.TypeToken;
|
55 | 61 |
|
56 |
| -import org.eclipse.esmf.samm.KnownVersion; |
57 |
| -import org.eclipse.esmf.metamodel.Aspect; |
58 |
| -import org.eclipse.esmf.metamodel.datatypes.LangString; |
59 |
| -import org.eclipse.esmf.metamodel.loader.AspectModelLoader; |
60 |
| -import org.eclipse.esmf.test.MetaModelVersions; |
61 |
| -import org.eclipse.esmf.test.TestAspect; |
62 |
| -import org.eclipse.esmf.test.TestResources; |
63 |
| - |
64 | 62 | public class AspectModelJavaGeneratorTest extends MetaModelVersions {
|
65 | 63 |
|
66 | 64 | private Collection<JavaGenerator> getGenerators( final TestAspect testAspect, final KnownVersion metaModelVersion, final String customJavaPackageName ) {
|
@@ -340,6 +338,24 @@ ImmutableMap.<String, String> builder()
|
340 | 338 | assertConstructor( result, "AspectWithConstraints", expectedFieldsForAspectClass );
|
341 | 339 | }
|
342 | 340 |
|
| 341 | + @ParameterizedTest |
| 342 | + @MethodSource( value = "versionsStartingWith2_0_0" ) |
| 343 | + public void testGenerateAspectModelWithOptionalAndConstraints( final KnownVersion metaModelVersion ) throws IOException { |
| 344 | + final ImmutableMap<String, Object> expectedFieldsForAspectClass = ImmutableMap.<String, Object> builder() |
| 345 | + .put( "stringProperty", "Optional<@Size(max = 3) String>" ) |
| 346 | + .build(); |
| 347 | + |
| 348 | + final TestAspect aspect = TestAspect.ASPECT_WITH_OPTIONAL_PROPERTY_AND_CONSTRAINT; |
| 349 | + final GenerationResult result = TestContext.generateAspectCode().apply( getGenerators( aspect, metaModelVersion, |
| 350 | + true, false, null ) ); |
| 351 | + result.assertNumberOfFiles( 1 ); |
| 352 | + result.assertFields( "AspectWithOptionalPropertyAndConstraint", expectedFieldsForAspectClass, |
| 353 | + ImmutableMap.<String, String> builder() |
| 354 | + .put( "stringProperty", "" ) |
| 355 | + .build() ); |
| 356 | + assertConstructor( result, "AspectWithOptionalPropertyAndConstraint", expectedFieldsForAspectClass ); |
| 357 | + } |
| 358 | + |
343 | 359 | @ParameterizedTest
|
344 | 360 | @MethodSource( value = "allVersions" )
|
345 | 361 | public void testGenerateAspectWithConstrainedCollection( final KnownVersion metaModelVersion ) throws IOException {
|
@@ -396,7 +412,7 @@ ImmutableMap.<String, String> builder()
|
396 | 412 | @MethodSource( value = "allVersions" )
|
397 | 413 | public void testGenerateAspectWithEither( final KnownVersion metaModelVersion ) throws IOException {
|
398 | 414 | final ImmutableMap<String, Object> expectedFieldsForAspectClass = ImmutableMap.<String, Object> builder()
|
399 |
| - .put( "testProperty", "Either<LeftEntity,RightEntity>" ) |
| 415 | + .put( "testProperty", "Either<LeftEntity, RightEntity>" ) |
400 | 416 | .build();
|
401 | 417 |
|
402 | 418 | final TestAspect aspect = TestAspect.ASPECT_WITH_EITHER_WITH_COMPLEX_TYPES;
|
|
0 commit comments