View Javadoc

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