2010-02-23 16:24:00 +01:00
|
|
|
/**
|
2014-02-04 19:00:36 +01:00
|
|
|
* Copyright (C) 2006-2014 Christian Pierre MOMON
|
|
|
|
*
|
|
|
|
* This file is part of Xidyn.
|
|
|
|
*
|
|
|
|
* Xidyn is free software: you can redistribute it and/or modify
|
2014-11-09 10:06:13 +01:00
|
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
2014-02-04 19:00:36 +01:00
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Xidyn is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2014-11-09 10:06:13 +01:00
|
|
|
* GNU Lesser General Public License for more details.
|
2014-02-04 19:00:36 +01:00
|
|
|
*
|
2014-11-09 10:06:13 +01:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
2014-02-04 19:00:36 +01:00
|
|
|
* along with Xidyn. If not, see <http://www.gnu.org/licenses/>
|
2010-02-23 16:24:00 +01:00
|
|
|
*/
|
2013-06-26 18:13:50 +02:00
|
|
|
import org.apache.log4j.Level;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
2013-07-13 18:46:25 +02:00
|
|
|
import fr.devinsy.xidyn.data.SimpleTagData;
|
|
|
|
import fr.devinsy.xidyn.data.TagDataManager;
|
|
|
|
import fr.devinsy.xidyn.presenters.StringPresenter;
|
2010-02-23 16:24:00 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2013-06-26 18:13:50 +02:00
|
|
|
class XidynTest
|
2010-02-23 16:24:00 +01:00
|
|
|
{
|
2013-06-21 02:55:52 +02:00
|
|
|
public enum MONTHS
|
|
|
|
{
|
2013-06-23 01:28:40 +02:00
|
|
|
JANUARY, FEBRUARY, MARCH, APRIL, MAY, JUNE, JULY, AUGUST, SEPTEMBER, OCTOBER, NOVEMBRE, DECEMBRE
|
2013-06-21 02:55:52 +02:00
|
|
|
}
|
|
|
|
|
2013-06-26 18:13:50 +02:00
|
|
|
static private Logger logger = LoggerFactory.getLogger(XidynTest.class);
|
2010-02-23 16:24:00 +01:00
|
|
|
static
|
2013-06-21 02:55:52 +02:00
|
|
|
{
|
2010-02-23 16:24:00 +01:00
|
|
|
// Initialize logger.
|
2013-06-21 02:55:52 +02:00
|
|
|
org.apache.log4j.BasicConfigurator.configure();
|
2013-06-26 18:13:50 +02:00
|
|
|
org.apache.log4j.Logger.getRootLogger().setLevel(Level.INFO);
|
2010-02-23 16:24:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2013-06-21 02:55:52 +02:00
|
|
|
public static String check(final String title, final StringBuffer source, final String model)
|
2010-02-23 16:24:00 +01:00
|
|
|
{
|
|
|
|
String result;
|
|
|
|
|
2013-06-21 02:55:52 +02:00
|
|
|
if (source.indexOf(model) == -1)
|
2010-02-23 16:24:00 +01:00
|
|
|
{
|
2013-06-21 02:55:52 +02:00
|
|
|
result = String.format("%-40s -> KO <-", title) + "\nGet:\n" + source + "\nWaiting:\n" + model;
|
2010-02-23 16:24:00 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-21 02:55:52 +02:00
|
|
|
result = String.format("%-40s [ OK ] ", title);
|
2010-02-23 16:24:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
return (result);
|
2013-06-21 02:55:52 +02:00
|
|
|
};
|
2010-02-23 16:24:00 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2013-06-21 02:55:52 +02:00
|
|
|
public static void main(final String[] args)
|
2010-02-23 16:24:00 +01:00
|
|
|
{
|
|
|
|
System.out.println("Automatic test action for Xid!");
|
|
|
|
|
2013-06-23 02:17:42 +02:00
|
|
|
TagDataManager datas;
|
2013-06-23 18:03:53 +02:00
|
|
|
SimpleTagData tag;
|
2010-02-23 16:24:00 +01:00
|
|
|
|
|
|
|
String htmlSource;
|
|
|
|
StringBuffer html;
|
|
|
|
|
|
|
|
// Populate attributes of Test 03.
|
2013-06-21 02:55:52 +02:00
|
|
|
System.out.println("----------------------------");
|
2013-06-23 02:17:42 +02:00
|
|
|
datas = new TagDataManager();
|
2013-06-21 02:55:52 +02:00
|
|
|
datas.setContent("name", "Superman");
|
|
|
|
try
|
|
|
|
{
|
2013-06-23 01:51:00 +02:00
|
|
|
html = StringPresenter.dynamize("<div id='name'>a name</div >", datas);
|
2013-06-21 02:55:52 +02:00
|
|
|
}
|
|
|
|
catch (Exception exception)
|
|
|
|
{
|
|
|
|
System.out.println(exception.getMessage());
|
|
|
|
html = null;
|
|
|
|
}
|
2010-02-23 16:24:00 +01:00
|
|
|
|
2013-06-21 02:55:52 +02:00
|
|
|
System.out.println(check("only content change", html, "<div id=\"name\">Superman</div>"));
|
2010-02-23 16:24:00 +01:00
|
|
|
|
|
|
|
// Populate attributes of Test 03.
|
2013-06-21 02:55:52 +02:00
|
|
|
System.out.println("----------------------------");
|
2013-06-23 02:17:42 +02:00
|
|
|
datas = new TagDataManager();
|
2013-06-21 02:55:52 +02:00
|
|
|
datas.setContent("lastname", "Spiderman");
|
|
|
|
datas.appendAttribute("lastname", "style", "background: blue;");
|
|
|
|
datas.appendAttribute("lastname", "style", "foreground: red;");
|
|
|
|
datas.setAttribute("lastname", "class", "nameClass");
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2013-06-23 01:51:00 +02:00
|
|
|
html = StringPresenter.dynamize("<div id='lastname'>a last name</div >", datas);
|
2013-06-21 02:55:52 +02:00
|
|
|
}
|
|
|
|
catch (Exception exception)
|
|
|
|
{
|
|
|
|
System.out.println(exception.getMessage());
|
|
|
|
html = null;
|
|
|
|
}
|
2013-06-23 01:28:40 +02:00
|
|
|
System.out.println(check("content and attributes", html, "<div id=\"lastname\" style=\"background: blue;foreground: red;\" class=\"nameClass\">Spiderman</div>"));
|
2010-02-23 16:24:00 +01:00
|
|
|
|
|
|
|
// Populate attributes of Test 03.
|
2013-06-21 02:55:52 +02:00
|
|
|
System.out.println("----------------------------");
|
2013-06-23 02:17:42 +02:00
|
|
|
datas = new TagDataManager();
|
2013-06-21 02:55:52 +02:00
|
|
|
datas.setContent("words", 0, "alpha");
|
|
|
|
datas.setContent("words", 1, "bravo");
|
|
|
|
datas.setContent("words", 2, "charlie");
|
|
|
|
datas.setContent("words", 3, "delta");
|
|
|
|
datas.setContent("words", 4, "echo");
|
|
|
|
datas.setContent("words", 5, "fox");
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2013-06-23 01:51:00 +02:00
|
|
|
html = StringPresenter.dynamize("<ul>\n <li id='words'>a word</li>\n</ul>", datas);
|
2013-06-21 02:55:52 +02:00
|
|
|
}
|
|
|
|
catch (Exception exception)
|
|
|
|
{
|
|
|
|
System.out.println(exception.getMessage());
|
|
|
|
html = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
System.out.println(check("list assertion 1", html, "<li id=\"words_0\">alpha</li>"));
|
|
|
|
System.out.println(check("list assertion 2", html, "<li id=\"words_1\">bravo</li>"));
|
|
|
|
System.out.println(check("list assertion 3", html, "<li id=\"words_2\">charlie</li>"));
|
|
|
|
System.out.println(check("list assertion 4", html, "<li id=\"words_3\">delta</li>"));
|
|
|
|
System.out.println(check("list assertion 5", html, "<li id=\"words_4\">echo</li>"));
|
|
|
|
System.out.println(check("list assertion 6", html, "<li id=\"words_5\">fox</li>"));
|
2010-02-23 16:24:00 +01:00
|
|
|
|
|
|
|
// Populate attributes of Test 03.
|
2013-06-21 02:55:52 +02:00
|
|
|
System.out.println("----------------------------");
|
2013-06-23 02:17:42 +02:00
|
|
|
datas = new TagDataManager();
|
2013-06-21 02:55:52 +02:00
|
|
|
datas.setContent("identity", 0, "nom", "Jemba");
|
|
|
|
datas.setContent("identity", 0, "prenom", "Epo");
|
|
|
|
datas.setContent("identity", 1, "nom", "Momon");
|
|
|
|
datas.setContent("identity", 1, "prenom", "Christian");
|
|
|
|
datas.setContent("identity", 2, "nom", "Tronche");
|
|
|
|
datas.setContent("identity", 2, "prenom", "Christophe");
|
|
|
|
|
|
|
|
StringBuffer source = new StringBuffer();
|
|
|
|
source.append("<table>\n");
|
|
|
|
source.append(" <tr id='identity'><td>noid</td><td id='nom'>un nom</td><td id='prenom'>un prenom</td></tr>\n");
|
|
|
|
source.append("</table>");
|
|
|
|
htmlSource = source.toString();
|
|
|
|
try
|
|
|
|
{
|
2013-06-23 01:51:00 +02:00
|
|
|
html = StringPresenter.dynamize(htmlSource, datas);
|
2013-06-21 02:55:52 +02:00
|
|
|
}
|
|
|
|
catch (Exception exception)
|
|
|
|
{
|
|
|
|
System.out.println(exception.getMessage());
|
|
|
|
html = null;
|
|
|
|
}
|
|
|
|
|
2013-06-23 01:28:40 +02:00
|
|
|
System.out.println(check("table 1 assertion 1", html, "<tr id=\"identity_0\"><td>noid</td><td id=\"nom_0\">Jemba</td><td id=\"prenom_0\">Epo</td></tr>"));
|
|
|
|
System.out.println(check("table 1 assertion 2", html, "<tr id=\"identity_1\"><td>noid</td><td id=\"nom_1\">Momon</td><td id=\"prenom_1\">Christian</td></tr>"));
|
|
|
|
System.out.println(check("table 1 assertion 3", html, "<tr id=\"identity_2\"><td>noid</td><td id=\"nom_2\">Tronche</td><td id=\"prenom_2\">Christophe</td></tr>"));
|
2010-02-23 16:24:00 +01:00
|
|
|
|
|
|
|
/*
|
2013-06-21 02:55:52 +02:00
|
|
|
* // Populate attributes of Test 03. System.out.println
|
|
|
|
* ("----------------------------"); datas = new Data ();
|
|
|
|
* datas.setContent ("identity", 0, "nom", "Jemba"); datas.setContent
|
|
|
|
* ("identity", 0, "prenom", "Epo"); datas.setContent ("identity", 1,
|
|
|
|
* "nom", "Momon"); datas.setContent ("identity", 1, "prenom",
|
|
|
|
* "Christian"); datas.setContent ("identity", 2, "nom", "Tronche");
|
|
|
|
* datas.setContent ("identity", 2, "prenom", "Christophe");
|
|
|
|
* datas.setIterationStrategy ("identity",
|
|
|
|
* IdsDataByIndex.IterationStrategy.ONLY_FIRST_ROW);
|
|
|
|
* //datas.setIterationStrategy ("identity",
|
|
|
|
* IdsDataByIndex.IterationStrategy.ONLY_ROWS_WITH_ID);
|
|
|
|
* //datas.setIterationStrategy ("identity",
|
|
|
|
* IdsDataByIndex.IterationStrategy.ONLY_ROWS_WITHOUT_ID);
|
|
|
|
* //datas.setIterationStrategy ("identity",
|
|
|
|
* IdsDataByIndex.IterationStrategy.ALL_ROWS);
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* errorMessage = new StringBuffer (); source = new StringBuffer ();
|
|
|
|
* source.append ("<table>\n"); source.append (
|
|
|
|
* " <tr id='identity'><td>noid</td><td id='nom'>un nom</td><td id='prenom'>un prenom</td></tr>\n"
|
|
|
|
* ); source.append (
|
|
|
|
* " <tr id='identity2'><td>noid</td><td id='nom2'>un nom</td><td id='prenom2'>un prenom</td></tr>\n"
|
|
|
|
* ); source.append (
|
|
|
|
* " <tr><td>noid</td><td id='nom3'>un nom</td><td id='prenom3'>un prenom</td></tr>\n"
|
|
|
|
* ); source.append ("</table>"); htmlSource = source.toString ();
|
|
|
|
*
|
|
|
|
* System.out.println ("datas = new Data ();"); System.out.println
|
|
|
|
* ("datas.setContent (\"identity\", 0, \"nom\", \"Jemba\");");
|
|
|
|
* System.out.println
|
|
|
|
* ("datas.setContent (\"identity\", 0, \"prenom\", \"Epo\");");
|
|
|
|
* System.out.println
|
|
|
|
* ("datas.setContent (\"identity\", 1, \"nom\", \"Momon\");");
|
|
|
|
* System.out.println
|
|
|
|
* ("datas.setContent (\"identity\", 1, \"prenom\", \"Christian\");");
|
|
|
|
* System.out.println
|
|
|
|
* ("datas.setContent (\"identity\", 2, \"nom\", \"Tronche\");");
|
|
|
|
* System.out.println
|
|
|
|
* ("datas.setContent (\"identity\", 2, \"prenom\", \"Christophe\");");
|
|
|
|
*
|
|
|
|
* System.out.println ("+"); System.out.println (htmlSource);
|
|
|
|
* System.out.println ("=>");
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* datas.setIterationStrategy ("identity",
|
|
|
|
* IdsDataByIndex.IterationStrategy.ONLY_FIRST_ROW); System.out.println
|
2013-06-23 01:51:00 +02:00
|
|
|
* ("ONLY_FIRST_ROW:"); html = Presenter.dynamize (htmlSource, datas, "",
|
2013-06-21 02:55:52 +02:00
|
|
|
* errorMessage); System.out.println (html);
|
|
|
|
*
|
|
|
|
* datas.setIterationStrategy ("identity",
|
|
|
|
* IdsDataByIndex.IterationStrategy.ONLY_ROWS_WITH_ID);
|
2013-06-23 01:51:00 +02:00
|
|
|
* System.out.println ("ONLY_ROWS_WITH_ID:"); html = Presenter.dynamize
|
2013-06-21 02:55:52 +02:00
|
|
|
* (htmlSource, datas, "", errorMessage); System.out.println (html);
|
|
|
|
*
|
|
|
|
* datas.setIterationStrategy ("identity",
|
|
|
|
* IdsDataByIndex.IterationStrategy.ONLY_ROWS_WITHOUT_ID);
|
2013-06-23 01:51:00 +02:00
|
|
|
* System.out.println ("ONLY_ROWS_WITHOUT_ID:"); html = Presenter.dynamize
|
2013-06-21 02:55:52 +02:00
|
|
|
* (htmlSource, datas, "", errorMessage); System.out.println (html);
|
|
|
|
*
|
|
|
|
* datas.setIterationStrategy ("identity",
|
|
|
|
* IdsDataByIndex.IterationStrategy.ALL_ROWS); System.out.println
|
2013-06-23 01:51:00 +02:00
|
|
|
* ("ALL_ROWS:"); html = Presenter.dynamize (htmlSource, datas, "",
|
2013-06-21 02:55:52 +02:00
|
|
|
* errorMessage); System.out.println (html);
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* // Populate attributes of Test 03. System.out.println
|
|
|
|
* ("----------------------------"); datas = new Data ();
|
|
|
|
* datas.setAttribute ("<div>", "class", "aDivClass");
|
|
|
|
* datas.setAttribute ("<div>", "style", "background-color: #000000;");
|
|
|
|
* datas.setAttribute ("number", "style", "background-color: #0000FF;");
|
|
|
|
*
|
|
|
|
* errorMessage = new StringBuffer (); source = new StringBuffer ();
|
|
|
|
* source.append ("<div>\n"); source.append (" <h1>one</h1>\n");
|
|
|
|
* source.append ("</div>\n"); source.append ("<div id=\"number\">\n");
|
|
|
|
* source.append (" <h1>three</h1>\n"); source.append ("</div>");
|
2013-06-23 01:51:00 +02:00
|
|
|
* htmlSource = source.toString (); html = Presenter.dynamize (htmlSource,
|
2013-06-21 02:55:52 +02:00
|
|
|
* datas, "", errorMessage);
|
|
|
|
*
|
|
|
|
* System.out.println (htmlSource); System.out.println ("+");
|
|
|
|
* System.out.println ("datas = new Data ();"); System.out.println
|
|
|
|
* ("datas.setAttribute (\"<div>\", \"class\", \"aDivClass\");");
|
|
|
|
* System.out.println (
|
|
|
|
* "datas.setAttribute (\"<div>\", \"style\", \"background-color: #000000;\");"
|
|
|
|
* ); System.out.println (
|
|
|
|
* "datas.setAttribute (\"number\", \"style\", \"background-color: #0000FF;\");"
|
|
|
|
* );
|
|
|
|
*
|
|
|
|
* System.out.println ("=>"); System.out.println (html);
|
2010-02-23 16:24:00 +01:00
|
|
|
*/
|
|
|
|
}
|
|
|
|
}
|