|
28 | 28 | import java.util.List;
|
29 | 29 | import java.util.Optional;
|
30 | 30 | import java.util.Set;
|
| 31 | + |
31 | 32 | import javax.xml.datatype.Duration;
|
32 | 33 | import javax.xml.datatype.XMLGregorianCalendar;
|
33 | 34 |
|
|
63 | 64 | import org.junit.jupiter.params.provider.EnumSource;
|
64 | 65 |
|
65 | 66 | public class AspectModelJavaGeneratorTest {
|
66 |
| - private Collection<JavaGenerator> getGenerators( final TestAspect testAspect, final String customJavaPackageName ) { |
| 67 | + private Collection<JavaGenerator> getGenerators( final TestAspect testAspect, final JavaCodeGenerationConfig config ) { |
67 | 68 | final Aspect aspect = TestResources.load( testAspect ).aspect();
|
68 |
| - final JavaCodeGenerationConfig config = JavaCodeGenerationConfigBuilder.builder() |
69 |
| - .packageName( customJavaPackageName ) |
70 |
| - .enableJacksonAnnotations( true ) |
71 |
| - .executeLibraryMacros( false ) |
72 |
| - .build(); |
73 | 69 | return List.of( new AspectModelJavaGenerator( aspect, config ) );
|
74 | 70 | }
|
75 | 71 |
|
| 72 | + private Collection<JavaGenerator> getGenerators( final TestAspect testAspect, final String customJavaPackageName ) { |
| 73 | + return getGenerators( testAspect, |
| 74 | + JavaCodeGenerationConfigBuilder.builder() |
| 75 | + .packageName( customJavaPackageName ) |
| 76 | + .enableJacksonAnnotations( true ) |
| 77 | + .executeLibraryMacros( false ) |
| 78 | + .build() ); |
| 79 | + } |
| 80 | + |
76 | 81 | private Collection<JavaGenerator> getGenerators( final TestAspect testAspect, final boolean enableJacksonAnnotations,
|
77 | 82 | final boolean executeLibraryMacros, final File templateLibPath ) {
|
78 | 83 | final Aspect aspect = TestResources.load( testAspect ).aspect();
|
@@ -524,6 +529,34 @@ ImmutableMap.<String, String> builder()
|
524 | 529 |
|
525 | 530 | result.assertFields( "YesNo", ImmutableMap.<String, Object> builder().put( "value", String.class ).build(), new HashMap<>() );
|
526 | 531 | result.assertEnumConstants( "YesNo", ImmutableSet.of( "YES", "NO" ), Collections.emptyMap() );
|
| 532 | + |
| 533 | + assertThat( result.getGeneratedSource( new QualifiedName( "EvaluationResults", "org.eclipse.esmf.test" ) ) ) |
| 534 | + .contains( "@JsonFormat" ); |
| 535 | + } |
| 536 | + |
| 537 | + @Test |
| 538 | + void testGenerateAspectModelWithEnumerationDisableJsonFormatAnnotation() throws IOException { |
| 539 | + final ImmutableMap<String, Object> expectedFieldsForAspectClass = ImmutableMap.<String, Object> builder() |
| 540 | + .put( "result", "EvaluationResults" ) |
| 541 | + .put( "simpleResult", "YesNo" ) |
| 542 | + .build(); |
| 543 | + |
| 544 | + final ImmutableMap<String, Object> expectedFieldsForEvaluationResult = ImmutableMap.<String, Object> builder() |
| 545 | + .put( "numericCode", Short.class.getSimpleName() ) |
| 546 | + .put( "description", String.class.getSimpleName() ) |
| 547 | + .build(); |
| 548 | + |
| 549 | + final TestAspect aspect = TestAspect.ASPECT_WITH_COMPLEX_ENUM; |
| 550 | + final JavaCodeGenerationConfig codeGenerationConfig = JavaCodeGenerationConfigBuilder.builder() |
| 551 | + .enableJacksonAnnotations( true ) |
| 552 | + .executeLibraryMacros( false ) |
| 553 | + .packageName( aspect.getUrn().getNamespaceMainPart() ) |
| 554 | + .enableJacksonAnnotationJsonFormatShapeObject( false ) |
| 555 | + .build(); |
| 556 | + final GenerationResult result = TestContext.generateAspectCode().apply( getGenerators( aspect, codeGenerationConfig ) ); |
| 557 | + |
| 558 | + assertThat( result.getGeneratedSource( new QualifiedName( "EvaluationResults", "org.eclipse.esmf.test" ) ) ) |
| 559 | + .doesNotContain( "@JsonFormat" ); |
527 | 560 | }
|
528 | 561 |
|
529 | 562 | @Test
|
|
0 commit comments