001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/sam/tags/sakai_2-4-1/samigo-app/src/java/test/org/sakaiproject/tool/assessment/business/entity/helper/QTITester.java $
003: * $Id: QTITester.java 15448 2006-09-29 18:14:43Z ktsao@stanford.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2005 The Regents of the University of Michigan, Trustees of Indiana University,
007: * Board of Trustees of the Leland Stanford, Jr., University, and The MIT Corporation
008: *
009: * Licensed under the Educational Community License Version 1.0 (the "License");
010: * By obtaining, using and/or copying this Original Work, you agree that you have read,
011: * understand, and will comply with the terms and conditions of the Educational Community License.
012: * You may obtain a copy of the License at:
013: *
014: * http://cvs.sakaiproject.org/licenses/license_1_0.html
015: *
016: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
017: * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
018: * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
019: * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
020: * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
021: *
022: **********************************************************************************/package test.org.sakaiproject.tool.assessment.business.entity.helper;
023:
024: import java.io.InputStream;
025: import java.util.ArrayList; //import javax.faces.context.FacesContext;
026:
027: import org.apache.commons.logging.Log;
028: import org.apache.commons.logging.LogFactory;
029:
030: import org.w3c.dom.Document;
031: import org.sakaiproject.tool.assessment.facade.PublishedAssessmentFacade;
032: import org.sakaiproject.tool.assessment.qti.constants.QTIVersion;
033: import org.sakaiproject.tool.assessment.qti.helper.AuthoringHelper;
034: import org.sakaiproject.tool.assessment.qti.helper.AuthoringXml;
035: import org.sakaiproject.tool.assessment.services.assessment.AssessmentService;
036: import org.sakaiproject.tool.assessment.qti.util.XmlUtil;
037:
038: /**
039: * <p>Test bed for QTI utilities.</p>
040: * <p> </p>
041: * <p> </p>
042: * @author Ed Smiley esmiley@stanford.edu
043: * @version $Id: QTITester.java 15448 2006-09-29 18:14:43Z ktsao@stanford.edu $
044: */
045:
046: public class QTITester {
047: private static Log log = LogFactory.getLog(QTITester.class);
048: // private static boolean useContextPath = true;
049: private static boolean useContextPath = false;
050: // private static int version = QTIVersion.VERSION_1_2;
051: private static int version = QTIVersion.VERSION_2_0;
052:
053: public static void main(String[] args) {
054: // log.debug("testing: AuthoringHelper");
055: // testAuthoringHelper();
056: // log.debug("<!--testing: AuthoringXml templates-->");
057: // testAuthoringXmlTemplates();
058: log.debug("<!--testing: AuthoringXml routines-->");
059: testAuthoringXmlRoutines();
060:
061: }
062:
063: /*
064: private static void testAuthoringHelper()
065: {
066: AuthoringHelper authHelper = new AuthoringHelper(QTIVersion.VERSION_1_2);
067: AssessmentService aService = new AssessmentService();
068: ArrayList list = aService.getAllAssessments(1,1,"title");
069: AuthoringXml ax = new AuthoringXml(version);
070:
071: for (int i = 0; i < list.size(); i++)
072: {
073: PublishedAssessmentFacade pub = (PublishedAssessmentFacade) list.get(
074: i);
075: String pubid = pub.getAssessmentId().toString();
076: log.debug("testing: " + pubid);
077: log.debug(
078: "=======================================================");
079: InputStream is = ax.getTemplateInputStream(AuthoringXml.ASSESSMENT);
080: Document doc = authHelper.getAssessment(pubid, is);
081: log.debug(doc.toString());
082: log.debug(
083: "=======================================================");
084: }
085: }
086:
087: private static void testAuthoringXmlTemplates()
088: {
089: AuthoringXml ax = new AuthoringXml(version);
090: String[] template =
091: {
092: ax.ASSESSMENT, // "assessmentTemplate.xml";
093: ax.SECTION, // "sectionTemplate.xml";
094: ax.ITEM_AUDIO, // "audioRecordingTemplate.xml";
095: ax.ITEM_ESSAY, // "essayTemplate.xml";
096: ax.ITEM_FIB, // "fibTemplate.xml";
097: ax.ITEM_FIN, // "finTemplate.xml";
098: ax.ITEM_FILE, // "fileUploadTemplate.xml";
099: ax.ITEM_MATCH, // "matchTemplate.xml";
100: ax.ITEM_MCMC, // "mcMCTemplate.xml";
101: ax.ITEM_MCSC, // "mcSCTemplate.xml";
102: ax.ITEM_SURVEY, // "mcSurveyTemplate.xml";
103: ax.ITEM_TF, // "trueFalseTemplate.xml";
104: ax.SURVEY_10, // SURVEY_PATH + "10.xml";
105: ax.SURVEY_5, // SURVEY_PATH + "5.xml";
106: ax.SURVEY_AGREE, // SURVEY_PATH + "AGREE.xml";
107: ax.SURVEY_AVERAGE, // SURVEY_PATH + "AVERAGE.xml";
108: ax.SURVEY_EXCELLENT, // SURVEY_PATH + "EXCELLENT.xml";
109: ax.SURVEY_STRONGLY, // SURVEY_PATH + "STRONGLY_AGREE.xml";
110: ax.SURVEY_UNDECIDED, // SURVEY_PATH + "UNDECIDED.xml";
111: ax.SURVEY_YES, // SURVEY_PATH + "YES.xml";
112: };
113:
114: for (int i = 0; i < template.length; i++)
115: {
116: log.debug("<!--=======================================================");
117: log.debug("testing: " + template[i]);
118: log.debug("=======================================================-->");
119: InputStream is = null;
120:
121: if (useContextPath)
122: {
123: is = ax.getTemplateInputStream(template[i]);
124: }
125: else
126: {
127: is = ax.getTemplateInputStream(template[i]);
128: }
129: log.debug("<!--=======================================================-->");
130: log.debug(ax.getTemplateAsString(is));
131: log.debug("<!--=======================================================-->");
132:
133: }
134:
135: }
136: */
137:
138: public static void testAuthoringXmlRoutines() {
139: AuthoringXml ax = new AuthoringXml(version);
140: Document assessmentXml = null;
141: Document sectionXml = null;
142: InputStream is = null;
143:
144: is = ax.getTemplateInputStream(ax.ASSESSMENT);
145:
146: assessmentXml = ax.readXMLDocument(is);
147: log
148: .debug("<!--============= assessment ==============================-->");
149: log.debug(XmlUtil.getDOMString(assessmentXml));
150: log
151: .debug("<!--=======================================================-->");
152:
153: is = ax.getTemplateInputStream(ax.SECTION);
154:
155: sectionXml = ax.readXMLDocument(is);
156: log
157: .debug("<!--============= section ================================-->");
158: log.debug(XmlUtil.getDOMString(sectionXml));
159: log
160: .debug("<!--=======================================================-->");
161: try {
162: assessmentXml = ax.update(assessmentXml,
163: "questestinterop/assessment/@ident", "test_ident");
164: assessmentXml = ax.update(assessmentXml,
165: "questestinterop/assessment/@title",
166: "this is a title");
167: } catch (Exception ex) {
168: log.error("oops: " + ex);
169: }
170: log
171: .debug("<!--============= modified assessment =====================-->");
172: log.debug(XmlUtil.getDOMString(assessmentXml));
173: log
174: .debug("<!--=======================================================-->");
175: try {
176: sectionXml = ax.update(sectionXml, "section/@ident",
177: "test_section_ident");
178: sectionXml = ax.update(sectionXml, "section/@title",
179: "this is a section title");
180: } catch (Exception ex) {
181: log.error("oops: " + ex);
182: }
183: log
184: .debug("<!--============= modified section ===============-->");
185: log.debug(XmlUtil.getDOMString(sectionXml));
186: log
187: .debug("<!--=======================================================-->");
188:
189: try {
190: ax.addElement(assessmentXml, "questestinterop/assessment",
191: sectionXml.getDocumentElement());
192: ax.addAttribute(assessmentXml,
193: "questestinterop/assessment", "custom_attribute");
194: sectionXml = ax.update(assessmentXml,
195: "questestinterop/assessment/@custom_attribute",
196: "custom_value");
197: } catch (Exception ex) {
198: log.error("oops: " + ex);
199: }
200: log
201: .debug("<!--============= modified assessment and section ===============-->");
202: log.debug(XmlUtil.getDOMString(sectionXml));
203: log
204: .debug("<!--=======================================================-->");
205:
206: }
207:
208: }
|