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