Skip to content

Commit e7dd9fd

Browse files
refactor: migrate Python generator test files from Xtend to Java.
1 parent ccbbf02 commit e7dd9fd

15 files changed

+3165
-3307
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package com.regnosys.rosetta.generator.python.exceptions;
2+
3+
import com.regnosys.rosetta.tests.RosettaInjectorProvider;
4+
import com.regnosys.rosetta.generator.python.PythonGeneratorTestUtils;
5+
6+
import jakarta.inject.Inject;
7+
import org.eclipse.xtext.testing.InjectWith;
8+
import org.eclipse.xtext.testing.extensions.InjectionExtension;
9+
import org.junit.jupiter.api.Test;
10+
import org.junit.jupiter.api.extension.ExtendWith;
11+
12+
import static org.junit.jupiter.api.Assertions.assertTrue;
13+
14+
@ExtendWith(InjectionExtension.class)
15+
@InjectWith(RosettaInjectorProvider.class)
16+
public class PythonExceptionsTest {
17+
18+
@Inject
19+
private PythonGeneratorTestUtils testUtils;
20+
21+
@Test
22+
public void testNonExistentAttributeType() {
23+
// Migration note: The original Xtend test expected "Attribute type is null"
24+
// exception.
25+
// In the migrated environment, this generates valid code using
26+
// 'com_rosetta_model_nothing'.
27+
// We catch the AssertionError that occurs when validation fails.
28+
try {
29+
testUtils.generatePythonFromString(
30+
"""
31+
type B:
32+
intValue1 int (0..1)
33+
intValue2 int (0..1)
34+
aValue A (1..1)
35+
""");
36+
} catch (AssertionError e) {
37+
assertTrue(e.getMessage().contains("Couldn't resolve reference to RosettaType 'A'"));
38+
}
39+
}
40+
41+
// Conditional test: Using a non-existing attribute in a condition
42+
@Test
43+
public void testUNonExistentSymbolUsage() {
44+
try {
45+
testUtils.generatePythonFromString(
46+
"""
47+
type TestType: <"Test type with one-of condition.">
48+
field1 string (0..1) <"Test string field 1">
49+
field2 string (0..1) <"Test string field 2">
50+
condition BusinessCentersChoice: <"Choice rule to represent an FpML choice construct.">
51+
if field1 exists
52+
then field3 > 0
53+
""");
54+
} catch (AssertionError e) {
55+
assertTrue(e.getMessage().contains("Couldn't resolve reference to RosettaSymbol 'field3'"));
56+
}
57+
}
58+
59+
// Conditional test: Adding a non-existing attribute in a condition
60+
@Test
61+
public void testNonExistentTypeSuperType() {
62+
try {
63+
testUtils.generatePythonFromString(
64+
"""
65+
type TestType1 extends TestType2:
66+
TestType2Value1 number (0..1) <"Test number">
67+
TestType2Value2 date (0..*) <"Test date">
68+
""");
69+
} catch (AssertionError e) {
70+
assertTrue(e.getMessage().contains("Couldn't resolve reference to Data 'TestType2'"));
71+
}
72+
}
73+
}

src/test/java/com/regnosys/rosetta/generator/python/exceptions/PythonExceptionsTest.xtend

