KickJava   Java API By Example, From Geeks To Geeks.

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


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.IndexDescriptor;
8 import org.apache.ojb.broker.metadata.torque.TorqueIndexGenerator;
9
10 import java.util.Vector JavaDoc;
11
12 public class TorqueIndexGeneratorTest extends TestCase {
13
14     private TorqueIndexGenerator indexGenerator;
15     private static final String JavaDoc EXPECTED_INDICES =
16             " <unique name=\"JUnit name1\">\n" +
17             " <unique-column name=\"JUnit column1\"/>\n" +
18             " <unique-column name=\"JUnit column2\"/>\n" +
19             " </unique>\n" +
20             " <index name=\"JUnit name2\">\n" +
21             " <index-column name=\"JUnit column3\"/>\n" +
22             " </index>\n";
23
24     public TorqueIndexGeneratorTest(String JavaDoc name) {
25         super(name);
26     }
27
28     public void setUp() throws Exception JavaDoc {
29         this.indexGenerator = new TorqueIndexGenerator();
30     }
31
32     public void tearDown() throws Exception JavaDoc {
33         this.indexGenerator = null;
34     }
35
36     public void testGenerateIndices() {
37         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
38         Vector JavaDoc indexDescriptors = new Vector JavaDoc();
39
40         IndexDescriptor indexUnique = new IndexDescriptor();
41         indexUnique.setName("JUnit name1");
42         indexUnique.setUnique(true);
43         Vector JavaDoc columns = new Vector JavaDoc();
44         columns.add("JUnit column1");
45         columns.add("JUnit column2");
46         indexUnique.setIndexColumns(columns);
47         indexDescriptors.add(indexUnique);
48
49         IndexDescriptor indexNotUnique = new IndexDescriptor();
50         indexNotUnique.setName("JUnit name2");
51         indexNotUnique.setUnique(false);
52         columns = new Vector JavaDoc();
53         columns.add("JUnit column3");
54         indexNotUnique.setIndexColumns(columns);
55         indexDescriptors.add(indexNotUnique);
56
57         this.indexGenerator.generateIndices(indexDescriptors, buffer);
58
59
60         assertEquals("The damn thing doesn't work.", EXPECTED_INDICES, buffer.toString());
61     }
62
63     public static void main(String JavaDoc[] args) {
64         TestRunner.run(suite());
65     }
66
67     public static Test suite() {
68         return new TestSuite(TorqueIndexGeneratorTest.class);
69     }
70
71 }
72
Popular Tags