ConfigurationModelToDDMFormConverter { public DDMForm getDDMForm() { DDMForm ddmForm = getConfigurationDDMForm(); if (ddmForm == null) { ddmForm = new DDMForm(); } ddmForm.addAvailableLocale(_locale); ddmForm.setDefaultLocale(_locale); addRequiredDDMFormFields(ddmForm); addOptionalDDMFormFields(ddmForm); return ddmForm; } ConfigurationModelToDDMFormConverter(
		ConfigurationModel configurationModel, Locale locale,
		ResourceBundle resourceBundle); DDMForm getDDMForm();  }
@Test public void testGetWithCheckboxField() { ExtendedObjectClassDefinition extendedObjectClassDefinition = mock( ExtendedObjectClassDefinition.class); ExtendedAttributeDefinition extendedAttributeDefinition = mock( ExtendedAttributeDefinition.class); whenGetAttributeDefinitions( extendedObjectClassDefinition, new ExtendedAttributeDefinition[] {extendedAttributeDefinition}, ExtendedObjectClassDefinition.ALL); whenGetAttributeDefinitions( extendedObjectClassDefinition, new ExtendedAttributeDefinition[0], ExtendedObjectClassDefinition.OPTIONAL); whenGetAttributeDefinitions( extendedObjectClassDefinition, new ExtendedAttributeDefinition[] {extendedAttributeDefinition}, ExtendedObjectClassDefinition.REQUIRED); whenGetCardinality(extendedAttributeDefinition, 0); whenGetID(extendedAttributeDefinition, "Boolean"); whenGetType( extendedAttributeDefinition, ExtendedAttributeDefinition.BOOLEAN); ConfigurationModel configurationModel = new ConfigurationModel( null, null, null, extendedObjectClassDefinition, false); ConfigurationModelToDDMFormConverter configurationModelToDDMFormConverter = spy( new ConfigurationModelToDDMFormConverter( configurationModel, _enLocale, new EmptyResourceBundle())); whenGetConfigurationDDMForm(configurationModelToDDMFormConverter, null); DDMForm ddmForm = configurationModelToDDMFormConverter.getDDMForm(); Map<String, DDMFormField> ddmFormFieldsMap = ddmForm.getDDMFormFieldsMap(false); DDMFormField ddmFormField = ddmFormFieldsMap.get("Boolean"); Assert.assertNotNull(ddmFormField); Assert.assertEquals(DDMFormFieldType.CHECKBOX, ddmFormField.getType()); Assert.assertEquals("boolean", ddmFormField.getDataType()); Assert.assertFalse(ddmFormField.isRepeatable()); Assert.assertFalse(ddmFormField.isRequired()); Value predefinedValue = ddmFormField.getPredefinedValue(); Assert.assertEquals("false", predefinedValue.getString(_enLocale)); }
@Test public void testGetWithIntegerField() { ExtendedObjectClassDefinition extendedObjectClassDefinition = mock( ExtendedObjectClassDefinition.class); ExtendedAttributeDefinition extendedAttributeDefinition = mock( ExtendedAttributeDefinition.class); whenGetAttributeDefinitions( extendedObjectClassDefinition, new ExtendedAttributeDefinition[] {extendedAttributeDefinition}, ExtendedObjectClassDefinition.ALL); whenGetAttributeDefinitions( extendedObjectClassDefinition, new ExtendedAttributeDefinition[0], ExtendedObjectClassDefinition.OPTIONAL); whenGetAttributeDefinitions( extendedObjectClassDefinition, new ExtendedAttributeDefinition[] {extendedAttributeDefinition}, ExtendedObjectClassDefinition.REQUIRED); whenGetCardinality(extendedAttributeDefinition, 0); whenGetID(extendedAttributeDefinition, "Integer"); whenGetType( extendedAttributeDefinition, ExtendedAttributeDefinition.INTEGER); ConfigurationModel configurationModel = new ConfigurationModel( null, null, null, extendedObjectClassDefinition, false); ConfigurationModelToDDMFormConverter configurationModelToDDMFormConverter = spy( new ConfigurationModelToDDMFormConverter( configurationModel, _enLocale, new EmptyResourceBundle())); whenGetConfigurationDDMForm(configurationModelToDDMFormConverter, null); DDMForm ddmForm = configurationModelToDDMFormConverter.getDDMForm(); Map<String, DDMFormField> ddmFormFieldsMap = ddmForm.getDDMFormFieldsMap(false); DDMFormField ddmFormField = ddmFormFieldsMap.get("Integer"); Assert.assertNotNull(ddmFormField); Assert.assertEquals(DDMFormFieldType.TEXT, ddmFormField.getType()); Assert.assertEquals("integer", ddmFormField.getDataType()); Assert.assertFalse(ddmFormField.isRepeatable()); Assert.assertTrue(ddmFormField.isRequired()); LocalizedValue predefinedValue = ddmFormField.getPredefinedValue(); Assert.assertEquals(_enLocale, predefinedValue.getDefaultLocale()); Assert.assertEquals("0", predefinedValue.getString(_enLocale)); }
@Test public void testGetWithLocalizableTextField() { ExtendedObjectClassDefinition extendedObjectClassDefinition = mock( ExtendedObjectClassDefinition.class); ExtendedAttributeDefinition extendedAttributeDefinition = mock( ExtendedAttributeDefinition.class); whenGetAttributeDefinitions( extendedObjectClassDefinition, new ExtendedAttributeDefinition[] {extendedAttributeDefinition}, ExtendedObjectClassDefinition.ALL); whenGetAttributeDefinitions( extendedObjectClassDefinition, new ExtendedAttributeDefinition[] {extendedAttributeDefinition}, ExtendedObjectClassDefinition.OPTIONAL); whenGetAttributeDefinitions( extendedObjectClassDefinition, new ExtendedAttributeDefinition[0], ExtendedObjectClassDefinition.REQUIRED); whenGetCardinality(extendedAttributeDefinition, 0); whenGetID(extendedAttributeDefinition, "LocalizableText"); whenGetRequiredInput(extendedAttributeDefinition, true); whenGetType( extendedAttributeDefinition, ExtendedAttributeDefinition.LOCALIZED_VALUES_MAP); ConfigurationModel configurationModel = new ConfigurationModel( null, null, null, extendedObjectClassDefinition, false); ConfigurationModelToDDMFormConverter configurationModelToDDMFormConverter = spy( new ConfigurationModelToDDMFormConverter( configurationModel, _enLocale, new EmptyResourceBundle())); whenGetConfigurationDDMForm(configurationModelToDDMFormConverter, null); DDMForm ddmForm = configurationModelToDDMFormConverter.getDDMForm(); Map<String, DDMFormField> ddmFormFieldsMap = ddmForm.getDDMFormFieldsMap(false); DDMFormField ddmFormField = ddmFormFieldsMap.get("LocalizableText"); Assert.assertNotNull(ddmFormField); Assert.assertEquals( DDMFormFieldType.LOCALIZABLE_TEXT, ddmFormField.getType()); Assert.assertEquals("string", ddmFormField.getDataType()); Assert.assertFalse(ddmFormField.isRepeatable()); Assert.assertTrue(ddmFormField.isRequired()); }
@Test public void testGetWithPasswordField() { ExtendedObjectClassDefinition extendedObjectClassDefinition = mock( ExtendedObjectClassDefinition.class); ExtendedAttributeDefinition extendedAttributeDefinition = mock( ExtendedAttributeDefinition.class); whenGetAttributeDefinitions( extendedObjectClassDefinition, new ExtendedAttributeDefinition[] {extendedAttributeDefinition}, ExtendedObjectClassDefinition.ALL); whenGetAttributeDefinitions( extendedObjectClassDefinition, new ExtendedAttributeDefinition[] {extendedAttributeDefinition}, ExtendedObjectClassDefinition.OPTIONAL); whenGetAttributeDefinitions( extendedObjectClassDefinition, new ExtendedAttributeDefinition[0], ExtendedObjectClassDefinition.REQUIRED); whenGetCardinality(extendedAttributeDefinition, 0); whenGetID(extendedAttributeDefinition, "Password"); whenGetType( extendedAttributeDefinition, ExtendedAttributeDefinition.PASSWORD); ConfigurationModel configurationModel = new ConfigurationModel( null, null, null, extendedObjectClassDefinition, false); ConfigurationModelToDDMFormConverter configurationModelToDDMFormConverter = spy( new ConfigurationModelToDDMFormConverter( configurationModel, _enLocale, new EmptyResourceBundle())); whenGetConfigurationDDMForm(configurationModelToDDMFormConverter, null); DDMForm ddmForm = configurationModelToDDMFormConverter.getDDMForm(); Map<String, DDMFormField> ddmFormFieldsMap = ddmForm.getDDMFormFieldsMap(false); DDMFormField ddmFormField = ddmFormFieldsMap.get("Password"); Assert.assertNotNull(ddmFormField); Assert.assertEquals(DDMFormFieldType.PASSWORD, ddmFormField.getType()); Assert.assertEquals("string", ddmFormField.getDataType()); Assert.assertFalse(ddmFormField.isRepeatable()); Assert.assertFalse(ddmFormField.isRequired()); }
@Test public void testGetWithSelectField() { ExtendedObjectClassDefinition extendedObjectClassDefinition = mock( ExtendedObjectClassDefinition.class); ExtendedAttributeDefinition extendedAttributeDefinition = mock( ExtendedAttributeDefinition.class); whenGetAttributeDefinitions( extendedObjectClassDefinition, new ExtendedAttributeDefinition[] {extendedAttributeDefinition}, ExtendedObjectClassDefinition.ALL); whenGetAttributeDefinitions( extendedObjectClassDefinition, new ExtendedAttributeDefinition[0], ExtendedObjectClassDefinition.OPTIONAL); whenGetAttributeDefinitions( extendedObjectClassDefinition, new ExtendedAttributeDefinition[] {extendedAttributeDefinition}, ExtendedObjectClassDefinition.REQUIRED); whenGetCardinality(extendedAttributeDefinition, 0); whenGetID(extendedAttributeDefinition, "Select"); whenGetType( extendedAttributeDefinition, ExtendedAttributeDefinition.STRING); whenGetOptionLabels( extendedAttributeDefinition, new String[] {"Label 1", "Label 2"}); whenGetOptionValues( extendedAttributeDefinition, new String[] {"Value 1", "Value 2"}); ConfigurationModel configurationModel = new ConfigurationModel( null, null, null, extendedObjectClassDefinition, false); ConfigurationModelToDDMFormConverter configurationModelToDDMFormConverter = spy( new ConfigurationModelToDDMFormConverter( configurationModel, _enLocale, new EmptyResourceBundle())); whenGetConfigurationDDMForm(configurationModelToDDMFormConverter, null); DDMForm ddmForm = configurationModelToDDMFormConverter.getDDMForm(); Map<String, DDMFormField> ddmFormFieldsMap = ddmForm.getDDMFormFieldsMap(false); DDMFormField ddmFormField = ddmFormFieldsMap.get("Select"); Assert.assertNotNull(ddmFormField); Assert.assertEquals(DDMFormFieldType.SELECT, ddmFormField.getType()); Assert.assertEquals("string", ddmFormField.getDataType()); Assert.assertFalse(ddmFormField.isRepeatable()); Assert.assertTrue(ddmFormField.isRequired()); DDMFormFieldOptions ddmFormFieldOptions = ddmFormField.getDDMFormFieldOptions(); Assert.assertEquals(_enLocale, ddmFormFieldOptions.getDefaultLocale()); Set<String> optionsValues = ddmFormFieldOptions.getOptionsValues(); Assert.assertTrue( optionsValues.toString(), optionsValues.contains("Value 1")); Assert.assertTrue( optionsValues.toString(), optionsValues.contains("Value 2")); LocalizedValue value1Labels = ddmFormFieldOptions.getOptionLabels( "Value 1"); Assert.assertEquals(_enLocale, value1Labels.getDefaultLocale()); Assert.assertEquals("Label 1", value1Labels.getString(_enLocale)); LocalizedValue value2Labels = ddmFormFieldOptions.getOptionLabels( "Value 2"); Assert.assertEquals(_enLocale, value2Labels.getDefaultLocale()); Assert.assertEquals("Label 2", value2Labels.getString(_enLocale)); }
@Test public void testGetWithTextField() { ExtendedObjectClassDefinition extendedObjectClassDefinition = mock( ExtendedObjectClassDefinition.class); ExtendedAttributeDefinition extendedAttributeDefinition = mock( ExtendedAttributeDefinition.class); whenGetAttributeDefinitions( extendedObjectClassDefinition, new ExtendedAttributeDefinition[] {extendedAttributeDefinition}, ExtendedObjectClassDefinition.ALL); whenGetAttributeDefinitions( extendedObjectClassDefinition, new ExtendedAttributeDefinition[] {extendedAttributeDefinition}, ExtendedObjectClassDefinition.OPTIONAL); whenGetAttributeDefinitions( extendedObjectClassDefinition, new ExtendedAttributeDefinition[0], ExtendedObjectClassDefinition.REQUIRED); whenGetCardinality(extendedAttributeDefinition, 0); whenGetID(extendedAttributeDefinition, "Text"); whenGetType( extendedAttributeDefinition, ExtendedAttributeDefinition.STRING); ConfigurationModel configurationModel = new ConfigurationModel( null, null, null, extendedObjectClassDefinition, false); ConfigurationModelToDDMFormConverter configurationModelToDDMFormConverter = spy( new ConfigurationModelToDDMFormConverter( configurationModel, _enLocale, new EmptyResourceBundle())); whenGetConfigurationDDMForm(configurationModelToDDMFormConverter, null); DDMForm ddmForm = configurationModelToDDMFormConverter.getDDMForm(); Map<String, DDMFormField> ddmFormFieldsMap = ddmForm.getDDMFormFieldsMap(false); DDMFormField ddmFormField = ddmFormFieldsMap.get("Text"); Assert.assertNotNull(ddmFormField); Assert.assertEquals(DDMFormFieldType.TEXT, ddmFormField.getType()); Assert.assertEquals("string", ddmFormField.getDataType()); Assert.assertFalse(ddmFormField.isRepeatable()); Assert.assertFalse(ddmFormField.isRequired()); }
@Test public void testRequiredInputWithTextField() { ExtendedObjectClassDefinition extendedObjectClassDefinition = mock( ExtendedObjectClassDefinition.class); ExtendedAttributeDefinition extendedAttributeDefinition = mock( ExtendedAttributeDefinition.class); whenGetAttributeDefinitions( extendedObjectClassDefinition, new ExtendedAttributeDefinition[] {extendedAttributeDefinition}, ExtendedObjectClassDefinition.ALL); whenGetAttributeDefinitions( extendedObjectClassDefinition, new ExtendedAttributeDefinition[] {extendedAttributeDefinition}, ExtendedObjectClassDefinition.OPTIONAL); whenGetAttributeDefinitions( extendedObjectClassDefinition, new ExtendedAttributeDefinition[0], ExtendedObjectClassDefinition.REQUIRED); whenGetCardinality(extendedAttributeDefinition, 0); whenGetID(extendedAttributeDefinition, "Text"); whenGetRequiredInput(extendedAttributeDefinition, true); whenGetType( extendedAttributeDefinition, ExtendedAttributeDefinition.STRING); ConfigurationModel configurationModel = new ConfigurationModel( null, null, null, extendedObjectClassDefinition, false); ConfigurationModelToDDMFormConverter configurationModelToDDMFormConverter = spy( new ConfigurationModelToDDMFormConverter( configurationModel, _enLocale, new EmptyResourceBundle())); whenGetConfigurationDDMForm(configurationModelToDDMFormConverter, null); DDMForm ddmForm = configurationModelToDDMFormConverter.getDDMForm(); Map<String, DDMFormField> ddmFormFieldsMap = ddmForm.getDDMFormFieldsMap(false); DDMFormField ddmFormField = ddmFormFieldsMap.get("Text"); Assert.assertNotNull(ddmFormField); Assert.assertEquals(DDMFormFieldType.TEXT, ddmFormField.getType()); Assert.assertEquals("string", ddmFormField.getDataType()); Assert.assertFalse(ddmFormField.isRepeatable()); Assert.assertTrue(ddmFormField.isRequired()); }