1 16 17 package org.apache.jetspeed.services.security; 18 19 import junit.framework.Test; 21 import junit.framework.TestSuite; 22 23 import org.apache.turbine.services.TurbineServices; 24 import org.apache.turbine.util.TurbineConfig; 25 import org.apache.turbine.util.StringUtils; 26 27 import org.apache.jetspeed.test.JetspeedTestCase; 29 import org.apache.jetspeed.om.security.JetspeedUser; 30 31 37 38 public class TestPortalAuthentication extends JetspeedTestCase { 39 40 45 public TestPortalAuthentication( String name ) { 46 super( name ); 47 } 48 49 54 public static void main(String args[]) 55 { 56 junit.awtui.TestRunner.main( new String [] { TestPortalAuthentication.class.getName() } ); 57 } 58 59 public void setup() 60 { 61 System.out.println("Setup: Testing Turbine Authentication"); 62 } 63 64 70 public static Test suite() 71 { 72 return new TestSuite( TestPortalAuthentication.class ); 74 } 75 76 77 82 83 public void testLogin() throws Exception 84 { 85 setup(); 86 87 PortalAuthentication service = getService(); 88 JetspeedUser user = null; 89 90 try 91 { 92 user = service.login("baduser", "badpassword"); 93 } 94 catch (Exception e) 95 { 96 System.out.println("exception = " + e.toString()); 97 assertTrue(e instanceof FailedLoginException); 98 } 99 try 100 { 101 user = service.login("turbine", "badpassword"); 102 } 103 catch (Exception e) 104 { 105 System.out.println("e = " + e); 106 assertTrue(e instanceof FailedLoginException); 107 } 108 try 109 { 110 user = service.login("turbine", "turbine"); 111 } 112 catch (Exception e) 113 { 114 fail(StringUtils.stackTrace(e)); 115 } 116 117 assertTrue(user.hasLoggedIn() == true); 118 119 System.out.println("Completed Login Test OK "); 120 121 } 122 123 128 129 public void testGetAnonymousUser() 130 { 131 setup(); 132 133 PortalAuthentication service = getService(); 134 JetspeedUser user = null; 135 136 try 137 { 138 user = service.getAnonymousUser(); 139 } 140 catch (Exception e) 141 { 142 fail(StringUtils.stackTrace(e)); 143 } 144 145 assertTrue(user.hasLoggedIn() == false); 146 147 System.out.println("Completed Anonymous Test OK"); 148 149 } 150 151 152 156 private static TurbineConfig config = null; 157 158 162 static 163 { 164 try 165 { 166 config = new TurbineConfig( "webapp", "/WEB-INF/conf/TurbineResources.properties"); 167 config.init(); 168 } 169 catch (Exception e) 170 { 171 fail(StringUtils.stackTrace(e)); 172 } 173 } 174 175 private static PortalAuthentication getService() 176 { 177 return (PortalAuthentication)TurbineServices 178 .getInstance() 179 .getService(PortalAuthentication.SERVICE_NAME); 180 } 181 182 } 183 184 185 186 | Popular Tags |