1
2
3
4
5
6
7
8
9 package bexee.dao;
10
11 import junit.framework.TestCase;
12 import bexee.util.Constants;
13
14 /***
15 * @version $Revision: 1.1 $, $Date: 2004/12/15 14:18:20 $
16 * @author Patric Fornasier
17 */
18 public class DAOFactoryTest extends TestCase {
19
20 private static final String FACTORY_IMPL = "bexee.dao.DAOFactoryTest$MockDAOFactory";
21
22 protected void tearDown() throws Exception {
23 super.tearDown();
24
25
26 System.getProperties().remove(Constants.OPT_DAO_FACTORY);
27 }
28
29 /***
30 * Test if the factory returns the correct default implementation if no
31 * system property is set.
32 */
33 public void testGetInstance() {
34 DAOFactory factory = DAOFactory.getInstance();
35 assertTrue(factory instanceof MemoryDAOFactory);
36 }
37
38 /***
39 * Test whether the factory returns the right implementation based on a
40 * system property.
41 */
42 public void testGetInstanceBySystemProperty() {
43
44
45 System.setProperty(Constants.OPT_DAO_FACTORY, FACTORY_IMPL);
46
47 DAOFactory factory = DAOFactory.getInstance();
48 assertTrue(factory instanceof DAOFactoryTest.MockDAOFactory);
49 }
50
51 /***
52 * Test whether the factory returns the default implementation if an invalid
53 * class name is provided.
54 */
55 public void testWrongClassName()
56 {
57
58 System.setProperty(Constants.OPT_DAO_FACTORY, "nonExistingClass");
59
60
61 DAOFactory factory = DAOFactory.getInstance();
62 assertTrue(factory instanceof MemoryDAOFactory);
63 }
64
65 /***
66 * Mock class extending the <code>DAOFactory</code> for testing.
67 *
68 * @version $Revision: 1.1 $, $Date: 2004/12/15 14:18:20 $
69 * @author Patric Fornasier
70 */
71 public static class MockDAOFactory extends DAOFactory {
72
73 /***
74 * Doesn't do anything
75 */
76 public BPELProcessDAO createBPELProcessDAO() {
77 return null;
78 }
79
80 /***
81 * Doesn't do anything
82 */
83 public ProcessContextDAO createProcessContextDAO() {
84 return null;
85 }
86
87 }
88 }