KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > broker > metadata > torque > TorqueRepositoryGeneratorTest


1 package org.apache.ojb.broker.metadata.torque;
2
3 import junit.framework.Test;
4 import junit.framework.TestCase;
5 import junit.framework.TestSuite;
6 import junit.textui.TestRunner;
7 import org.apache.ojb.broker.metadata.DescriptorRepository;
8 import org.apache.ojb.broker.metadata.RepositoryPersistor;
9 import org.apache.ojb.broker.metadata.torque.TorqueRepositoryGenerator;
10 import org.apache.ojb.broker.TestHelper;
11
12 import java.io.File JavaDoc;
13 import java.io.FileReader JavaDoc;
14
15 public class TorqueRepositoryGeneratorTest extends TestCase {
16
17     private static final String JavaDoc INPUT_FILE = TestHelper.DEF_REPOSITORY;
18     private static final String JavaDoc OUTPUT_FILE = "test-project-schema.xml";
19     private static final String JavaDoc EXPECTED_OUTPUT_FILE = "expected-project-schema.xml";
20     private TorqueRepositoryGenerator torqueRepositoryGenerator;
21     private DescriptorRepository repository;
22
23     public TorqueRepositoryGeneratorTest(String JavaDoc name) {
24         super(name);
25     }
26
27     public void setUp() throws Exception JavaDoc {
28         RepositoryPersistor repositoryPersistor = new RepositoryPersistor();
29         this.repository = repositoryPersistor.readDescriptorRepository(INPUT_FILE);
30         this.torqueRepositoryGenerator = new TorqueRepositoryGenerator(INPUT_FILE, false);
31     }
32
33     public void tearDown() throws Exception JavaDoc {
34         this.torqueRepositoryGenerator = null;
35         File JavaDoc outputFile = new File JavaDoc(OUTPUT_FILE);
36         outputFile.delete();
37     }
38
39     public void testGenerateTorqueRepository() throws Exception JavaDoc {
40         this.torqueRepositoryGenerator.generateTorqueRepository(OUTPUT_FILE, "test", "testIdx");
41         File JavaDoc outputFile = new File JavaDoc(OUTPUT_FILE);
42         File JavaDoc expectedFile = new File JavaDoc(EXPECTED_OUTPUT_FILE);
43         FileReader JavaDoc outputFileReader = new FileReader JavaDoc(outputFile);
44         FileReader JavaDoc expectedFileReader = new FileReader JavaDoc(expectedFile);
45         assertEquals("The generated test-project-schema.xml is a different length than expected.", expectedFile.length(), outputFile.length());
46
47         while (outputFileReader.ready()) {
48             assertEquals("The generated test-project-schema.xml was not identical to the expected-project-schema.xml.", outputFileReader.read(), expectedFileReader.read());
49         }
50     }
51
52     public static void main(String JavaDoc[] args) {
53         TestRunner.run(suite());
54     }
55
56     public static Test suite() {
57         return new TestSuite(TorqueRepositoryGeneratorTest.class);
58     }
59
60 }
61
Popular Tags