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 ; 13 import java.io.FileReader ; 14 15 public class TorqueRepositoryGeneratorTest extends TestCase { 16 17 private static final String INPUT_FILE = TestHelper.DEF_REPOSITORY; 18 private static final String OUTPUT_FILE = "test-project-schema.xml"; 19 private static final String EXPECTED_OUTPUT_FILE = "expected-project-schema.xml"; 20 private TorqueRepositoryGenerator torqueRepositoryGenerator; 21 private DescriptorRepository repository; 22 23 public TorqueRepositoryGeneratorTest(String name) { 24 super(name); 25 } 26 27 public void setUp() throws Exception { 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 { 34 this.torqueRepositoryGenerator = null; 35 File outputFile = new File (OUTPUT_FILE); 36 outputFile.delete(); 37 } 38 39 public void testGenerateTorqueRepository() throws Exception { 40 this.torqueRepositoryGenerator.generateTorqueRepository(OUTPUT_FILE, "test", "testIdx"); 41 File outputFile = new File (OUTPUT_FILE); 42 File expectedFile = new File (EXPECTED_OUTPUT_FILE); 43 FileReader outputFileReader = new FileReader (outputFile); 44 FileReader expectedFileReader = new FileReader (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 [] args) { 53 TestRunner.run(suite()); 54 } 55 56 public static Test suite() { 57 return new TestSuite(TorqueRepositoryGeneratorTest.class); 58 } 59 60 } 61 | Popular Tags |