1 31 32 package org.apache.commons.httpclient; 33 34 import junit.framework.Test; 35 import junit.framework.TestCase; 36 import junit.framework.TestSuite; 37 38 45 public class TestCredentials extends TestCase { 46 47 public TestCredentials(String testName) { 49 super(testName); 50 } 51 52 public static void main(String args[]) { 54 String [] testCaseName = { TestCredentials.class.getName() }; 55 junit.textui.TestRunner.main(testCaseName); 56 } 57 58 60 public static Test suite() { 61 return new TestSuite(TestCredentials.class); 62 } 63 64 public void testCredentialConstructors() { 65 try { 66 new UsernamePasswordCredentials(null, null); 67 fail("IllegalArgumentException should have been thrown"); 68 } catch (IllegalArgumentException e) { 69 } 71 try { 72 new NTCredentials("user", "password", null, null); 73 fail("IllegalArgumentException should have been thrown"); 74 } catch (IllegalArgumentException e) { 75 } 77 try { 78 new NTCredentials("user", "password", "host", null); 79 fail("IllegalArgumentException should have been thrown"); 80 } catch (IllegalArgumentException e) { 81 } 83 NTCredentials creds = new NTCredentials("user", null, "host", "domain"); 84 assertNotNull(creds.getUserName()); 85 assertNull(creds.getPassword()); 86 assertNotNull(creds.getDomain()); 87 assertNotNull(creds.getHost()); 88 } 89 90 93 public void testCredentialEquals() { 94 95 Credentials creds1 = new UsernamePasswordCredentials("user1", "password1"); 96 Credentials creds1Again = new UsernamePasswordCredentials("user1", "password1"); 97 Credentials creds2 = new UsernamePasswordCredentials("user2", "password2"); 98 Credentials creds3 = new UsernamePasswordCredentials("user3", null); 99 Credentials creds3Again = new UsernamePasswordCredentials("user3", null); 100 101 assertEquals(creds1, creds1Again); 102 assertNotSame(creds1, creds2); 103 assertEquals(creds3, creds3Again); 104 105 Credentials ntCreds1 = new NTCredentials("user1", "password1", "host1", "domain1"); 106 Credentials ntCreds1Again = new NTCredentials("user1", "password1", "host1", "domain1"); 107 Credentials ntCreds2 = new NTCredentials("user1", "password2", "host1", "domain1"); 108 Credentials ntCreds3 = new NTCredentials("user1", "password1", "host2", "domain1"); 109 Credentials ntCreds4 = new NTCredentials("user1", "password1", "host1", "domain2"); 110 111 assertEquals(ntCreds1, ntCreds1Again); 112 assertNotSame(ntCreds1, creds1); 113 assertNotSame(creds1, ntCreds1); 114 assertNotSame(ntCreds1, ntCreds2); 115 assertNotSame(ntCreds1, ntCreds3); 116 assertNotSame(ntCreds1, ntCreds4); 117 } 118 } 119 | Popular Tags |