Source Code Cross Referenced for SQLAuthorizationPropTest.java in  » Database-DBMS » db-derby-10.2 » org » apache » derbyTesting » functionTests » tests » lang » 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 DBMS » db derby 10.2 » org.apache.derbyTesting.functionTests.tests.lang 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *
003:         * Derby - Class org.apache.derbyTesting.functionTests.lang.SQLAuthorizationPropTest
004:         *
005:         * Licensed to the Apache Software Foundation (ASF) under one or more
006:         * contributor license agreements.  See the NOTICE file distributed with
007:         * this work for additional information regarding copyright ownership.
008:         * The ASF licenses this file to You under the Apache License, Version 2.0
009:         * (the "License"); you may not use this file except in compliance with
010:         * the License.  You may obtain a copy of the License at
011:         *
012:         *    http://www.apache.org/licenses/LICENSE-2.0
013:         *
014:         * Unless required by applicable law or agreed to in writing, 
015:         * software distributed under the License is distributed on an 
016:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
017:         * either express or implied. See the License for the specific 
018:         * language governing permissions and limitations under the License.
019:         */
020:
021:        package org.apache.derbyTesting.functionTests.tests.lang;
022:
023:        import java.io.IOException;
024:        import java.sql.CallableStatement;
025:        import java.sql.Connection;
026:        import java.sql.PreparedStatement;
027:        import java.sql.SQLException;
028:        import java.sql.Statement;
029:        import java.util.Properties;
030:
031:        import junit.framework.Test;
032:        import junit.framework.TestSuite;
033:
034:        import org.apache.derbyTesting.junit.BaseJDBCTestCase;
035:        import org.apache.derbyTesting.junit.DatabasePropertyTestSetup;
036:        import org.apache.derbyTesting.functionTests.util.SQLStateConstants;
037:
038:        public class SQLAuthorizationPropTest extends BaseJDBCTestCase {
039:
040:            public SQLAuthorizationPropTest(String name) {
041:                super (name);
042:            }
043:
044:            public static Test suite() {
045:                TestSuite suite = new TestSuite();
046:                suite.addTestSuite(SQLAuthorizationPropTest.class);
047:
048:                // Use DatabasePropertyTestSetup decorator to set the property
049:                // required by this test. 
050:                Properties props = new Properties();
051:                props.setProperty("derby.database.sqlAuthorization", "true");
052:                Test test = new SQLAuthorizationPropTest(
053:                        "grantRevokeAfterSettingSQLAuthProperty");
054:                suite.addTest(new DatabasePropertyTestSetup(test, props));
055:
056:                // This test has to be run after SQL authorization property has been 
057:                // set to true. 
058:                suite.addTest(new SQLAuthorizationPropTest(
059:                        "resetSQLAuthProperty"));
060:
061:                return suite;
062:            }
063:
064:            /**
065:             * Create a table to test grant/revoke statements
066:             */
067:            protected void setUp() throws SQLException {
068:                Statement stmt = createStatement();
069:                stmt.execute("create table GR_TAB (id int)");
070:                stmt.close();
071:            }
072:
073:            /**
074:             * Drop the table created during setup.
075:             * @throws Exception 
076:             */
077:            protected void tearDown() throws Exception {
078:                Statement stmt = createStatement();
079:                stmt.execute("drop table GR_TAB");
080:                stmt.close();
081:                super .tearDown();
082:            }
083:
084:            /**
085:             * This method tests that grant/revoke is not available if 
086:             * derby.database.sqlAuthorization property is not set.
087:             * 
088:             * @throws SQLException
089:             */
090:            public void testGrantRevokeWithoutSQLAuthProperty()
091:                    throws SQLException {
092:                Statement stmt = createStatement();
093:
094:                try {
095:                    stmt.execute("grant select on GR_TAB to some_user");
096:                    fail("FAIL: Grant statement should have failed when SQL authorization is not set");
097:                } catch (SQLException sqle) {
098:                    assertSQLState(
099:                            SQLStateConstants.LANG_GRANT_REVOKE_WITH_LEGACY_ACCESS,
100:                            sqle);
101:                }
102:
103:                try {
104:                    stmt.execute("revoke select on GR_TAB from some_user");
105:                    fail("FAIL: Revoke statement should have failed when SQL authorization is not set");
106:                } catch (SQLException sqle) {
107:                    assertSQLState(
108:                            SQLStateConstants.LANG_GRANT_REVOKE_WITH_LEGACY_ACCESS,
109:                            sqle);
110:                }
111:                stmt.close();
112:            }
113:
114:            /**
115:             * This method tests that grant/revoke is available 
116:             * once derby.database.sqlAuthorization property is set to true.
117:             * 
118:             * @throws SQLException
119:             */
120:            public void grantRevokeAfterSettingSQLAuthProperty()
121:                    throws SQLException {
122:                // Shutdown the database for derby.database.sqlAuthorization property 
123:                // to take effect. This was set by DatabasePropertyTestSetup decorator.
124:                try {
125:                    getDefaultConnection("shutdown=true");
126:                    fail("FAIL: Failed to shutdown database");
127:                } catch (SQLException sqle) {
128:                    assertSQLState(SQLStateConstants.SHUTDOWN_DATABASE, sqle);
129:                }
130:
131:                Statement stmt = createStatement();
132:                stmt.execute("grant select on GR_TAB to some_user");
133:                stmt.execute("revoke select on GR_TAB from some_user");
134:                stmt.close();
135:            }
136:
137:            /**
138:             * This method tests that once derby.database.sqlAuthorization property 
139:             * has been set to true, it cannot be reset to any other value. For the 
140:             * test to be valid, it must follow the test method which sets 
141:             * derby.database.sqlAuthorization property to true.
142:             * 
143:             * @throws SQLException
144:             */
145:            public void resetSQLAuthProperty() throws SQLException {
146:                Connection conn = getConnection();
147:                conn.setAutoCommit(false);
148:
149:                CallableStatement setDBP = conn
150:                        .prepareCall("CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY(?, ?)");
151:                setDBP.setString(1, "derby.database.sqlAuthorization");
152:                // Resetting to any value other than true should fail
153:                testPropertyReset(setDBP, "false");
154:                testPropertyReset(setDBP, null);
155:                testPropertyReset(setDBP, "some_value");
156:                // This should work
157:                testPropertyReset(setDBP, "true");
158:            }
159:
160:            /**
161:             * This method executes a callable statement to set the database property
162:             * to a given value. It checks that reset to any value other than "true" 
163:             * fails.
164:             * 
165:             * @param cs CallableStatement object used to set database property
166:             * @param value value of database property
167:             * @throws SQLException
168:             */
169:            public void testPropertyReset(CallableStatement cs, String value)
170:                    throws SQLException {
171:
172:                cs.setString(2, value);
173:
174:                try {
175:                    cs.executeUpdate();
176:                    if (value.compareToIgnoreCase("true") != 0)
177:                        fail("FAIL: Should not be possible to reset sql authorization once it has been turned on");
178:                } catch (SQLException sqle) {
179:                    assertSQLState(
180:                            SQLStateConstants.PROPERTY_UNSUPPORTED_CHANGE, sqle);
181:                }
182:
183:            }
184:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.