KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > rift > coad > lib > deployment > rmi > TieGeneratorTest


1 /*
2  * CoadunationLib: The coaduntion implementation library.
3  * Copyright (C) 2006 Rift IT Contracting
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * TieGeneratorTest.java
20  *
21  * JUnit based test
22  */

23
24 package com.rift.coad.lib.deployment.rmi;
25
26 import junit.framework.*;
27 import java.io.File JavaDoc;
28 import java.lang.reflect.Method JavaDoc;
29 import java.lang.reflect.Type JavaDoc;
30 import java.net.URLClassLoader JavaDoc;
31 import java.net.URL JavaDoc;
32 import java.util.StringTokenizer JavaDoc;
33 import java.util.Vector JavaDoc;
34 import java.util.Iterator JavaDoc;
35 import java.util.regex.Matcher JavaDoc;
36 import java.util.regex.Pattern JavaDoc;
37 import org.apache.log4j.Logger;
38 import com.rift.coad.lib.common.ClassUtil;
39 import com.rift.coad.lib.common.FileUtil;
40 import com.rift.coad.lib.common.RandomGuid;
41 import com.rift.coad.lib.common.ResourceReader;
42 import com.rift.coad.lib.common.TextFile;
43 import com.rift.coad.lib.common.JarUtil;
44 import com.rift.coad.lib.deployment.CoadunationParser;
45 import com.rift.coad.lib.deployment.BeanInfo;
46 import com.rift.coad.lib.deployment.DeploymentLoader;
47 import com.rift.coad.lib.thirdparty.ant.JavaC;
48 import com.rift.coad.lib.thirdparty.ant.RMIC;
49
50 /**
51  *
52  * @author mincemeat
53  */

54 public class TieGeneratorTest extends TestCase {
55     
56     public TieGeneratorTest(String JavaDoc testName) {
57         super(testName);
58     }
59
60     protected void setUp() throws Exception JavaDoc {
61     }
62
63     protected void tearDown() throws Exception JavaDoc {
64     }
65
66     public static Test suite() {
67         TestSuite suite = new TestSuite(TieGeneratorTest.class);
68         
69         return suite;
70     }
71     
72     
73     /**
74      * This method will generate a temporary file using the source file.
75      *
76      * @return The path to the newly created temporary file.
77      */

78     private File JavaDoc createTmpDir(File JavaDoc source, File JavaDoc tmpDirBase) throws Exception JavaDoc {
79         File JavaDoc tmpDir = new File JavaDoc(tmpDirBase,
80                 RandomGuid.getInstance().getGuid());
81         if (tmpDir.mkdirs() == false) {
82             throw new Exception JavaDoc("Failed to create the director ["
83                     + tmpDir.getAbsolutePath() + "]");
84         }
85         JarUtil.extract(source,tmpDir);
86         return tmpDir;
87     }
88     
89     /**
90      * Test of generate method, of class com.rift.coad.lib.deployment.rmi.TieGenerator.
91      */

92     public void testGenerate() throws Exception JavaDoc {
93         System.out.println("generate");
94         
95         // load the deployment loader
96
File JavaDoc tmpDir = createTmpDir(new File JavaDoc(System.getProperty("test.jar")),
97                 new File JavaDoc(System.getProperty("test.tmp.dir")));
98         
99         // parse the coadunation file
100
TextFile textFile = new TextFile(new File JavaDoc(tmpDir,
101                 DeploymentLoader.META_FILE));
102         CoadunationParser coadunationParser = new CoadunationParser(
103                 textFile.getTextDocument());
104         
105         BeanInfo bean = (BeanInfo)coadunationParser.getDeploymentInfo().
106                 getBeans().get("com.test.BeanImpl");
107         BeanInfo bean2 = (BeanInfo)coadunationParser.getDeploymentInfo().
108                 getBeans().get("com.test3.BeanImpl");
109         File JavaDoc tmpSource = new File JavaDoc(tmpDir,RandomGuid.getInstance().getGuid());
110         tmpSource.mkdir();
111         TieGenerator instance = new TieGenerator(tmpDir,tmpSource,bean);
112         instance.generate();
113         TieGenerator instance2 = new TieGenerator(tmpDir,tmpSource,bean2);
114         instance2.generate();
115         
116         // test the compiling of these classes
117
File JavaDoc[] classPath = new File JavaDoc[] { tmpDir,
118                 new File JavaDoc("./dist/CoadunationLib.jar"),
119                 new File JavaDoc("../CoadunationBase/dist/CoadunationBase.jar"),
120                 new File JavaDoc("../CoadInclude/dist/CoadunationInclude.jar"),
121                 new File JavaDoc("../CoadunationInclude/dist/CoadunationInclude.jar")};
122         JavaC javaC = new JavaC(classPath,tmpSource,tmpSource);
123         System.out.println("Compiling dir [" + tmpSource.getAbsolutePath() + "]");
124         javaC.compileClasses();
125         
126         RMIC rmic = new RMIC(classPath,tmpSource,"**/*.class",tmpSource);
127         System.out.println("Compiling dir [" + tmpSource.getAbsolutePath() + "]");
128         rmic.parse();
129     }
130     
131     
132 }
133
Popular Tags