001: /********************************************************************************
002: * DDTUnit, a Datadriven Approach to Unit- and Moduletesting
003: * Copyright (c) 2004, Joerg and Kai Gellien
004: * All rights reserved.
005: *
006: * The Software is provided under the terms of the Common Public License 1.0
007: * as provided with the distribution of DDTUnit in the file cpl-v10.html.
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: *
012: * + Redistributions of source code must retain the above copyright
013: * notice, this list of conditions and the following disclaimer.
014: *
015: * + Redistributions in binary form must reproduce the above
016: * copyright notice, this list of conditions and the following
017: * disclaimer in the documentation and/or other materials provided
018: * with the distribution.
019: *
020: * + Neither the name of the authors or DDTUnit, nor the
021: * names of its contributors may be used to endorse or promote
022: * products derived from this software without specific prior
023: * written permission.
024: *
025: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
026: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
027: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
028: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
029: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
030: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
031: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
032: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
033: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
034: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
035: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
036: ********************************************************************************/package junitx.ddtunit.resources;
037:
038: /**
039: * @author jg
040: *
041: * To change the template for this generated type comment go to
042: * Window>Preferences>Java>Code Generation>Code and Comments
043: */
044: public class TestData {
045: /**
046: * objectId identifying xml object to parse
047: */
048: public String objectId = "myObj";
049:
050: private static final String XML_HEAD = "<?xml version=\"1.0\"?>";
051:
052: private static final String RESOURCE_START = "<ddtunit><class id=\"testclass\">"
053: + "<method id=\"testmethod\"><test id=\"testcase\"><objs>";
054:
055: private static final String RESOURCE_END = "</objs></test></method></class></ddtunit>";
056:
057: /**
058: * Instanciate TestData - no special processing
059: */
060: public TestData() {
061: // no special processing
062: }
063:
064: /**
065: * DOCUMENT ME!
066: *
067: * @param testId DOCUMENT ME!
068: * @param testType DOCUMENT ME!
069: * @param testValue DOCUMENT ME!
070: *
071: * @return DOCUMENT ME!
072: */
073: public String getObj(String testId, String testType,
074: String testValue) {
075: String objText = "<obj id=\"" + testId + "\" type=\""
076: + testType + "\">" + testValue + "</obj>";
077:
078: return XML_HEAD + RESOURCE_START + objText + RESOURCE_END;
079: }
080:
081: /**
082: * DOCUMENT ME!
083: *
084: * @param testId DOCUMENT ME!
085: * @param testType DOCUMENT ME!
086: * @param testValue DOCUMENT ME!
087: *
088: * @return DOCUMENT ME!
089: */
090: public String getTwoObj(String testId, String testType,
091: String testValue) {
092: String objText = "<obj id=\"" + testId + 1 + "\" type=\""
093: + testType + "\">" + testValue + 1 + "</obj>";
094: String obj2Text = "<obj id=\"" + testId + 2 + "\" type=\""
095: + testType + "\">" + testValue + 2 + "</obj>";
096:
097: return XML_HEAD + RESOURCE_START + objText + obj2Text
098: + RESOURCE_END;
099: }
100:
101: /**
102: * DOCUMENT ME!
103: *
104: * @param testId DOCUMENT ME!
105: * @param testType DOCUMENT ME!
106: * @param testValue DOCUMENT ME!
107: *
108: * @return DOCUMENT ME!
109: */
110: public String getNObj(String[] testId, String[] testType,
111: String[] testValue) {
112: StringBuffer sb = new StringBuffer();
113:
114: if ((testId.length == testType.length)
115: && (testType.length == testValue.length)) {
116: sb.append(XML_HEAD).append(RESOURCE_START);
117:
118: for (int i = 0; i < testId.length; i++) {
119: String objText = "<obj id=\"" + testId[i]
120: + "\" type=\"" + testType[i] + "\">"
121: + testValue[i] + "</obj>";
122:
123: sb.append(objText);
124: }
125:
126: sb.append(RESOURCE_END);
127: }
128:
129: return sb.toString();
130: }
131: }
|