ValueTypeDAO mockedValueTypeDAO = mock(ValueTypeDAO.class);
mappingAction.setValueTypeDAO(mockedValueTypeDAO);
when(mockedValueTypeDAO.findAll()).thenReturn(valueTypeList);
//Code for creating List<Mapping> & mock for it.
Mapping mapping = new Mapping();
ColumnAlias columnAlias1 = new ColumnAlias(mapping, valueType1,"columnFamily", "qualifier", "alias");
ColumnAlias columnAlias2 = new ColumnAlias(mapping, valueType1,"columnFamily", "qualifier", "alias");
ColumnAlias columnAlias3= new ColumnAlias(mapping, valueType1,"columnFamily", "qualifier", "alias");
Map<String, ColumnAlias> columnAliasMap = new HashMap<String, ColumnAlias>();
columnAliasMap.put("columnAlias1", columnAlias1);
columnAliasMap.put("columnAlias2", columnAlias2);
columnAliasMap.put("columnAlias3", columnAlias3);
RowAlias rowAlias1 = new RowAlias(901, mapping, valueType1, 4 ,"rowAliasName1");
RowAlias rowAlias2 = new RowAlias(902, mapping, valueType1, 4 ,"rowAliasName2");
RowAlias rowAlias3 = new RowAlias(903, mapping, valueType1, 4 ,"rowAliasName3");
Map<String, RowAlias> rowAliasMap = new TreeMap<String, RowAlias>();
rowAliasMap.put("rowAlias1", rowAlias1);
rowAliasMap.put("rowAlias2", rowAlias2);
rowAliasMap.put("rowAlias3", rowAlias3);
Mapping mapping1 = new Mapping(connection1, "mappingParameterName1", "ParameterTableName1", columnAliasMap, rowAliasMap);
Mapping mapping2 = new Mapping(connection2, "mappingParameterName2", "ParameterTableName2", columnAliasMap, rowAliasMap);
Mapping mapping3 = new Mapping(connection3, "mappingParameterName3", "ParameterTableName3", columnAliasMap, rowAliasMap);
ArrayList<Mapping> mappingList = new ArrayList<Mapping>();
mappingList.add(mapping1);
mappingList.add(mapping2);
mappingList.add(mapping3);
MappingDAO mockedMappingDAO = mock(MappingDAO.class);
mappingAction.setMappingDAO(mockedMappingDAO);
when(mockedMappingDAO.findAll()).thenReturn(mappingList);
String successString = mappingAction.initializeMappings();
assertEquals(successString, "success");
//Test for same connections
assertEquals(mappingAction.getConnections().get(0), connection1);
assertEquals(mappingAction.getConnections().get(1), connection2);
assertEquals(mappingAction.getConnections().get(2), connection3);
//Test for same valueTypes - columnTypeList in the MappingAction class
assertEquals(mappingAction.getColumnTypeList().get(0), valueType1);
assertEquals(mappingAction.getColumnTypeList().get(1), valueType2);
assertEquals(mappingAction.getColumnTypeList().get(2), valueType3);
//Test for same mappings
//test mapping1
assertEquals(mappingAction.getMappingViewList().get(0).getId(), mapping1.getId());
assertEquals(mappingAction.getMappingViewList().get(0).getName(), mapping1.getName());
assertEquals(mappingAction.getMappingViewList().get(0).getConnectionName(), mapping1.getConnection().getName());
assertEquals(mappingAction.getMappingViewList().get(0).getTableName(), mapping1.getTableName());
//test mapping2
assertEquals(mappingAction.getMappingViewList().get(1).getId(), mapping2.getId());
assertEquals(mappingAction.getMappingViewList().get(1).getName(), mapping2.getName());
assertEquals(mappingAction.getMappingViewList().get(1).getConnectionName(), mapping2.getConnection().getName());
assertEquals(mappingAction.getMappingViewList().get(1).getTableName(), mapping2.getTableName());
//test mapping3
assertEquals(mappingAction.getMappingViewList().get(2).getId(), mapping3.getId());
assertEquals(mappingAction.getMappingViewList().get(2).getName(), mapping3.getName());
assertEquals(mappingAction.getMappingViewList().get(2).getConnectionName(), mapping3.getConnection().getName());
assertEquals(mappingAction.getMappingViewList().get(2).getTableName(), mapping3.getTableName());
}