Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

AuthToolTest.java

Go to the documentation of this file.
00001 package net.threebit.utils.sosc.test;
00002 
00003 /*
00004         Copyright 2003 Shawn Deleurme
00005         Copyright 2003 Kevin O'Donnell
00006 
00007         This program is free software; you can redistribute it and/or modify
00008         it under the terms of the GNU General Public License as published by
00009         the Free Software Foundation; either version 2 of the License, or
00010         (at your option) any later version.
00011 
00012         This program is distributed in the hope that it will be useful,
00013         but WITHOUT ANY WARRANTY; without even the implied warranty of
00014         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015         GNU General Public License for more details.
00016 
00017         You should have received a copy of the GNU General Public License
00018         along with this program; if not, write to the Free Software
00019         Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 */
00021 
00022 import java.io.*;
00023 import java.sql.*;
00024 import java.util.*;
00025 import java.util.logging.*;
00026 import junit.framework.*;
00027 import net.threebit.utils.sosc.*;
00028 
00033 public class AuthToolTest extends TestCase {
00034 
00035         String tablePrefix = System.getProperty("net.threebit.utils.sosc.AuthTool.tablePrefix");
00036         DbTool db = null;
00037 
00038         private AuthTool getAuthTool() throws Exception {
00039                 String url = System.getProperty("net.threebit.utils.sosc.DbTool.jdbcURL");
00040                 String className = System.getProperty("net.threebit.utils.sosc.DbTool.jdbcURLClassName");
00041                 String userName = System.getProperty("net.threebit.utils.sosc.DbTool.jdbcURLUserName");
00042                 String password = System.getProperty("net.threebit.utils.sosc.DbTool.jdbcURLPassword");
00043                 db = new DbTool(className, url, userName, password);
00044                 AuthTool at = new AuthTool(db, tablePrefix);
00045                 at.refreshSchema();
00046                 return at;
00047         }
00048 
00049         public void test1() throws Exception {
00050 
00051                 AuthTool at = getAuthTool();
00052                 ResultSet r;
00053                 r = db.query(" select * from " + at.userTable() + "; "); assertTrue( db.rowCount(r) == 0 );
00054                 r = db.query(" select * from " + at.groupTable() + "; "); assertTrue( db.rowCount(r) == 0 );
00055                 r = db.query(" select * from " + at.groupMemberTable() + "; "); assertTrue( db.rowCount(r) == 0 );
00056 
00057                 at.addUser("user1","pw1");
00058                 r = db.query(" select * from " + at.userTable() + "; "); assertTrue( db.rowCount(r) == 1 );
00059                 at.addGroup("group1");
00060                 r = db.query(" select * from " + at.groupTable() + "; "); assertTrue( db.rowCount(r) == 1 );
00061                 at.addGroupMember("group1","user1");
00062                 r = db.query(" select * from " + at.groupMemberTable() + "; "); assertTrue( db.rowCount(r) == 1 );
00063 
00064                 assertTrue( at.authenticate("user1","pw1") );
00065                 assertTrue(! at.authenticate("user1","pw") );
00066                 assertTrue(! at.authenticate("user","pw1") );
00067 
00068                 assertTrue( at.isGroupMember("group1","user1"));
00069                 assertTrue(! at.isGroupMember("group","user1"));
00070 
00071                 at.removeGroupMember("group1","user1");
00072                 assertTrue(! at.isGroupMember("group1","user1"));
00073         }
00074 
00075         public void test2() throws Exception {
00076                 AuthTool at = getAuthTool();
00077                 String userName = "" + (new java.util.Date()).hashCode();
00078                 String email = "test@test.com";
00079                 at.addUser(userName,"testPW",email);
00080                 assertTrue(email.equals(at.getUserEmail(userName)));
00081         }
00082 
00083 
00084 }

Generated on Mon Jul 14 17:19:19 2003 for SOSC by doxygen1.2.15