DDMFormFieldTemplateContextFactory { public List<Object> create() { return createDDMFormFieldTemplateContexts( _ddmFormFieldValues, StringPool.BLANK); } DDMFormFieldTemplateContextFactory(
		DDMFormEvaluator ddmFormEvaluator, String ddmFormFieldName,
		Map<String, DDMFormField> ddmFormFieldsMap,
		Map<DDMFormEvaluatorFieldContextKey, Map<String, Object>>
			ddmFormFieldsPropertyChanges,
		List<DDMFormFieldValue> ddmFormFieldValues,
		DDMFormRenderingContext ddmFormRenderingContext,
		DDMStructureLayoutLocalService ddmStructureLayoutLocalService,
		DDMStructureLocalService ddmStructureLocalService,
		JSONFactory jsonFactory, boolean pageEnabled,
		DDMFormLayout parentDDMFormLayout); List<Object> create();  }
@Test public void testNotReadOnlyTextFieldAndReadOnlyForm() { DDMForm ddmForm = DDMFormTestUtil.createDDMForm(); DDMFormField ddmFormField = DDMFormTestUtil.createTextDDMFormField( "Field1", false, false, false); boolean readOnly = false; ddmFormField.setReadOnly(readOnly); ddmForm.addDDMFormField(ddmFormField); String instanceId = StringUtil.randomString(); Map<DDMFormEvaluatorFieldContextKey, Map<String, Object>> ddmFormFieldsPropertyChanges = HashMapBuilder. <DDMFormEvaluatorFieldContextKey, Map<String, Object>>put( new DDMFormEvaluatorFieldContextKey( "Field1", instanceId), HashMapBuilder.<String, Object>put( "readOnly", readOnly ).put( "visible", true ).build() ).build(); List<DDMFormFieldValue> ddmFormFieldValues = new ArrayList<>(); DDMFormFieldValue ddmFormFieldValue = DDMFormValuesTestUtil.createUnlocalizedDDMFormFieldValue( "Field1", "Value 1"); ddmFormFieldValue.setInstanceId(instanceId); ddmFormFieldValues.add(ddmFormFieldValue); DDMFormFieldTemplateContextFactory ddmFormFieldTemplateContextFactory = createDDMFormFieldTemplateContextFactory( ddmForm, ddmFormField.getName(), ddmFormFieldsPropertyChanges, ddmFormFieldValues, true, getTextDDMFormFieldRenderer(), getTextDDMFormFieldTemplateContextContributor()); List<Object> fields = ddmFormFieldTemplateContextFactory.create(); Assert.assertEquals(fields.toString(), 1, fields.size()); Map<String, Object> fieldTemplateContext = (Map<String, Object>)fields.get(0); Assert.assertEquals( true, MapUtil.getBoolean(fieldTemplateContext, "readOnly")); }
@Test public void testReadOnlyTextFieldAndNotReadOnlyForm() { DDMForm ddmForm = DDMFormTestUtil.createDDMForm(); DDMFormField ddmFormField = DDMFormTestUtil.createTextDDMFormField( "Field1", false, false, true); boolean readOnly = true; ddmFormField.setReadOnly(readOnly); ddmForm.addDDMFormField(ddmFormField); String instanceId = StringUtil.randomString(); Map<DDMFormEvaluatorFieldContextKey, Map<String, Object>> ddmFormFieldsPropertyChanges = HashMapBuilder. <DDMFormEvaluatorFieldContextKey, Map<String, Object>>put( new DDMFormEvaluatorFieldContextKey( "Field1", instanceId), HashMapBuilder.<String, Object>put( "readOnly", readOnly ).put( "visible", true ).build() ).build(); List<DDMFormFieldValue> ddmFormFieldValues = new ArrayList<>(); DDMFormFieldValue ddmFormFieldValue = DDMFormValuesTestUtil.createUnlocalizedDDMFormFieldValue( "Field1", "Value 1"); ddmFormFieldValue.setInstanceId(instanceId); ddmFormFieldValues.add(ddmFormFieldValue); DDMFormFieldTemplateContextFactory ddmFormFieldTemplateContextFactory = createDDMFormFieldTemplateContextFactory( ddmForm, ddmFormField.getName(), ddmFormFieldsPropertyChanges, ddmFormFieldValues, false, getTextDDMFormFieldRenderer(), getTextDDMFormFieldTemplateContextContributor()); List<Object> fields = ddmFormFieldTemplateContextFactory.create(); Assert.assertEquals(fields.toString(), 1, fields.size()); Map<String, Object> fieldTemplateContext = (Map<String, Object>)fields.get(0); Assert.assertEquals( true, MapUtil.getBoolean(fieldTemplateContext, "readOnly")); }
@Test public void testTextField() { DDMForm ddmForm = DDMFormTestUtil.createDDMForm(); boolean required = true; DDMFormField ddmFormField = DDMFormTestUtil.createTextDDMFormField( "Field1", false, false, required); ddmFormField.setLabel( DDMFormValuesTestUtil.createLocalizedValue("Field 1", _LOCALE)); ddmFormField.setReadOnly(false); ddmFormField.setTip( DDMFormValuesTestUtil.createLocalizedValue( "This is a tip.", _LOCALE)); ddmFormField.setProperty("displayStyle", "singleline"); ddmForm.addDDMFormField(ddmFormField); String instanceId = StringUtil.randomString(); Map<DDMFormEvaluatorFieldContextKey, Map<String, Object>> ddmFormFieldsPropertyChanges = HashMapBuilder. <DDMFormEvaluatorFieldContextKey, Map<String, Object>>put( new DDMFormEvaluatorFieldContextKey( "Field1", instanceId), HashMapBuilder.<String, Object>put( "required", true ).put( "valid", true ).put( "visible", true ).build() ).build(); List<DDMFormFieldValue> ddmFormFieldValues = new ArrayList<>(); DDMFormFieldValue ddmFormFieldValue = DDMFormValuesTestUtil.createUnlocalizedDDMFormFieldValue( "Field1", "Value 1"); ddmFormFieldValue.setInstanceId(instanceId); ddmFormFieldValues.add(ddmFormFieldValue); DDMFormFieldTemplateContextFactory ddmFormFieldTemplateContextFactory = createDDMFormFieldTemplateContextFactory( ddmForm, ddmFormField.getName(), ddmFormFieldsPropertyChanges, ddmFormFieldValues, false, getTextDDMFormFieldRenderer(), getTextDDMFormFieldTemplateContextContributor()); List<Object> fields = ddmFormFieldTemplateContextFactory.create(); Assert.assertEquals(fields.toString(), 1, fields.size()); Map<String, Object> fieldTemplateContext = (Map<String, Object>)fields.get(0); Assert.assertEquals( "singleline", MapUtil.getString(fieldTemplateContext, "displayStyle")); Assert.assertEquals( "Field 1", MapUtil.getString(fieldTemplateContext, "label")); Assert.assertEquals( false, MapUtil.getBoolean(fieldTemplateContext, "readOnly")); Assert.assertEquals( false, MapUtil.getBoolean(fieldTemplateContext, "repeatable")); Assert.assertEquals( true, MapUtil.getBoolean(fieldTemplateContext, "required")); Assert.assertEquals( "This is a tip.", MapUtil.getString(fieldTemplateContext, "tip")); Assert.assertEquals( true, MapUtil.getBoolean(fieldTemplateContext, "valid")); Assert.assertEquals( StringPool.BLANK, MapUtil.getString(fieldTemplateContext, "validationErrorMessage")); Assert.assertEquals( "Value 1", MapUtil.getString(fieldTemplateContext, "value")); Assert.assertEquals( true, MapUtil.getBoolean(fieldTemplateContext, "visible")); String expectedName = String.format( _FIELD_NAME_FORMAT, "Field1", instanceId, 0, _LOCALE.toString()); Assert.assertEquals( expectedName, MapUtil.getString(fieldTemplateContext, "name")); }