1   ////////////////////////////////////////////////////////////////////////////////
2   //CabaWeb
3   //Copyright (C) 2004  Thomas Vogt <Thomas.Vogt@TVC-Software.com>
4   //
5   //This library is free software; you can redistribute it and/or
6   //modify it under the terms of the GNU Lesser General Public
7   //License as published by the Free Software Foundation; either
8   //version 2.1 of the License, or (at your option) any later version.
9   //
10  //This library is distributed in the hope that it will be useful,
11  //but WITHOUT ANY WARRANTY; without even the implied warranty of
12  //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  //Lesser General Public License for more details.
14  //
15  //You should have received a copy of the GNU Lesser General Public
16  //License along with this library; if not, write to the Free Software
17  //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  ////////////////////////////////////////////////////////////////////////////////
19  
20  package org.fhw.cabaweb.junittests;
21  
22  import org.fhw.cabaweb.tools.Password;
23  
24  import junit.framework.TestCase;
25  
26  /***
27   * Klasse f&uuml;r den Test der Passwortfunktionen
28   *
29   * @author  <a href="mailto:thomas.vogt@tvc-software.com">Thomas Vogt</a>
30   * @version Version 1.0 10.03.2004
31   */
32  public class PasswordTest extends TestCase
33  {
34  
35  	public static void main(String args[])
36  	{
37  		//		junit.swingui.TestRunner.run(PasswordTest.class);
38  		junit.textui.TestRunner.run(PasswordTest.class);
39  	}
40  
41  	public void testPasswortGenerator()
42  	{
43  		assertNotNull("", Password.passwortGenerator(0));
44  		assertNotNull("", Password.passwortGenerator(8));
45  	}
46  
47  	public void testGenerateMD5()
48  	{
49  		assertNotNull("", Password.generateMD5(null));
50  		assertNotNull("", Password.generateMD5(""));
51  		assertNotNull("", Password.generateMD5("test"));
52  		assertEquals(Password.generateMD5("test"), Password.generateMD5("test"));
53  		assertEquals(Password.generateMD5("1234test1234"), Password.generateMD5("1234test1234"));
54  	}
55  
56  	public void testCompareMD5Hashes()
57  	{
58  		assertEquals(new Boolean(true), Password.compareMD5Hashes("", ""));
59  		assertEquals(
60  			new Boolean(true),
61          Password.compareMD5Hashes("d41d8cd98f00b204e9800998ecf8427e", "d41d8cd98f00b204e9800998ecf8427e"));
62          assertEquals(
63              new Boolean(true),
64              Password.compareMD5Hashes("daa912465bf0b1fc24a2edfb147eb899", "daa912465bf0b1fc24a2edfb147eb899"));
65          assertEquals(
66              new Boolean(false),
67              Password.compareMD5Hashes("daa912465bf0b1fc24a2edfb147eb899", "daa912465bf0b1fc24a2edfb147eb898"));
68  	}
69  
70  	public void testCompareMD5HashToString()
71  	{
72  		assertEquals(new Boolean(true), Password.compareMD5HashToString("d41d8cd98f00b204e9800998ecf8427e", ""));
73          assertEquals(new Boolean(true), Password.compareMD5HashToString("098f6bcd4621d373cade4e832627b4f6", "test"));
74          assertEquals(new Boolean(false), Password.compareMD5HashToString("098f6bcd4621d373cade4e832627b4f6", "test2"));
75  	}
76  
77  }