@Test public void testConvertJsonToDmn_OK() throws Exception { JsonNode testJsonResource = parseJson(JSON_RESOURCE_1); DmnDefinition dmnDefinition = new DmnJsonConverter().convertToDmn(testJsonResource, "xyz", 1, new Date()); Assert.assertNotNull(dmnDefinition); Assert.assertEquals(DmnJsonConverter.MODEL_NAMESPACE, dmnDefinition.getNamespace()); Assert.assertEquals(DmnJsonConverter.URI_JSON, dmnDefinition.getTypeLanguage()); Assert.assertEquals("definition_xyz", dmnDefinition.getId()); Assert.assertEquals("decisionTableRule1", dmnDefinition.getName()); Assert.assertNotNull(dmnDefinition.getDecisions()); Assert.assertEquals(1, dmnDefinition.getDecisions().size()); Decision decision = dmnDefinition.getDecisions().get(0); Assert.assertNotNull(decision); Assert.assertEquals("decTable1", decision.getId()); DecisionTable decisionTable = (DecisionTable) decision.getExpression(); Assert.assertNotNull(decisionTable); Assert.assertEquals("decisionTable_11", decisionTable.getId()); Assert.assertEquals(HitPolicy.ANY, decisionTable.getHitPolicy()); Assert.assertEquals(DecisionTableOrientation.RULE_AS_ROW, decisionTable.getPreferredOrientation()); List<InputClause> inputClauses = decisionTable.getInputs(); Assert.assertNotNull(inputClauses); Assert.assertEquals(2, inputClauses.size()); List<OutputClause> outputClauses = decisionTable.getOutputs(); Assert.assertNotNull(outputClauses); Assert.assertEquals(1, outputClauses.size()); InputClause condition1 = inputClauses.get(0); Assert.assertNotNull(condition1.getInputExpression()); LiteralExpression inputExpression11 = condition1.getInputExpression(); Assert.assertNotNull(inputExpression11); Assert.assertEquals("Order Size", inputExpression11.getLabel()); Assert.assertEquals("inputExpression_input1", inputExpression11.getId()); InputClause condition2 = inputClauses.get(1); Assert.assertNotNull(condition2.getInputExpression()); LiteralExpression inputExpression21 = condition2.getInputExpression(); Assert.assertNotNull(inputExpression21); Assert.assertEquals("Registered On", inputExpression21.getLabel()); Assert.assertEquals("inputExpression_input2", inputExpression21.getId()); OutputClause conclusion1 = outputClauses.get(0); Assert.assertNotNull(conclusion1); Assert.assertEquals("Has discount", conclusion1.getLabel()); Assert.assertEquals("outputExpression_output1", conclusion1.getId()); Assert.assertEquals("boolean", conclusion1.getTypeRef()); Assert.assertEquals("newVariable1", conclusion1.getName()); Assert.assertNotNull(decisionTable.getRules()); Assert.assertEquals(2, decisionTable.getRules().size()); List<DecisionRule> rules = decisionTable.getRules(); Assert.assertEquals(2, rules.get(0).getInputEntries().size()); RuleInputClauseContainer ruleClauseContainer11 = rules.get(0).getInputEntries().get(0); UnaryTests inputEntry11 = ruleClauseContainer11.getInputEntry(); Assert.assertNotNull(inputEntry11); Assert.assertEquals("< 10", inputEntry11.getText()); Assert.assertSame(condition1, ruleClauseContainer11.getInputClause()); RuleInputClauseContainer ruleClauseContainer12 = rules.get(0).getInputEntries().get(1); UnaryTests inputEntry12 = ruleClauseContainer12.getInputEntry(); Assert.assertNotNull(inputEntry12); Assert.assertEquals("<= 18-09-1977", inputEntry12.getText()); Assert.assertSame(condition2, ruleClauseContainer12.getInputClause()); Assert.assertEquals(1, rules.get(0).getOutputEntries().size()); RuleOutputClauseContainer ruleClauseContainer13 = rules.get(0).getOutputEntries().get(0); LiteralExpression outputEntry13 = ruleClauseContainer13.getOutputEntry(); Assert.assertNotNull(outputEntry13); Assert.assertEquals("false", outputEntry13.getText()); Assert.assertSame(conclusion1, ruleClauseContainer13.getOutputClause()); RuleInputClauseContainer ruleClauseContainer21 = rules.get(1).getInputEntries().get(0); UnaryTests inputEntry21 = ruleClauseContainer21.getInputEntry(); Assert.assertNotNull(inputEntry21); Assert.assertEquals("> 10", inputEntry21.getText()); Assert.assertSame(condition1, ruleClauseContainer21.getInputClause()); RuleInputClauseContainer ruleClauseContainer22 = rules.get(1).getInputEntries().get(1); UnaryTests inputEntry22 = ruleClauseContainer22.getInputEntry(); Assert.assertNotNull(inputEntry22); Assert.assertEquals("> 18-09-1977", inputEntry22.getText()); Assert.assertSame(condition2, ruleClauseContainer22.getInputClause()); Assert.assertEquals(1, rules.get(1).getOutputEntries().size()); RuleOutputClauseContainer ruleClauseContainer23 = rules.get(1).getOutputEntries().get(0); LiteralExpression outputEntry23 = ruleClauseContainer23.getOutputEntry(); Assert.assertNotNull(outputEntry23); Assert.assertEquals("true", outputEntry23.getText()); Assert.assertSame(conclusion1, ruleClauseContainer23.getOutputClause()); }
public DmnDefinition convertToDmn(JsonNode modelNode, String modelId, int modelVersion, Date lastUpdated) { DmnDefinition definition = new DmnDefinition(); definition.setId("definition_"+modelId); definition.setName(DmnJsonConverterUtil.getValueAsString("name", modelNode)); definition.setNamespace(MODEL_NAMESPACE); definition.setTypeLanguage(URI_JSON); Decision decision = new Decision(); decision.setId(DmnJsonConverterUtil.getValueAsString("key", modelNode)); decision.setName(DmnJsonConverterUtil.getValueAsString("name", modelNode)); decision.setDescription(DmnJsonConverterUtil.getValueAsString("description", modelNode)); definition.addDecision(decision); DecisionTable decisionTable = new DecisionTable(); decisionTable.setId("decisionTable_"+DmnJsonConverterUtil.getValueAsString("id", modelNode)); if (modelNode.has("hitIndicator")) { decisionTable.setHitPolicy(HitPolicy.valueOf(DmnJsonConverterUtil.getValueAsString("hitIndicator", modelNode))); } else { decisionTable.setHitPolicy(HitPolicy.FIRST); } decisionTable.setPreferredOrientation(DecisionTableOrientation.RULE_AS_ROW); decision.setExpression(decisionTable); processDecisionTable(modelNode, definition, decisionTable); return definition; }
DmnJsonConverter { public DmnDefinition convertToDmn(JsonNode modelNode, String modelId, int modelVersion, Date lastUpdated) { DmnDefinition definition = new DmnDefinition(); definition.setId("definition_"+modelId); definition.setName(DmnJsonConverterUtil.getValueAsString("name", modelNode)); definition.setNamespace(MODEL_NAMESPACE); definition.setTypeLanguage(URI_JSON); Decision decision = new Decision(); decision.setId(DmnJsonConverterUtil.getValueAsString("key", modelNode)); decision.setName(DmnJsonConverterUtil.getValueAsString("name", modelNode)); decision.setDescription(DmnJsonConverterUtil.getValueAsString("description", modelNode)); definition.addDecision(decision); DecisionTable decisionTable = new DecisionTable(); decisionTable.setId("decisionTable_"+DmnJsonConverterUtil.getValueAsString("id", modelNode)); if (modelNode.has("hitIndicator")) { decisionTable.setHitPolicy(HitPolicy.valueOf(DmnJsonConverterUtil.getValueAsString("hitIndicator", modelNode))); } else { decisionTable.setHitPolicy(HitPolicy.FIRST); } decisionTable.setPreferredOrientation(DecisionTableOrientation.RULE_AS_ROW); decision.setExpression(decisionTable); processDecisionTable(modelNode, definition, decisionTable); return definition; } }
DmnJsonConverter { public DmnDefinition convertToDmn(JsonNode modelNode, String modelId, int modelVersion, Date lastUpdated) { DmnDefinition definition = new DmnDefinition(); definition.setId("definition_"+modelId); definition.setName(DmnJsonConverterUtil.getValueAsString("name", modelNode)); definition.setNamespace(MODEL_NAMESPACE); definition.setTypeLanguage(URI_JSON); Decision decision = new Decision(); decision.setId(DmnJsonConverterUtil.getValueAsString("key", modelNode)); decision.setName(DmnJsonConverterUtil.getValueAsString("name", modelNode)); decision.setDescription(DmnJsonConverterUtil.getValueAsString("description", modelNode)); definition.addDecision(decision); DecisionTable decisionTable = new DecisionTable(); decisionTable.setId("decisionTable_"+DmnJsonConverterUtil.getValueAsString("id", modelNode)); if (modelNode.has("hitIndicator")) { decisionTable.setHitPolicy(HitPolicy.valueOf(DmnJsonConverterUtil.getValueAsString("hitIndicator", modelNode))); } else { decisionTable.setHitPolicy(HitPolicy.FIRST); } decisionTable.setPreferredOrientation(DecisionTableOrientation.RULE_AS_ROW); decision.setExpression(decisionTable); processDecisionTable(modelNode, definition, decisionTable); return definition; }  }
DmnJsonConverter { public DmnDefinition convertToDmn(JsonNode modelNode, String modelId, int modelVersion, Date lastUpdated) { DmnDefinition definition = new DmnDefinition(); definition.setId("definition_"+modelId); definition.setName(DmnJsonConverterUtil.getValueAsString("name", modelNode)); definition.setNamespace(MODEL_NAMESPACE); definition.setTypeLanguage(URI_JSON); Decision decision = new Decision(); decision.setId(DmnJsonConverterUtil.getValueAsString("key", modelNode)); decision.setName(DmnJsonConverterUtil.getValueAsString("name", modelNode)); decision.setDescription(DmnJsonConverterUtil.getValueAsString("description", modelNode)); definition.addDecision(decision); DecisionTable decisionTable = new DecisionTable(); decisionTable.setId("decisionTable_"+DmnJsonConverterUtil.getValueAsString("id", modelNode)); if (modelNode.has("hitIndicator")) { decisionTable.setHitPolicy(HitPolicy.valueOf(DmnJsonConverterUtil.getValueAsString("hitIndicator", modelNode))); } else { decisionTable.setHitPolicy(HitPolicy.FIRST); } decisionTable.setPreferredOrientation(DecisionTableOrientation.RULE_AS_ROW); decision.setExpression(decisionTable); processDecisionTable(modelNode, definition, decisionTable); return definition; }  DmnDefinition convertToDmn(JsonNode modelNode, String modelId, int modelVersion, Date lastUpdated); ObjectNode convertToJson(DmnDefinition definition); }
DmnJsonConverter { public DmnDefinition convertToDmn(JsonNode modelNode, String modelId, int modelVersion, Date lastUpdated) { DmnDefinition definition = new DmnDefinition(); definition.setId("definition_"+modelId); definition.setName(DmnJsonConverterUtil.getValueAsString("name", modelNode)); definition.setNamespace(MODEL_NAMESPACE); definition.setTypeLanguage(URI_JSON); Decision decision = new Decision(); decision.setId(DmnJsonConverterUtil.getValueAsString("key", modelNode)); decision.setName(DmnJsonConverterUtil.getValueAsString("name", modelNode)); decision.setDescription(DmnJsonConverterUtil.getValueAsString("description", modelNode)); definition.addDecision(decision); DecisionTable decisionTable = new DecisionTable(); decisionTable.setId("decisionTable_"+DmnJsonConverterUtil.getValueAsString("id", modelNode)); if (modelNode.has("hitIndicator")) { decisionTable.setHitPolicy(HitPolicy.valueOf(DmnJsonConverterUtil.getValueAsString("hitIndicator", modelNode))); } else { decisionTable.setHitPolicy(HitPolicy.FIRST); } decisionTable.setPreferredOrientation(DecisionTableOrientation.RULE_AS_ROW); decision.setExpression(decisionTable); processDecisionTable(modelNode, definition, decisionTable); return definition; }  DmnDefinition convertToDmn(JsonNode modelNode, String modelId, int modelVersion, Date lastUpdated); ObjectNode convertToJson(DmnDefinition definition); final static String MODEL_NAMESPACE; final static String URI_JSON; }