001: //$Id: ContentCreatorActionTest.java 198 2005-11-06 23:15:52Z jg_hamburg $
002: /********************************************************************************
003: * DDTUnit, a Datadriven Approach to Unit- and Moduletesting
004: * Copyright (c) 2004, Joerg and Kai Gellien
005: * All rights reserved.
006: *
007: * The Software is provided under the terms of the Common Public License 1.0
008: * as provided with the distribution of DDTUnit in the file cpl-v10.html.
009: * Redistribution and use in source and binary forms, with or without
010: * modification, are permitted provided that the following conditions
011: * are met:
012: *
013: * + Redistributions of source code must retain the above copyright
014: * notice, this list of conditions and the following disclaimer.
015: *
016: * + Redistributions in binary form must reproduce the above
017: * copyright notice, this list of conditions and the following
018: * disclaimer in the documentation and/or other materials provided
019: * with the distribution.
020: *
021: * + Neither the name of the authors or DDTUnit, nor the
022: * names of its contributors may be used to endorse or promote
023: * products derived from this software without specific prior
024: * written permission.
025: *
026: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
027: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
028: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
029: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
030: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
031: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
032: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
033: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
034: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
035: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
036: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
037: ********************************************************************************/package junitx.ddtunit.data.processing;
038:
039: import java.util.HashMap;
040: import java.util.Map;
041:
042: import junit.framework.Test;
043: import junit.framework.TestCase;
044: import junit.framework.TestSuite;
045: import junitx.ddtunit.data.TypedObject;
046:
047: /**
048: * Test to check functionallity of {@link ContentCreatorActionTest}.<br/>
049: * Contract of Action class: <br/>
050: * <ul>
051: * <li>Content action must be the last on action stack</li>
052: * <li>There must be a valid root action distinct from content action.</li>
053: * <li> </li>
054: * </ul>
055: *
056: * @author jg
057: */
058: public class ContentCreatorActionTest extends TestCase {
059: private ActionStack actionStack;
060:
061: /**
062: * Instanciate test providing method to test
063: *
064: * @param name of method to execute
065: */
066: public ContentCreatorActionTest(String name) {
067: super (name);
068: }
069:
070: /**
071: * @return suite of tests to execute
072: */
073: public static Test suite() {
074: return new TestSuite(ContentCreatorActionTest.class);
075: }
076:
077: public void setUp() {
078: this .actionStack = new ActionStack();
079: }
080:
081: /**
082: * Test processing operation of {@link CollectionCreatorAction}
083: */
084: public void testSingleContentForSubelement() {
085: // prepare object element
086: Map objAttribs = new HashMap();
087: objAttribs.put("id", "object");
088: objAttribs.put("type", "junitx.ddtunit.resources.ComplexVO");
089: ActionBase baseAction = new SubelementCreatorAction(objAttribs);
090: baseAction.inject();
091: this .actionStack.push(baseAction);
092: // prepare subelement to use content on
093: Map rootAttribs = new HashMap();
094: rootAttribs.put("id", "text");
095: rootAttribs.put("type", "java.lang.String");
096: ActionBase rootAction = new SubelementCreatorAction(rootAttribs);
097: rootAction.inject();
098: this .actionStack.push(rootAction);
099: // prepare content action
100: String testContent = "Hallo World";
101: Map attribs = new HashMap();
102: attribs.put("id", "content");
103: attribs.put("hint", "content");
104: attribs.put("type", "java.lang.StringBuffer");
105: attribs.put("content", new StringBuffer(testContent));
106: ActionBase action = new ContentCreatorAction(attribs);
107: assertNull("Internal object should be null", action.getObject());
108: action.inject();
109: this .actionStack.push(action);
110: TypedObject obj = action.getObject();
111: assertNotNull("Internal object should not be null", obj);
112: assertEquals("Wrong type of internal object",
113: "java.lang.StringBuffer", obj.getType());
114: assertNotNull("Value of internal object should not be null",
115: obj.getValue());
116: IAction cAction = this .actionStack.peek();
117: assertSame("Actions should be same.", action, cAction);
118: // process content action
119: cAction.process();
120: assertEquals("Wrong class of internal object",
121: "java.util.Vector", this .actionStack.peek().getType());
122: assertEquals("Wrong id of internal object", "attrlist",
123: this .actionStack.peek().getId());
124: }
125:
126: public void testMultipleContentActionProcessing() {
127: // prepare object element
128: Map objAttribs = new HashMap();
129: objAttribs.put("id", "object");
130: objAttribs.put("type", "junitx.ddtunit.resources.ComplexVO");
131: ActionBase baseAction = new SubelementCreatorAction(objAttribs);
132: baseAction.inject();
133: this .actionStack.push(baseAction);
134: // prepare subelement
135: Map rootAttribs = new HashMap();
136: rootAttribs.put("id", "text");
137: rootAttribs.put("type", "java.lang.String");
138: ActionBase rootAction = new SubelementCreatorAction(rootAttribs);
139: rootAction.inject();
140: this .actionStack.push(rootAction);
141: // prepare content action
142: Map attribs = new HashMap();
143: attribs.put("id", "content");
144: attribs.put("hint", "content");
145: attribs.put("type", "java.lang.StringBuffer");
146: attribs.put("content", new StringBuffer("First line\n"));
147: IAction action = new ContentCreatorAction(attribs);
148: assertNull("Internal object should be null", action.getObject());
149: action.inject();
150: this .actionStack.push(action);
151: // second content info
152: attribs = new HashMap();
153: attribs.put("id", "content");
154: attribs.put("hint", "content");
155: attribs.put("type", "java.lang.StringBuffer");
156: attribs.put("content", new StringBuffer("Second line\n"));
157: action = new ContentCreatorAction(attribs);
158: assertNull("Internal object should be null", action.getObject());
159: action.inject();
160: this .actionStack.push(action);
161: // process content action
162: action = this .actionStack.peek();
163: action.process();
164: assertEquals("Wrong class of internal object",
165: "java.util.Vector", this .actionStack.peek().getType());
166: assertEquals("Wrong id of internal object", "attrlist",
167: this.actionStack.peek().getId());
168: }
169: }
|