RadioDDMFormFieldTemplateContextContributor implements DDMFormFieldTemplateContextContributor { @Override public Map<String, Object> getParameters( DDMFormField ddmFormField, DDMFormFieldRenderingContext ddmFormFieldRenderingContext) { Map<String, Object> parameters = HashMapBuilder.<String, Object>put( "inline", GetterUtil.getBoolean(ddmFormField.getProperty("inline")) ).put( "options", getOptions(ddmFormField, ddmFormFieldRenderingContext) ).build(); String predefinedValue = getPredefinedValue( ddmFormField, ddmFormFieldRenderingContext); if (predefinedValue != null) { parameters.put("predefinedValue", predefinedValue); } parameters.put( "value", getValue( GetterUtil.getString( ddmFormFieldRenderingContext.getValue(), "[]"))); return parameters; }  @Override Map<String, Object> getParameters(
		DDMFormField ddmFormField,
		DDMFormFieldRenderingContext ddmFormFieldRenderingContext);  }
@Test public void testGetInline() { DDMFormField ddmFormField = createDDMFormField(); DDMFormFieldRenderingContext ddmFormFieldRenderingContext = new DDMFormFieldRenderingContext(); ddmFormField.setProperty("inline", true); ddmFormField.setProperty("dataSourceType", "data-provider"); Map<String, Object> parameters = _radioDDMFormFieldTemplateContextContributor.getParameters( ddmFormField, ddmFormFieldRenderingContext); Assert.assertEquals(true, parameters.get("inline")); }
@Test public void testGetNotDefinedPredefinedValue() { DDMFormField ddmFormField = createDDMFormField(); ddmFormField.setProperty("dataSourceType", "manual"); DDMFormFieldRenderingContext ddmFormFieldRenderingContext = new DDMFormFieldRenderingContext(); ddmFormFieldRenderingContext.setLocale(LocaleUtil.US); ddmFormFieldRenderingContext.setProperty( "options", createDDMFormOptions()); Map<String, Object> parameters = _radioDDMFormFieldTemplateContextContributor.getParameters( ddmFormField, ddmFormFieldRenderingContext); Assert.assertEquals( StringPool.BLANK, parameters.get("predefinedValue")); }
@Test public void testGetPredefinedValueInJSONArrayFormat() { DDMFormField ddmFormField = createDDMFormField(); ddmFormField.setProperty("dataSourceType", "manual"); DDMFormFieldRenderingContext ddmFormFieldRenderingContext = new DDMFormFieldRenderingContext(); ddmFormFieldRenderingContext.setLocale(LocaleUtil.US); List<Map<String, String>> keyValuePairs = new ArrayList<>(); ddmFormFieldRenderingContext.setProperty("options", keyValuePairs); LocalizedValue predefinedValue = new LocalizedValue(LocaleUtil.US); predefinedValue.addString(LocaleUtil.US, "[\"value\"]"); ddmFormField.setProperty("predefinedValue", predefinedValue); Map<String, Object> parameters = _radioDDMFormFieldTemplateContextContributor.getParameters( ddmFormField, ddmFormFieldRenderingContext); Assert.assertEquals("value", parameters.get("predefinedValue")); }
@Test public void testGetValueInJSONArrayFormat() { DDMFormField ddmFormField = createDDMFormField(); ddmFormField.setProperty("dataSourceType", "manual"); DDMFormFieldRenderingContext ddmFormFieldRenderingContext = new DDMFormFieldRenderingContext(); ddmFormFieldRenderingContext.setLocale(LocaleUtil.US); ddmFormFieldRenderingContext.setProperty( "options", createDDMFormOptions()); ddmFormFieldRenderingContext.setValue("[\"value\"]"); Map<String, Object> parameters = _radioDDMFormFieldTemplateContextContributor.getParameters( ddmFormField, ddmFormFieldRenderingContext); Assert.assertEquals("value", parameters.get("value")); }