KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > jca > test > HAConnectionFactoryUnitTestCase


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.jca.test;
23
24 import org.jboss.test.JBossTestCase;
25 import org.jboss.test.jca.interfaces.HAConnectionSessionHome;
26 import org.jboss.resource.adapter.jdbc.local.HALocalManagedConnectionFactory;
27
28 import java.util.Arrays JavaDoc;
29
30 import junit.framework.Test;
31
32
33 /**
34  * @author <a HREF="mailto:alex@jboss.org">Alexey Loubyansky</a>
35  * @version <tt>$Revision: 37406 $</tt>
36  */

37 public class HAConnectionFactoryUnitTestCase
38    extends JBossTestCase
39 {
40    /**
41     * Constructor for the JBossTestCase object
42     *
43     * @param name Test case name
44     */

45    public HAConnectionFactoryUnitTestCase(String JavaDoc name)
46    {
47       super(name);
48    }
49
50    public static Test suite() throws Exception JavaDoc
51    {
52       Test t;
53       t = getDeploySetup(HAConnectionFactoryUnitTestCase.class, "jcatest.jar");
54       t = getDeploySetup(t, "test-ha-ds.xml");
55       t = getDeploySetup(t, "test-ha-xa-ds.xml");
56       t = getDeploySetup(t, "jbosstestadapter.rar");
57
58       // this is for deploying the ha rar which is not deployed by default
59
// FIXME: is there a better way to do it?
60
//String connectorLib = System.getProperty("jbosstest.deploy.dir") + "/../../../connector/output/lib/";
61
// these RARs are now in the all/default config?
62
//t = getDeploySetup(t, new File(connectorLib + "jboss-ha-local-jdbc.rar").toURL().toString());
63
//t = getDeploySetup(t, new File(connectorLib + "jboss-ha-xa-jdbc.rar").toURL().toString());
64
return t;
65    }
66
67    public void testFailoverLocalMCF() throws Exception JavaDoc
68    {
69       HAConnectionSessionHome home = (HAConnectionSessionHome)getInitialContext().lookup("HAConnectionSession");
70       home.create().testHaLocalConnection();
71    }
72
73    public void testFailoverXaMCF() throws Exception JavaDoc
74    {
75       HAConnectionSessionHome home = (HAConnectionSessionHome)getInitialContext().lookup("HAConnectionSession");
76       home.create().testHaXaConnection();
77    }
78
79    public void testURLSelector() throws Exception JavaDoc
80    {
81       Object JavaDoc[] urls = new Object JavaDoc[]{"url1", "url2", "url3"};
82       HALocalManagedConnectionFactory.URLSelector selector = new HALocalManagedConnectionFactory.URLSelector(
83          Arrays.asList(urls)
84       );
85
86       String JavaDoc url = selector.getUrl();
87       assertEquals(urls[0], url);
88       url = selector.getUrl();
89       assertEquals(urls[0], url);
90       url = selector.getUrl();
91       assertEquals(urls[0], url);
92
93       selector.failedUrl(url);
94       url = selector.getUrl();
95       assertEquals(urls[1], url);
96       url = selector.getUrl();
97       assertEquals(urls[1], url);
98
99       selector.failedUrl(url);
100       url = selector.getUrl();
101       assertEquals(urls[2], url);
102       url = selector.getUrl();
103       assertEquals(urls[2], url);
104
105       for(int i = 0; i < 10; ++i)
106       {
107          selector.failedUrl(url);
108          url = selector.getUrl();
109          assertEquals(urls[i % 3], url);
110       }
111    }
112 }
113
Popular Tags