1   /***
2    Copyright (C) 2005 The Java Community
3   
4    This program is free software; you can redistribute it and/or modify  it under
5    the terms of the GNU General Public License as published by  the Free Software
6    Foundation; either version 2 of the License, or  (at your option) any later
7    version.
8   
9    This program is distributed in the hope that it will be useful,  but WITHOUT
10   ANY WARRANTY; without even the implied warranty of  MERCHANTABILITY or FITNESS
11   FOR A PARTICULAR PURPOSE. See the  GNU General Public License for more details.
12  
13   You should have received a copy of the GNU General Public License  along with
14   this program; if not, write to the Free Software  Foundation, Inc., 59 Temple
15   Place, Suite 330, Boston, MA 02111-1307 USA.
16   */
17  package org.bejug.javacareers.jobs.common.velocity;
18  
19  import java.util.List;
20  
21  import junit.framework.Assert;
22  
23  import org.apache.commons.logging.Log;
24  import org.apache.commons.logging.LogFactory;
25  import org.bejug.javacareers.common.templates.TemplateHolder;
26  import org.bejug.javacareers.common.templates.TemplateUtilities;
27  import org.bejug.javacareers.jobs.common.AbstractSpringContextTests;
28  
29  /***
30   * Created by IntelliJ IDEA.
31   * User: bbr
32   * Date: 1-sep-2005
33   * Time: 15:32:33
34   * To change this template use File | Settings | File Templates.
35   */
36  
37  /***
38   * @author bbr (last modified by $Author: shally $)
39   * @version $Revision: 1.7 $ - $Date: 2005/12/21 11:38:42 $
40   */
41  public class VelocityTests extends AbstractSpringContextTests {
42  
43      /***
44       * The instance of the velocity engine, injected.
45       */
46      protected TemplateUtilities templateUtilities;
47  
48      private static final Log LOG = LogFactory.getLog(VelocityTests.class);
49  
50      /***
51       * 
52       */
53      public void testTemplateUpdate(){
54  
55  
56          TemplateHolder testHolder = templateUtilities.getTemplate("test.vm");
57          String content = testHolder.getContent();
58          LOG.info("Debug: Content: \n" + content);
59          testHolder.setContent("test2");
60          try {
61  			testHolder.update();
62  		} catch (Exception e) {
63  			Assert.fail("Debug: Content update failed, exception:"+e.getMessage());
64  		}
65          TemplateHolder testHolder2 = templateUtilities.getTemplate("test.vm");
66          LOG.info("Debug: Content after update: \n" + testHolder2.getContent());
67          LOG.info("Debug: Name: " + testHolder2.getFilepath());
68          assertEquals(testHolder2.getContent(),"test2");
69          testHolder.setContent("test1");
70          try {
71  			testHolder.update();
72  		} catch (Exception e) {
73  			Assert.fail("Debug: Content update failed, exception:"+e.getMessage());
74  		}
75          testHolder2 = templateUtilities.getTemplate("test.vm");
76          assertEquals(testHolder2.getContent(),"test1");
77      }
78  
79      /***
80       * 
81       */
82      public void testFileLoad() {
83          LOG.info("Debug: Testing VM load");
84          List files = templateUtilities.getAllTemplates();
85          List fileByLanguage = templateUtilities.getAllTemplatesByLanguage("testlang");
86          for (int i = 0; i < fileByLanguage.size(); i++) {
87              TemplateHolder templateHolder = (TemplateHolder) fileByLanguage.get(i);
88              LOG.info("Debug: Got by lang: " + templateHolder.getFilepath());
89          }
90          assertEquals(fileByLanguage.size(),1);
91          for (int i = 0; i < files.size(); i++) {
92              TemplateHolder templateHolder = (TemplateHolder) files.get(i);
93              LOG.info("Debug: Got by all: " + templateHolder.getFilepath());
94          }
95          assertNotSame(new Integer(files.size()),new Integer(0));
96          LOG.info("Debug: Done testing VM load");
97          
98          List fileByName = templateUtilities.getAllTemplatesByName("c://test.vm");
99          for (int i = 0; i < fileByName.size(); i++) {
100             TemplateHolder templateHolder = (TemplateHolder) fileByName.get(i);
101             LOG.info("Debug: Got by name: " + templateHolder.getFilepath());
102         }
103         assertEquals(fileByName.size(),1);
104 
105     }
106 
107     /***
108      * @return templateUtilities
109      */
110     public TemplateUtilities getTemplateUtilities() {
111         return templateUtilities;
112     }
113 
114     /***
115      * @param templateUtilities to be set
116      */
117     public void setTemplateUtilities(TemplateUtilities templateUtilities) {
118         this.templateUtilities = templateUtilities;
119     }
120 }
121 
122 /***
123  * $Log: VelocityTests.java,v $
124  * Revision 1.7  2005/12/21 11:38:42  shally
125  * *** empty log message ***
126  *
127  * Revision 1.6  2005/12/08 14:53:46  shally
128  * Opkuis voor checkstyle.
129  *
130  * Revision 1.5  2005/12/07 23:12:59  shally
131  * Adding editing for velocity templates, fixing some cosmetics
132  *
133  * Revision 1.4  2005/09/30 14:38:08  bavo_jcs
134  * Fixed URL
135  *
136  * Revision 1.3  2005/09/14 10:46:22  schauwvliege
137  * Upload files
138  *
139  * Revision 1.2  2005/09/13 08:11:06  schauwvliege
140  * organize imports
141  *
142  * Revision 1.1  2005/09/01 14:32:18  bavo_jcs
143  * Velocity update
144  *
145  */