001: /*
002: * Copyright 2005-2007 The Kuali Foundation.
003: *
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.opensource.org/licenses/ecl1.php
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package edu.iu.uis.eden.edl;
018:
019: import javax.servlet.http.HttpServletRequest;
020: import javax.xml.transform.OutputKeys;
021: import javax.xml.transform.Transformer;
022: import javax.xml.transform.TransformerConfigurationException;
023: import javax.xml.transform.dom.DOMSource;
024: import javax.xml.transform.stream.StreamResult;
025:
026: import org.junit.Ignore;
027: import org.junit.Test;
028: import org.kuali.workflow.test.WorkflowTestCase;
029: import org.w3c.dom.Document;
030:
031: import edu.iu.uis.eden.KEWServiceLocator;
032: import edu.iu.uis.eden.user.WorkflowUser;
033: import edu.iu.uis.eden.web.session.UserSession;
034:
035: public class EDLCreationTest extends WorkflowTestCase {
036:
037: protected void loadTestData() throws Exception {
038: super .loadXmlFile("widgets.xml");
039: super .loadXmlFile("edlstyle.xml");
040: super .loadXmlFile("TestEDL1.xml");
041: super .loadXmlFile("EDLRoutingData.xml");
042: }
043:
044: @Ignore("This test needs to be implemented!")
045: @Test
046: public void testEDLDOMCreationAndTransformation() throws Exception {
047: // Core.getCurrentContextConfig().overrideProperty(Config.EDL_CONFIG_LOCATION, "classpath:edu/iu/uis/eden/edl/EDLConfig1.xml");
048: // WorkflowUser user = SpringServiceLocator.getUserService().getWorkflowUser(new NetworkIdVO("user1"));
049: // EDLController edlController = getEDLService().getEDLController("TestEDL1");
050: //
051: // MockHttpServletRequest request = new MockHttpServletRequest();
052: // request.setContentType("text/html");
053: // request.setMethod("POST");
054: // Transformer transformer = TransformerFactory.newInstance().newTransformer();
055: // edlController.setEdlContext(getEDLContext(edlController, request, transformer, user));
056: // Document dom = edlController.notifyComponents();
057: // System.out.print(XmlHelper.jotNode(dom));
058: // transform(dom, edlController.getStyle().newTransformer());
059: }
060:
061: @Ignore("This test needs to be implemented!")
062: @Test
063: public void testEDLCreationWithWorkflowDocument() throws Exception {
064: // Core.getCurrentContextConfig().overrideProperty(Config.EDL_CONFIG_LOCATION, "classpath:edu/iu/uis/eden/edl/EDLConfig1.xml");
065: // WorkflowUser user = SpringServiceLocator.getUserService().getWorkflowUser(new NetworkIdVO("user1"));
066: // EDLController edlController = getEDLService().getEDLController("TestEDL1");
067: //
068: // MockHttpServletRequest request = new MockHttpServletRequest();
069: // request.setContentType("text/html");
070: // //make our params create the document
071: // request.addParameter("userAction", "create");
072: // request.setMethod("POST");
073: // Transformer transformer = edlController.getStyle().newTransformer();
074: // EDLContext edlContext = getEDLContext(edlController, request, transformer, user);
075: // edlController.setEdlContext(edlContext);
076: // Document dom = edlController.notifyComponents();
077: // System.out.print(XmlHelper.jotNode(dom));
078: // transform(dom, transformer);
079: //
080: // //now let's route our document
081: // HttpSession session = request.getSession();
082: // request = new MockHttpServletRequest();
083: // request.setContentType("text/html");
084: // request.setMethod("POST");
085: // //make our params create the document
086: // request.addParameter("userAction", "route");
087: // request.addParameter("department", "AFRI COAS");
088: // request.addParameter("creditType", "undergraduateCredit");
089: // request.addParameter("academicSubjectCode", "American Studies");
090: // request.addParameter("courseNumber", "A321");
091: // request.addParameter("currentVersion", "0");
092: // request.setSession(session);
093: // edlContext.getRequestParser().setRequest(request);
094: //
095: // transformer = edlController.getStyle().newTransformer();
096: // edlController.setEdlContext(getEDLContext(edlController, request, transformer, user));
097: // dom = edlController.notifyComponents();
098: // System.out.print(XmlHelper.jotNode(dom));
099: // transform(dom, transformer);
100: }
101:
102: private void transform(Document dom, Transformer transformer)
103: throws Exception {
104: transformer.setOutputProperty("indent", "yes");
105: transformer.setOutputProperty(OutputKeys.INDENT, "yes");
106: transformer.transform(new DOMSource(dom), new StreamResult(
107: System.out));
108: }
109:
110: private EDLContext getEDLContext(EDLController edlController,
111: HttpServletRequest request, Transformer transformer,
112: WorkflowUser user) throws TransformerConfigurationException {
113: EDLContext edlContext = new EDLContext();
114: edlContext.setEdocLiteAssociation(edlController
115: .getEdocLiteAssociation());
116: edlContext.setUserSession(new UserSession(user));
117: edlContext.setTransformer(transformer);
118: // edlContext.setSessionAccessor(new SessionAccessor(request));
119: edlContext.setRequestParser(new RequestParser(request));
120: return edlContext;
121: }
122:
123: private EDocLiteService getEDLService() {
124: return (EDocLiteService) KEWServiceLocator.getEDocLiteService();
125: }
126:
127: }
|