KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sleepycat > persist > test > NegativeTest


1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2002,2006 Oracle. All rights reserved.
5  *
6  * $Id: NegativeTest.java,v 1.4 2006/10/30 21:14:55 bostic Exp $
7  */

8
9 package com.sleepycat.persist.test;
10
11 import static com.sleepycat.persist.model.Relationship.ONE_TO_ONE;
12 import junit.framework.Test;
13
14 import com.sleepycat.je.DatabaseException;
15 import com.sleepycat.je.test.TxnTestCase;
16 import com.sleepycat.persist.EntityStore;
17 import com.sleepycat.persist.PrimaryIndex;
18 import com.sleepycat.persist.StoreConfig;
19 import com.sleepycat.persist.model.Entity;
20 import com.sleepycat.persist.model.Persistent;
21 import com.sleepycat.persist.model.PrimaryKey;
22 import com.sleepycat.persist.model.SecondaryKey;
23
24 /**
25  * Negative tests.
26  *
27  * @author Mark Hayes
28  */

29 public class NegativeTest extends TxnTestCase {
30  
31     public static Test suite() {
32         return txnTestSuite(NegativeTest.class, null, null);
33     }
34
35     private EntityStore store;
36
37     private void open()
38         throws DatabaseException {
39
40         StoreConfig config = new StoreConfig();
41         config.setAllowCreate(envConfig.getAllowCreate());
42         config.setTransactional(envConfig.getTransactional());
43
44         store = new EntityStore(env, "test", config);
45     }
46
47     private void close()
48         throws DatabaseException {
49
50         store.close();
51     }
52     
53     public void testBadKeyClass1()
54         throws DatabaseException {
55
56         open();
57         try {
58             PrimaryIndex<BadKeyClass1,UseBadKeyClass1> index =
59                 store.getPrimaryIndex
60                     (BadKeyClass1.class, UseBadKeyClass1.class);
61             fail();
62         } catch (IllegalArgumentException JavaDoc expected) {
63             assertTrue(expected.getMessage().indexOf("@KeyField") >= 0);
64         }
65         close();
66     }
67     
68     /** Missing @KeyField in composite key class. */
69     @Persistent
70     static class BadKeyClass1 {
71
72         private int f1;
73     }
74     
75     @Entity
76     static class UseBadKeyClass1 {
77
78         @PrimaryKey
79         private BadKeyClass1 f1 = new BadKeyClass1();
80
81         @SecondaryKey(relate=ONE_TO_ONE)
82         private BadKeyClass1 f2 = new BadKeyClass1();
83     }
84 }
85
Popular Tags