001: ///////////////////////////////
002: // Makumba, Makumba tag library
003: // Copyright (C) 2000-2003 http://www.makumba.org
004: //
005: // This library is free software; you can redistribute it and/or
006: // modify it under the terms of the GNU Lesser General Public
007: // License as published by the Free Software Foundation; either
008: // version 2.1 of the License, or (at your option) any later version.
009: //
010: // This library is distributed in the hope that it will be useful,
011: // but WITHOUT ANY WARRANTY; without even the implied warranty of
012: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: // Lesser General Public License for more details.
014: //
015: // You should have received a copy of the GNU Lesser General Public
016: // License along with this library; if not, write to the Free Software
017: // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: //
019: // -------------
020: // $Id: mdd.java 2119 2007-11-22 01:12:14Z cristian_bogdan $
021: // $Name$
022: /////////////////////////////////////
023:
024: package test;
025:
026: import java.util.Enumeration;
027: import java.util.Vector;
028:
029: import junit.framework.Test;
030: import junit.framework.TestCase;
031: import junit.framework.TestSuite;
032:
033: import org.makumba.DataDefinitionNotFoundError;
034: import org.makumba.DataDefinitionParseError;
035: import org.makumba.providers.DataDefinitionProvider;
036:
037: /**
038: * Testing mdd handling & parsing
039: *
040: * @author Stefan Baebler
041: */
042: public class mdd extends TestCase {
043:
044: private DataDefinitionProvider ddp = new DataDefinitionProvider();
045:
046: public mdd(String name) {
047: super (name);
048: }
049:
050: public static void main(String[] args) {
051: junit.textui.TestRunner.run(suite());
052: }
053:
054: public static Test suite() {
055: return new TestSuite(mdd.class);
056: }
057:
058: public void testMdd() {
059: ddp.getDataDefinition("test.Person");
060: ddp.getDataDefinition("test.Person.address.sth");
061: }
062:
063: /** removed printers, so no need to test them anymore! */
064: // public void testMddPrinter()
065: // {
066: // System.out.println("\n"+new
067: // org.makumba.abstr.printer.RecordPrinter("test.Individual"));
068: // String personMdd=new
069: // org.makumba.abstr.printer.RecordPrinter("test.Person").toString();
070: // //IMPROVE: should try to parse the printer output again as another MDD,
071: // //then compare them (eg by comparing the printer output of the new and
072: // original MDD).
073: // }
074: public void testNonexistingMdd() {
075: try {
076: ddp.getDataDefinition("test.brokenMdds.NonexistingMdd");
077: fail("Should raise DataDefinitionNotFoundError");
078: } catch (DataDefinitionNotFoundError e) {
079: }
080: }
081:
082: /**
083: * This test can't be performed on a Windows platform! Windows does not
084: * support capitalization in file name
085: */
086: // public void testWronglyCapitalizedMdd() {
087: // try {
088: // MakumbaSystem.getDataDefinition("test.person");
089: // fail("Should raise DataDefinitionNotFoundError");
090: // } catch (DataDefinitionNotFoundError e) { }
091: // }
092: public void testAllValidMdds() {
093: String base = "test/validMdds/";
094: Vector mdds = ddp.getDataDefinitionsInLocation(base);
095:
096: // we have to collect all errors if we want to run tests on all
097: // MDDs in directory instead of stoping at first fail()ure.
098: Vector errors = new Vector();
099: for (Enumeration e = mdds.elements(); e.hasMoreElements();) {
100: String mdd = (String) e.nextElement();
101: try {
102: ddp.getDataDefinition("test.validMdds." + mdd);
103: } catch (DataDefinitionParseError ex) {
104: errors.add("\n ." + (errors.size() + 1)
105: + ") Error reported in valid MDD <" + mdd
106: + ">:\n" + ex);
107: //ex.printStackTrace();
108: }
109: }
110: if (errors.size() > 0)
111: fail("\n Tested " + mdds.size()
112: + " valid MDDs, but found " + errors.size()
113: + " problems: " + errors.toString());
114: }
115:
116: public void testIfAllBrokenMddsThrowErrors() {
117: String base = "test/brokenMdds/";
118: Vector mdds = ddp.getDataDefinitionsInLocation(base);
119:
120: // we have to collect all errors if we want to run tests on all
121: // MDDs in directory instead of stoping at first fail()ure.
122: Vector errors = new Vector();
123: for (Enumeration e = mdds.elements(); e.hasMoreElements();) {
124: DataDefinitionParseError expected = new DataDefinitionParseError();
125: DataDefinitionParseError actual = expected;
126: String mdd = (String) e.nextElement();
127: try {
128: ddp.getDataDefinition("test.brokenMdds." + mdd);
129: } catch (DataDefinitionParseError thrown) {
130: actual = thrown;
131: }
132:
133: if (expected == actual)
134: errors.add("\n ." + (errors.size() + 1)
135: + ") Error report missing from broken MDD <"
136: + mdd + "> ");
137: if (!expected.getClass().equals(actual.getClass()))
138: errors.add("\n ." + (errors.size() + 1) + ") MDD "
139: + mdd + " threw <" + actual.getClass()
140: + "> instead of expected <"
141: + expected.getClass() + ">");
142: }
143: if (errors.size() > 0)
144: fail("\n Tested " + mdds.size() + " broken MDDs, but "
145: + errors.size() + " reported wrong/no error: "
146: + errors.toString());
147: }
148:
149: }
|