KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.objectweb.sys.FileProp2Ctx;
31

32 import junit.framework.Test;
33 import junit.framework.TestSuite;
34 import junit.textui.TestRunner;
35 import org.objectweb.perseus.LogBoot;
36 import org.objectweb.perseus.connector.ra.TestRAUnman;
37
38 import java.util.Properties JavaDoc;
39 import java.util.Vector JavaDoc;
40 import javax.naming.Context JavaDoc;
41 import javax.resource.cci.Connection JavaDoc;
42 import javax.resource.spi.ManagedConnectionFactory JavaDoc;
43
44 /**
45  * The <b>TestRAFileUnman</b> class instanciates TestRABasicUnman for the File
46  * Resource Adapter.
47  */

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

67     protected ManagedConnectionFactory JavaDoc getNewMCFInstance()
68         throws Exception JavaDoc {
69         return (ManagedConnectionFactory JavaDoc) new FosManagedConnectionFactory();
70     }
71
72     /**
73      * The method implementation must initialize the resource adapter
74      */

75     protected void initMCF() throws Exception JavaDoc {
76         ((FosManagedConnectionFactory) mcf).setConnectionURL(dbDir);
77         ((FosManagedConnectionFactory) mcf).setInitializeAtStartUp(true);
78         ((FosManagedConnectionFactory) mcf).setMonologFactory(LogBoot.getLoggerFactory());
79         ((FosManagedConnectionFactory) mcf).start();
80     }
81
82     protected void endMCF() throws Exception JavaDoc {
83         ((FosManagedConnectionFactory) mcf).stop();
84     }
85
86     public void testConnPassThrough() {
87         try {
88             Connection JavaDoc c = cf.getConnection();
89             if (!((FosWriting) writings.elements().nextElement()).passThrough(c))
90                 fail();
91             c.close();
92         } catch (Exception JavaDoc e) {
93             e.printStackTrace();
94             fail();
95         }
96     }
97
98     /**
99      * Constructs the suite containing all test cases defined within
100      * TestRAUnman.
101      */

102     public static Test suite() {
103         return new TestSuite(TestRAFosUnman.class);
104     }
105
106     /**
107      * For running the TestRAFileUnman suite standalone.
108      */

109     public static void main(String JavaDoc args[]) {
110         TestRunner.run(suite());
111     }
112
113     /**
114      * Constructs a TestRAFileUnman.
115      */

116     public TestRAFosUnman(String JavaDoc tn) {
117         super(tn);
118         Properties JavaDoc prop = new Properties JavaDoc();
119         try {
120             prop.load(ClassLoader.getSystemResourceAsStream("owfos.properties"));
121         } catch (Exception JavaDoc e) {
122             e.printStackTrace();
123             System.exit(1);
124         }
125         dbDir = prop.getProperty("dbdir", null);
126         if (dbDir == null) {
127             System.out.println("Cannot find the 'dbdir' property");
128             System.exit(1);
129         }
130     }
131 }
Popular Tags