001 /* 002 * Copyright 2005-2007 The Kuali Foundation 003 * 004 * 005 * Licensed under the Educational Community License, Version 2.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/ecl2.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 org.kuali.rice.edl.impl; 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.rice.edl.impl.service.EDocLiteService; 029 import org.kuali.rice.edl.impl.service.EdlServiceLocator; 030 import org.kuali.rice.kew.test.KEWTestCase; 031 import org.kuali.rice.krad.UserSession; 032 import org.w3c.dom.Document; 033 034 035 public class EDLCreationTest extends KEWTestCase { 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 public void testEDLDOMCreationAndTransformation() throws Exception { 046 // ConfigContext.getCurrentContextConfig().overrideProperty(Config.EDL_CONFIG_LOCATION, "classpath:org/kuali/rice/kew/edl/EDLConfig1.xml"); 047 // WorkflowUser user = SpringServiceLocator.getUserService().getWorkflowUser(new NetworkIdVO("user1")); 048 // EDLController edlController = getEDLService().getEDLController("TestEDL1"); 049 // 050 // MockHttpServletRequest request = new MockHttpServletRequest(); 051 // request.setContentType("text/html"); 052 // request.setMethod("POST"); 053 // Transformer transformer = TransformerFactory.newInstance().newTransformer(); 054 // edlController.setEdlContext(getEDLContext(edlController, request, transformer, user)); 055 // Document dom = edlController.notifyComponents(); 056 // System.out.print(XmlJotter.jotNode(dom)); 057 // transform(dom, edlController.getStyle().newTransformer()); 058 } 059 060 @Ignore("This test needs to be implemented!") 061 @Test public void testEDLCreationWithWorkflowDocument() throws Exception { 062 // ConfigContext.getCurrentContextConfig().overrideProperty(Config.EDL_CONFIG_LOCATION, "classpath:org/kuali/rice/kew/edl/EDLConfig1.xml"); 063 // WorkflowUser user = SpringServiceLocator.getUserService().getWorkflowUser(new NetworkIdVO("user1")); 064 // EDLController edlController = getEDLService().getEDLController("TestEDL1"); 065 // 066 // MockHttpServletRequest request = new MockHttpServletRequest(); 067 // request.setContentType("text/html"); 068 // //make our params create the document 069 // request.addParameter("userAction", "create"); 070 // request.setMethod("POST"); 071 // Transformer transformer = edlController.getStyle().newTransformer(); 072 // EDLContext edlContext = getEDLContext(edlController, request, transformer, user); 073 // edlController.setEdlContext(edlContext); 074 // Document dom = edlController.notifyComponents(); 075 // System.out.print(XmlJotter.jotNode(dom)); 076 // transform(dom, transformer); 077 // 078 // //now let's route our document 079 // HttpSession session = request.getSession(); 080 // request = new MockHttpServletRequest(); 081 // request.setContentType("text/html"); 082 // request.setMethod("POST"); 083 // //make our params create the document 084 // request.addParameter("userAction", "route"); 085 // request.addParameter("department", "AFRI COAS"); 086 // request.addParameter("creditType", "undergraduateCredit"); 087 // request.addParameter("academicSubjectCode", "American Studies"); 088 // request.addParameter("courseNumber", "A321"); 089 // request.addParameter("currentVersion", "0"); 090 // request.setSession(session); 091 // edlContext.getRequestParser().setRequest(request); 092 // 093 // transformer = edlController.getStyle().newTransformer(); 094 // edlController.setEdlContext(getEDLContext(edlController, request, transformer, user)); 095 // dom = edlController.notifyComponents(); 096 // System.out.print(XmlJotter.jotNode(dom)); 097 // transform(dom, transformer); 098 } 099 100 private void transform(Document dom, Transformer transformer) throws Exception { 101 transformer.setOutputProperty("indent", "yes"); 102 transformer.setOutputProperty(OutputKeys.INDENT, "yes"); 103 transformer.transform(new DOMSource(dom), new StreamResult(System.out)); 104 } 105 106 private EDLContext getEDLContext(EDLController edlController, HttpServletRequest request, Transformer transformer, String principalId) throws TransformerConfigurationException { 107 EDLContext edlContext = new EDLContext(); 108 edlContext.setEdocLiteAssociation(edlController.getEdocLiteAssociation()); 109 edlContext.setUserSession(new UserSession(principalId)); 110 edlContext.setTransformer(transformer); 111 // edlContext.setSessionAccessor(new SessionAccessor(request)); 112 edlContext.setRequestParser(new RequestParser(request)); 113 return edlContext; 114 } 115 116 private EDocLiteService getEDLService() { 117 return EdlServiceLocator.getEDocLiteService(); 118 } 119 120 }