Source Code Cross Referenced for F_JonasAdminLogger.java in  » J2EE » JOnAS-4.8.6 » org » objectweb » jonas » jonasadmin » test » logging » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » JOnAS 4.8.6 » org.objectweb.jonas.jonasadmin.test.logging 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * JOnAS: Java(TM) Open Application Server
003:         * Copyright (C) 2005 Bull S.A.
004:         * Contact: jonas-team@objectweb.org
005:         *
006:         * This library is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU Lesser General Public
008:         * License as published by the Free Software Foundation; either
009:         * version 2.1 of the License, or 1any later version.
010:         *
011:         * This library is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         * Lesser General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU Lesser General Public
017:         * License along with this library; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
019:         * USA
020:         *
021:         * --------------------------------------------------------------------------
022:         * $Id: F_JonasAdminLogger.java 7381 2005-09-14 16:00:02Z kemlerp $
023:         * --------------------------------------------------------------------------
024:         */package org.objectweb.jonas.jonasadmin.test.logging;
025:
026:        import junit.framework.TestSuite;
027:
028:        import org.objectweb.jonas.jonasadmin.test.util.JonasAdminAuth;
029:        import org.objectweb.jonas.jonasadmin.test.util.JonasAdminTestCase;
030:        import org.objectweb.jonas.jonasadmin.test.util.JonasAdminUtils;
031:        import org.xml.sax.SAXException;
032:
033:        import com.meterware.httpunit.HttpUnitOptions;
034:        import com.meterware.httpunit.SubmitButton;
035:        import com.meterware.httpunit.WebConversation;
036:        import com.meterware.httpunit.WebForm;
037:        import com.meterware.httpunit.WebLink;
038:        import com.meterware.httpunit.WebResponse;
039:        import com.meterware.httpunit.WebTable;
040:
041:        /**
042:         * Define a class to test the JOnAS Admin console
043:         * Test logging
044:         * @author Paul Kemler
045:         *
046:         */
047:        public class F_JonasAdminLogger extends JonasAdminTestCase {
048:
049:            /**
050:             * URL of Jonas Logger
051:             */
052:            private static final String URL_JONASADMIN_JONAS_LOGGER = "/EditLoggingJonas.do";
053:
054:            /**
055:             * INPUT Checkbox
056:             */
057:            private static final String INPUT_CHECKBOX = "input type=\"checkbox\"";
058:
059:            /**
060:             * Title logger type
061:             */
062:            private static final String TITLE_LOGGER_TYPE = "Logger type";
063:
064:            /**
065:             * Title container type
066:             */
067:            private static final String TITLE_CONTAINER_TYPE = "Container type";
068:
069:            /**
070:             * Title container name
071:             */
072:            private static final String TITLE_CONTAINER_NAME = "Container name (or path)";
073:
074:            /**
075:             * A 2nd connection to jonasAdmin
076:             */
077:            private static WebConversation wc2 = new WebConversation();
078:
079:            /**
080:             * Constructor with a specified name
081:             * @param s name
082:             */
083:            public F_JonasAdminLogger(String s) {
084:                super (s, URL_JONASADMIN);
085:            }
086:
087:            /**
088:             * Main method
089:             * @param args the arguments
090:             */
091:            public static void main(String[] args) {
092:
093:                String testtorun = null;
094:                // Get args
095:                for (int argn = 0; argn < args.length; argn++) {
096:                    String sArg = args[argn];
097:                    if (sArg.equals("-n")) {
098:                        testtorun = args[++argn];
099:                    }
100:                }
101:                if (testtorun == null) {
102:                    junit.textui.TestRunner.run(suite());
103:                } else {
104:                    junit.textui.TestRunner.run(new F_JonasAdminLogger(
105:                            testtorun));
106:                }
107:            }
108:
109:            /**
110:             * Get a new TestSuite for this class
111:             * @return a new TestSuite for this class
112:             */
113:            public static TestSuite suite() {
114:                return new TestSuite(F_JonasAdminLogger.class);
115:            }
116:
117:            /**
118:             * Setup need for these tests
119:             * jonasAdmin is required
120:             * @throws Exception if it fails
121:             */
122:            protected void setUp() throws Exception {
123:                super .setUp();
124:
125:                if (wc.getCurrentPage().getURL() == null) {
126:                    useWar("jonasAdmin");
127:                    // login to jonas admin
128:                    try {
129:                        JonasAdminAuth.doValidAuth(wc, url);
130:                    } catch (Exception e) {
131:                        fail("authentification failed :  " + e);
132:                    }
133:                } else {
134:                    // if there was an error, the connection must be restablished
135:                    try {
136:                        wc.getFrameContents(FRAME_TREE);
137:                    } catch (Exception e) {
138:                        wc.getResponse(urlLogOut);
139:                        // login to jonas admin
140:                        try {
141:                            JonasAdminAuth.doValidAuth(wc, url);
142:                        } catch (Exception auth) {
143:                            fail("authentification failed :  " + auth);
144:                        }
145:                    }
146:                }
147:            }
148:
149:            /**
150:             * Test creation, modification et removal acces log valves
151:             * @throws Exception if error occurs
152:             *
153:             */
154:            public void testLoggers() throws Exception {
155:
156:                WebResponse wr;
157:                WebLink link;
158:                WebTable table;
159:                WebForm form;
160:                String host = "localhost";
161:                int row;
162:                int columnLoggerType;
163:                JonasAdminUtils utils = new JonasAdminUtils();
164:
165:                // Disable errors of javascript
166:                HttpUnitOptions.setExceptionsThrownOnScriptError(false);
167:                // Disable exception thrown on error status
168:                HttpUnitOptions.setExceptionsThrownOnErrorStatus(false);
169:
170:                // OPEN A SECOND CONNECTION
171:                // login to jonas admin
172:                try {
173:                    JonasAdminAuth.doValidAuth(wc2, url);
174:                } catch (Exception e) {
175:                    fail("authentification failed :  " + e);
176:                }
177:
178:                if (jProp.isCatalina()) {
179:                    wr = LoggerUtils.getLoggerPage(wc);
180:                    table = utils.getTable(wr, 3);
181:
182:                    if (table.getRowCount() == 2) {
183:                        assertFalse("There is a remove button. ", wr.getText()
184:                                .indexOf("'remove'") != -1);
185:                    } else {
186:                        assertTrue(
187:                                "There is no remove button but there is no one and only one logger. ",
188:                                wr.getText().indexOf("'remove'") != -1);
189:                    }
190:
191:                    // 1-Create new loggers
192:                    LoggerUtils.createNewEngineLogger(wc);
193:                    // Verify
194:                    wr = LoggerUtils.getLoggerPage(wc);
195:                    table = utils.getTable(wr, 3);
196:                    form = wr.getForms()[0];
197:                    columnLoggerType = utils
198:                            .getColumn(TITLE_LOGGER_TYPE, table).intValue();
199:                    row = utils.getFirstRow("Access log valve engine", table,
200:                            columnLoggerType).intValue();
201:                    if (row == -1) {
202:                        throw new IllegalThreadStateException(
203:                                "There is no row, which contains 'Access log valve engine'. ");
204:                    }
205:                    assertEquals("There is no the correct number of loggers. ",
206:                            3, table.getRowCount());
207:                    assertTrue("There is no remove button. ", wr.getText()
208:                            .indexOf("'remove'") != -1);
209:                    assertEquals(
210:                            "There is no the correct number of parameters in the form. ",
211:                            2, form.getParameterNames().length);
212:                    assertTrue("There is no checkbox", wr.getText().indexOf(
213:                            INPUT_CHECKBOX) != -1);
214:                    assertEquals("The container type is not 'Engine'. ",
215:                            "Engine", table.getTableCell(
216:                                    row,
217:                                    utils
218:                                            .getColumn(TITLE_CONTAINER_TYPE,
219:                                                    table).intValue())
220:                                    .getText());
221:                    assertEquals("The container name is not 'engine'. ",
222:                            "engine", table.getTableCell(
223:                                    row,
224:                                    utils
225:                                            .getColumn(TITLE_CONTAINER_NAME,
226:                                                    table).intValue())
227:                                    .getText());
228:
229:                    LoggerUtils.createNewHostLogger(wc);
230:                    // Verify
231:                    wr = LoggerUtils.getLoggerPage(wc);
232:                    table = utils.getTable(wr, 3);
233:                    form = wr.getForms()[0];
234:                    row = utils.getFirstRow("Access log valve " + host, table,
235:                            columnLoggerType).intValue();
236:                    if (row == -1) {
237:                        throw new IllegalThreadStateException(
238:                                "There is no row, which contains 'Access log valve "
239:                                        + host + "'. ");
240:                    }
241:                    assertEquals("There is no the correct number of loggers. ",
242:                            4, table.getRowCount());
243:                    assertTrue("There is no remove button. ", wr.getText()
244:                            .indexOf("'remove'") != -1);
245:                    assertEquals(
246:                            "There is no the correct number of parameters in the form. ",
247:                            2, form.getParameterNames().length);
248:                    assertEquals("The container type is not 'Host'. ", "Host",
249:                            table.getTableCell(
250:                                    row,
251:                                    utils
252:                                            .getColumn(TITLE_CONTAINER_TYPE,
253:                                                    table).intValue())
254:                                    .getText());
255:                    assertEquals("The container name is not '" + host + "'. ",
256:                            host, table.getTableCell(
257:                                    row,
258:                                    utils
259:                                            .getColumn(TITLE_CONTAINER_NAME,
260:                                                    table).intValue())
261:                                    .getText());
262:
263:                    // 2-Modify loggers
264:                    LoggerUtils.modifyLogger(wc, null, "dir", "true", "false",
265:                            ".suffix", "prefix_", "%v");
266:                    // Verify
267:                    wr = wc.getFrameContents(FRAME_CONTENT);
268:                    verifyAccessLogValve(wr, "dir", "true", "false", ".suffix",
269:                            "prefix_", "%v");
270:
271:                    LoggerUtils.modifyLogger(wc, host, "dir", "true", "false",
272:                            ".suffix", "prefix_", "%v");
273:                    // Verify
274:                    wr = wc.getFrameContents(FRAME_CONTENT);
275:                    verifyAccessLogValve(wr, "dir", "true", "false", ".suffix",
276:                            "prefix_", "%v");
277:
278:                    // 3-Remove loggers
279:                    LoggerUtils.deleteLogger(wc, null);
280:                    // Verify
281:                    wr = LoggerUtils.getLoggerPage(wc);
282:                    table = utils.getTable(wr, 3);
283:                    assertEquals("The number of loggers is not 2. ", 3, table
284:                            .getRowCount());
285:
286:                    LoggerUtils.deleteLogger(wc, host);
287:                    // Verify
288:                    wr = LoggerUtils.getLoggerPage(wc);
289:                    table = utils.getTable(wr, 3);
290:                    assertEquals("The number of loggers is not 1. ", 2, table
291:                            .getRowCount());
292:                }
293:            }
294:
295:            /**
296:             * Test JOnAS logger
297:             * @throws Exception if error occurs
298:             */
299:            public void testJonasLogger() throws Exception {
300:
301:                if (jProp.isCatalina()) {
302:                    WebResponse wr;
303:                    WebLink link;
304:                    WebTable table;
305:                    WebForm form;
306:                    SubmitButton button = null;
307:                    int row;
308:                    int columnLevels;
309:                    int columnTopics;
310:                    JonasAdminUtils utils = new JonasAdminUtils();
311:
312:                    // Disable errors of javascript
313:                    HttpUnitOptions.setExceptionsThrownOnScriptError(false);
314:                    // Disable exception thrown on error status
315:                    HttpUnitOptions.setExceptionsThrownOnErrorStatus(false);
316:
317:                    wr = LoggerUtils.getLoggerPage(wc);
318:                    link = wr.getFirstMatchingLink(WebLink.MATCH_URL_STRING,
319:                            URL_JONASADMIN_JONAS_LOGGER);
320:                    if (link != null) {
321:                        link.click();
322:                    } else {
323:                        throw new IllegalThreadStateException("The link "
324:                                + URL_JONASADMIN_JONAS_LOGGER
325:                                + " is not found. ");
326:                    }
327:
328:                    // Verify topics
329:                    wr = wc.getFrameContents(FRAME_CONTENT);
330:                    table = utils.getTable(wr, 3);
331:                    form = wr.getForms()[0];
332:                    String[] topics = form.getOptions("topic");
333:                    columnTopics = utils.getColumn("Topics", table).intValue();
334:                    if (columnTopics == -1) {
335:                        throw new IllegalThreadStateException(
336:                                "There is no column, which contains 'Topics'. ");
337:                    }
338:                    assertEquals(
339:                            "Number of topics is not the same in the select menu and in the table.",
340:                            topics.length, table.getRowCount() - 1);
341:                    for (int i = 0; i < topics.length; i++) {
342:                        assertEquals("Topic " + topics[i]
343:                                + " is not found in the table. ", topics[i],
344:                                table.getTableCell(i + 1, columnTopics)
345:                                        .getText());
346:                    }
347:
348:                    // Modify level of a topic
349:                    columnLevels = utils.getColumn("Levels", table).intValue();
350:                    if (columnLevels == -1) {
351:                        throw new IllegalThreadStateException(
352:                                "There is no column, which contains 'Levels'. ");
353:                    }
354:                    String level = table.getTableCell(topics.length,
355:                            columnLevels).getText();
356:                    String topic = "org.objectweb.jonas.web";
357:                    if (level.equals("WARN")) {
358:                        level = "INFO";
359:                    } else if (level.equals("INFO")) {
360:                        level = "ERROR";
361:                    } else if (level.equals("FATAL")) {
362:                        level = "INHERIT";
363:                    } else if (level.equals("INHERIT")) {
364:                        level = "DEBUG";
365:                    } else if (level.equals("DEBUG")) {
366:                        level = "WARN";
367:                    }
368:
369:                    form.setParameter("topic", topic);
370:                    form.setParameter("level", level);
371:
372:                    button = form.getSubmitButtons()[0];
373:                    button.click();
374:
375:                    // Verify topics
376:                    wr = wc.getFrameContents(FRAME_CONTENT);
377:                    table = utils.getTable(wr, 3);
378:                    if (level.equals("ERROR")) {
379:                        level = "FATAL";
380:                    }
381:                    row = utils.getFirstRow(topic, table, columnTopics)
382:                            .intValue();
383:                    if (row == -1) {
384:                        throw new IllegalThreadStateException(
385:                                "There is no row, which contains '" + topic
386:                                        + "' in the topic column. ");
387:                    }
388:                    assertEquals("The level of " + topic + " is not " + level
389:                            + ". ", level, table
390:                            .getTableCell(row, columnLevels).getText());
391:                }
392:            }
393:
394:            /**
395:             * Verify access log valve properties
396:             * @param wr Content frame
397:             * @param directory value of the directory parameter
398:             * @param resolveHosts value of the resolveHosts parameter
399:             * @param rotatable value of the rotatable parameter
400:             * @param suffix value of the suffix parameter
401:             * @param prefix value of the prefix parameter
402:             * @param pattern value of the pattern parameter
403:             * @throws SAXException if an error occurs while form is got
404:             */
405:            private void verifyAccessLogValve(WebResponse wr, String directory,
406:                    String resolveHosts, String rotatable, String suffix,
407:                    String prefix, String pattern) throws SAXException {
408:                WebForm form = wr.getForms()[0];
409:                assertEquals("Directory value is not" + directory + ". ",
410:                        directory, form.getParameterValue("directory"));
411:                assertEquals(
412:                        "Resolve hosts value is not" + resolveHosts + ". ",
413:                        resolveHosts, form.getParameterValue("resolveHosts"));
414:                assertEquals("Rotatable value is not" + rotatable + ". ",
415:                        rotatable, form.getParameterValue("rotatable"));
416:                assertEquals("Suffix value is not" + suffix + ". ", suffix,
417:                        form.getParameterValue("suffix"));
418:                assertEquals("Prefix value is not" + prefix + ". ", prefix,
419:                        form.getParameterValue("prefix"));
420:                assertEquals("Pattern value is not" + pattern + ". ", pattern,
421:                        form.getParameterValue("pattern"));
422:            }
423:
424:            /**
425:             * Tear Down cleanUp action
426:             * @throws Exception if an error occurs
427:             */
428:            public void tearDown() throws Exception {
429:                super.tearDown();
430:            }
431:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.