CalculateDDMFormRuleActionSerializer implements SPIDDMFormRuleActionSerializer { @Override public String serialize( SPIDDMFormRuleSerializerContext spiDDMFormRuleSerializerContext) { if (Validator.isNull(_calculateDDMFormRuleAction.getTarget())) { return null; } DDMForm ddmForm = spiDDMFormRuleSerializerContext.getAttribute("form"); Map<String, DDMFormField> ddmFormFieldsMap = ddmForm.getDDMFormFieldsMap(true); String expression = removeBrackets( _calculateDDMFormRuleAction.getExpression()); Set<String> keySet = ddmFormFieldsMap.keySet(); Stream<String> ddmFormFieldStream = keySet.stream(); Set<String> ddmFormFieldNames = ddmFormFieldStream.filter( ddmFormField -> expression.contains(ddmFormField) ).collect( Collectors.toSet() ); String newExpression = buildExpression(expression, ddmFormFieldNames); return String.format( _FUNCTION_CALL_BINARY_EXPRESSION_FORMAT, "calculate", _calculateDDMFormRuleAction.getTarget(), newExpression); } CalculateDDMFormRuleActionSerializer(
		CalculateDDMFormRuleAction calculateDDMFormRuleAction); @Override String serialize(
		SPIDDMFormRuleSerializerContext spiDDMFormRuleSerializerContext);  }
@Test public void testSerialize() { when( _calculateDDMFormRuleAction.getExpression() ).thenReturn( "(text + text1) * 2" ); when( _calculateDDMFormRuleAction.getTarget() ).thenReturn( "text2" ); DDMForm ddmForm = new DDMForm(); DDMFormField ddmFormField1 = new DDMFormField("text", "string"); DDMFormField ddmFormField2 = new DDMFormField("text1", "string"); ddmForm.setDDMFormFields(Arrays.asList(ddmFormField1, ddmFormField2)); when( _serviceContext.getAttribute("form") ).thenReturn( ddmForm ); CalculateDDMFormRuleActionSerializer calculateDDMFormRuleActionSerializer = new CalculateDDMFormRuleActionSerializer( _calculateDDMFormRuleAction); PowerMockito.when( _spiDDMFormRuleSerializerContext.getAttribute("form") ).thenReturn( ddmForm ); String result = calculateDDMFormRuleActionSerializer.serialize( _spiDDMFormRuleSerializerContext); Assert.assertEquals( "calculate('text2', (getValue('text') + getValue('text1')) * 2)", result); }