KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > perseus > connector > ra > fos > TestRAFosMan


1 /**
2  * ObjectWeb Connector: an implementation of JCA Sun specification along
3  * with some extensions of this specification.
4  * Copyright (C) 2001-2002 France Telecom R&D - INRIA
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  * Release: 0.1
21  *
22  * Contact: jorm@objectweb.org
23  *
24  * Author: S. Chassande-Barrioz, P. Dechamboux
25  *
26  */

27
28 package org.objectweb.perseus.connector.ra.fos;
29
30 import junit.framework.Test;
31 import junit.framework.TestSuite;
32 import junit.textui.TestRunner;
33 import org.objectweb.perseus.LogBoot;
34 import org.objectweb.perseus.connector.ra.TestRAMan;
35
36 import java.util.Properties JavaDoc;
37 import java.util.Vector JavaDoc;
38 import javax.resource.spi.ManagedConnectionFactory JavaDoc;
39
40 /**
41  * The <b>TestRAFileMan</b> class instanciates TestRABasicMan for the File
42  * Resource Adapter.
43  */

44 public class TestRAFosMan extends TestRAMan {
45     private String JavaDoc dbDir;
46
47     protected Vector JavaDoc getWritings() {
48         if (writings == null) {
49             writings = new Vector JavaDoc();
50             // initialise with a set of tests
51
writings.add(new FosWriting(1, "azerty1"));
52             writings.add(new FosWriting(2, "azerty2"));
53             writings.add(new FosWriting(3, "azerty3"));
54         }
55         return writings;
56     }
57
58     /**
59      * The method implementation must return a new instance of the resource
60      * adapter. The ManagedConnectionFactory is the identifer of the
61      * resource adapter.
62      */

63     protected ManagedConnectionFactory JavaDoc getNewMCFInstance()
64         throws Exception JavaDoc {
65         return (ManagedConnectionFactory JavaDoc) new FosManagedConnectionFactory();
66     }
67
68     /**
69      * The method implementation must initialize the resource adapter
70      */

71     protected void initMCF() throws Exception JavaDoc {
72         ((FosManagedConnectionFactory) mcf).setConnectionURL(dbDir);
73         ((FosManagedConnectionFactory) mcf).setInitializeAtStartUp(true);
74         ((FosManagedConnectionFactory) mcf).setMonologFactory(LogBoot.getLoggerFactory());
75         ((FosManagedConnectionFactory) mcf).setConnectionManager(this);
76         ((FosManagedConnectionFactory) mcf).start();
77     }
78
79     protected void endMCF() throws Exception JavaDoc {
80         ((FosManagedConnectionFactory) mcf).stop();
81     }
82
83     /**
84      * Constructs the suite containing all test cases defined within
85      * TestRAMan.
86      */

87     public static Test suite() {
88         return new TestSuite(TestRAFosMan.class);
89     }
90
91     /**
92      * For running the TestRAFileMan suite standalone.
93      */

94     public static void main(String JavaDoc args[]) {
95         TestRunner.run(suite());
96     }
97
98     /**
99      * Constructs a TestRAFileMan.
100      */

101     public TestRAFosMan(String JavaDoc tn) {
102         super(tn);
103         Properties JavaDoc prop = new Properties JavaDoc();
104         try {
105             prop.load(ClassLoader.getSystemResourceAsStream("owfos.properties"));
106         } catch (Exception JavaDoc e) {
107             e.printStackTrace();
108             System.exit(1);
109         }
110         dbDir = prop.getProperty("dbdir", null);
111         if (dbDir == null) {
112             System.out.println("Cannot find the 'dbdir' property");
113             System.exit(1);
114         }
115     }
116 }
Popular Tags