DefaultDDMFormValuesFactory { public DDMFormValues create() { DDMFormValues ddmFormValues = new DDMFormValues(_ddmForm); ddmFormValues.addAvailableLocale(_locale); ddmFormValues.setDefaultLocale(_locale); for (DDMFormField ddmFormField : _ddmForm.getDDMFormFields()) { DDMFormFieldValue ddmFormFieldValue = createDefaultDDMFormFieldValue(ddmFormField); ddmFormValues.addDDMFormFieldValue(ddmFormFieldValue); } return ddmFormValues; } DefaultDDMFormValuesFactory(DDMForm ddmForm, Locale locale); DDMFormValues create();  }
@Test public void testAvailableLocales() { Set<Locale> expectedAvailableLocales = SetUtil.fromArray( new Locale[] {LocaleUtil.BRAZIL}); DDMForm ddmForm = DDMFormTestUtil.createDDMForm(); DefaultDDMFormValuesFactory defaultDDMFormValuesFactory = new DefaultDDMFormValuesFactory(ddmForm, LocaleUtil.BRAZIL); DDMFormValues ddmFormValues = defaultDDMFormValuesFactory.create(); Assert.assertEquals( expectedAvailableLocales, ddmFormValues.getAvailableLocales()); }
@Test public void testDDMFormFieldValueLocalizedValue() { DDMForm ddmForm = DDMFormTestUtil.createDDMForm(); ddmForm.addDDMFormField( DDMFormTestUtil.createTextDDMFormField("Name", true, false, false)); DefaultDDMFormValuesFactory defaultDDMFormValuesFactory = new DefaultDDMFormValuesFactory(ddmForm, LocaleUtil.BRAZIL); DDMFormValues ddmFormValues = defaultDDMFormValuesFactory.create(); List<DDMFormFieldValue> ddmFormFieldValues = ddmFormValues.getDDMFormFieldValues(); Assert.assertEquals( ddmFormFieldValues.toString(), 1, ddmFormFieldValues.size()); DDMFormFieldValue ddmFormFieldValue = ddmFormFieldValues.get(0); Value value = ddmFormFieldValue.getValue(); Assert.assertTrue(value instanceof LocalizedValue); Assert.assertEquals( StringPool.BLANK, value.getString(LocaleUtil.BRAZIL)); Assert.assertEquals(StringPool.BLANK, value.getString(LocaleUtil.US)); }
@Test public void testDDMFormFieldValuePredefinedValue() { DDMForm ddmForm = DDMFormTestUtil.createDDMForm(); DDMFormField ddmFormField = DDMFormTestUtil.createTextDDMFormField( "Name", false, false, false); LocalizedValue predefinedValue = new LocalizedValue(LocaleUtil.US); predefinedValue.addString(LocaleUtil.BRAZIL, "Roberto"); predefinedValue.addString(LocaleUtil.US, "Robert"); ddmFormField.setPredefinedValue(predefinedValue); ddmForm.addDDMFormField(ddmFormField); DefaultDDMFormValuesFactory defaultDDMFormValuesFactory = new DefaultDDMFormValuesFactory(ddmForm, LocaleUtil.BRAZIL); DDMFormValues ddmFormValues = defaultDDMFormValuesFactory.create(); List<DDMFormFieldValue> ddmFormFieldValues = ddmFormValues.getDDMFormFieldValues(); DDMFormFieldValue ddmFormFieldValue = ddmFormFieldValues.get(0); Value value = ddmFormFieldValue.getValue(); Assert.assertEquals("Roberto", value.getString(LocaleUtil.BRAZIL)); defaultDDMFormValuesFactory = new DefaultDDMFormValuesFactory( ddmForm, LocaleUtil.SPAIN); ddmFormValues = defaultDDMFormValuesFactory.create(); ddmFormFieldValues = ddmFormValues.getDDMFormFieldValues(); ddmFormFieldValue = ddmFormFieldValues.get(0); value = ddmFormFieldValue.getValue(); Assert.assertEquals("Robert", value.getString(LocaleUtil.SPAIN)); }
@Test public void testDDMFormFieldValueUnlocalizedValue() { DDMForm ddmForm = DDMFormTestUtil.createDDMForm(); ddmForm.addDDMFormField( DDMFormTestUtil.createTextDDMFormField( "Name", false, false, false)); DefaultDDMFormValuesFactory defaultDDMFormValuesFactory = new DefaultDDMFormValuesFactory(ddmForm, LocaleUtil.BRAZIL); DDMFormValues ddmFormValues = defaultDDMFormValuesFactory.create(); List<DDMFormFieldValue> ddmFormFieldValues = ddmFormValues.getDDMFormFieldValues(); Assert.assertEquals( ddmFormFieldValues.toString(), 1, ddmFormFieldValues.size()); DDMFormFieldValue ddmFormFieldValue = ddmFormFieldValues.get(0); Value value = ddmFormFieldValue.getValue(); Assert.assertTrue(value instanceof UnlocalizedValue); Assert.assertEquals( StringPool.BLANK, value.getString(LocaleUtil.BRAZIL)); }
@Test public void testDefaultLocale() { DDMForm ddmForm = DDMFormTestUtil.createDDMForm(); DefaultDDMFormValuesFactory defaultDDMFormValuesFactory = new DefaultDDMFormValuesFactory(ddmForm, LocaleUtil.BRAZIL); DDMFormValues ddmFormValues = defaultDDMFormValuesFactory.create(); Assert.assertEquals( LocaleUtil.BRAZIL, ddmFormValues.getDefaultLocale()); }
@Test public void testNestedDDMFormFieldValue() { DDMForm ddmForm = DDMFormTestUtil.createDDMForm(); DDMFormField nameDDMFormField = DDMFormTestUtil.createTextDDMFormField( "Name", false, false, false); nameDDMFormField.addNestedDDMFormField( DDMFormTestUtil.createTextDDMFormField("Age", false, false, false)); ddmForm.addDDMFormField(nameDDMFormField); DefaultDDMFormValuesFactory defaultDDMFormValuesFactory = new DefaultDDMFormValuesFactory(ddmForm, LocaleUtil.BRAZIL); DDMFormValues ddmFormValues = defaultDDMFormValuesFactory.create(); List<DDMFormFieldValue> ddmFormFieldValues = ddmFormValues.getDDMFormFieldValues(); DDMFormFieldValue nameDDMFormFieldValue = ddmFormFieldValues.get(0); Value nameValue = nameDDMFormFieldValue.getValue(); Assert.assertEquals( StringPool.BLANK, nameValue.getString(LocaleUtil.BRAZIL)); List<DDMFormFieldValue> nestedDDMFormFieldValues = nameDDMFormFieldValue.getNestedDDMFormFieldValues(); DDMFormFieldValue ageDDMFormFieldValue = nestedDDMFormFieldValues.get( 0); Value ageValue = ageDDMFormFieldValue.getValue(); Assert.assertEquals( StringPool.BLANK, ageValue.getString(LocaleUtil.BRAZIL)); }