1 36 package org.columba.ristretto.auth; 37 38 import java.util.List ; 39 40 import junit.framework.TestCase; 41 42 import org.columba.ristretto.auth.mechanism.PlainMechanism; 43 44 public class AuthenticationFactoryTest extends TestCase { 45 46 public void testSupports() { 47 assertEquals(AuthenticationFactory.getInstance().isSupported("PLAIN"), true ); 48 assertEquals(AuthenticationFactory.getInstance().isSupported("XYZ"), false ); 49 } 50 51 public void testGetSupportedMechanisms() { 52 List mechanisms = AuthenticationFactory.getInstance().getSupportedMechanisms(); 53 54 assertNotNull( mechanisms ); 55 assertEquals( mechanisms.size() >= 2, true); 56 } 57 58 public void testGetSecurestMechanism() { 59 try { 60 assertEquals( AuthenticationFactory.getInstance().getSecurestMethod("AUTH LOGIN PLAIN"), "LOGIN" ); 61 } catch (NoSuchAuthenticationException e) { 62 fail(e.getMessage()); 63 } 64 65 try { 66 assertEquals( AuthenticationFactory.getInstance().getSecurestMethod("AUTH XYZ PLAIN"), "PLAIN" ); 67 } catch (NoSuchAuthenticationException e) { 68 fail(e.getMessage()); 69 } 70 71 try { 72 AuthenticationFactory.getInstance().getSecurestMethod("AUTH XYZ UVW"); 73 fail(); 74 } catch (NoSuchAuthenticationException e) { 75 assertEquals( e.getMessage(),"AUTH XYZ UVW" ); 76 } 77 } 78 79 public void testGetAuthenticationMethod() { 80 try { 81 assertTrue( AuthenticationFactory.getInstance().getAuthentication("PLAIN") instanceof PlainMechanism); 82 } catch (NoSuchAuthenticationException e) { 83 fail(e.getMessage()); 84 } 85 86 try { 87 AuthenticationFactory.getInstance().getAuthentication("XYZ"); 88 fail(); 89 } catch (NoSuchAuthenticationException e) { 90 assertEquals( e.getMessage(), "XYZ"); 91 } 92 93 } 94 } 95 | Popular Tags |