View Javadoc

1   /**
2    * Copyright 2005-2011 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.edl.impl;
17  
18  import javax.servlet.http.HttpServletRequest;
19  import javax.xml.transform.OutputKeys;
20  import javax.xml.transform.Transformer;
21  import javax.xml.transform.TransformerConfigurationException;
22  import javax.xml.transform.dom.DOMSource;
23  import javax.xml.transform.stream.StreamResult;
24  
25  import org.junit.Ignore;
26  import org.junit.Test;
27  import org.kuali.rice.edl.impl.service.EDocLiteService;
28  import org.kuali.rice.edl.impl.service.EdlServiceLocator;
29  import org.kuali.rice.kew.test.KEWTestCase;
30  import org.kuali.rice.krad.UserSession;
31  import org.w3c.dom.Document;
32  
33  
34  public class EDLCreationTest extends KEWTestCase {
35  
36  	protected void loadTestData() throws Exception {
37  		super.loadXmlFile("widgets.xml");
38  		super.loadXmlFile("edlstyle.xml");
39  		super.loadXmlFile("TestEDL1.xml");
40  		super.loadXmlFile("EDLRoutingData.xml");
41  	}
42  
43  	@Ignore("This test needs to be implemented!")
44  	@Test public void testEDLDOMCreationAndTransformation() throws Exception {
45  //		ConfigContext.getCurrentContextConfig().overrideProperty(Config.EDL_CONFIG_LOCATION, "classpath:org/kuali/rice/kew/edl/EDLConfig1.xml");
46  //		WorkflowUser user = SpringServiceLocator.getUserService().getWorkflowUser(new NetworkIdVO("user1"));
47  //		EDLController edlController = getEDLService().getEDLController("TestEDL1");
48  //
49  //		MockHttpServletRequest request = new MockHttpServletRequest();
50  //		request.setContentType("text/html");
51  //		request.setMethod("POST");
52  //		Transformer transformer = TransformerFactory.newInstance().newTransformer();
53  //		edlController.setEdlContext(getEDLContext(edlController, request, transformer, user));
54  //		Document dom = edlController.notifyComponents();
55  //		System.out.print(XmlJotter.jotNode(dom));
56  //		transform(dom, edlController.getStyle().newTransformer());
57  	}
58  
59  	@Ignore("This test needs to be implemented!")
60  	@Test public void testEDLCreationWithWorkflowDocument() throws Exception {
61  //		ConfigContext.getCurrentContextConfig().overrideProperty(Config.EDL_CONFIG_LOCATION, "classpath:org/kuali/rice/kew/edl/EDLConfig1.xml");
62  //		WorkflowUser user = SpringServiceLocator.getUserService().getWorkflowUser(new NetworkIdVO("user1"));
63  //		EDLController edlController = getEDLService().getEDLController("TestEDL1");
64  //
65  //		MockHttpServletRequest request = new MockHttpServletRequest();
66  //		request.setContentType("text/html");
67  //		//make our params create the document
68  //		request.addParameter("userAction", "create");
69  //		request.setMethod("POST");
70  //		Transformer transformer = edlController.getStyle().newTransformer();
71  //		EDLContext edlContext = getEDLContext(edlController, request, transformer, user);
72  //		edlController.setEdlContext(edlContext);
73  //		Document dom = edlController.notifyComponents();
74  //		System.out.print(XmlJotter.jotNode(dom));
75  //		transform(dom, transformer);
76  //
77  //		//now let's route our document
78  //		HttpSession session = request.getSession();
79  //		request = new MockHttpServletRequest();
80  //		request.setContentType("text/html");
81  //		request.setMethod("POST");
82  //		//make our params create the document
83  //		request.addParameter("userAction", "route");
84  //		request.addParameter("department", "AFRI COAS");
85  //		request.addParameter("creditType", "undergraduateCredit");
86  //		request.addParameter("academicSubjectCode", "American Studies");
87  //		request.addParameter("courseNumber", "A321");
88  //		request.addParameter("currentVersion", "0");
89  //		request.setSession(session);
90  //		edlContext.getRequestParser().setRequest(request);
91  //
92  //		transformer = edlController.getStyle().newTransformer();
93  //		edlController.setEdlContext(getEDLContext(edlController, request, transformer, user));
94  //		dom = edlController.notifyComponents();
95  //		System.out.print(XmlJotter.jotNode(dom));
96  //		transform(dom, transformer);
97  	}
98  
99  	private void transform(Document dom, Transformer transformer) throws Exception {
100         transformer.setOutputProperty("indent", "yes");
101         transformer.setOutputProperty(OutputKeys.INDENT, "yes");
102         transformer.transform(new DOMSource(dom), new StreamResult(System.out));
103 	}
104 
105 	private EDLContext getEDLContext(EDLController edlController, HttpServletRequest request, Transformer transformer, String principalId) throws TransformerConfigurationException {
106 		EDLContext edlContext = new EDLContext();
107 		edlContext.setEdocLiteAssociation(edlController.getEdocLiteAssociation());
108 		edlContext.setUserSession(new UserSession(principalId));
109 		edlContext.setTransformer(transformer);
110 //		edlContext.setSessionAccessor(new SessionAccessor(request));
111 		edlContext.setRequestParser(new RequestParser(request));
112 		return edlContext;
113 	}
114 
115 	private EDocLiteService getEDLService() {
116 		return EdlServiceLocator.getEDocLiteService();
117 	}
118 
119 }