Iterator<Field> iterator = fields.iterator();
Field field = iterator.next();
//Creating the FieldVariables
FieldVariable fieldVariable = new FieldVariable();
fieldVariable.setFieldId( field.getInode() );
fieldVariable.setName( NAME_ORIGINAL );
fieldVariable.setKey( "test_variable_key" );
fieldVariable.setValue( "test variable value" );
fieldVariable.setLastModifierId( user.getUserId() );
fieldVariable.setLastModDate( new Date() );
FieldVariable fieldVariable2 = new FieldVariable();
fieldVariable2.setFieldId( field.getInode() );
fieldVariable2.setName( NAME_ORIGINAL + "_2" );
fieldVariable2.setKey( "test_variable_key_2" );
fieldVariable2.setValue( "test variable value_2" );
fieldVariable2.setLastModifierId( user.getUserId() );
fieldVariable2.setLastModDate( new Date() );
//++++++++++++++++++++++++++++++++++++++++++++
//Saving the field variable
FieldFactory.saveFieldVariable( fieldVariable );
//Validations
assertNotNull( fieldVariable.getId() );
//++++++++++++++++++++++++++++++++++++++++++++
//Getting the variable we just saved
FieldVariable savedVariable = FieldFactory.getFieldVariable( fieldVariable.getId() );
//Validations
assertEquals( fieldVariable.getId(), savedVariable.getId() );
//++++++++++++++++++++++++++++++++++++++++++++
//Updating the field variable
savedVariable.setName( NAME_UPDATED );
FieldFactory.saveFieldVariable( fieldVariable );
//Getting again the saved variable
fieldVariable = FieldFactory.getFieldVariable( fieldVariable.getId() );
//Validations
assertNotNull( fieldVariable.getId() );
assertEquals( fieldVariable.getName(), NAME_UPDATED );
//++++++++++++++++++++++++++++++++++++++++++++
//Getting all the variables for a given field
Collection<FieldVariable> variables = FieldFactory.getFieldVariablesForField( field.getInode() );
//Validations
assertTrue( variables != null && !variables.isEmpty() );
//++++++++++++++++++++++++++++++++++++++++++++
//Getting all the variables
variables = FieldFactory.getAllFieldVariables();
//Validations
assertTrue( variables != null && !variables.isEmpty() );
//++++++++++++++++++++++++++++++++++++++++++++
//Delete a given variable
String variableId = fieldVariable.getId();
FieldFactory.deleteFieldVariable( fieldVariable );
//Try to get the deleted variable
FieldVariable tempFieldVariable = FieldFactory.getFieldVariable( variableId );
//validations
assertTrue( tempFieldVariable == null || tempFieldVariable.getId() == null || tempFieldVariable.getId().isEmpty() );
//++++++++++++++++++++++++++++++++++++++++++++
//Delete a given variable
variableId = fieldVariable2.getId();
FieldFactory.deleteFieldVariable( variableId );
//Try to get the deleted variable
tempFieldVariable = FieldFactory.getFieldVariable( variableId );
//validations
assertTrue( tempFieldVariable == null || tempFieldVariable.getId() == null || tempFieldVariable.getId().isEmpty() );
}