r138 - in trunk/msm-fromtoXML/src: main/java/org/nuiton/mapstoragemanager/plugins/exporter test/java/org/nuiton/mapstoragemanager/plugins/exporter
Author: dlanglais Date: 2010-02-27 17:24:45 +0100 (Sat, 27 Feb 2010) New Revision: 138 Modified: trunk/msm-fromtoXML/src/main/java/org/nuiton/mapstoragemanager/plugins/exporter/ToXML.java trunk/msm-fromtoXML/src/test/java/org/nuiton/mapstoragemanager/plugins/exporter/ExporterTest.java Log: commencement de classe de test pour ToXML (ne marche pas pour le moment). 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-02-27 04:20:25 UTC (rev 137) +++ trunk/msm-fromtoXML/src/main/java/org/nuiton/mapstoragemanager/plugins/exporter/ToXML.java 2010-02-27 16:24:45 UTC (rev 138) @@ -41,28 +41,14 @@ racine = new Element("database"); document = new Document(racine); + // Construction of the document. forEachTable(bigTable, racine); -// //On crée un nouvel Element etudiant et on l'ajoute -// //en tant qu'Element de racine -// Element etudiant = new Element("etudiant"); -// racine.addContent(etudiant); -// for() -// //On crée un nouvel Attribut classe et on l'ajoute à etudiant -// //grâce à la méthode setAttribute -// Attribute classe = new Attribute("classe", "P2"); -// etudiant.setAttribute(classe); -// -// //On crée un nouvel Element nom, on lui assigne du texte -// //et on l'ajoute en tant qu'Element de etudiant -// Element nom = new Element("nom"); -// nom.setText("CynO"); -// etudiant.addContent(nom); - // the methods to print and to save the database in XML file. - toSreen(); - if(file != null) + //toSreen(); + if (file != null) { save(file); + } } /** @@ -122,9 +108,6 @@ * @param column the column Element. */ private void forEachCell(NewBigTable bigTable, Element column) { - System.out.println(column.getParentElement().toString()); - - // the table name. String tableName = column.getParentElement().getAttributeValue("tableName"); @@ -140,7 +123,7 @@ content = bigTable.get(tableName, columnName, key); } catch (NoSuchElementException e) { -// LOG.error(e, e); +// LOG.warn(e, e); } if ( ! "".equals(content)) { Modified: trunk/msm-fromtoXML/src/test/java/org/nuiton/mapstoragemanager/plugins/exporter/ExporterTest.java =================================================================== --- trunk/msm-fromtoXML/src/test/java/org/nuiton/mapstoragemanager/plugins/exporter/ExporterTest.java 2010-02-27 04:20:25 UTC (rev 137) +++ trunk/msm-fromtoXML/src/test/java/org/nuiton/mapstoragemanager/plugins/exporter/ExporterTest.java 2010-02-27 16:24:45 UTC (rev 138) @@ -5,7 +5,18 @@ package org.nuiton.mapstoragemanager.plugins.exporter; +import java.io.IOException; +import java.lang.reflect.Field; +import java.util.logging.Level; +import java.util.logging.Logger; import junit.framework.TestCase; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.jdom.Attribute; +import org.jdom.Document; +import org.jdom.Element; +import org.jdom.output.Format; +import org.jdom.output.XMLOutputter; import org.nuiton.mapstoragemanager.plugins.Exporter; import org.nuiton.mapstoragemanager.plugins.NewBigTable; import org.nuiton.mapstoragemanager.plugins.bighashmapv2.BigHashMap; @@ -16,8 +27,197 @@ */ public class ExporterTest extends TestCase { - public void testToXML(){ + /** + * Logger. + */ + private static final Log LOG = LogFactory.getLog(ExporterTest.class); +// private static final Log LOGXML = LogFactory.getLog(ToXML.class); + public void testToXML() { + + Document actual = null; + Document expected = new Document(); + + /******************************** + * Creation of the database. * + ********************************/ + NewBigTable nbt = new BigHashMap(); + Element database = new Element("database"); + expected.addContent(database); + + /******************************** + * Creation of the tables. * + ********************************/ + nbt.createTable("table1"); + Element table1 = new Element("table"); + Attribute table1name = new Attribute("tableName", "table1"); + table1.setAttribute(table1name); + database.addContent(table1); + nbt.createTable("table2"); + Element table2 = new Element("table"); + Attribute table2name = new Attribute("tableName", "table2"); + table2.setAttribute(table2name); + database.addContent(table2); + + /******************************** + * Creation of the columns. * + ********************************/ + nbt.createColumn("table1", "column1"); + Element column1 = new Element("column"); + Attribute column1name = new Attribute("columnName", "column1"); + column1.setAttribute(column1name); + table1.addContent(column1); + nbt.createColumn("table1", "column2"); + Element column2 = new Element("column"); + Attribute column2name = new Attribute("columnName", "column2"); + column2.setAttribute(column2name); + table1.addContent(column2); + + nbt.createColumn("table2", "column3"); + Element column3 = new Element("column"); + Attribute column3name = new Attribute("columnName", "column3"); + column3.setAttribute(column3name); + table2.addContent(column3); + + nbt.createColumn("table2", "column4"); + Element column4 = new Element("column"); + Attribute column4name = new Attribute("columnName", "column4"); + column4.setAttribute(column4name); + table2.addContent(column4); + + nbt.createColumn("table2", "column5"); + Element column5 = new Element("column"); + Attribute column5name = new Attribute("columnName", "column5"); + column5.setAttribute(column5name); + table2.addContent(column5); + + + /******************************** + * Put elements in the columns. * + ********************************/ + nbt.put("table1", "column1", "1", "content1"); + Element cell1 = new Element("cell"); + Attribute cell1key = new Attribute("key", "1"); + cell1.setAttribute(cell1key); + column1.addContent(cell1); + Element value1 = new Element("value"); + value1.setText("content1"); + cell1.addContent(value1); + + nbt.put("table1", "column1", "2", "content2"); + Element cell2 = new Element("cell"); + Attribute cell2key = new Attribute("key", "2"); + cell2.setAttribute(cell2key); + column1.addContent(cell2); + Element value2 = new Element("value"); + value2.setText("content2"); + cell2.addContent(value2); + +// nbt.put("table1", "column2", "3", "content3"); +// Element cell3 = new Element("cell"); +// Attribute cell3key = new Attribute("key", "3"); +// cell3.setAttribute(cell3key); +// column2.addContent(cell3); +// Element value3 = new Element("value"); +// value3.setText("content3"); +// cell3.addContent(value3); + +// nbt.put("table1", "column2", "4", "content4"); +// Element cell4 = new Element("cell"); +// Attribute cell4key = new Attribute("key", "4"); +// cell4.setAttribute(cell4key); +// column2.addContent(cell4); +// Element value4 = new Element("value"); +// value4.setText("content4"); +// cell4.addContent(value4); + +// nbt.put("table2", "column3", "5", "content5"); +// Element cell5 = new Element("cell"); +// Attribute cell5key = new Attribute("key", "5"); +// cell5.setAttribute(cell5key); +// column3.addContent(cell5); +// Element value5 = new Element("value"); +// value5.setText("content5"); +// cell5.addContent(value5); + +// nbt.put("table2", "column3", "6", "content6"); +// Element cell6 = new Element("cell"); +// Attribute cell6key = new Attribute("key", "6"); +// cell6.setAttribute(cell6key); +// column3.addContent(cell6); +// Element value6 = new Element("value"); +// value6.setText("content6"); +// cell6.addContent(value6); + +// nbt.put("table2", "column4", "7", "content7"); +// Element cell7 = new Element("cell"); +// Attribute cell7key = new Attribute("key", "7"); +// cell7.setAttribute(cell7key); +// column4.addContent(cell7); +// Element value7 = new Element("value"); +// value7.setText("content7"); +// cell7.addContent(value7); + +// nbt.put("table2", "column4", "8", "content8"); +// Element cell8 = new Element("cell"); +// Attribute cell8key = new Attribute("key", "8"); +// cell8.setAttribute(cell8key); +// column4.addContent(cell8); +// Element value8 = new Element("value"); +// value8.setText("content8"); +// cell8.addContent(value8); + +// nbt.put("table2", "column5", "9", "content9"); +// Element cell9 = new Element("cell"); +// Attribute cell9key = new Attribute("key", "9"); +// cell9.setAttribute(cell9key); +// column5.addContent(cell9); +// Element value9 = new Element("value"); +// value9.setText("content9"); +// cell9.addContent(value9); + +// nbt.put("table2", "column5", "10", "content10"); +// Element cell10 = new Element("cell"); +// Attribute cell10key = new Attribute("key", "10"); +// cell10.setAttribute(cell10key); +// column5.addContent(cell10); +// Element value10 = new Element("value"); +// value10.setText("content10"); +// cell10.addContent(value10); + + Exporter exporter = new ToXML(); + exporter.exportTo(nbt, null); + + +// expected.toString(); + + Field fdocument; + try { + fdocument = exporter.getClass().getDeclaredField("document"); + fdocument.setAccessible(true); + actual = (Document) fdocument.get(exporter); + } catch (IllegalArgumentException ex) { + LOG.error(ex, ex); + } catch (IllegalAccessException ex) { + LOG.error(ex, ex); + } catch (NoSuchFieldException ex) { + LOG.error(ex, ex); + } catch (SecurityException ex) { + LOG.error(ex, ex); + } + + try { + XMLOutputter output = new XMLOutputter(Format.getPrettyFormat()); + output.output(expected, System.out); + output.output(actual, System.out); + } catch (IOException ex) { + LOG.error(ex, ex); + } + +// System.out.println(expected); +// System.out.println(actual); +// assertEquals(expected.toString(),actual.toString()); +// assertEquals(expected, actual); } public static void main(String[] args) { @@ -46,5 +246,8 @@ Exporter exporter = new ToXML(); exporter.exportTo(nbt, null); + + Document a = new Document(); + Document b = new Document(); } }
participants (1)
-
dlanglais@users.nuiton.org