Source Code Cross Referenced for BlackboxTests.java in  » Database-ORM » Velosurf » blackbox » 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 » Database ORM » Velosurf » blackbox 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package blackbox;
002:
003:        import java.io.PrintWriter;
004:        import java.util.Arrays;
005:
006:        import org.junit.*;
007:        import static org.junit.Assert.*;
008:
009:        import com.meterware.httpunit.*;
010:
011:        import velosurf.util.Logger;
012:
013:        public class BlackboxTests {
014:
015:            /* TODO parametrize the port number with ant property ${test.webcontainer.port}
016:               (requires a filtered copy of the source files) */
017:            public static final int SERVER_PORT = 8081;
018:
019:            private void checkText(WebResponse resp, String id, String text)
020:                    throws Exception {
021:                HTMLElement element = resp.getElementWithID(id);
022:                assertNotNull(element);
023:                assertEquals(text, element.getText());
024:            }
025:
026:            public @BeforeClass
027:            static void initLogger() throws Exception {
028:                Logger.setWriter(new PrintWriter("log/blackbox.log"));
029:            }
030:
031:            public @Test
032:            void basicTests() throws Exception {
033:                WebConversation wc = new WebConversation();
034:                WebRequest req = new GetMethodWebRequest("http://localhost:"
035:                        + SERVER_PORT + "/basic.html");
036:                WebResponse resp = wc.getResponse(req);
037:                checkText(resp, "test1", "Addison Wesley Professional");
038:                checkText(resp, "test2.1", "Effective Java");
039:                checkText(resp, "test2.2", "TCP/IP Illustrated, Volume 1");
040:                assertNull(resp.getElementWithID("test2.3"));
041:                checkText(resp, "test3", "Effective Java");
042:                checkText(resp, "test4", "Joshua Bloch");
043:            }
044:
045:            public @Test
046:            void paramfetching() throws Exception {
047:                WebConversation wc = new WebConversation();
048:                WebRequest req = new GetMethodWebRequest("http://localhost:"
049:                        + SERVER_PORT + "/obfuscate.html?id=1");
050:                WebResponse resp = wc.getResponse(req);
051:                String obfId = resp.getElementWithID("obfuscated").getText();
052:                req = new GetMethodWebRequest("http://localhost:" + SERVER_PORT
053:                        + "/fetch.html?publisher_id=" + obfId + "&book_id="
054:                        + obfId);
055:                resp = wc.getResponse(req);
056:                checkText(resp, "publisher", "Addison Wesley Professional");
057:                checkText(resp, "book", "Effective Java");
058:            }
059:
060:            public @Test
061:            void authentication() throws Exception {
062:                /* try to reach a protected resource */
063:                WebConversation wc = new WebConversation();
064:                WebRequest req = new GetMethodWebRequest("http://localhost:"
065:                        + SERVER_PORT + "/auth/protected.html");
066:                WebResponse resp = wc.getResponse(req);
067:                assertEquals("Login", resp.getTitle());
068:                /* log in */
069:                WebForm form = resp.getFormWithName("login");
070:                form.setParameter("login", "foo");
071:                form.setParameter("password", "bar");
072:                resp = form.submit();
073:                /* check we reach the initially requested resource */
074:                assertEquals("protected", resp.getTitle());
075:                /* log out */
076:                WebLink logout = resp.getLinkWith("logout");
077:                assertNotNull(logout);
078:                resp = logout.click();
079:                assertEquals("Login", resp.getTitle());
080:                /* bad login */
081:                form = resp.getFormWithName("login");
082:                form.setParameter("login", "foo");
083:                form.setParameter("password", "badpass");
084:                resp = form.submit();
085:                assertEquals("Login", resp.getTitle());
086:                String msg = resp.getElementWithID("message").getText();
087:                /* in english or french, may depend of the system */
088:                assertTrue(Arrays
089:                        .asList(
090:                                new String[] { "Bad login or password.",
091:                                        "Mauvais login ou mot de passe...",
092:                                        "badLogin" }).contains(msg));
093:                /* log in again, check we reach the auth index */
094:                form = resp.getFormWithName("login");
095:                form.setParameter("login", "foo");
096:                form.setParameter("password", "bar");
097:                resp = form.submit();
098:                assertEquals("Protected Index", resp.getTitle());
099:            }
100:
101:            public @Test
102:            void validation() throws Exception {
103:                WebConversation wc = new WebConversation();
104:                WebRequest req = new GetMethodWebRequest("http://localhost:"
105:                        + SERVER_PORT + "/input.html");
106:                WebResponse resp = wc.getResponse(req);
107:                assertEquals("Input form", resp.getTitle());
108:                /* first try with bad values */
109:                WebForm form = resp.getFormWithName("input");
110:                form.setParameter("string", "aa");
111:                form.setParameter("string2", "123-1234");
112:                form.setParameter("number", "0");
113:                form.setParameter("oneof", "test0");
114:                form.setParameter("mydate", "2-7-2006");
115:                form.setParameter("email", "toto@tata@titi");
116:                //form.setParameter("email2",(String)null);
117:                form.setParameter("book_id", "0");
118:                resp = form.submit();
119:                assertEquals("Input form", resp.getTitle());
120:                /* check error messages */
121:                checkText(resp, "1",
122:                        "field string: value 'aa' is not of the proper length");
123:                checkText(resp, "2",
124:                        "field string2: value '123-1234' is not valid");
125:                checkText(resp, "3",
126:                        "field number: '0' is not in the valid range");
127:                checkText(resp, "4",
128:                        "field oneof: value 'test0' must be one of: test1, test2, test3");
129:                checkText(resp, "5",
130:                        "field mydate: '2-7-2006' is not a valid date or is outside range");
131:                checkText(resp, "6",
132:                        "field email: 'toto@tata@titi' is not a valid email");
133:                checkText(resp, "7", "field email2 cannot be empty");
134:                checkText(resp, "8",
135:                        "field book_id: value '0' not found in book.book_id");
136:                assertNull(resp.getElementWithID("9"));
137:                /* check that the form retained the values */
138:                form = resp.getFormWithName("input");
139:                assertEquals("aa", form.getParameterValue("string"));
140:                assertEquals("123-1234", form.getParameterValue("string2"));
141:                assertEquals("0", form.getParameterValue("number"));
142:                assertEquals("test0", form.getParameterValue("oneof"));
143:                assertEquals("2-7-2006", form.getParameterValue("mydate"));
144:                assertEquals("toto@tata@titi", form.getParameterValue("email"));
145:                assertEquals("", form.getParameterValue("email2"));
146:                assertEquals("0", form.getParameterValue("book_id"));
147:                /* resubmit with good values excecpt for email2*/
148:                form.setParameter("string", "aaaaaa");
149:                form.setParameter("string2", "123-123");
150:                form.setParameter("number", "1");
151:                form.setParameter("oneof", "test1");
152:                form.setParameter("mydate", "2-8-2006");
153:                form.setParameter("email", "claude@renegat.net");
154:                form.setParameter("book_id", "1");
155:                /* test DNS email checking */
156:                form.setParameter("email2", "toto@azerty.blabla");
157:                resp = form.submit();
158:                assertEquals("Input form", resp.getTitle());
159:                checkText(resp, "1",
160:                        "field email2: 'toto@azerty.blabla' is not a valid email");
161:                assertNull(resp.getElementWithID("2"));
162:                /* test SMTP email checking */
163:                form = resp.getFormWithName("input");
164:                form.setParameter("email2", "inexistant_email@gmail.com");
165:                resp = form.submit();
166:                assertEquals("Input form", resp.getTitle());
167:                checkText(resp, "1",
168:                        "field email2: 'inexistant_email@gmail.com' is not a valid email");
169:                assertNull(resp.getElementWithID("2"));
170:                /* now with a valid email... */
171:                form = resp.getFormWithName("input");
172:                form.setParameter("email2", "claude.brisson@gmail.com");
173:                resp = form.submit();
174:                assertEquals("Good values!", resp.getTitle());
175:            }
176:
177:            public @Test
178:            void xinclude() throws Exception {
179:                WebConversation wc = new WebConversation();
180:                WebRequest req = new GetMethodWebRequest("http://localhost:"
181:                        + SERVER_PORT + "/xinclude.html");
182:                WebResponse resp = wc.getResponse(req);
183:                assertEquals("XInclude", resp.getTitle());
184:                checkText(resp, "result", "1");
185:            }
186:
187:            public @Test
188:            void testinsert() throws Exception {
189:                WebConversation wc = new WebConversation();
190:                WebRequest req = new GetMethodWebRequest("http://localhost:"
191:                        + SERVER_PORT + "/insert.html");
192:                WebResponse resp = wc.getResponse(req);
193:                checkText(resp, "result", "3");
194:            }
195:
196:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.