AddFormInstanceRecordMVCResourceCommand extends BaseMVCResourceCommand { protected DDMFormValues createDDMFormValues( DDMFormInstance ddmFormInstance, ResourceRequest resourceRequest) throws Exception { String serializedDDMFormValues = ParamUtil.getString( resourceRequest, "serializedDDMFormValues"); if (Validator.isNull(serializedDDMFormValues)) { return null; } DDMFormContextDeserializerRequest ddmFormContextDeserializerRequest = DDMFormContextDeserializerRequest.with( getDDMForm(ddmFormInstance), serializedDDMFormValues); Locale currentLocale = LocaleUtil.fromLanguageId( LanguageUtil.getLanguageId(resourceRequest)); ddmFormContextDeserializerRequest.addProperty( "currentLocale", currentLocale); return _ddmFormBuilderContextToDDMFormValues.deserialize( ddmFormContextDeserializerRequest); }    }
@Test public void testCreateDDMFormValues() throws Exception { String serializedDDMFormValues = read("ddm-form-values.json"); when( _resourceRequest.getParameter("serializedDDMFormValues") ).thenReturn( serializedDDMFormValues ); when( _language.getLanguageId(_resourceRequest) ).thenReturn( "pt_BR" ); when( _language.isAvailableLocale(LocaleUtil.BRAZIL) ).thenReturn( true ); DDMForm ddmForm = DDMFormTestUtil.createDDMForm(); ddmForm.addDDMFormField( DDMFormTestUtil.createTextDDMFormField( "TextField1", true, false, false)); ddmForm.addDDMFormField( DDMFormTestUtil.createTextDDMFormField( "TextField2", true, false, false)); when( _ddmStructure.getDDMForm() ).thenReturn( ddmForm ); LocalizedValue value1 = new LocalizedValue(); value1.addString(LocaleUtil.BRAZIL, "Texto 1"); DDMFormFieldValue ddmFormFieldValue1 = DDMFormValuesTestUtil.createDDMFormFieldValue( "eBvF8zup", "TextField1", value1); LocalizedValue value2 = new LocalizedValue(); value2.addString(LocaleUtil.BRAZIL, "Texto 2"); DDMFormFieldValue ddmFormFieldValue2 = DDMFormValuesTestUtil.createDDMFormFieldValue( "6VYYLvfJ", "TextField2", value2); DDMFormValues ddmFormValues1 = DDMFormValuesTestUtil.createDDMFormValues( ddmForm, SetUtil.fromArray(new Locale[] {LocaleUtil.BRAZIL}), LocaleUtil.BRAZIL); ddmFormValues1.addDDMFormFieldValue(ddmFormFieldValue1); ddmFormValues1.addDDMFormFieldValue(ddmFormFieldValue2); DDMFormValues ddmFormValues2 = _addFormInstanceRecordMVCResourceCommand.createDDMFormValues( _ddmFormInstance, _resourceRequest); Assert.assertNotEquals(LocaleUtil.getSiteDefault(), LocaleUtil.BRAZIL); Assert.assertTrue(Objects.equals(ddmFormValues1, ddmFormValues2)); }