1 16 17 package org.apache.jetspeed.test; 18 19 import junit.awtui.TestRunner; 21 import junit.framework.Test; 22 import junit.framework.TestSuite; 23 24 import org.apache.cactus.ServletTestCase; 26 import org.apache.cactus.WebRequest; 27 import org.apache.cactus.WebResponse; 28 29 import org.apache.jetspeed.capability.CapabilityMap; 31 import org.apache.jetspeed.om.profile.Profile; 32 import org.apache.jetspeed.om.profile.ProfileLocator; 33 import org.apache.jetspeed.om.profile.PSMLDocument; 34 import org.apache.jetspeed.services.Profiler; 35 import org.apache.jetspeed.services.rundata.JetspeedRunData; 36 import org.apache.jetspeed.test.TurbineTestUtilities; 37 38 import org.apache.turbine.services.pull.TurbinePull; 40 import org.apache.turbine.services.velocity.TurbineVelocity; 41 import org.apache.turbine.util.RunData; 42 import org.apache.turbine.util.RunDataFactory; 43 44 import org.apache.jetspeed.om.security.JetspeedUser; 45 46 import org.apache.velocity.context.Context; 48 49 54 55 public class TestBasicSanity extends ServletTestCase 56 { 57 private static String TEST_ANON_USER_NAME = ""; 58 private static String TEST_CONTEXT = null; 59 private static String TEST_DEFAULT_PAGE = "default"; 60 private static String TEST_HOST = "localhost"; 61 private static String TEST_SERVLET = "/portal"; 62 private static String TEST_GROUP = "apache"; 63 private static String TEST_PAGE = "news"; 64 private static String TEST_USER = "turbine"; 65 private static String TEST_USER_PASSWORD ="turbine"; 66 67 private RunData rundata = null; 68 69 74 public TestBasicSanity(String name) 75 { 76 super( name ); 77 } 78 79 84 public static void main(String args[]) 85 { 86 TestRunner.main( new String [] { TestBasicSanity.class.getName() } ); 87 } 88 89 95 public static Test suite() 96 { 97 return new TestSuite( TestBasicSanity.class ); 99 } 100 101 105 protected void setUp () throws Exception 106 { 107 } 108 109 116 public void beginDefaultURL(WebRequest theRequest) 117 { 118 System.out.println("URL = " + theRequest.getURL()); 119 theRequest.setURL(TEST_HOST, TEST_CONTEXT, TEST_SERVLET, "", null); 120 System.out.println("post set URL = " + theRequest.getURL()); 121 } 122 123 128 public void testDefaultURL() throws Exception 129 { 130 rundata = RunDataFactory.getRunData ( request, response, config ); 132 assertNotNull( "Got rundata", rundata); 133 TurbineTestUtilities.setupRunData(rundata); 134 135 JetspeedUser user = (JetspeedUser)rundata.getUser(); 137 assertNotNull( "Got user", user); 138 139 CapabilityMap cm = ((JetspeedRunData)rundata).getCapability(); 141 assertNotNull( "Got Capability", cm); 142 143 Profile profile = Profiler.getProfile(rundata); 145 assertNotNull( "Got profile from Profiler", profile); 146 147 if (profile instanceof ProfileLocator) 149 { 150 ProfileLocator profileLocator = (ProfileLocator) profile; 151 assertTrue("Verify the 'anonymous' is set", profileLocator.getAnonymous()); 152 assertNull("Verify the group is null", profileLocator.getGroup()); 153 assertNull("Verify the role is null", profileLocator.getRole()); 154 } else 155 { 156 assertTrue( "profile does not implement ProfileLocator", false); 157 } 158 159 160 PSMLDocument psmlDoc = profile.getDocument(); 162 assertNotNull( "Got psmlDocument", psmlDoc); 163 164 System.out.println("DocumentName = " + profile.getDocument().getName()); 165 166 Context context = TurbineVelocity.getContext(rundata); 168 assertNotNull( "Got context", context); 169 TurbinePull.populateContext( context, rundata); 170 171 assertNotNull( "Got jlink from context", context.get("jlink")); 173 174 TurbineTestUtilities.generatePage(rundata); 176 TurbineTestUtilities.outputPage(rundata); 177 178 RunDataFactory.putRunData(rundata); 180 } 181 182 public void endDefaultURL(org.apache.cactus.WebResponse theResponse) 183 { 184 System.out.println("text length = " + theResponse.getText().length()); 185 } 187 188 196 public void beginGroupUrl(WebRequest theRequest) 197 { 198 System.out.println("URL = " + theRequest.getURL()); 199 theRequest.setURL(TEST_HOST, TEST_CONTEXT, TEST_SERVLET 200 , "/group/" + TEST_GROUP , null); 201 System.out.println("post set URL = " + theRequest.getURL()); 202 } 203 204 208 public void testGroupUrl() throws Exception 209 { 210 rundata = RunDataFactory.getRunData ( request, response, config ); 212 assertNotNull( "Got rundata", rundata); 213 214 TurbineTestUtilities.setupRunData(rundata); 215 216 Profile profile = Profiler.getProfile(rundata); 218 assertNotNull( "Got profile from Profiler", profile); 219 220 if (profile instanceof ProfileLocator) 222 { 223 ProfileLocator profileLocator = (ProfileLocator) profile; 225 assertNotNull("Verify the group is not null", profileLocator.getGroup()); 227 assertNull("Verify the role is null", profileLocator.getRole()); 228 } else 229 { 230 assertTrue( "profile does not implement ProfileLocator", false); 231 } 232 TurbineTestUtilities.generatePage(rundata); 233 TurbineTestUtilities.outputPage(rundata); 234 235 RunDataFactory.putRunData(rundata); 237 } 238 239 public void endGroupURL(WebResponse theResponse) 240 { 241 System.out.println("text length = " + theResponse.getText().length()); 242 } 244 245 253 public void beginPageUrl(WebRequest theRequest) 254 { 255 System.out.println("URL = " + theRequest.getURL()); 256 theRequest.setURL(TEST_HOST, TEST_CONTEXT, TEST_SERVLET 257 , "/page/" + TEST_PAGE , null); 258 System.out.println("post set URL = " + theRequest.getURL()); 259 } 260 261 266 public void testPageUrl() throws Exception 267 { 268 rundata = RunDataFactory.getRunData ( request, response, config ); 270 assertNotNull( "Got rundata", rundata); 271 272 TurbineTestUtilities.setupRunData(rundata); 273 274 Profile profile = Profiler.getProfile(rundata); 276 assertNotNull( "Got profile from Profiler", profile); 277 278 if (profile instanceof ProfileLocator) 280 { 281 ProfileLocator profileLocator = (ProfileLocator) profile; 282 assertTrue("Verify the 'anonymous' is set", profileLocator.getAnonymous()); 284 assertNull("Verify the group is null", profileLocator.getGroup()); 285 assertNull("Verify the role is null", profileLocator.getRole()); 286 assertEquals("Verify the page name", profileLocator.getName(), TEST_PAGE + ".psml"); 287 } else 288 { 289 assertTrue( "profile does not implement ProfileLocator", false); 290 } 291 TurbineTestUtilities.generatePage(rundata); 292 TurbineTestUtilities.outputPage(rundata); 293 294 RunDataFactory.putRunData(rundata); 296 } 297 298 public void endPageURL(WebResponse theResponse) 299 { 300 System.out.println("text length = " + theResponse.getText().length()); 301 } 303 311 public void beginUserPageUrl(WebRequest theRequest) 312 { 313 System.out.println("URL = " + theRequest.getURL()); 314 theRequest.setURL(TEST_HOST, TEST_CONTEXT, TEST_SERVLET 315 , "/page/" + TEST_DEFAULT_PAGE ,"action=JLoginUser&username=turbine&password=turbine"); 316 System.out.println("post set URL = " + theRequest.getURL()); 317 } 318 319 324 public void testUserPageUrl() throws Exception 325 { 326 rundata = RunDataFactory.getRunData ( request, response, config ); 328 assertNotNull( "Got rundata", rundata); 329 330 TurbineTestUtilities.setupRunData(rundata); 331 332 Profile profile = Profiler.getProfile(rundata); 334 assertNotNull( "Got profile from Profiler", profile); 335 336 if (profile instanceof ProfileLocator) 338 { 339 ProfileLocator profileLocator = (ProfileLocator) profile; 340 assertTrue("Verify the 'anonymous' is not", !profileLocator.getAnonymous()); 342 assertNull("Verify the group is null", profileLocator.getGroup()); 343 assertNull("Verify the role is null", profileLocator.getRole()); 344 assertNotNull("Verify the user is not null", profileLocator.getUser()); 345 assertTrue("Verify the user is logged in", profileLocator.getUser().hasLoggedIn()); 346 assertEquals("Verify the user's username", profileLocator.getUser().getUserName(),TEST_USER); 347 assertEquals("Verify the page name", profileLocator.getName(), TEST_DEFAULT_PAGE + ".psml"); 348 } else 349 { 350 assertTrue( "profile does not implement ProfileLocator", false); 351 } 352 TurbineTestUtilities.generatePage(rundata); 353 TurbineTestUtilities.outputPage(rundata); 354 355 RunDataFactory.putRunData(rundata); 357 } 358 359 public void endUserPageURL(WebResponse theResponse) 360 { 361 System.out.println("text length = " + theResponse.getText().length()); 362 } 364 } 365 | Popular Tags |