ConfigurationModelToDDMFormValuesConverter { public DDMFormValues getDDMFormValues() { DDMFormValues ddmFormValues = new DDMFormValues(_ddmForm); ddmFormValues.addAvailableLocale(_locale); ddmFormValues.setDefaultLocale(_locale); addDDMFormFieldValues( _configurationModel.getAttributeDefinitions(ConfigurationModel.ALL), ddmFormValues); return ddmFormValues; } ConfigurationModelToDDMFormValuesConverter(
		ConfigurationModel configurationModel, DDMForm ddmForm, Locale locale);  ConfigurationModelToDDMFormValuesConverter(
		ConfigurationModel configurationModel, DDMForm ddmForm, Locale locale,
		LocationVariableResolver locationVariableResolver); DDMFormValues getDDMFormValues();  }
@Test public void testGetValuesByConfigurationAndNegativeCardinalityWithTextField() { ExtendedObjectClassDefinition extendedObjectClassDefinition = mock( ExtendedObjectClassDefinition.class); ExtendedAttributeDefinition extendedAttributeDefinition = mock( ExtendedAttributeDefinition.class); whenGetAttributeDefinitions( extendedObjectClassDefinition, new ExtendedAttributeDefinition[] {extendedAttributeDefinition}); whenGetCardinality(extendedAttributeDefinition, -2); whenGetDefaultValue(extendedAttributeDefinition, null); whenGetID(extendedAttributeDefinition, "Text"); Configuration configuration = mock(Configuration.class); Dictionary<String, Object> properties = new Hashtable<>(); Vector<String> vector = new Vector<>(); vector.add("Joe Bloggs"); vector.add("Ella Fitzgerald"); properties.put("Text", vector); whenGetProperties(configuration, properties); ConfigurationModel configurationModel = new ConfigurationModel( null, null, configuration, extendedObjectClassDefinition, false); DDMFormValues ddmFormValues = getDDMFormValues( configurationModel, getDDMForm(configurationModel)); List<DDMFormFieldValue> ddmFormFieldValues = ddmFormValues.getDDMFormFieldValues(); Assert.assertEquals( ddmFormFieldValues.toString(), 2, ddmFormFieldValues.size()); Assert.assertEquals( "Joe Bloggs", getValueString(ddmFormFieldValues.get(0))); Assert.assertEquals( "Ella Fitzgerald", getValueString(ddmFormFieldValues.get(1))); }
@Test public void testGetValuesByConfigurationAndPositiveCardinalityWithTextField() { ExtendedObjectClassDefinition extendedObjectClassDefinition = mock( ExtendedObjectClassDefinition.class); ExtendedAttributeDefinition extendedAttributeDefinition = mock( ExtendedAttributeDefinition.class); whenGetAttributeDefinitions( extendedObjectClassDefinition, new ExtendedAttributeDefinition[] {extendedAttributeDefinition}); whenGetCardinality(extendedAttributeDefinition, 2); whenGetDefaultValue(extendedAttributeDefinition, null); whenGetID(extendedAttributeDefinition, "Text"); Configuration configuration = mock(Configuration.class); Dictionary<String, Object> properties = new Hashtable<>(); properties.put("Text", new String[] {"Joe Bloggs", "Ella Fitzgerald"}); whenGetProperties(configuration, properties); ConfigurationModel configurationModel = new ConfigurationModel( null, null, configuration, extendedObjectClassDefinition, false); DDMFormValues ddmFormValues = getDDMFormValues( configurationModel, getDDMForm(configurationModel)); List<DDMFormFieldValue> ddmFormFieldValues = ddmFormValues.getDDMFormFieldValues(); Assert.assertEquals( ddmFormFieldValues.toString(), 2, ddmFormFieldValues.size()); Assert.assertEquals( "Joe Bloggs", getValueString(ddmFormFieldValues.get(0))); Assert.assertEquals( "Ella Fitzgerald", getValueString(ddmFormFieldValues.get(1))); }
@Test public void testGetValuesByConfigurationWithCheckboxField() { ExtendedObjectClassDefinition extendedObjectClassDefinition = mock( ExtendedObjectClassDefinition.class); ExtendedAttributeDefinition extendedAttributeDefinition = mock( ExtendedAttributeDefinition.class); whenGetAttributeDefinitions( extendedObjectClassDefinition, new ExtendedAttributeDefinition[] {extendedAttributeDefinition}); whenGetCardinality(extendedAttributeDefinition, 0); whenGetID(extendedAttributeDefinition, "Boolean"); Configuration configuration = mock(Configuration.class); Dictionary<String, Object> properties = new Hashtable<>(); properties.put("Boolean", Boolean.TRUE); whenGetProperties(configuration, properties); ConfigurationModel configurationModel = new ConfigurationModel( null, null, configuration, extendedObjectClassDefinition, false); DDMFormValues ddmFormValues = getDDMFormValues( configurationModel, getDDMForm(configurationModel)); List<DDMFormFieldValue> ddmFormFieldValues = ddmFormValues.getDDMFormFieldValues(); Assert.assertEquals( ddmFormFieldValues.toString(), 1, ddmFormFieldValues.size()); Assert.assertEquals("true", getValueString(ddmFormFieldValues.get(0))); }
@Test public void testGetValuesByConfigurationWithPresentKey() { ExtendedObjectClassDefinition extendedObjectClassDefinition = mock( ExtendedObjectClassDefinition.class); ExtendedAttributeDefinition extendedAttributeDefinition = mock( ExtendedAttributeDefinition.class); whenGetAttributeDefinitions( extendedObjectClassDefinition, new ExtendedAttributeDefinition[] {extendedAttributeDefinition}); whenGetCardinality(extendedAttributeDefinition, 0); whenGetDefaultValue(extendedAttributeDefinition, new String[] {"9999"}); whenGetID(extendedAttributeDefinition, "Long"); Configuration configuration = mock(Configuration.class); Dictionary<String, Object> properties = new Hashtable<>(); whenGetProperties(configuration, properties); ConfigurationModel configurationModel = new ConfigurationModel( null, null, configuration, extendedObjectClassDefinition, false); DDMFormValues ddmFormValues = getDDMFormValues( configurationModel, getDDMForm(configurationModel)); List<DDMFormFieldValue> ddmFormFieldValues = ddmFormValues.getDDMFormFieldValues(); Assert.assertEquals( ddmFormFieldValues.toString(), 1, ddmFormFieldValues.size()); Assert.assertEquals( "It should return the default value when no key is set", "9999", getValueString(ddmFormFieldValues.get(0))); properties.put("Long", 0L); ddmFormValues = getDDMFormValues( configurationModel, getDDMForm(configurationModel)); ddmFormFieldValues = ddmFormValues.getDDMFormFieldValues(); Assert.assertEquals( ddmFormFieldValues.toString(), 1, ddmFormFieldValues.size()); Assert.assertEquals( "It should return the configuration value if they key is set", "0", getValueString(ddmFormFieldValues.get(0))); }
@Test public void testGetValuesByDefaultValueWithCheckboxField() { ExtendedObjectClassDefinition extendedObjectClassDefinition = mock( ExtendedObjectClassDefinition.class); ExtendedAttributeDefinition extendedAttributeDefinition = mock( ExtendedAttributeDefinition.class); whenGetAttributeDefinitions( extendedObjectClassDefinition, new ExtendedAttributeDefinition[] {extendedAttributeDefinition}); whenGetCardinality(extendedAttributeDefinition, 0); whenGetID(extendedAttributeDefinition, "Boolean"); whenGetDefaultValue( extendedAttributeDefinition, new String[] {"false"}); ConfigurationModel configurationModel = new ConfigurationModel( null, null, null, extendedObjectClassDefinition, false); DDMFormValues ddmFormValues = getDDMFormValues( configurationModel, getDDMForm(configurationModel)); List<DDMFormFieldValue> ddmFormFieldValues = ddmFormValues.getDDMFormFieldValues(); Assert.assertEquals( ddmFormFieldValues.toString(), 1, ddmFormFieldValues.size()); Assert.assertEquals("false", getValueString(ddmFormFieldValues.get(0))); }
@Test public void testGetValuesByDefaultValueWithSelectField() { ExtendedObjectClassDefinition extendedObjectClassDefinition = mock( ExtendedObjectClassDefinition.class); ExtendedAttributeDefinition extendedAttributeDefinition = mock( ExtendedAttributeDefinition.class); whenGetAttributeDefinitions( extendedObjectClassDefinition, new ExtendedAttributeDefinition[] {extendedAttributeDefinition}); whenGetCardinality(extendedAttributeDefinition, 0); whenGetDefaultValue( extendedAttributeDefinition, new String[] {"REQUEST_HEADER"}); whenGetID(extendedAttributeDefinition, "Select"); whenGetOptionLabels( extendedAttributeDefinition, new String[] {"COOKIE", "REQUEST_HEADER"}); whenGetOptionValues( extendedAttributeDefinition, new String[] {"COOKIE", "REQUEST_HEADER"}); ConfigurationModel configurationModel = new ConfigurationModel( null, null, null, extendedObjectClassDefinition, false); DDMFormValues ddmFormValues = getDDMFormValues( configurationModel, getDDMForm(configurationModel)); List<DDMFormFieldValue> ddmFormFieldValues = ddmFormValues.getDDMFormFieldValues(); Assert.assertEquals( ddmFormFieldValues.toString(), 1, ddmFormFieldValues.size()); Assert.assertEquals( "[\"REQUEST_HEADER\"]", getValueString(ddmFormFieldValues.get(0))); }
@Test public void testGetValuesByDefaultValueWithTextField() { ExtendedObjectClassDefinition extendedObjectClassDefinition = mock( ExtendedObjectClassDefinition.class); ExtendedAttributeDefinition extendedAttributeDefinition = mock( ExtendedAttributeDefinition.class); whenGetAttributeDefinitions( extendedObjectClassDefinition, new ExtendedAttributeDefinition[] {extendedAttributeDefinition}); whenGetCardinality(extendedAttributeDefinition, 2); whenGetDefaultValue( extendedAttributeDefinition, new String[] {"Joe Bloggs|Ella Fitzgerald"}); whenGetID(extendedAttributeDefinition, "Text"); ConfigurationModel configurationModel = new ConfigurationModel( null, null, null, extendedObjectClassDefinition, false); DDMFormValues ddmFormValues = getDDMFormValues( configurationModel, getDDMForm(configurationModel)); List<DDMFormFieldValue> ddmFormFieldValues = ddmFormValues.getDDMFormFieldValues(); Assert.assertEquals( ddmFormFieldValues.toString(), 2, ddmFormFieldValues.size()); Assert.assertEquals( "Joe Bloggs", getValueString(ddmFormFieldValues.get(0))); Assert.assertEquals( "Ella Fitzgerald", getValueString(ddmFormFieldValues.get(1))); }
@Test public void testGetValuesByEmptyDefaultValueWithTextField() { ExtendedObjectClassDefinition extendedObjectClassDefinition = mock( ExtendedObjectClassDefinition.class); ExtendedAttributeDefinition extendedAttributeDefinition = mock( ExtendedAttributeDefinition.class); whenGetAttributeDefinitions( extendedObjectClassDefinition, new ExtendedAttributeDefinition[] {extendedAttributeDefinition}); whenGetCardinality(extendedAttributeDefinition, 0); whenGetDefaultValue(extendedAttributeDefinition, null); whenGetID(extendedAttributeDefinition, "Text"); ConfigurationModel configurationModel = new ConfigurationModel( null, null, null, extendedObjectClassDefinition, false); DDMFormValues ddmFormValues = getDDMFormValues( configurationModel, getDDMForm(configurationModel)); List<DDMFormFieldValue> ddmFormFieldValues = ddmFormValues.getDDMFormFieldValues(); Assert.assertEquals( ddmFormFieldValues.toString(), 1, ddmFormFieldValues.size()); Assert.assertEquals( StringPool.BLANK, getValueString(ddmFormFieldValues.get(0))); }