-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix extended rule source with extended type (#932)
* Add test for rule source with extended type * Fix issue * Fix tests
- Loading branch information
1 parent
484546e
commit 3ae11df
Showing
3 changed files
with
250 additions
and
9 deletions.
There are no files selected for viewing
245 changes: 245 additions & 0 deletions
245
...-tests/src/test/java/com/regnosys/rosetta/generator/java/reports/ReportGeneratorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,245 @@ | ||
package com.regnosys.rosetta.generator.java.reports; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.Map; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.eclipse.xtext.testing.InjectWith; | ||
import org.eclipse.xtext.testing.extensions.InjectionExtension; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
|
||
import com.regnosys.rosetta.generator.java.RosettaJavaPackages.RootPackage; | ||
import com.regnosys.rosetta.generator.java.function.FunctionGeneratorHelper; | ||
import com.regnosys.rosetta.tests.RosettaTestInjectorProvider; | ||
import com.regnosys.rosetta.tests.util.CodeGeneratorTestHelper; | ||
import com.rosetta.model.lib.RosettaModelObject; | ||
import com.rosetta.model.lib.functions.RosettaFunction; | ||
import com.rosetta.util.DottedPath; | ||
|
||
@ExtendWith(InjectionExtension.class) | ||
@InjectWith(RosettaTestInjectorProvider.class) | ||
public class ReportGeneratorTest { | ||
|
||
private static final CharSequence COMMON_REPORT_TYPES = """ | ||
type BarReportInstruction: | ||
bar1 string (0..1) | ||
bar2 string (0..1) | ||
bar3 string (0..1) | ||
bar4 string (0..1) | ||
bar5 string (0..1) | ||
bar6 string (0..1) | ||
bar7 string (0..1) | ||
"""; | ||
|
||
private static final CharSequence INLINE_REPORT_RULES = """ | ||
body Authority TestBody | ||
corpus TestBody TestCorpus1 | ||
report TestBody TestCorpus1 in T+1 | ||
from BarReportInstruction | ||
when FooEligibilityRule | ||
with type BarReport | ||
type BarReport: | ||
out1 string (1..1) | ||
[ruleReference CommonBar1] | ||
out2 string (1..1) | ||
[ruleReference CommonBar2] | ||
out3 string (0..1) | ||
eligibility rule FooEligibilityRule from BarReportInstruction: | ||
filter bar1 exists | ||
reporting rule CommonBar1 from BarReportInstruction: | ||
extract bar1 | ||
reporting rule CommonBar2 from BarReportInstruction: | ||
extract bar2 | ||
"""; | ||
|
||
private static final CharSequence EXTERNAL_REPORT_RULES = """ | ||
corpus TestBody TestCorpus2 | ||
report TestBody TestCorpus2 in T+1 | ||
from BarReportInstruction | ||
when FooEligibilityRule | ||
with type BarReport | ||
with source ExtRules | ||
rule source ExtRules | ||
{ | ||
BarReport: | ||
- out1 | ||
+ out1 | ||
[ruleReference ExtBar1] | ||
+ out3 | ||
[ruleReference ExtBar3] | ||
} | ||
reporting rule ExtBar1 from BarReportInstruction: | ||
extract bar3 | ||
reporting rule ExtBar3 from BarReportInstruction: | ||
extract bar4 | ||
"""; | ||
|
||
private static final CharSequence EXTENDED_EXT_REPORT_RULES = """ | ||
corpus TestBody TestCorpus3 | ||
report TestBody TestCorpus3 in T+1 | ||
from BarReportInstruction | ||
when FooEligibilityRule | ||
with type BarReport | ||
with source ExtendedExtRules | ||
rule source ExtendedExtRules extends ExtRules | ||
{ | ||
BarReport: | ||
- out1 | ||
+ out1 | ||
[ruleReference ExtendedExtBar1] | ||
} | ||
reporting rule ExtendedExtBar1 from BarReportInstruction: | ||
extract bar5 | ||
"""; | ||
|
||
private static final CharSequence EXTENDED_EXT2_REPORT_RULES = """ | ||
corpus TestBody TestCorpus4 | ||
report TestBody TestCorpus4 in T+1 | ||
from BarReportInstruction | ||
when FooEligibilityRule | ||
with type ExtendedBarReport | ||
with source ExtendedExt2Rules | ||
type ExtendedBarReport extends BarReport: | ||
out4 string (0..1) | ||
[ruleReference ExtendedExt2Bar4] | ||
out5 string (0..1) | ||
rule source ExtendedExt2Rules extends ExtRules | ||
{ | ||
ExtendedBarReport: | ||
- out1 | ||
+ out1 | ||
[ruleReference ExtendedExt2Bar1] | ||
+ out5 | ||
[ruleReference ExtendedExt2Bar5] | ||
} | ||
reporting rule ExtendedExt2Bar1 from BarReportInstruction: | ||
extract bar5 | ||
reporting rule ExtendedExt2Bar4 from BarReportInstruction: | ||
extract bar6 | ||
reporting rule ExtendedExt2Bar5 from BarReportInstruction: | ||
extract bar7 | ||
"""; | ||
|
||
|
||
@Inject | ||
FunctionGeneratorHelper functionGeneratorHelper; | ||
@Inject | ||
CodeGeneratorTestHelper generatorTestHelper; | ||
|
||
@Test | ||
void shouldReportBasedOnInlineRuleReference() { | ||
var code = generatorTestHelper.generateCode(COMMON_REPORT_TYPES, INLINE_REPORT_RULES); | ||
var classes = generatorTestHelper.compileToClasses(code); | ||
var reportFunc = getFunc(classes, "TestBodyTestCorpus1ReportFunction"); | ||
|
||
var result = functionGeneratorHelper.invokeFunc(reportFunc, RosettaModelObject.class, getInput(classes)); | ||
|
||
var expectedResult = getOutput(classes, "BarReport", Map.of( | ||
"out1", "v1", | ||
"out2", "v2" | ||
)); | ||
|
||
assertEquals(expectedResult, result); | ||
} | ||
|
||
@Test | ||
void shouldReportBasedOnExternalRuleReference() { | ||
var code = generatorTestHelper.generateCode(COMMON_REPORT_TYPES, INLINE_REPORT_RULES, EXTERNAL_REPORT_RULES); | ||
var classes = generatorTestHelper.compileToClasses(code); | ||
var reportFunc = getFunc(classes, "TestBodyTestCorpus2ReportFunction"); | ||
|
||
var result = functionGeneratorHelper.invokeFunc(reportFunc, RosettaModelObject.class, getInput(classes)); | ||
|
||
var expectedResult = getOutput(classes, "BarReport", Map.of( | ||
"out1", "v3", | ||
"out2", "v2", | ||
"out3", "v4" | ||
)); | ||
|
||
assertEquals(expectedResult, result); | ||
} | ||
|
||
|
||
@Test | ||
void shouldReportBasedOnExtendedExternalRuleReference() { | ||
var code = generatorTestHelper.generateCode(COMMON_REPORT_TYPES, INLINE_REPORT_RULES, EXTERNAL_REPORT_RULES, EXTENDED_EXT_REPORT_RULES); | ||
var classes = generatorTestHelper.compileToClasses(code); | ||
var reportFunc = getFunc(classes, "TestBodyTestCorpus3ReportFunction"); | ||
|
||
var result = functionGeneratorHelper.invokeFunc(reportFunc, RosettaModelObject.class, getInput(classes)); | ||
|
||
var expectedResult = getOutput(classes, "BarReport", Map.of( | ||
"out1", "v5", | ||
"out2", "v2", | ||
"out3", "v4" | ||
)); | ||
|
||
assertEquals(expectedResult, result); | ||
} | ||
|
||
@Test | ||
void shouldReportBasedOnExtendedExternalRuleReferenceAndExtendedReportType() { | ||
var code = generatorTestHelper.generateCode(COMMON_REPORT_TYPES, INLINE_REPORT_RULES, EXTERNAL_REPORT_RULES, EXTENDED_EXT2_REPORT_RULES); | ||
var classes = generatorTestHelper.compileToClasses(code); | ||
var reportFunc = getFunc(classes, "TestBodyTestCorpus4ReportFunction"); | ||
|
||
var result = functionGeneratorHelper.invokeFunc(reportFunc, RosettaModelObject.class, getInput(classes)); | ||
|
||
var expectedResult = getOutput(classes, "ExtendedBarReport", Map.of( | ||
"out1", "v5", | ||
"out2", "v2", | ||
"out3", "v4", | ||
"out4", "v6", | ||
"out5", "v7" | ||
)); | ||
|
||
assertEquals(expectedResult, result); | ||
} | ||
|
||
|
||
private RosettaModelObject getInput(Map<String, Class<?>> classes) { | ||
return generatorTestHelper.createInstanceUsingBuilder(classes, new RootPackage("com.rosetta.test.model"), "BarReportInstruction", Map.of( | ||
"bar1", "v1", | ||
"bar2", "v2", | ||
"bar3", "v3", | ||
"bar4", "v4", | ||
"bar5", "v5", | ||
"bar6", "v6", | ||
"bar7", "v7" | ||
)); | ||
} | ||
|
||
private RosettaFunction getFunc(Map<String, Class<?>> classes, String funcName) { | ||
return functionGeneratorHelper.createFunc(classes, funcName, DottedPath.of("com.rosetta.test.model.reports")); | ||
} | ||
|
||
private RosettaModelObject getOutput(Map<String, Class<?>> classes, String typeName, Map<String, Object> values) { | ||
return generatorTestHelper.createInstanceUsingBuilder(classes, new RootPackage("com.rosetta.test.model"), typeName, values); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters