001: /*
002: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
003: * Distributed under the terms of either:
004: * - the common development and distribution license (CDDL), v1.0; or
005: * - the GNU Lesser General Public License, v2.1 or later
006: * $Id: TestXml2ElementModel.java 3634 2007-01-08 21:42:24Z gbevin $
007: */
008: package com.uwyn.rife.gui.model;
009:
010: import com.uwyn.rife.resources.ResourceFinderClasspath;
011: import java.util.Iterator;
012: import junit.framework.TestCase;
013:
014: public class TestXml2ElementModel extends TestCase {
015: public TestXml2ElementModel(String name) {
016: super (name);
017: }
018:
019: public void testInstantiation() {
020: Xml2ElementModel xml2elementmodel = new Xml2ElementModel();
021:
022: assertNotNull(xml2elementmodel);
023: }
024:
025: public void testParser() {
026: ResourceFinderClasspath resourcefinder = ResourceFinderClasspath
027: .getInstance();
028: Xml2ElementModel xml2elementmodel = new Xml2ElementModel();
029:
030: xml2elementmodel.processXml("xml/test_xml2elementmodel.xml",
031: resourcefinder);
032:
033: ElementModel elementmodel = xml2elementmodel.getElementModel();
034:
035: assertEquals(elementmodel.getId().getName(), "JustSomeElement");
036: assertEquals(elementmodel.getImplementation().getName(),
037: "com.uwyn.rife.element.elementModel");
038: assertEquals(elementmodel.getDescription(),
039: "This is the description of the element.");
040:
041: ElementInputModel input = null;
042: Iterator<ElementInputModel> input_it = null;
043: assertEquals(elementmodel.countInputs(), 3);
044: input_it = elementmodel.getInputs().iterator();
045: input = input_it.next();
046: assertEquals(input.getName(), "Input1");
047: assertEquals(input.getDescription(), "This is the first input.");
048: input = input_it.next();
049: assertEquals(input.getName(), "Input2");
050: assertEquals(input.getDescription(),
051: "This is the second input.");
052: input = input_it.next();
053: assertEquals(input.getName(), "Input3");
054: assertEquals(input.getDescription(), "This is the third input.");
055: assertTrue(false == input_it.hasNext());
056:
057: ElementOutputModel output = null;
058: Iterator<ElementOutputModel> output_it = null;
059: assertEquals(elementmodel.countOutputs(), 2);
060: output_it = elementmodel.getOutputs().iterator();
061: output = output_it.next();
062: assertEquals(output.getName(), "Output1");
063: assertEquals(output.getDescription(),
064: "This is the first output.");
065: output = output_it.next();
066: assertEquals(output.getName(), "Output2");
067: assertEquals(output.getDescription(),
068: "This is the second output.");
069: assertTrue(false == output_it.hasNext());
070:
071: ElementExitModel exit = null;
072: Iterator<ElementExitModel> exit_it = null;
073: assertEquals(elementmodel.countExits(), 4);
074: exit_it = elementmodel.getExits().iterator();
075: exit = exit_it.next();
076: assertEquals(exit.getName(), "Exit1");
077: assertEquals(exit.getDescription(), "This is the first exit.");
078: exit = exit_it.next();
079: assertEquals(exit.getName(), "Exit2");
080: assertEquals(exit.getDescription(), "This is the second exit.");
081: exit = exit_it.next();
082: assertEquals(exit.getName(), "Exit3");
083: assertEquals(exit.getDescription(), "This is the third exit.");
084: exit = exit_it.next();
085: assertEquals(exit.getName(), "Exit4");
086: assertEquals(exit.getDescription(), "This is the fourth exit.");
087: assertTrue(false == exit_it.hasNext());
088:
089: SubmissionModel submission = null;
090: Iterator<SubmissionModel> submission_it = null;
091: SubmissionParameterModel parameter = null;
092: Iterator<SubmissionParameterModel> parameter_it = null;
093: assertEquals(elementmodel.countSubmissions(), 2);
094: submission_it = elementmodel.getSubmissions().iterator();
095: submission = submission_it.next();
096: assertEquals(submission.getId().getName(), "Submission1");
097: assertEquals(submission.getDescription(),
098: "This is the first submission.");
099: assertEquals(submission.countParameters(), 3);
100: parameter_it = submission.getParameters().iterator();
101: parameter = parameter_it.next();
102: assertEquals(parameter.getName(), "Param1");
103: assertEquals(parameter.getDescription(),
104: "This is the first parameter of the first submission.");
105: parameter = parameter_it.next();
106: assertEquals(parameter.getName(), "Param2");
107: assertEquals(parameter.getDescription(),
108: "This is the second parameter of the first submission.");
109: parameter = parameter_it.next();
110: assertEquals(parameter.getName(), "Param3");
111: assertEquals(parameter.getDescription(),
112: "This is the third parameter of the first submission.");
113: assertTrue(false == parameter_it.hasNext());
114: submission = submission_it.next();
115: assertEquals(submission.getId().getName(), "Submission2");
116: assertEquals(submission.getDescription(),
117: "This is the second submission.");
118: assertEquals(submission.countParameters(), 2);
119: parameter_it = submission.getParameters().iterator();
120: parameter = parameter_it.next();
121: assertEquals(parameter.getName(), "Param1");
122: assertEquals(parameter.getDescription(),
123: "This is the first parameter of the second submission.");
124: parameter = parameter_it.next();
125: assertEquals(parameter.getName(), "Param2");
126: assertEquals(parameter.getDescription(),
127: "This is the second parameter of the second submission.");
128: assertTrue(false == parameter_it.hasNext());
129: assertTrue(false == submission_it.hasNext());
130: }
131: }
|