0001: /**
0002: * JOnAS: Java(TM) Open Application Server
0003: * Copyright (C) 2005 Bull S.A.
0004: * Contact: jonas-team@objectweb.org
0005: *
0006: * This library is free software; you can redistribute it and/or
0007: * modify it under the terms of the GNU Lesser General Public
0008: * License as published by the Free Software Foundation; either
0009: * version 2.1 of the License, or 1any later version.
0010: *
0011: * This library is distributed in the hope that it will be useful,
0012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0014: * Lesser General Public License for more details.
0015: *
0016: * You should have received a copy of the GNU Lesser General Public
0017: * License along with this library; if not, write to the Free Software
0018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
0019: * USA
0020: *
0021: * --------------------------------------------------------------------------
0022: * $Id: F_JonasAdminResource.java 8191 2006-03-31 09:59:21Z danesa $
0023: * --------------------------------------------------------------------------
0024: */package org.objectweb.jonas.jonasadmin.test.service.resource;
0025:
0026: import java.io.File;
0027:
0028: import javax.management.ObjectName;
0029:
0030: import junit.framework.TestSuite;
0031:
0032: import org.objectweb.jonas.jonasadmin.test.util.JonasAdminAuth;
0033: import org.objectweb.jonas.jonasadmin.test.util.JonasAdminTestCase;
0034: import org.objectweb.jonas.jonasadmin.test.util.JonasAdminUtils;
0035:
0036: import com.meterware.httpunit.Button;
0037: import com.meterware.httpunit.HttpUnitOptions;
0038: import com.meterware.httpunit.TableCell;
0039: import com.meterware.httpunit.WebConversation;
0040: import com.meterware.httpunit.WebForm;
0041: import com.meterware.httpunit.WebLink;
0042: import com.meterware.httpunit.WebResponse;
0043: import com.meterware.httpunit.WebTable;
0044:
0045: /**
0046: * Class for testing resource service
0047: * @author Paul Kemler
0048: *
0049: */
0050: public class F_JonasAdminResource extends JonasAdminTestCase {
0051:
0052: /**
0053: * URL of Resource Adapters
0054: */
0055: private static final String URL_JONASADMIN_RESOURCE = "ListResourceAdapters.do";
0056:
0057: /**
0058: * URL of earsample.ra-sample
0059: */
0060: private static final String URL_JONASADMIN_RA_SAMPLE = "earsample.ra-sample";
0061:
0062: /**
0063: * URL of db_access_jdbc1
0064: */
0065: private static final String URL_JONASADMIN_JONAS_JDBC = "db_access_jdbc1";
0066:
0067: /**
0068: * URL of Statistics tab
0069: */
0070: private static final String URL_JONASADMIN_STATISTICS = "EditResourceAdapterStat.do";
0071:
0072: /**
0073: * URL of Used by
0074: */
0075: private static final String URL_JONASADMIN_USED_BY = "rarUsedBy";
0076:
0077: /**
0078: * URL of ErsatzEIS
0079: */
0080: private static final String URL_JONASADMIN_ERSATZ = "ErsatzEIS";
0081:
0082: /**
0083: * URL of connection factories
0084: */
0085: private static final String URL_JONASADMIN_CONNECTION_FACTORIES = "service/rar15CFs.jsp";
0086:
0087: /**
0088: * URL of activationSpecs
0089: */
0090: private static final String URL_JONASADMIN_ACTIVATION_SPECS = "service/rar15ASs.jsp";
0091:
0092: /**
0093: * URL of CF Statistics
0094: */
0095: private static final String URL_JONASADMIN_STATISTICS_CF = "EditResourceAdapterCFStat.do";
0096:
0097: /**
0098: * URL of Resource Adapter
0099: */
0100: private static final String URL_JONASADMIN_RA = "EditResourceAdapter.do";
0101:
0102: /**
0103: * URL of Resource Adapter CF
0104: */
0105: private static final String URL_JONASADMIN_RA_CF = "EditResourceAdapterCF.do";
0106:
0107: /**
0108: * number of tabs when you are in resource
0109: */
0110: private static final int NUMBER_OF_TABS_FOR_RESOURCE = 1;
0111:
0112: /**
0113: * number of tabs when you are in earsample.ra-sample
0114: */
0115: private static final int NUMBER_OF_TABS_FOR_RA_SAMPLE = 2;
0116:
0117: /**
0118: * number of tabs when you are in 'db_access_jdbc1' tab
0119: */
0120: private static final int NUMBER_OF_TABS_FOR_JDBC = 4;
0121:
0122: /**
0123: * number of tabs when you are in 'ErsatzEIS'
0124: */
0125: private static final int NUMBER_OF_TABS_RA15 = 4;
0126:
0127: /**
0128: * number of tabs for a connection factory
0129: */
0130: private static final int NUMBER_OF_TABS_CF = 6;
0131:
0132: /**
0133: * number of tabs for a activation spec
0134: */
0135: private static final int NUMBER_OF_TABS_AS = 5;
0136:
0137: /**
0138: * Constructor with a specified name
0139: * @param s name
0140: */
0141: public F_JonasAdminResource(String s) {
0142: super (s, URL_JONASADMIN);
0143: }
0144:
0145: /**
0146: * Main method
0147: * @param args the arguments
0148: */
0149: public static void main(String[] args) {
0150:
0151: String testtorun = null;
0152: // Get args
0153: for (int argn = 0; argn < args.length; argn++) {
0154: String sArg = args[argn];
0155: if (sArg.equals("-n")) {
0156: testtorun = args[++argn];
0157: }
0158: }
0159: if (testtorun == null) {
0160: junit.textui.TestRunner.run(suite());
0161: } else {
0162: junit.textui.TestRunner.run(new F_JonasAdminResource(
0163: testtorun));
0164: }
0165: }
0166:
0167: /**
0168: * Get a new TestSuite for this class
0169: * @return a new TestSuite for this class
0170: */
0171: public static TestSuite suite() {
0172: return new TestSuite(F_JonasAdminResource.class);
0173: }
0174:
0175: /**
0176: * Setup need for these tests
0177: * jonasAdmin is required
0178: * @throws Exception if it fails
0179: */
0180: protected void setUp() throws Exception {
0181: super .setUp();
0182:
0183: if (wc.getCurrentPage().getURL() == null) {
0184: useWar("jonasAdmin");
0185: // login to jonas admin
0186: try {
0187: JonasAdminAuth.doValidAuth(wc, url);
0188: } catch (Exception e) {
0189: fail("authentification failed : " + e);
0190: }
0191: } else {
0192: // if there was an error, the connection must be restablished
0193: try {
0194: wc.getFrameContents(FRAME_TREE);
0195: } catch (Exception e) {
0196: wc.getResponse(urlLogOut);
0197: // login to jonas admin
0198: try {
0199: JonasAdminAuth.doValidAuth(wc, url);
0200: } catch (Exception auth) {
0201: fail("authentification failed : " + auth);
0202: }
0203: }
0204: }
0205: }
0206:
0207: /**
0208: * Test Resource service with rar in an ear.
0209: * @throws Exception if error occurs
0210: *
0211: */
0212: public void testResourceInEar() throws Exception {
0213:
0214: WebResponse wr;
0215: WebLink link;
0216: WebTable table;
0217: WebTable tabTable;
0218: int selectedTab;
0219: String name;
0220: String file = null;
0221: String path = null;
0222: JonasAdminUtils utils = new JonasAdminUtils();
0223:
0224: // Disable errors of javascript
0225: HttpUnitOptions.setExceptionsThrownOnScriptError(false);
0226: // Disable exception thrown on error status
0227: HttpUnitOptions.setExceptionsThrownOnErrorStatus(false);
0228:
0229: // Test only if the resource service is enabled
0230: if (jProp.isResource()) {
0231:
0232: // Add earsample.ear
0233: useEar("earsample");
0234:
0235: // Go to resource adapters
0236: wr = wc.getFrameContents(FRAME_TREE);
0237: link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
0238: URL_JONASADMIN_RESOURCE);
0239: link.click();
0240: wr = wc.getFrameContents(FRAME_CONTENT);
0241: selectedTab = 1;
0242:
0243: // Verify 'Resource Adapters' page
0244: table = utils.getTable(wr, 0);
0245: testResourceAdapterNames(table);
0246: name = "earsample.ra-sample";
0247: int rowRASample = utils.getFirstRow(name, table, 0)
0248: .intValue();
0249: if (rowRASample != -1) {
0250: // Verify File
0251: file = table.getTableCell(rowRASample, 1).getText();
0252: assertEquals(
0253: "It is not the name of the file of the 'earsample.ra-sample'. ",
0254: "ra-sample.rar", file);
0255: // Verify Path
0256: path = table.getTableCell(rowRASample, 2).getText();
0257: assertTrue(
0258: "It is not the end of the path of the 'earsample.ra-sample'. ",
0259: path.endsWith(File.separator + "ra-sample.rar"));
0260: } else {
0261: fail("The RA 'earsample.ra-sample' is not found in the "
0262: + table.getTableCell(0, 0).getText() + ". ");
0263: }
0264:
0265: // Verify there is 1 tab
0266: tabTable = utils.getTabTable(wr);
0267: testTabs(tabTable, NUMBER_OF_TABS_FOR_RESOURCE,
0268: selectedTab, "Problem in 'Resource Adapter' tab.");
0269:
0270: // Go to 'earsample.ra-sample'
0271: link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
0272: URL_JONASADMIN_RA_SAMPLE);
0273: link.click();
0274: wr = wc.getFrameContents(FRAME_CONTENT);
0275: selectedTab = 2;
0276:
0277: // Verify Resource Adapter Infos
0278: table = utils.getTable(wr, 1);
0279: testRAInfos(table, name, file, path);
0280:
0281: // Verify 'In application'
0282: table = utils.getTable(wr, 4);
0283: testInApplication(table);
0284:
0285: // Verify 'Properties'
0286: table = utils.getTable(wr, 7);
0287: testEarSampleProperties(table);
0288:
0289: // Verify there are 2 tabs
0290: tabTable = utils.getTabTable(wr);
0291: testTabs(tabTable, NUMBER_OF_TABS_FOR_RA_SAMPLE,
0292: selectedTab,
0293: "Problem in 'earsample.ra-sample' tab.");
0294: }
0295:
0296: }
0297:
0298: /**
0299: * Test Resource service with a JONAS_jdbc rar.
0300: * @throws Exception if error occurs
0301: *
0302: */
0303: public void testResource10Jdbc() throws Exception {
0304:
0305: WebResponse wr;
0306: WebLink link;
0307: WebTable table;
0308: WebTable tabTable;
0309: int selectedTab;
0310: JonasAdminUtils utils = new JonasAdminUtils();
0311:
0312: // Disable errors of javascript
0313: HttpUnitOptions.setExceptionsThrownOnScriptError(false);
0314: // Disable exception thrown on error status
0315: HttpUnitOptions.setExceptionsThrownOnErrorStatus(false);
0316:
0317: // Test only if the resource service is enabled
0318: if (jProp.isResource()) {
0319: // Add db_access_jdbc1
0320: useRar("db_access_jdbc1");
0321:
0322: // Add alarm.ear to add the 4th tab "used by"
0323: unUseEar("alarm");
0324: useEar("alarm");
0325:
0326: // Go to resource adapters
0327: wr = wc.getFrameContents(FRAME_TREE);
0328: link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
0329: URL_JONASADMIN_RESOURCE);
0330: link.click();
0331: wr = wc.getFrameContents(FRAME_CONTENT);
0332:
0333: // Go to 'db_access_jdbc1'
0334: link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
0335: URL_JONASADMIN_JONAS_JDBC);
0336: link.click();
0337: wr = wc.getFrameContents(FRAME_CONTENT);
0338: selectedTab = 2;
0339:
0340: // Verify PoolProperties
0341: testPoolProperties(wr, wc);
0342:
0343: // Verify there are 4 tabs
0344: tabTable = utils.getTabTable(wr);
0345: testTabs(tabTable, NUMBER_OF_TABS_FOR_JDBC, selectedTab,
0346: "Problem in 'db_access_jdbc1' tab.");
0347: // - links
0348: assertTrue("The link " + URL_JONASADMIN_RESOURCE
0349: + " is not found in the first tab. ", tabTable
0350: .getTableCell(0, 0).getLinks()[0].getURLString()
0351: .endsWith(URL_JONASADMIN_RESOURCE));
0352: assertTrue("The link " + URL_JONASADMIN_STATISTICS
0353: + " is not found in the third tab. ", tabTable
0354: .getTableCell(0, 4).getLinks()[0].getURLString()
0355: .endsWith(URL_JONASADMIN_STATISTICS));
0356: assertTrue("The link " + URL_JONASADMIN_USED_BY
0357: + " is not found in the fourth tab. ", tabTable
0358: .getTableCell(0, 6).getLinks()[0].getURLString()
0359: .indexOf(URL_JONASADMIN_USED_BY) != -1);
0360:
0361: // Go to 'Statistics'
0362: link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
0363: URL_JONASADMIN_STATISTICS);
0364: link.click();
0365: wr = wc.getFrameContents(FRAME_CONTENT);
0366: selectedTab = 3;
0367:
0368: // Verify Connections Pool State
0369: table = utils.getTable(wr, 1);
0370: testConnectionsPoolState(table);
0371:
0372: // Verify Statistics on getConnection operations
0373: table = utils.getTable(wr, 4);
0374: testStatisticsOnGetConnectionOperations(table, wr, wc,
0375: utils);
0376:
0377: // Verify Statistics on waiters
0378: table = utils.getTable(wr, 7);
0379: testStatisticsOnWaiters(table);
0380:
0381: // Verify Connection to database statistics
0382: table = utils.getTable(wr, 10);
0383: testConnectionToDatabaseStatistics(table);
0384:
0385: // Verify there are 4 tabs
0386: tabTable = utils.getTabTable(wr);
0387: testTabs(tabTable, NUMBER_OF_TABS_FOR_JDBC, selectedTab,
0388: "Problem in 'Statistics' tab.");
0389: // - links
0390: assertTrue("The link " + URL_JONASADMIN_RESOURCE
0391: + " is not found in the first tab. ", tabTable
0392: .getTableCell(0, 0).getLinks()[0].getURLString()
0393: .endsWith(URL_JONASADMIN_RESOURCE));
0394: assertTrue("The link " + URL_JONASADMIN_RA
0395: + " is not found in the second tab. ", tabTable
0396: .getTableCell(0, 2).getLinks()[0].getURLString()
0397: .endsWith(URL_JONASADMIN_RA));
0398: assertTrue("The link " + URL_JONASADMIN_USED_BY
0399: + " is not found in the fourth tab. ", tabTable
0400: .getTableCell(0, 6).getLinks()[0].getURLString()
0401: .indexOf(URL_JONASADMIN_USED_BY) != -1);
0402:
0403: // Go to 'Used by'
0404: link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
0405: URL_JONASADMIN_USED_BY);
0406: if (link == null) {
0407: throw new IllegalStateException("The link "
0408: + URL_JONASADMIN_USED_BY
0409: + " is not found from 'Statistics' tab. ");
0410: }
0411: link.click();
0412: wr = wc.getFrameContents(FRAME_CONTENT);
0413: selectedTab = 4;
0414:
0415: // Verify 'Used by'
0416: table = utils.getTable(wr, 0);
0417: testUsedBy(table);
0418:
0419: // Verify there are 4 tabs
0420: tabTable = utils.getTabTable(wr);
0421: testTabs(tabTable, NUMBER_OF_TABS_FOR_JDBC, selectedTab,
0422: "Problem in 'Used by' tab.");
0423: // - links
0424: assertTrue("The link " + URL_JONASADMIN_RESOURCE
0425: + " is not found in the first tab. ", tabTable
0426: .getTableCell(0, 0).getLinks()[0].getURLString()
0427: .endsWith(URL_JONASADMIN_RESOURCE));
0428: assertTrue("The link " + URL_JONASADMIN_RA
0429: + " is not found in the second tab. ", tabTable
0430: .getTableCell(0, 2).getLinks()[0].getURLString()
0431: .endsWith(URL_JONASADMIN_RA));
0432: assertTrue("The link " + URL_JONASADMIN_STATISTICS
0433: + " is not found in the third tab. ", tabTable
0434: .getTableCell(0, 4).getLinks()[0].getURLString()
0435: .endsWith(URL_JONASADMIN_STATISTICS));
0436: }
0437: }
0438:
0439: /**
0440: * Test Resource Adapter 1.5 with ErsatzEIS.rar
0441: * @throws Exception if an error occurs
0442: */
0443: public void testResource15() throws Exception {
0444: WebResponse wr;
0445: WebLink link;
0446: WebTable table;
0447: WebTable tabTable;
0448: int selectedTab;
0449: JonasAdminUtils utils = new JonasAdminUtils();
0450:
0451: // Disable errors of javascript
0452: HttpUnitOptions.setExceptionsThrownOnScriptError(false);
0453: // Disable exception thrown on error status
0454: HttpUnitOptions.setExceptionsThrownOnErrorStatus(false);
0455:
0456: // Test only if the resource service is enabled
0457: if (jProp.isResource()) {
0458: // Add ErsatzEIS.rar
0459: useRar("ErsatzEIS");
0460:
0461: // Go to resource adapters
0462: wr = wc.getFrameContents(FRAME_TREE);
0463: link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
0464: URL_JONASADMIN_RESOURCE);
0465: link.click();
0466: wr = wc.getFrameContents(FRAME_CONTENT);
0467:
0468: // Go to 'ErsatzEIS.rar'
0469: link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
0470: URL_JONASADMIN_ERSATZ);
0471: link.click();
0472: wr = wc.getFrameContents(FRAME_CONTENT);
0473: selectedTab = 2;
0474:
0475: // Verify there are 4 tabs
0476: tabTable = utils.getTabTable(wr);
0477: testTabs(tabTable, NUMBER_OF_TABS_RA15, selectedTab,
0478: "Problem in 'ErsatzEIS' tab.");
0479: // - links
0480: assertTrue("The link " + URL_JONASADMIN_RESOURCE
0481: + " is not found in the first tab. ", tabTable
0482: .getTableCell(0, 0).getLinks()[0].getURLString()
0483: .endsWith(URL_JONASADMIN_RESOURCE));
0484: assertTrue("The link "
0485: + URL_JONASADMIN_CONNECTION_FACTORIES
0486: + " is not found in the third tab. ", tabTable
0487: .getTableCell(0, 4).getLinks()[0].getURLString()
0488: .endsWith(URL_JONASADMIN_CONNECTION_FACTORIES));
0489: assertTrue("The link " + URL_JONASADMIN_ACTIVATION_SPECS
0490: + " is not found in the fourth tab. ", tabTable
0491: .getTableCell(0, 6).getLinks()[0].getURLString()
0492: .endsWith(URL_JONASADMIN_ACTIVATION_SPECS));
0493:
0494: // Go to 'Connection Factories'
0495: link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
0496: URL_JONASADMIN_CONNECTION_FACTORIES);
0497: link.click();
0498: wr = wc.getFrameContents(FRAME_CONTENT);
0499: selectedTab = 3;
0500:
0501: // Verify there are 4 tabs
0502: tabTable = utils.getTabTable(wr);
0503: testTabs(tabTable, NUMBER_OF_TABS_RA15, selectedTab,
0504: "Problem in 'Connection Factories' tab.");
0505: // - links
0506: assertTrue("The link " + URL_JONASADMIN_RESOURCE
0507: + " is not found in the first tab. ", tabTable
0508: .getTableCell(0, 0).getLinks()[0].getURLString()
0509: .endsWith(URL_JONASADMIN_RESOURCE));
0510: assertTrue("The link " + URL_JONASADMIN_RA
0511: + " is not found in the second tab. ", tabTable
0512: .getTableCell(0, 2).getLinks()[0].getURLString()
0513: .indexOf(URL_JONASADMIN_RA) != -1);
0514: assertTrue("The link " + URL_JONASADMIN_ACTIVATION_SPECS
0515: + " is not found in the fourth tab. ", tabTable
0516: .getTableCell(0, 6).getLinks()[0].getURLString()
0517: .endsWith(URL_JONASADMIN_ACTIVATION_SPECS));
0518:
0519: // Test 'Connection Factories'
0520: table = utils.getTable(wr, 0);
0521: testConnectionFactories(table, wc, utils);
0522:
0523: // Go to 'ActivationSpecs'
0524: link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
0525: URL_JONASADMIN_ACTIVATION_SPECS);
0526: link.click();
0527: wr = wc.getFrameContents(FRAME_CONTENT);
0528: selectedTab = 4;
0529:
0530: // Verify there are 4 tabs
0531: tabTable = utils.getTabTable(wr);
0532: testTabs(tabTable, NUMBER_OF_TABS_RA15, selectedTab,
0533: "Problem in 'ActivationSpecs' tab.");
0534: // - links
0535: assertTrue("The link " + URL_JONASADMIN_RESOURCE
0536: + " is not found in the first tab. ", tabTable
0537: .getTableCell(0, 0).getLinks()[0].getURLString()
0538: .endsWith(URL_JONASADMIN_RESOURCE));
0539: assertTrue("The link " + URL_JONASADMIN_RA
0540: + " is not found in the second tab. ", tabTable
0541: .getTableCell(0, 2).getLinks()[0].getURLString()
0542: .indexOf(URL_JONASADMIN_RA) != -1);
0543: assertTrue("The link "
0544: + URL_JONASADMIN_CONNECTION_FACTORIES
0545: + " is not found in the third tab. ", tabTable
0546: .getTableCell(0, 4).getLinks()[0].getURLString()
0547: .endsWith(URL_JONASADMIN_CONNECTION_FACTORIES));
0548:
0549: // Test 'ActivationSpecs'
0550: table = utils.getTable(wr, 0);
0551: testActivationSpecs(table, wc, utils);
0552: }
0553: }
0554:
0555: /**
0556: * Test 'Resource Adapters' table
0557: * @param table the 'Resource Adapters' table
0558: */
0559: private void testResourceAdapterNames(WebTable table) {
0560: TableCell cell;
0561:
0562: for (int i = 1; i < table.getRowCount(); i++) {
0563: // Verify there is a link for each name
0564: cell = table.getTableCell(i, 0);
0565: assertEquals("There is no one link for the context : "
0566: + cell.getText(), 1, cell.getLinks().length);
0567: }
0568: }
0569:
0570: /**
0571: * Test the RA infos
0572: * @param table the RA info table
0573: * @param name the RA name
0574: * @param file the RA file
0575: * @param path the RA path
0576: */
0577: private void testRAInfos(WebTable table, String name, String file,
0578: String path) {
0579: assertEquals("It is not the name of the Resource Adapter. ",
0580: name, table.getTableCell(0, 2).getText());
0581: assertEquals("It is not the file of the Resource Adapter. ",
0582: file, table.getTableCell(1, 2).getText());
0583: assertEquals("It is not the path of the Resource Adapter. ",
0584: path, table.getTableCell(2, 2).getText());
0585: }
0586:
0587: /**
0588: * Test 'In Application' table
0589: * @param table 'In Application' table
0590: */
0591: private void testInApplication(WebTable table) {
0592: TableCell cell = table.getTableCell(0, 0);
0593: // There is 1 link
0594: assertEquals("There is not 1 link in 'In Application' table. ",
0595: 1, cell.getLinks().length);
0596: // earsample.ear
0597: assertEquals(
0598: "There is not 'earsample.ear' in 'In Application' table. ",
0599: "earsample.ear", cell.getText());
0600:
0601: cell = table.getTableCell(0, 2);
0602: // path
0603: assertTrue("It is not the end of the path. ", cell.getText()
0604: .endsWith(File.separator + "earsample.ear"));
0605: }
0606:
0607: /**
0608: * Test earsample.ra-sample properties
0609: * @param table the property table
0610: */
0611: private void testEarSampleProperties(WebTable table) {
0612: // EisURL EIS_URL
0613: TableCell cell = table.getTableCell(0, 0);
0614: assertEquals("It is not the name of the 1st property. ",
0615: "EisURL", cell.getText());
0616: cell = table.getTableCell(0, 2);
0617: assertEquals("It is not the value of the 1st property. ",
0618: "EIS_URL", cell.getText());
0619:
0620: // jndiName eisName
0621: cell = table.getTableCell(1, 0);
0622: assertEquals("It is not the name of the 2nd property. ",
0623: "jndiName", cell.getText());
0624: cell = table.getTableCell(1, 2);
0625: assertEquals("It is not the value of the 2nd property. ",
0626: "eisName", cell.getText());
0627: }
0628:
0629: /**
0630: * Test pool properties
0631: * @param wr the content frame of Resource Adapter page
0632: * @param wc the jonasAdmin WebConversation
0633: * @throws Exception if an error occurs
0634: */
0635: private void testPoolProperties(WebResponse wr, WebConversation wc)
0636: throws Exception {
0637: WebForm form = wr.getForms()[0];
0638: String jdbcConnCheckLevel = "0";
0639: String connMaxAge = "0";
0640: String maxOpentime = "0";
0641: String jdbcTestStatement = "";
0642: String maxSize = "-1";
0643: String minSize = "0";
0644: String maxWaitTime = "0";
0645: String maxWaiters = "0";
0646: String samplingPeriod = "30";
0647:
0648: ResourceUtils.modifyPoolProperties(form, jdbcConnCheckLevel,
0649: connMaxAge, maxOpentime, jdbcTestStatement, maxSize,
0650: minSize, maxWaitTime, maxWaiters, samplingPeriod);
0651:
0652: wr = wc.getFrameContents(FRAME_CONTENT);
0653: form = wr.getForms()[0];
0654: assertEquals("The value of 'Pool maximum' is not '-1'. ",
0655: maxSize, form.getParameterValue("maxSize"));
0656: assertEquals("The value of 'Maximum age' is not '" + connMaxAge
0657: + "'. ", connMaxAge, form
0658: .getParameterValue("connMaxAge"));
0659: assertEquals("The value of 'Maximum open time' is not '"
0660: + maxOpentime + "'. ", maxOpentime, form
0661: .getParameterValue("maxOpentime"));
0662: assertEquals("The value of 'Test' is not '" + jdbcTestStatement
0663: + "'. ", jdbcTestStatement, form
0664: .getParameterValue("jdbcTestStatement"));
0665: assertEquals("The value of 'Pool minimum' is not '" + minSize
0666: + "'. ", minSize, form.getParameterValue("minSize"));
0667: assertEquals("The value of 'Max Wait Time' is not '"
0668: + maxWaitTime + "'. ", maxWaitTime, form
0669: .getParameterValue("maxWaitTime"));
0670: assertEquals("The value of 'Max Waiters' is not '" + maxWaiters
0671: + "'. ", maxWaiters, form
0672: .getParameterValue("maxWaiters"));
0673: assertEquals("The value of 'Sampling Period' is not '"
0674: + samplingPeriod + "'. ", samplingPeriod, form
0675: .getParameterValue("samplingPeriod"));
0676: assertEquals("The value of 'Checking level' is not '"
0677: + jdbcConnCheckLevel + "'. ", jdbcConnCheckLevel, form
0678: .getParameterValue("jdbcConnCheckLevel"));
0679: }
0680:
0681: /**
0682: * Test Connections Pool State
0683: * @param table The connection pool state table
0684: */
0685: private void testConnectionsPoolState(WebTable table)
0686: throws Exception {
0687: ObjectName jcaConnFactOn = getJCAConnectionFactory("jdbc_1",
0688: "db_access_jdbc1");
0689: // Current pool size
0690: Integer val = getIntegerMBeanAttribute(jcaConnFactOn,
0691: "currentOpened");
0692: String currentPoolsize = val.toString();
0693: //assertEquals("It is not the expected value of 'Current pool size'. ", "1", table.getTableCell(0, 2).getText());
0694: assertEquals(
0695: "It is not the expected value of 'Current pool size'. ",
0696: currentPoolsize, table.getTableCell(0, 2).getText());
0697: // Busy connections
0698: val = getIntegerMBeanAttribute(jcaConnFactOn, "currentBusy");
0699: //assertEquals("It is not the expected value of 'Busy connections'. ", "0", table.getTableCell(1, 2).getText());
0700: assertEquals(
0701: "It is not the expected value of 'Busy connections'. ",
0702: val.toString(), table.getTableCell(1, 2).getText());
0703: // Busy in transactions
0704: val = getIntegerMBeanAttribute(jcaConnFactOn, "currentInTx");
0705: //assertEquals("It is not the expected value of 'Busy in transactions'. ", "0", table.getTableCell(2, 2).getText());
0706: assertEquals(
0707: "It is not the expected value of 'Busy in transactions'. ",
0708: val.toString(), table.getTableCell(2, 2).getText());
0709: // Min busy in last period
0710: val = getIntegerMBeanAttribute(jcaConnFactOn, "busyMin");
0711: //assertEquals("It is not the expected value of 'Min busy in last period'. ", "0", table.getTableCell(3, 2).getText());
0712: assertEquals(
0713: "It is not the expected value of 'Min busy in last period'. ",
0714: val.toString(), table.getTableCell(3, 2).getText());
0715: // Max busy in last period
0716: val = getIntegerMBeanAttribute(jcaConnFactOn, "busyMax");
0717: //assertEquals("It is not the expected value of 'Max busy in last period'. ", "0", table.getTableCell(4, 2).getText());
0718: assertEquals(
0719: "It is not the expected value of 'Max busy in last period'. ",
0720: val.toString(), table.getTableCell(4, 2).getText());
0721: // Connection leaks
0722: val = getIntegerMBeanAttribute(jcaConnFactOn, "connectionLeaks");
0723: //assertEquals("It is not the expected value of 'Connection leaks'. ", "0", table.getTableCell(5, 2).getText());
0724: assertEquals(
0725: "It is not the expected value of 'Connection leaks'. ",
0726: val.toString(), table.getTableCell(5, 2).getText());
0727: }
0728:
0729: /**
0730: * Test Statistics On GetConnection Operations
0731: * @param table The 'Statistics on getConnection operations' table
0732: * @param wr the content frame
0733: * @param wc the jonasAdmin connection
0734: * @param utils jonasAdmin utils
0735: * @throws Exception if an error occurs
0736: */
0737: private void testStatisticsOnGetConnectionOperations(
0738: WebTable table, WebResponse wr, WebConversation wc,
0739: JonasAdminUtils utils) throws Exception {
0740: Button button;
0741: int servedConnections = Integer.parseInt(table.getTableCell(0,
0742: 2).getText());
0743: // Create connections
0744: createConnections();
0745: //Refresh
0746: wc.sendRequest(wr.getRefreshRequest());
0747: wr = wc.getFrameContents(FRAME_CONTENT);
0748: table = utils.getTable(wr, 4);
0749:
0750: // Served connections have increased
0751: assertTrue(
0752: "The 'Served connections' number has not increased. ",
0753: servedConnections < Integer.parseInt(table
0754: .getTableCell(0, 2).getText()));
0755: // Rejected connections 0
0756: assertEquals(
0757: "The value of 'Rejected connections' is not '0'. ",
0758: "0", table.getTableCell(1, 2).getText());
0759: // By waiter overflow 0
0760: assertEquals("The value of 'By waiter overflow' is not '0'. ",
0761: "0", table.getTableCell(2, 2).getText());
0762: // By waiter timeout 0
0763: assertEquals("The value of 'By waiter timeout' is not '0'. ",
0764: "0", table.getTableCell(3, 2).getText());
0765: // By any other reason 0
0766: assertEquals("The value of 'By any other reason' is not '0'. ",
0767: "0", table.getTableCell(4, 2).getText());
0768: }
0769:
0770: /**
0771: * Test 'Used By' infos and link
0772: * @param table the 'Used by' table
0773: * @throws Exception if an error occurs to send request.
0774: */
0775: private void testUsedBy(WebTable table) throws Exception {
0776: WebLink link;
0777: // Ejb AlarmRecord
0778: assertEquals("It is not used by 'AlarmRecord'. ",
0779: "AlarmRecord", table.getTableCell(1, 0).getText());
0780: link = table.getTableCell(1, 0).getLinks()[0];
0781: int code = wc.sendRequest(link.getRequest()).getResponseCode();
0782: assertEquals("The '" + link.getURLString()
0783: + "' link creates a '" + code + "' error. ", 200, code);
0784: // Type EntityBean
0785: assertEquals("It is not the Type of AlarmRecord. ",
0786: "EntityBean", table.getTableCell(1, 1).getText());
0787: }
0788:
0789: /**
0790: * Test Statistics On Waiters
0791: * @param table the 'Statistics On Waiters' table
0792: * @throws Exception if an error occurs.
0793: */
0794: private void testStatisticsOnWaiters(WebTable table)
0795: throws Exception {
0796: // Current number of waiters 0
0797: int nbWaiters = Integer.parseInt(table.getTableCell(0, 2)
0798: .getText());
0799: // Max waiters 0
0800: int maxWaiters = Integer.parseInt(table.getTableCell(1, 2)
0801: .getText());
0802: // Max waiters in last period 0
0803: int maxWaitersLastPeriod = Integer.parseInt(table.getTableCell(
0804: 2, 2).getText());
0805: // Total waiters 0
0806: int totalWaiters = Integer.parseInt(table.getTableCell(3, 2)
0807: .getText());
0808: // Max waiting time 0
0809: int maxWaitingTime = Integer.parseInt(table.getTableCell(4, 2)
0810: .getText());
0811: // Max waiting in last period 0
0812: int maxWaitingLastPeriod = Integer.parseInt(table.getTableCell(
0813: 5, 2).getText());
0814: // Total waiting 0
0815: int totalWaiting = Integer.parseInt(table.getTableCell(6, 2)
0816: .getText());
0817:
0818: // 0 < nbWaiters < maxWaitersLastPeriod < maxWaiters < totalWaiters
0819: assertTrue("The current number of waiters is not positif. ",
0820: 0 <= nbWaiters);
0821: assertTrue("Current number of waiters > Max waiters. ",
0822: nbWaiters <= maxWaitersLastPeriod);
0823: assertTrue("Max waiters > Max waiters in last period. ",
0824: maxWaitersLastPeriod <= maxWaiters);
0825: assertTrue("Max waiters in last period > Total waiters. ",
0826: maxWaiters <= totalWaiters);
0827:
0828: // 0 < maxWaitingLastPeriod < maxWaitingTime < totalWaiting
0829: assertTrue("Max waiting in last period < 0. ",
0830: 0 <= maxWaitingLastPeriod);
0831: assertTrue("Max waiting time < Max waiting in last period. ",
0832: maxWaitingLastPeriod <= maxWaitingTime);
0833: assertTrue("Max waiting time > Total waiting. ",
0834: maxWaitingTime <= totalWaiting);
0835: }
0836:
0837: /**
0838: * Test Connection To Database Statistics
0839: * @param table the 'Connection To Database Statistics' table
0840: */
0841: private void testConnectionToDatabaseStatistics(WebTable table) {
0842: // Number of connections > 0
0843: int nbConnections = Integer.parseInt(table.getTableCell(0, 2)
0844: .getText());
0845: // Number of failures 0
0846: int nbFailures = Integer.parseInt(table.getTableCell(1, 2)
0847: .getText());
0848:
0849: assertTrue("The number of connections is not positif. ",
0850: 0 < nbConnections);
0851: assertEquals("The expected number of failures was '0'. ", 0,
0852: nbFailures);
0853: }
0854:
0855: /**
0856: * Test connection factories
0857: * @param table the 'connection factories' table
0858: * @param wc the jonasAdmin connection
0859: * @param utils the jonasAdmin utils
0860: * @throws Exception if an error occurs
0861: */
0862: private void testConnectionFactories(WebTable table,
0863: WebConversation wc, JonasAdminUtils utils) throws Exception {
0864: WebResponse wr;
0865: WebLink link;
0866: WebTable tabTable;
0867: TableCell cell;
0868: int selectedTab;
0869:
0870: cell = table.getTableCell(1, 0);
0871: // Name eis/ErsatzEIS
0872: assertEquals(
0873: "It is not the expeted name of Connection Factory",
0874: "eis/ErsatzEIS", cell.getText());
0875:
0876: // Go to 'eis/ErsatzEIS'
0877: link = cell.getLinks()[0];
0878: link.click();
0879: wr = wc.getFrameContents(FRAME_CONTENT);
0880: selectedTab = 5;
0881:
0882: // Verify there are 6 tabs
0883: tabTable = utils.getTabTable(wr);
0884: testTabs(tabTable, NUMBER_OF_TABS_CF, selectedTab,
0885: "Problem in 'Connection Factory' tab.");
0886: // - links
0887: assertTrue("The link " + URL_JONASADMIN_RESOURCE
0888: + " is not found in the first tab. ", tabTable
0889: .getTableCell(0, 0).getLinks()[0].getURLString()
0890: .endsWith(URL_JONASADMIN_RESOURCE));
0891: assertTrue("The link " + URL_JONASADMIN_RA
0892: + " is not found in the second tab. ", tabTable
0893: .getTableCell(0, 2).getLinks()[0].getURLString()
0894: .indexOf(URL_JONASADMIN_RA) != -1);
0895: assertTrue("The link " + URL_JONASADMIN_CONNECTION_FACTORIES
0896: + " is not found in the third tab. ", tabTable
0897: .getTableCell(0, 4).getLinks()[0].getURLString()
0898: .endsWith(URL_JONASADMIN_CONNECTION_FACTORIES));
0899: assertTrue("The link " + URL_JONASADMIN_ACTIVATION_SPECS
0900: + " is not found in the fourth tab. ", tabTable
0901: .getTableCell(0, 6).getLinks()[0].getURLString()
0902: .endsWith(URL_JONASADMIN_ACTIVATION_SPECS));
0903: assertTrue("The link " + URL_JONASADMIN_STATISTICS_CF
0904: + " is not found in the sixth tab. ", tabTable
0905: .getTableCell(0, 10).getLinks()[0].getURLString()
0906: .endsWith(URL_JONASADMIN_STATISTICS_CF));
0907:
0908: // Verify there are 10 tables
0909: try {
0910: // Try to get the last table with 'Apply' button.
0911: table = utils.getTable(wr, 9);
0912: } catch (ArrayIndexOutOfBoundsException e) {
0913: fail("The number of tables is too little in the content frame of the connection factory page. ");
0914: }
0915: try {
0916: // Try to get the eleventh table that doesn't exist.
0917: table = utils.getTable(wr, 10);
0918: fail("The number of tables is too big in the content frame of the connection factory page. ");
0919: } catch (ArrayIndexOutOfBoundsException e) {
0920: // ok
0921: }
0922:
0923: // Go to 'Statistics'
0924: link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
0925: URL_JONASADMIN_STATISTICS_CF);
0926: link.click();
0927: wr = wc.getFrameContents(FRAME_CONTENT);
0928: selectedTab = 6;
0929:
0930: // Verify there are 6 tabs
0931: tabTable = utils.getTabTable(wr);
0932: testTabs(tabTable, NUMBER_OF_TABS_CF, selectedTab,
0933: "Problem in CF 'Statistics' tab. ");
0934: // - links
0935: assertTrue("The link " + URL_JONASADMIN_RESOURCE
0936: + " is not found in the first tab. ", tabTable
0937: .getTableCell(0, 0).getLinks()[0].getURLString()
0938: .endsWith(URL_JONASADMIN_RESOURCE));
0939: assertTrue("The link " + URL_JONASADMIN_RA
0940: + " is not found in the second tab. ", tabTable
0941: .getTableCell(0, 2).getLinks()[0].getURLString()
0942: .indexOf(URL_JONASADMIN_RA) != -1);
0943: assertTrue("The link " + URL_JONASADMIN_CONNECTION_FACTORIES
0944: + " is not found in the third tab. ", tabTable
0945: .getTableCell(0, 4).getLinks()[0].getURLString()
0946: .endsWith(URL_JONASADMIN_CONNECTION_FACTORIES));
0947: assertTrue("The link " + URL_JONASADMIN_ACTIVATION_SPECS
0948: + " is not found in the fourth tab. ", tabTable
0949: .getTableCell(0, 6).getLinks()[0].getURLString()
0950: .endsWith(URL_JONASADMIN_ACTIVATION_SPECS));
0951: assertTrue("The link " + URL_JONASADMIN_RA_CF
0952: + " is not found in the fifth tab. ", tabTable
0953: .getTableCell(0, 8).getLinks()[0].getURLString()
0954: .endsWith(URL_JONASADMIN_RA_CF));
0955:
0956: // Verify there are 13 tables
0957: try {
0958: // Try to get the last table with 'Apply' button.
0959: table = utils.getTable(wr, 12);
0960: } catch (ArrayIndexOutOfBoundsException e) {
0961: fail("The number of tables is too little in the content frame of the CF statistic page. ");
0962: }
0963: try {
0964: // Try to get the fourteenth table that doesn't exist.
0965: table = utils.getTable(wr, 13);
0966: fail("The number of tables is too big in the content frame of the CF statistic page. ");
0967: } catch (ArrayIndexOutOfBoundsException e) {
0968: // ok
0969: }
0970:
0971: }
0972:
0973: /**
0974: * Test Activation Specs
0975: * @param table the 'ActivationSpecs' table
0976: * @param wc the jonasAdmin connection
0977: * @param utils the jonasAdmin utils
0978: * @throws Exception if an error occurs
0979: */
0980: private void testActivationSpecs(WebTable table,
0981: WebConversation wc, JonasAdminUtils utils) throws Exception {
0982: WebResponse wr;
0983: WebLink link;
0984: WebTable tabTable;
0985: TableCell cell;
0986: int selectedTab;
0987:
0988: cell = table.getTableCell(1, 0);
0989: // Name eis/ErsatzAS
0990: assertEquals("It is not the expeted name of ActivationSpec",
0991: "eis/ErsatzAS", cell.getText());
0992:
0993: // Go to 'eis/ErsatzAS'
0994: link = cell.getLinks()[0];
0995: link.click();
0996: wr = wc.getFrameContents(FRAME_CONTENT);
0997: selectedTab = 5;
0998:
0999: // Verify there are 5 tabs
1000: tabTable = utils.getTabTable(wr);
1001: testTabs(tabTable, NUMBER_OF_TABS_AS, selectedTab,
1002: "Problem in 'ActivationSpecs' tab.");
1003: // - links
1004: assertTrue("The link " + URL_JONASADMIN_RESOURCE
1005: + " is not found in the first tab. ", tabTable
1006: .getTableCell(0, 0).getLinks()[0].getURLString()
1007: .endsWith(URL_JONASADMIN_RESOURCE));
1008: assertTrue("The link " + URL_JONASADMIN_RA
1009: + " is not found in the second tab. ", tabTable
1010: .getTableCell(0, 2).getLinks()[0].getURLString()
1011: .indexOf(URL_JONASADMIN_RA) != -1);
1012: assertTrue("The link " + URL_JONASADMIN_CONNECTION_FACTORIES
1013: + " is not found in the third tab. ", tabTable
1014: .getTableCell(0, 4).getLinks()[0].getURLString()
1015: .endsWith(URL_JONASADMIN_CONNECTION_FACTORIES));
1016: assertTrue("The link " + URL_JONASADMIN_ACTIVATION_SPECS
1017: + " is not found in the fourth tab. ", tabTable
1018: .getTableCell(0, 6).getLinks()[0].getURLString()
1019: .endsWith(URL_JONASADMIN_ACTIVATION_SPECS));
1020:
1021: // Verify there are 5 tables
1022: try {
1023: // Try to get the last table with required properties.
1024: table = utils.getTable(wr, 4);
1025: } catch (ArrayIndexOutOfBoundsException e) {
1026: fail("The number of tables is too little in the content frame of the activation spec page. ");
1027: }
1028: try {
1029: // Try to get the eleventh table that doesn't exist.
1030: table = utils.getTable(wr, 5);
1031: fail("The number of tables is too big in the content frame of the activation spec page. ");
1032: } catch (ArrayIndexOutOfBoundsException e) {
1033: // ok
1034: }
1035: }
1036:
1037: /**
1038: * Use Alarm Demo for creating connections
1039: * @throws Exception if an error occurs
1040: */
1041: private void createConnections() throws Exception {
1042: WebConversation wc2 = new WebConversation();
1043: String urlAlarm = prefixUrl + "/alarm/secured/list.jsp";
1044: // Start the alarm demo
1045: wc2.setAuthorization("jonas", "jonas");
1046: WebResponse wr = wc2.getResponse(urlAlarm);
1047: }
1048:
1049: /**
1050: * Tear Down cleanUp action
1051: * @throws Exception if an error occurs
1052: */
1053: public void tearDown() throws Exception {
1054: super.tearDown();
1055: }
1056: }
|