001: //$Id: SubelementCreatorActionTest.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 SubelementCreatorAction}.<br/>
049: * Contract of Action class: <br/>
050: * <ul>
051: * <li>Subelement action are not allowed to be first in list. There must be a
052: * root action.</li>
053: * <li>Subelement action will create a {@link CollectionCreatorAction}action
054: * containing all field data processed for basic root element from xml
055: * resource..</li>
056: * <li> </li>
057: * </ul>
058: *
059: * @author jg
060: */
061: public class SubelementCreatorActionTest extends TestCase {
062: private ActionStack actionStack;
063:
064: private String testContent;
065:
066: /**
067: * Instanciate test providing method to test
068: *
069: * @param name of method to execute
070: */
071: public SubelementCreatorActionTest(String name) {
072: super (name);
073: }
074:
075: /**
076: * @return suite of tests to execute
077: */
078: public static Test suite() {
079: return new TestSuite(SubelementCreatorActionTest.class);
080: }
081:
082: public void setUp() {
083: this .actionStack = new ActionStack();
084: // prepare object element to use subelement on
085: Map rootAttrbs = new HashMap();
086: rootAttrbs.put(ParserConstants.XML_ATTR_ID, "object");
087: rootAttrbs.put(ParserConstants.XML_ATTR_TYPE,
088: "junitx.ddtunit.resources.SimpleVO");
089: ActionBase rootAction = new SubelementCreatorAction(rootAttrbs);
090: rootAction.inject();
091: this .actionStack.push(rootAction);
092: // prepare subelement to use content on
093: Map subAttrbs = new HashMap();
094: subAttrbs.put(ParserConstants.XML_ATTR_ID, "stringValue");
095: subAttrbs
096: .put(ParserConstants.XML_ATTR_TYPE, "java.lang.String");
097: ActionBase subAction = new SubelementCreatorAction(subAttrbs);
098: subAction.inject();
099: this .actionStack.push(subAction);
100: this .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: }
111:
112: /**
113: * Test processing operation of {@link SubelementCreatorAction}
114: */
115: public void testActionSubelementCreator() {
116: // start with content processing on field element
117: TypedObject obj = this .actionStack.peek().getObject();
118: assertNotNull("Internal object should not be null", obj);
119: assertEquals("Wrong type of internal object",
120: "java.lang.StringBuffer", obj.getType());
121: this .actionStack.process();
122: assertNotNull("Internal object should not be null",
123: this .actionStack.peek().getValue());
124: assertEquals("Wrong class of internal object",
125: "java.util.Vector", this .actionStack.peek().getType());
126: assertEquals("Wrong id of internal object", "attrlist",
127: this .actionStack.peek().getId());
128: // process implicite field container on object element
129: IAction base = this .actionStack.process();
130: assertEquals(
131: "Wrong Action type",
132: "junitx.ddtunit.data.processing.SubelementCreatorAction",
133: base.getClass().getName());
134: assertEquals("Wrong type of created object",
135: "junitx.ddtunit.resources.SimpleVO", base.getType());
136: }
137:
138: }
|