View Javadoc
1   package org.melati.poem.test;
2   
3   import java.util.Enumeration;
4   
5   import org.melati.poem.Capability;
6   import org.melati.poem.Group;
7   import org.melati.poem.ReferencePoemType;
8   import org.melati.poem.SQLPoemType;
9   import org.melati.poem.ValidationPoemException;
10  
11  /**
12   * @author timp
13   * @since 21 Dec 2006
14   *
15   */
16  public class NotNullableReferencePoemTypeTest extends SQLPoemTypeSpec<Integer> {
17  
18    public NotNullableReferencePoemTypeTest() {
19    }
20  
21    public NotNullableReferencePoemTypeTest(String name) {
22      super(name);
23    }
24  
25    void setObjectUnderTest() {
26      it = new ReferencePoemType(getDb().getCapabilityTable(), false);
27    }
28  
29    /**
30     * Test method for {@link org.melati.poem.SQLType#quotedRaw(java.lang.Object)}.
31     */
32    public void testQuotedRaw() {
33      assertEquals(((SQLPoemType<Integer>)it).sqlDefaultValue(getDb().getDbms()), 
34          ((SQLPoemType<Integer>)it).quotedRaw(
35              ((SQLPoemType<Integer>)it).rawOfString(
36                  ((SQLPoemType<Integer>)it).sqlDefaultValue(getDb().getDbms()))));
37  
38    }
39    
40    public void testAssertValidCooked() {
41      super.testAssertValidCooked();
42      Group g = (Group)getDb().getGroupTable().firstSelection(null);
43      try {
44        it.assertValidCooked(g);
45        fail("Should have blown up");
46      } catch (ValidationPoemException e) { 
47        e = null;
48      }
49    }
50  
51    public void testPossibleRaws() {
52      super.testPossibleRaws();
53      Enumeration<Integer> them = it.possibleRaws();
54      them = it.possibleRaws();
55      int count = 0;
56      while(them.hasMoreElements()) {
57        them.nextElement();
58        count++;
59      }
60      if (it.getNullable())
61        assertEquals(6,count);
62      else {
63        Enumeration<Integer> them2 = it.possibleRaws();
64        while (them2.hasMoreElements()) {
65          Integer raw = (Integer)them2.nextElement();
66          System.err.println(raw + 
67              ((Capability)getDb().getCapabilityTable().getObject(raw.intValue())).getName());
68          
69        }
70       assertEquals(5,count);
71      }
72      
73    }
74  
75    public void testRawOfCooked() {
76      super.testRawOfCooked();
77      assertEquals(new Integer(0), it.rawOfCooked(getDb().administerCapability()));
78      
79    }
80  
81    /**
82     * Test method for {@link org.melati.poem.PoemType#toDsdType()}.
83     */
84    public void testToDsdType() {
85      assertEquals("Capability", it.toDsdType()); 
86  
87    }
88  
89    /**
90  Test with wrong parameters.   * 
91     */
92    public void testBadConstructor() {
93      try {
94        new ReferencePoemType(null, false);
95        fail("Should have blown up");
96      } catch (NullPointerException e) {
97        e = null;
98      }
99    }
100 }