|
14 | 14 | package org.eclipse.esmf.aspectmodel.java;
|
15 | 15 |
|
16 | 16 | import static org.assertj.core.api.Assertions.assertThat;
|
| 17 | +import static org.assertj.core.api.Assertions.assertThatThrownBy; |
| 18 | +import static org.junit.jupiter.params.provider.Arguments.arguments; |
17 | 19 |
|
18 | 20 | import java.io.IOException;
|
19 | 21 | import java.lang.reflect.InvocationTargetException;
|
20 | 22 | import java.lang.reflect.Method;
|
21 | 23 | import java.util.List;
|
| 24 | +import java.util.stream.Stream; |
22 | 25 |
|
23 | 26 | import org.eclipse.esmf.staticmetamodel.ComputedProperty;
|
24 | 27 | import org.eclipse.esmf.staticmetamodel.StaticContainerProperty;
|
|
30 | 33 |
|
31 | 34 | import org.apache.commons.lang3.reflect.ConstructorUtils;
|
32 | 35 | import org.junit.jupiter.api.Test;
|
| 36 | +import org.junit.jupiter.params.ParameterizedTest; |
| 37 | +import org.junit.jupiter.params.provider.Arguments; |
| 38 | +import org.junit.jupiter.params.provider.MethodSource; |
33 | 39 |
|
34 | 40 | public class ExtendedStaticMetaModelFunctionalityTest extends StaticMetaModelGeneratorTest {
|
35 | 41 | @Test
|
@@ -253,10 +259,8 @@ void testCollectionPropertyPredicates() throws IOException, ReflectiveOperationE
|
253 | 259 | final StaticClassGenerationResult result = TestContext.generateStaticAspectCode().apply( getGenerators( aspect, false,
|
254 | 260 | JavaCodeGenerationConfig.SetterStyle.STANDARD ) );
|
255 | 261 |
|
256 |
| - final Class<?> aspectClass = findGeneratedClass( result, "AspectWithNestedEntityList" ); |
257 | 262 | final Class<?> entityClass = findGeneratedClass( result, "TestFirstEntity" );
|
258 | 263 | final Class<?> nestedEntityClass = findGeneratedClass( result, "TestSecondEntity" );
|
259 |
| - final Class<?> metaAspectClass = findGeneratedClass( result, "MetaAspectWithNestedEntityList" ); |
260 | 264 | final Class<?> metaEntity = findGeneratedClass( result, "MetaTestFirstEntity" );
|
261 | 265 | final Class<?> metaNestedEntity = findGeneratedClass( result, "MetaTestSecondEntity" );
|
262 | 266 |
|
@@ -290,4 +294,41 @@ void testCollectionPropertyPredicates() throws IOException, ReflectiveOperationE
|
290 | 294 | assertThat( entities.stream().filter( matchNestedEntityStringAll ) ).containsExactly( e1 );
|
291 | 295 | assertThat( entities.stream().filter( matchNestedEntityStringAnyWithNoneMatching ) ).isEmpty();
|
292 | 296 | }
|
| 297 | + |
| 298 | + @ParameterizedTest( name = "{0}" ) |
| 299 | + @MethodSource( "mutatePropertiesInput" ) |
| 300 | + void testMutatePropertiesThroughStaticProperties( final String testName, final boolean generateSetters, |
| 301 | + final JavaCodeGenerationConfig.SetterStyle setterStyle, |
| 302 | + final boolean expectException ) throws IOException, ReflectiveOperationException { |
| 303 | + final TestAspect aspect = TestAspect.ASPECT_WITH_PROPERTY; |
| 304 | + final StaticClassGenerationResult result = TestContext.generateStaticAspectCode().apply( getGenerators( aspect, generateSetters, |
| 305 | + setterStyle ) ); |
| 306 | + |
| 307 | + final Class<?> aspectClass = findGeneratedClass( result, "AspectWithProperty" ); |
| 308 | + final Class<?> metaAspectClass = findGeneratedClass( result, "MetaAspectWithProperty" ); |
| 309 | + |
| 310 | + final StaticProperty<Object, Object> testProperty = (StaticProperty<Object, Object>) metaAspectClass.getField( "TEST_PROPERTY" ) |
| 311 | + .get( null ); |
| 312 | + |
| 313 | + final String originalValue = "SOMEVALUE"; |
| 314 | + final String changedValue = "CHANGEDVALUE"; |
| 315 | + final Object aspectInstance = ConstructorUtils.invokeConstructor( aspectClass, "SOMEVALUE" ); |
| 316 | + |
| 317 | + assertThat( testProperty.getValue( aspectInstance ) ).isEqualTo( originalValue ); |
| 318 | + if ( expectException ) { |
| 319 | + assertThatThrownBy( () -> testProperty.setValue( aspectInstance, changedValue ) ).isInstanceOf( |
| 320 | + UnsupportedOperationException.class ); |
| 321 | + } else { |
| 322 | + testProperty.setValue( aspectInstance, changedValue ); |
| 323 | + assertThat( testProperty.getValue( aspectInstance ) ).isEqualTo( changedValue ); |
| 324 | + } |
| 325 | + } |
| 326 | + |
| 327 | + static Stream<Arguments> mutatePropertiesInput() { |
| 328 | + return Stream.of( |
| 329 | + arguments( "Setters disabled, should fail with exception", false, null, true ), |
| 330 | + arguments( "Setters STANDARD, should succeed", true, JavaCodeGenerationConfig.SetterStyle.STANDARD, false ), |
| 331 | + arguments( "Setters FLUENT, should succeed", true, JavaCodeGenerationConfig.SetterStyle.FLUENT, false ), |
| 332 | + arguments( "Setters FLUENT_COMPACT, should succeed", true, JavaCodeGenerationConfig.SetterStyle.FLUENT_COMPACT, false ) ); |
| 333 | + } |
293 | 334 | }
|
0 commit comments