Author: dlanglais Date: 2010-03-01 20:52:08 +0100 (Mon, 01 Mar 2010) New Revision: 152 Added: trunk/msm-fromtoXML/src/test/resources/fiveColumns.xml trunk/msm-fromtoXML/src/test/resources/sixCells.xml Removed: trunk/msm-fromtoXML/src/test/resources/twoTablesFiveColumns.xml Modified: trunk/msm-fromtoXML/src/main/java/org/nuiton/mapstoragemanager/plugins/exporter/ToXML.java trunk/msm-fromtoXML/src/main/java/org/nuiton/mapstoragemanager/plugins/importer/FromXML.java trunk/msm-fromtoXML/src/test/java/org/nuiton/mapstoragemanager/plugins/importer/FromXMLTest.java Log: Avancement test de FromXML.java. Import cellules OK. Pas de prise en compte de version. Modified: trunk/msm-fromtoXML/src/main/java/org/nuiton/mapstoragemanager/plugins/exporter/ToXML.java =================================================================== --- trunk/msm-fromtoXML/src/main/java/org/nuiton/mapstoragemanager/plugins/exporter/ToXML.java 2010-03-01 18:25:21 UTC (rev 151) +++ trunk/msm-fromtoXML/src/main/java/org/nuiton/mapstoragemanager/plugins/exporter/ToXML.java 2010-03-01 19:52:08 UTC (rev 152) @@ -52,7 +52,7 @@ } /** - * For eath table of the database, the document is constructed. + * For each table of the database, the document is constructed. * @param bigTable the bigTable. * @param database the database Element. */ @@ -76,7 +76,7 @@ } /** - * For eath column of the table, the document is constructed. + * For each column of the table, the document is constructed. * @param bigTable the bigTable. * @param table the table Element. */ @@ -103,7 +103,7 @@ } /** - * For eath cell of the column, the document is constructed. + * For each cell of the column, the document is constructed. * @param bigTable the bigTable. * @param column the column Element. */ Modified: trunk/msm-fromtoXML/src/main/java/org/nuiton/mapstoragemanager/plugins/importer/FromXML.java =================================================================== --- trunk/msm-fromtoXML/src/main/java/org/nuiton/mapstoragemanager/plugins/importer/FromXML.java 2010-03-01 18:25:21 UTC (rev 151) +++ trunk/msm-fromtoXML/src/main/java/org/nuiton/mapstoragemanager/plugins/importer/FromXML.java 2010-03-01 19:52:08 UTC (rev 152) @@ -57,15 +57,15 @@ } /** - * For eath table of the database, the document is constructed. + * For each table of the database, the document is constructed. * @param bigTable the bigTable. * @param database the database Element. */ private void forEachTable(NewBigTable bigTable, final Element database) { - // the tables name. - List<Element> tableElements = database.getChildren("table"); + // the table elements. + List<Element> tables = database.getChildren("table"); - for (Element table : tableElements) { + for (Element table : tables) { // get table name and add to the bigTable. String tableName = table.getAttributeValue("tableName"); bigTable.createTable(tableName); @@ -76,7 +76,7 @@ } /** - * For eath column of the table, the document is constructed. + * For each column of the table, the document is constructed. * @param bigTable the bigTable. * @param table the table Element. */ @@ -84,10 +84,10 @@ // the table name. String tableName = table.getAttributeValue("tableName"); - // the columns name. - List<Element> columnElements = table.getChildren("column"); + // the column elements. + List<Element> columns = table.getChildren("column"); - for (Element column : columnElements) { + for (Element column : columns) { // get column name and add to the table. String columnName = column.getAttributeValue("columnName"); bigTable.createColumn(tableName, columnName); @@ -98,7 +98,7 @@ } /** - * For eath cell of the column, the document is constructed. + * For each cell of the column, the document is constructed. * @param bigTable the bigTable. * @param column the column Element. */ @@ -109,36 +109,16 @@ // the column name. String columnName = column.getAttributeValue("columnName"); - // the table keys. - Set<String> keys = bigTable.getKeys(tableName); + // the cell elements. + List<Element> cells = column.getChildren("cell"); - String content = ""; - for (String key : keys) { - try{ - content = bigTable.get(tableName, columnName, key); - if ( ! "".equals(content)) { + for (Element cell : cells) { + // get cell key and content. + String cellKey = cell.getAttributeValue("key"); + String cellContent = cell.getChild("value").getText(); - // new cell Element. - Element cell = new Element("cell"); - // new attribute which contain the cell key. - Attribute cellKeyAttr = new Attribute("key", key); - cell.setAttribute(cellKeyAttr); - - // we add the cell to the column. - column.addContent(cell); - - // new value Element. - Element value = new Element("value"); - value.setText(content); - - // we add the value to the cell. - cell.addContent(value); - } - } - catch (NoSuchElementException e) { - LOG.trace(e, e); - } - + // add content to the bigtable. + bigTable.put(tableName, columnName, cellKey, cellContent); } } Modified: trunk/msm-fromtoXML/src/test/java/org/nuiton/mapstoragemanager/plugins/importer/FromXMLTest.java =================================================================== --- trunk/msm-fromtoXML/src/test/java/org/nuiton/mapstoragemanager/plugins/importer/FromXMLTest.java 2010-03-01 18:25:21 UTC (rev 151) +++ trunk/msm-fromtoXML/src/test/java/org/nuiton/mapstoragemanager/plugins/importer/FromXMLTest.java 2010-03-01 19:52:08 UTC (rev 152) @@ -8,8 +8,12 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Map; +import java.util.NoSuchElementException; import java.util.Set; +import junit.framework.Assert; import junit.framework.TestCase; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.nuiton.mapstoragemanager.plugins.Importer; import org.nuiton.mapstoragemanager.plugins.NewBigTable; import org.nuiton.mapstoragemanager.plugins.bighashmapv2.BigHashMap; @@ -21,12 +25,18 @@ */ public class FromXMLTest extends TestCase { + /** + * Logger. + */ + private static final Log LOG = LogFactory.getLog(FromXMLTest.class); + // public void testImportFrom() { // Assert.fail(); // } /** - * Import the database from the file fiveTables and verify the content. + * Import the database from the file fiveTables. + * Verify the content. */ public void testImportFromFiveTables() { @@ -39,6 +49,9 @@ importer.importFrom(bigTable, fiveTables); + /************************ + * Test Tables * + ************************/ Set<String> tableNamesExpected; { /** @@ -62,10 +75,14 @@ } } - public void testImportFromTwoTablesFiveColumns() { + /** + * Import the database from the file fiveColumns. + * Verify the content. + */ + public void testImportFromFiveColumns() { File twoTablesFiveColumns = - getFile.getTestFile("/src/test/resources/twoTablesFiveColumns.xml"); + getFile.getTestFile("/src/test/resources/fiveColumns.xml"); // import fiveTables. Importer importer = new FromXML(); @@ -73,6 +90,9 @@ importer.importFrom(bigTable, twoTablesFiveColumns); + /************************ + * Test Tables * + ************************/ Set<String> tableNamesExpected; { /** @@ -85,6 +105,9 @@ Set<String> tableNamesActual = bigTable.getTablesNames(); assertEquals(tableNamesExpected, tableNamesActual); + /************************ + * Test Columns * + ************************/ Map<String, Set<String>> columnNamesExpected; { /** @@ -101,11 +124,143 @@ columnNamesExpected.put("table1", table1ColumnNames); columnNamesExpected.put("table2", table2ColumnNames); } - + Set<String> columnNamesActual; for (String tableName : tableNamesActual) { columnNamesActual = bigTable.getColumnsNames(tableName); assertEquals(columnNamesExpected.get(tableName), columnNamesActual); } } + + /** + * Import the database from the file tenCells. + * Verify the content. + */ + public void testImportFromThreeTenCells() { + + File twoTablesFiveColumns = + getFile.getTestFile("/src/test/resources/sixCells.xml"); + + // import fiveTables. + Importer importer = new FromXML(); + NewBigTable bigTable = new BigHashMap(); + + importer.importFrom(bigTable, twoTablesFiveColumns); + + /************************ + * Test Tables * + ************************/ + Set<String> tableNamesExpected; + { + /** + * Init tableNames. + */ + tableNamesExpected = new HashSet<String>(); + tableNamesExpected.add("table1"); + tableNamesExpected.add("table2"); + } + Set<String> tableNamesActual = bigTable.getTablesNames(); + assertEquals(tableNamesExpected, tableNamesActual); + + /************************ + * Test Columns * + ************************/ + Map<String, Set<String>> columnNamesExpected; + { + /** + * Init columnNames. + */ + columnNamesExpected = new HashMap<String, Set<String>>(); + Set<String> table1ColumnNames = new HashSet<String>(); + table1ColumnNames.add("column1"); + Set<String> table2ColumnNames = new HashSet<String>(); + table2ColumnNames.add("column2"); + table2ColumnNames.add("column3"); + columnNamesExpected.put("table1", table1ColumnNames); + columnNamesExpected.put("table2", table2ColumnNames); + } + + Set<String> columnNamesActual; + for (String tableName : tableNamesActual) { + columnNamesActual = bigTable.getColumnsNames(tableName); + assertEquals(columnNamesExpected.get(tableName), columnNamesActual); + } + + /************************ + * Test Cells * + ************************/ + Map<String, Map<String, Map<String, String>>> CellContentExpected; + { + /** + * Init cellContent. + */ + CellContentExpected = new HashMap<String, + Map<String, Map<String, String>>>(); + // table 1. + Map<String, Map<String, String>> table1 = + new HashMap<String, Map<String, String>>(); + // column 1. + Map<String,String> column1 = new HashMap<String, String>(); + column1.put("111", "111"); + table1.put("column1", column1); + // table 2. + Map<String, Map<String, String>> table2 = + new HashMap<String, Map<String, String>>(); + // column 2. + Map<String,String> column2 = new HashMap<String, String>(); + column2.put("221", "221"); + column2.put("222", "222"); + table2.put("column2", column2); + // column 3. + Map<String,String> column3 = new HashMap<String, String>(); + column3.put("231", "231"); + column3.put("232", "232"); + column3.put("233", "233"); + table2.put("column3", column3); + + CellContentExpected.put("table1", table1); + CellContentExpected.put("table2", table2); + LOG.info(CellContentExpected); + } + + Set<String> tableKeys; + String cellContentActual; + String cellContentExpected = null; + for (String tableName : tableNamesActual) { + columnNamesActual = bigTable.getColumnsNames(tableName); + tableKeys = bigTable.getKeys(tableName); + for (String columnName : columnNamesActual) { + for (String cellKey : tableKeys) { + + try { + try{ + cellContentExpected = + CellContentExpected + .get(tableName) + .get(columnName) + .get(cellKey); + } catch (NullPointerException ex) { + LOG.trace(ex); + } + + LOG.info(tableName + ' ' + + columnName + ' ' + + cellKey + ' ' + + cellContentExpected); + + cellContentActual = + bigTable.get(tableName, columnName, cellKey); + assertEquals(cellContentExpected, cellContentActual); + } catch (NoSuchElementException ex) { + if(cellContentExpected != null) { + LOG.error(ex, ex); + Assert.fail(); + } else { + LOG.trace(ex); + } + } + } + } + } + } } Added: trunk/msm-fromtoXML/src/test/resources/fiveColumns.xml =================================================================== --- trunk/msm-fromtoXML/src/test/resources/fiveColumns.xml (rev 0) +++ trunk/msm-fromtoXML/src/test/resources/fiveColumns.xml 2010-03-01 19:52:08 UTC (rev 152) @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="UTF-8"?> +<database> + <table tableName="table1"> + <column columnName="column1" /> + <column columnName="column2" /> + </table> + <table tableName="table2"> + <column columnName="column3" /> + <column columnName="column4" /> + <column columnName="column5" /> + </table> +</database> + Added: trunk/msm-fromtoXML/src/test/resources/sixCells.xml =================================================================== --- trunk/msm-fromtoXML/src/test/resources/sixCells.xml (rev 0) +++ trunk/msm-fromtoXML/src/test/resources/sixCells.xml 2010-03-01 19:52:08 UTC (rev 152) @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8"?> +<database> + <table tableName="table1"> + <column columnName="column1"> + <cell key="111"> + <value>111</value> + </cell> + </column> + </table> + <table tableName="table2"> + <column columnName="column2"> + <cell key="221"> + <value>221</value> + </cell> + <cell key="222"> + <value>222</value> + </cell> + </column> + <column columnName="column3"> + <cell key="231"> + <value>231</value> + </cell> + <cell key="232"> + <value>232</value> + </cell> + <cell key="233"> + <value>233</value> + </cell> + </column> + </table> +</database> + Deleted: trunk/msm-fromtoXML/src/test/resources/twoTablesFiveColumns.xml =================================================================== --- trunk/msm-fromtoXML/src/test/resources/twoTablesFiveColumns.xml 2010-03-01 18:25:21 UTC (rev 151) +++ trunk/msm-fromtoXML/src/test/resources/twoTablesFiveColumns.xml 2010-03-01 19:52:08 UTC (rev 152) @@ -1,13 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<database> - <table tableName="table1"> - <column columnName="column1" /> - <column columnName="column2" /> - </table> - <table tableName="table2"> - <column columnName="column3" /> - <column columnName="column4" /> - <column columnName="column5" /> - </table> -</database> -