Source code: com/javanicus/megg/test/MeggTest.java
1 /*
2 * The Apache Software License, Version 1.1
3 * Modified as I'm not a member of Apache,
4 * thus only the names have been changed,
5 * the intent is the same as the original license.
6 *
7 * Copyright (c) 2000-2003 The Apache Software Foundation. All rights
8 * reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 *
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 *
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in
19 * the documentation and/or other materials provided with the
20 * distribution.
21 *
22 * 3. The end-user documentation included with the redistribution, if
23 * any, must include the following acknowlegement:
24 * "This product includes software developed by
25 * Jeremy Rayner (http://www.javanicus.com/)."
26 * Alternately, this acknowlegement may appear in the software itself,
27 * if and wherever such third-party acknowlegements normally appear.
28 *
29 * 4. The names "Megg" and "Javanicus"
30 * must not be used to endorse or promote products derived
31 * from this software without prior written permission. For written
32 * permission, please contact jeremy.rayner@bigfoot.com
33 *
34 * 5. Products derived from this software may not be called "Javanicus"
35 * nor may "Javanicus" appear in their names without prior written
36 * permission of the Javanicus developers.
37 *
38 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
39 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
40 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
41 * DISCLAIMED. IN NO EVENT SHALL JAVANICUS OR
42 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
44 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
45 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
46 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
47 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
48 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
49 * SUCH DAMAGE.
50 * ====================================================================
51 *
52 * This software consists of voluntary contributions made by Jez. For more
53 * information on javanicus, please see
54 * <http://www.javanicus.com/>.
55 */
56
57 package com.javanicus.megg.test;
58
59 import java.io.*;
60 import java.util.*;
61 import junit.framework.*;
62 import com.javanicus.megg.*;
63
64 public class MeggTest extends TestCase {
65 private Megg megg;
66 private Map projectDetails;
67
68 public MeggTest(String name) {
69 super(name);
70 }
71
72 public static void main(String args[]) {
73 junit.textui.TestRunner.run(MeggTest.class);
74 }
75
76 protected void setUp() {
77 megg = Megg.getInstance();
78
79 projectDetails = new HashMap();
80 projectDetails.put("domainName","com.javanicus");
81 projectDetails.put("domainNamePath","com/javanicus");
82 projectDetails.put("projectName","cats");
83 projectDetails.put("mainClassName","Mog");
84 projectDetails.put("templateDirectory","templates/java");
85
86 }
87
88 public void testInstatiation() {
89 assertNotNull("megg should exist",megg);
90 }
91
92 public void testGenerate() {
93 assertTrue("generate should return success",megg.generate(projectDetails));
94 }
95
96 public void testInitialiseProject() {
97 assertTrue("initialise should return success",megg.initialiseProject(new ArrayList(), projectDetails));
98 assertTrue("subdirectory for project should now exist",new File((String)projectDetails.get("projectName")).exists());
99 }
100
101 public void testFetchTemplates() {
102 List templates = megg.fetchTemplates((String)projectDetails.get("templateDirectory"));
103 assertNotNull("should contain a valid List",templates);
104
105 assertTrue(templates.contains("templates/java/build.xml"));
106 assertTrue(templates.contains("templates/java/megg.conf"));
107 assertTrue(templates.contains("templates/java/src/manifest.txt"));
108 assertTrue(templates.contains("templates/java/src/MainClassNameTest.java"));
109 assertTrue(templates.contains("templates/java/src/MainClassName.java"));
110 }
111
112 public void testApply() {
113 List templates = new ArrayList();
114 templates.add("templates/java/build.xml");
115 assertTrue(megg.apply(templates,projectDetails));
116 }
117
118 protected void tearDown() {
119 megg = null;
120 projectDetails = null;
121 }
122 }