Skip to content

Commit

Permalink
fix mastery composer - extra comma being added (finos#2469)
Browse files Browse the repository at this point in the history
  • Loading branch information
sahil37 authored and AFine-gs committed Jan 9, 2024
1 parent 4dc04e2 commit 49d997a
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ private static String renderPrecedenceRules(List<PrecedenceRule> precedenceRules
{
String precedenceRuleString = precedenceRule.accept(new PrecedenceRuleComposer(indentLevel + 1, context, uniqueSourcePrecedenceRules));
nonSourcePrecedenceRulesBuilder.append(precedenceRuleString);
nonSourcePrecedenceRulesBuilder.append(i < precedenceRules.size() && !precedenceRuleString.equals("") ? "," : "");
nonSourcePrecedenceRulesBuilder.append(i < precedenceRules.size() - 1 && !precedenceRuleString.equals("") ? "," : "");
});
return combinePrecedenceRules(uniqueSourcePrecedenceRules, nonSourcePrecedenceRulesBuilder.toString(), indentLevel);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,60 @@ public class TestMasteryCompilationFromGrammar extends TestCompilationFromGramma
" }#;\n" +
"}\n";

public static String MASTERY_MODEL_WITH_ONE_RULE = "###Pure\n" +
"Class org::dataeng::Widget\n" +
"{\n" +
" widgetId: String[0..1];\n" +
" identifiers: org::dataeng::MilestonedIdentifier[*];\n" +
"}\n\n" +
"Class org::dataeng::MilestonedIdentifier\n" +
"{\n" +
" identifierType: String[1];\n" +
" identifier: String[1];\n" +
" FROM_Z: StrictDate[0..1];\n" +
" THRU_Z: StrictDate[0..1];\n" +
"}\n\n\n" +
MAPPING_AND_CONNECTION +
"###Service\n" +
"Service org::dataeng::ParseWidget\n" + WIDGET_SERVICE_BODY + "\n" +
"Service org::dataeng::TransformWidget\n" + WIDGET_SERVICE_BODY + "\n" +
"\n" +
"###Mastery\n" + "MasterRecordDefinition alloy::mastery::WidgetMasterRecord" +
"\n" +
"{\n" +
" modelClass: org::dataeng::Widget;\n" +
" identityResolution: \n" +
" {\n" +
" resolutionQueries:\n" +
" [\n" +
" {\n" +
" queries: [ {input: org::dataeng::Widget[1]|org::dataeng::Widget.all()->filter(widget|$widget.widgetId == $input.widgetId)}\n" +
" ];\n" +
" precedence: 1;\n" +
" }\n" +
" ]\n" +
" }\n" +
" precedenceRules: [\n" +
" DeleteRule: {\n" +
" path: org::dataeng::Widget.identifiers.identifier;\n" +
" ruleScope: [\n" +
" RecordSourceScope {widget-producer}\n" +
" ];\n" +
" }\n" +
" ]\n" +
" recordSources:\n" +
" [\n" +
" widget-producer: {\n" +
" description: 'REST Acquisition source.';\n" +
" status: Development;\n" +
" recordService: {\n" +
" acquisitionProtocol: REST;\n" +
" };\n" +
" trigger: Manual;\n" +
" }\n" +
" ]\n" +
"}\n";

public static String MINIMUM_CORRECT_MASTERY_MODEL = "###Pure\n" +
"Class org::dataeng::Widget\n" +
"{\n" +
Expand Down Expand Up @@ -926,6 +980,19 @@ public void testMasteryMinimumCorrectModel()
assertEquals("Widget", masterRecordDefinition._modelClass()._name());
}

@Test
public void testMasteryModelWithOneRule()
{
Pair<PureModelContextData, PureModel> result = test(MASTERY_MODEL_WITH_ONE_RULE);
PureModel model = result.getTwo();

PackageableElement packageableElement = model.getPackageableElement("alloy::mastery::WidgetMasterRecord");
assertNotNull(packageableElement);
assertTrue(packageableElement instanceof Root_meta_pure_mastery_metamodel_MasterRecordDefinition);
Root_meta_pure_mastery_metamodel_MasterRecordDefinition masterRecordDefinition = (Root_meta_pure_mastery_metamodel_MasterRecordDefinition) packageableElement;
assertEquals(1, masterRecordDefinition._precedenceRules().size());
}

@Test
public void testMasteryDeprecatedModelCanStillCompile()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ public void masteryRoundTripFull()
testWithSectionInfoPreserved(TestMasteryCompilationFromGrammar.COMPLETE_CORRECT_MASTERY_MODEL);
}

@Test
public void masteryRoundTripWithOneRule()
{
testWithSectionInfoPreserved(TestMasteryCompilationFromGrammar.MASTERY_MODEL_WITH_ONE_RULE);
}

@Test
public void masteryRoundTripMinimum()
{
Expand Down

0 comments on commit 49d997a

Please sign in to comment.