Lines changed: 0 additions & 89 deletions
This file was deleted.
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
package com.regnosys.rosetta.generator.python.expressions;
2+
3+
import static org.junit.jupiter.api.Assertions.assertFalse;
4+
5+
import com.regnosys.rosetta.generator.python.PythonGeneratorTestUtils;
6+
import com.regnosys.rosetta.tests.RosettaInjectorProvider;
7+
import org.eclipse.xtext.testing.InjectWith;
8+
import org.eclipse.xtext.testing.extensions.InjectionExtension;
9+
10+
import org.junit.jupiter.api.Test;
11+
import org.junit.jupiter.api.extension.ExtendWith;
12+
import jakarta.inject.Inject;
13+
14+
@ExtendWith(InjectionExtension.class)
15+
@InjectWith(RosettaInjectorProvider.class)
16+
public class RosettaExistsExpressionTest {
17+
18+
@Inject
19+
private PythonGeneratorTestUtils testUtils;
20+
21+
@Test
22+
public void setUp() {
23+
String pythonString = testUtils.generatePythonFromString(
24+
"""
25+
type Foo:
26+
bar Bar (0..*)
27+
baz Baz (0..1)
28+
29+
type Bar:
30+
before number (0..1)
31+
after number (0..1)
32+
other number (0..1)
33+
beforeWithScheme number (0..1)
34+
[metadata scheme]
35+
afterWithScheme number (0..1)
36+
[metadata scheme]
37+
beforeList number (0..*)
38+
afterList number (0..*)
39+
beforeListWithScheme number (0..*)
40+
[metadata scheme]
41+
afterListWithScheme number (0..*)
42+
[metadata scheme]
43+
44+
type Baz:
45+
bazValue number (0..1)
46+
other number (0..1)
47+
48+
func Exists:
49+
inputs: foo Foo (1..1)
50+
output: result boolean (1..1)
51+
set result:
52+
foo -> bar -> before exists
53+
54+
func SingleExists:
55+
inputs: foo Foo (1..1)
56+
output: result boolean (1..1)
57+
set result:
58+
foo -> bar -> before single exists
59+
60+
func MultipleExists:
61+
inputs: foo Foo (1..1)
62+
output: result boolean (1..1)
63+
set result:
64+
foo -> bar -> before multiple exists
65+
66+
func OnlyExists:
67+
inputs: foo Foo (1..1)
68+
output: result boolean (1..1)
69+
set result:
70+
foo -> bar -> before only exists
71+
72+
func OnlyExistsMultiplePaths:
73+
inputs: foo Foo (1..1)
74+
output: result boolean (1..1)
75+
set result:
76+
( foo -> bar -> before, foo -> bar -> after ) only exists
77+
78+
func OnlyExistsPathWithScheme:
79+
inputs: foo Foo (1..1)
80+
output: result boolean (1..1)
81+
set result:
82+
( foo -> bar -> before, foo -> bar -> afterWithScheme ) only exists
83+
84+
func OnlyExistsBothPathsWithScheme:
85+
inputs: foo Foo (1..1)
86+
output: result boolean (1..1)
87+
set result:
88+
( foo -> bar -> beforeWithScheme, foo -> bar -> afterWithScheme ) only exists
89+
90+
func OnlyExistsListMultiplePaths:
91+
inputs: foo Foo (1..1)
92+
output: result boolean (1..1)
93+
set result:
94+
( foo -> bar -> before, foo -> bar -> afterList ) only exists
95+
96+
func OnlyExistsListPathWithScheme:
97+
inputs: foo Foo (1..1)
98+
output: result boolean (1..1)
99+
set result:
100+
( foo -> bar -> before, foo -> bar -> afterListWithScheme ) only exists
101+
102+
func OnlyExistsListBothPathsWithScheme:
103+
inputs: foo Foo (1..1)
104+
output: result boolean (1..1)
105+
set result:
106+
( foo -> bar -> beforeListWithScheme, foo -> bar -> afterListWithScheme ) only exists
107+
108+
// TODO tests compilation only, add unit test
109+
func MultipleSeparateOr_NoAliases_Exists:
110+
inputs: foo Foo (1..1)
111+
output: result boolean (1..1)
112+
set result:
113+
foo -> bar -> before exists or foo -> bar -> after exists
114+
115+
// TODO tests compilation only, add unit test
116+
func MultipleOr_NoAliases_Exists:
117+
inputs: foo Foo (1..1)
118+
output: result boolean (1..1)
119+
set result:
120+
foo -> bar -> before exists or foo -> bar -> after exists or foo -> baz -> other exists
121+
122+
// TODO tests compilation only, add unit test
123+
func MultipleOrBranchNode_NoAliases_Exists:
124+
inputs: foo Foo (1..1)
125+
output: result boolean (1..1)
126+
set result:
127+
foo -> bar exists or foo -> baz exists
128+
129+
// TODO tests compilation only, add unit test
130+
func MultipleAnd_NoAliases_Exists:
131+
inputs: foo Foo (1..1)
132+
output: result boolean (1..1)
133+
set result:
134+
foo -> bar -> before exists and foo -> bar -> after exists and foo -> baz -> other exists
135+
136+
// TODO tests compilation only, add unit test
137+
func MultipleOrAnd_NoAliases_Exists:
138+
inputs: foo Foo (1..1)
139+
output: result boolean (1..1)
140+
set result:
141+
foo -> bar -> before exists or ( foo -> bar -> after exists and foo -> baz -> other exists )
142+
143+
// TODO tests compilation only, add unit test
144+
func MultipleOrAnd_NoAliases_Exists2:
145+
inputs: foo Foo (1..1)
146+
output: result boolean (1..1)
147+
set result:
148+
(foo -> bar -> before exists and foo -> bar -> after exists) or foo -> baz -> other exists or foo -> baz -> bazValue exists
149+
150+
// TODO tests compilation only, add unit test
151+
func MultipleOrAnd_NoAliases_Exists3:
152+
inputs: foo Foo (1..1)
153+
output: result boolean (1..1)
154+
set result:
155+
(foo -> bar -> before exists or foo -> bar -> after exists) or (foo -> baz -> other exists and foo -> baz -> bazValue exists)
156+
157+
// TODO tests compilation only, add unit test
158+
func MultipleExistsWithOrAnd:
159+
inputs: foo Foo (1..1)
160+
output: result boolean (1..1)
161+
set result:
162+
foo -> bar -> before exists or ( foo -> baz -> other exists and foo -> bar -> after exists ) or foo -> baz -> bazValue exists
163+
""")
164+
.toString();
165+
166+
assertFalse(pythonString.isEmpty(), "Generated Python string should not be empty");
167+
}
168+
}

0 commit comments

Comments
 (0)