Source Code Cross Referenced for C_alarm.java in  » J2EE » JOnAS-4.8.6 » org » objectweb » jonas » examples » clients » alarm » 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.examples.clients.alarm 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * JOnAS: Java(TM) Open Application Server
003:         * Copyright (C) 1999 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:         * Initial developer: Florent BENOIT
022:         * --------------------------------------------------------------------------
023:         * $Id: C_alarm.java 10557 2007-06-07 09:21:44Z coqp $
024:         * --------------------------------------------------------------------------
025:         */
026:
027:        package org.objectweb.jonas.examples.clients.alarm;
028:
029:        import junit.framework.TestSuite;
030:
031:        import org.objectweb.jonas.examples.util.JExampleTestCase;
032:
033:        import com.meterware.httpunit.AuthorizationRequiredException;
034:        import com.meterware.httpunit.TableCell;
035:        import com.meterware.httpunit.WebForm;
036:        import com.meterware.httpunit.WebLink;
037:        import com.meterware.httpunit.WebResponse;
038:        import com.meterware.httpunit.WebTable;
039:
040:        /**
041:         * Define a class to test the Alarm example
042:         * Test authentication, generate alarm and process alarms
043:         * @author Florent Benoit
044:         */
045:        public class C_alarm extends JExampleTestCase {
046:
047:            /**
048:             * URL of the alarm index
049:             */
050:            private static final String URL_ALARM = "/alarm/secured/list.jsp";
051:
052:            /**
053:             * URL of the list of alarms
054:             */
055:            private static final String URL_ALARM_LIST = "/alarm/secured/setfilter.jsp?profil=all-I";
056:
057:            /**
058:             * URL of the alarm generator
059:             */
060:            private static final String URL_ALARM_GENERATE = "/alarm/generator.html";
061:
062:            /**
063:             * Main method
064:             * @param args the arguments
065:             */
066:            public static void main(String[] args) {
067:
068:                String testtorun = null;
069:                // Get args
070:                for (int argn = 0; argn < args.length; argn++) {
071:                    String sArg = args[argn];
072:                    if (sArg.equals("-n")) {
073:                        testtorun = args[++argn];
074:                    }
075:                }
076:
077:                if (testtorun == null) {
078:                    junit.textui.TestRunner.run(suite());
079:                } else {
080:                    junit.textui.TestRunner.run(new C_alarm(testtorun));
081:                }
082:            }
083:
084:            /**
085:             * Get a new TestSuite for this class
086:             * @return a new TestSuite for this class
087:             */
088:            public static TestSuite suite() {
089:                return new TestSuite(C_alarm.class);
090:            }
091:
092:            /**
093:             * Setup need for these tests
094:             * alarm is required
095:             * @throws Exception if it fails
096:             */
097:            protected void setUp() throws Exception {
098:                super .setUp();
099:                useEar("alarm");
100:            }
101:
102:            /**
103:             * Constructor with a specified name
104:             * @param s name
105:             */
106:            public C_alarm(String s) {
107:                super (s, URL_ALARM);
108:            }
109:
110:            /**
111:             * Try to log in without authentication
112:             * @throws Exception if an error occurs
113:             */
114:            public void testTryWithoutAuth() throws Exception {
115:                try {
116:                    WebResponse wr = wc.getResponse(url);
117:                    fail("Alarm is not protected");
118:                } catch (AuthorizationRequiredException e) {
119:                    ;
120:                }
121:            }
122:
123:            /**
124:             * Try to authenticate with a bad login/password
125:             * @throws Exception if an error occurs
126:             */
127:            public void testTryWithBadAuth() throws Exception {
128:                try {
129:                    wc.setAuthorization("bad", "bad");
130:                    WebResponse wr = wc.getResponse(url);
131:                    fail("Alarm is not protected");
132:                } catch (AuthorizationRequiredException e) {
133:                    ;
134:                }
135:            }
136:
137:            /**
138:             * Try to authenticate with a right login/password (jetty)
139:             * @throws Exception if an error occurs
140:             */
141:            public void testTryWithJettyAuth() throws Exception {
142:                try {
143:                    wc.setAuthorization("jetty", "jetty");
144:                    WebResponse wr = wc.getResponse(url);
145:                } catch (AuthorizationRequiredException e) {
146:                    fail("Alarm don't accept l/p jetty/jetty");
147:                }
148:            }
149:
150:            /**
151:             * Try to authenticate with a right login/password (tomcat)
152:             * @throws Exception if an error occurs
153:             */
154:            public void testTryWithTomcatAuth() throws Exception {
155:                try {
156:                    wc.setAuthorization("tomcat", "tomcat");
157:                    WebResponse wr = wc.getResponse(url);
158:                } catch (AuthorizationRequiredException e) {
159:                    fail("Alarm don't accept l/p tomcat/tomcat");
160:                }
161:            }
162:
163:            /**
164:             * Try to generate alarms. One of each kind of alarm (severe, informative, warning)
165:             * @throws Exception if an error occurs
166:             */
167:            public void testGenerateAlarms() throws Exception {
168:                try {
169:                    wc.setAuthorization("tomcat", "tomcat");
170:                    WebResponse wr = wc
171:                            .getResponse(getAbsoluteUrl(URL_ALARM_GENERATE));
172:
173:                    WebForm[] webForms = wr.getForms();
174:
175:                    WebForm webForm = webForms[0];
176:                    assertNotNull("There must be a form in the html page",
177:                            webForm);
178:
179:                    String[] levels = new String[] { "S", "W", "I" };
180:
181:                    for (int i = 0; i < 3; i++) {
182:                        webForm.setParameter("message", "Automatic test" + i);
183:                        webForm.setParameter("device", "aut" + i);
184:                        webForm.setParameter("level", levels[i]);
185:                        WebResponse wFormRes = webForm.submit();
186:                        String txt = wFormRes.getText();
187:                        if (txt.indexOf("Message sent") == -1) {
188:                            fail("The alarm was not generated : " + txt);
189:                        }
190:                    }
191:
192:                } catch (AuthorizationRequiredException e) {
193:                    fail("Alarm don't accept l/p tomcat/tomcat");
194:                }
195:            }
196:
197:            /**
198:             * Try to process all alarms which were generated
199:             * @throws Exception if an error occurs
200:             */
201:            public void testProcessAlarms() throws Exception {
202:                try {
203:                    // Wait a little if the previous alarms were not generated
204:                    Thread.sleep(1000);
205:
206:                    wc.setAuthorization("tomcat", "tomcat");
207:                    WebResponse wr = wc
208:                            .getResponse(getAbsoluteUrl(URL_ALARM_LIST));
209:                    WebTable[] webTables = wr.getTables();
210:
211:                    WebTable wTable = webTables[1];
212:                    assertNotNull("There must be a table in the html page",
213:                            wTable);
214:
215:                    int rows = wTable.getRowCount();
216:                    int cols = wTable.getColumnCount();
217:
218:                    assertEquals("The tables must have 6 columns", 6, cols);
219:
220:                    // For each alarm
221:                    for (int i = 1; i < rows; i++) {
222:                        TableCell tableCell = wTable.getTableCell(i, cols - 1);
223:                        assertNotNull("There must be a cell in this row",
224:                                tableCell);
225:                        WebLink[] links = tableCell.getLinks();
226:                        assertNotNull("There must have links in this cell",
227:                                links);
228:                        for (int l = 0; l < links.length; l++) {
229:                            links[l].click();
230:                        }
231:                    }
232:
233:                    //Now check alarms are empty (rows = 1)
234:                    wr = wc.getResponse(getAbsoluteUrl(URL_ALARM_LIST));
235:                    webTables = wr.getTables();
236:                    wTable = webTables[1];
237:                    rows = wTable.getRowCount();
238:                    assertEquals(1, rows);
239:
240:                } catch (AuthorizationRequiredException e) {
241:                    fail("Authentication failed");
242:                }
243:            }
244:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.