1 16 17 package org.apache.jetspeed.util.template; 18 19 21 import junit.awtui.TestRunner; 23 import junit.framework.Test; 24 import junit.framework.TestSuite; 25 26 import org.apache.cactus.ServletTestCase; 28 import org.apache.cactus.WebRequest; 29 30 import org.apache.jetspeed.om.profile.ProfileLocator; 32 import org.apache.jetspeed.services.Profiler; 33 import org.apache.jetspeed.services.resources.JetspeedResources; 34 import org.apache.jetspeed.util.template.JetspeedLink; 35 import org.apache.jetspeed.util.template.JetspeedLinkFactory; 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.velocity.context.Context; 46 52 public class TestJetspeedLink extends ServletTestCase 53 { 54 private static String TEST_CONTEXT = "/test"; 55 private static String TEST_HOST = "localhost"; 56 private static String TEST_SERVLET = "/portal"; 57 58 63 public TestJetspeedLink(String name) 64 { 65 super( name ); 66 } 67 68 73 public static void main(String args[]) 74 { 75 TestRunner.main( new String [] { TestJetspeedLink.class.getName() } ); 76 } 77 78 84 public static Test suite() 85 { 86 return new TestSuite( TestJetspeedLink.class ); 88 } 89 90 91 public void beginBaseLink(WebRequest theRequest) 92 { 93 System.out.println("URL = " + theRequest.getURL()); 94 theRequest.setURL(TEST_HOST, TEST_CONTEXT, TEST_SERVLET, "", null); 95 System.out.println("post set URL = " + theRequest.getURL()); 96 } 97 98 102 public void testBaseLink() throws Exception 103 { 104 ProfileLocator profileLocator = null; 105 106 RunData rundata = RunDataFactory.getRunData( request, response, config ); 108 assertNotNull( "Got rundata", rundata); 109 TurbineTestUtilities.setupRunData(rundata); 110 111 Context context = TurbineVelocity.getContext(rundata); 113 assertNotNull( "Got context", context); 114 TurbinePull.populateContext( context, rundata); 115 116 JetspeedLink jsLink = (JetspeedLink) context.get("jslink"); 118 assertNotNull( "Got jslink from context", jsLink); 119 120 String link = jsLink.toString(); 122 System.out.println("Base link = " + link); 123 assertTrue( "Verifing base Link", 124 link.startsWith("http://" + TEST_HOST + TEST_CONTEXT + TEST_SERVLET)); 125 126 TurbineTestUtilities.generatePage(rundata); 128 TurbineTestUtilities.outputPage(rundata); 129 130 RunDataFactory.putRunData(rundata); 132 } 133 134 public void endBaseLink(org.apache.cactus.WebResponse theResponse) 135 { 136 System.out.println("text length = " + theResponse.getText().length()); 137 } 138 139 public void beginGroupLink(WebRequest theRequest) 140 { 141 theRequest.setURL(TEST_HOST, TEST_CONTEXT, TEST_SERVLET 142 , "/" + Profiler.PARAM_GROUP + "/apache" , null); 143 System.out.println("post set URL = " + theRequest.getURL()); 144 } 145 146 150 public void testGroupLink() throws Exception 151 { 152 RunData rundata = RunDataFactory.getRunData( request, response, config ); 154 assertNotNull( "Got rundata", rundata); 155 TurbineTestUtilities.setupRunData(rundata); 156 157 Context context = TurbineVelocity.getContext(rundata); 159 assertNotNull( "Got context", context); 160 TurbinePull.populateContext( context, rundata); 161 162 JetspeedLink jsLink = (JetspeedLink) context.get("jslink"); 164 assertNotNull( "Got jslink from context", jsLink); 165 166 String link = jsLink.toString(); 168 System.out.println("Group link = " + link); 169 assertTrue( "Verifing base Link", 170 link.startsWith("http://" + TEST_HOST + TEST_CONTEXT + TEST_SERVLET)); 171 172 assertTrue( "Verify link contains /" + Profiler.PARAM_GROUP + "/apache", 173 (link.indexOf("/" + Profiler.PARAM_GROUP + "/apache") >0)); 174 175 assertEquals( "Verify link does NOT contain /" + Profiler.PARAM_USER, -1, 176 link.indexOf("/" + Profiler.PARAM_USER )); 177 178 TurbineTestUtilities.generatePage(rundata); 180 TurbineTestUtilities.outputPage(rundata); 181 182 RunDataFactory.putRunData(rundata); 184 185 } 186 187 public void endGroupLink(org.apache.cactus.WebResponse theResponse) 188 { 189 System.out.println("text = " + theResponse.getText().length()); 190 } 191 192 public void beginPageLink(WebRequest theRequest) 193 { 194 theRequest.setURL(TEST_HOST, TEST_CONTEXT, TEST_SERVLET 195 , "/" + Profiler.PARAM_PAGE + "/news" , null); 196 System.out.println("post set URL = " + theRequest.getURL()); 197 } 198 199 203 public void testPageLink() throws Exception 204 { 205 RunData rundata = RunDataFactory.getRunData( request, response, config ); 207 assertNotNull( "Got rundata", rundata); 208 TurbineTestUtilities.setupRunData(rundata); 209 210 Context context = TurbineVelocity.getContext(rundata); 212 assertNotNull( "Got context", context); 213 TurbinePull.populateContext( context, rundata); 214 215 JetspeedLink jsLink = (JetspeedLink) context.get("jslink"); 217 assertNotNull( "Got jslink from context", jsLink); 218 219 String link = jsLink.toString(); 221 System.out.println("Page Link = " + link); 222 assertTrue( "Verifing base Link", 223 link.startsWith("http://" + TEST_HOST + TEST_CONTEXT + TEST_SERVLET)); 224 225 assertTrue( "Verify link contains /" + Profiler.PARAM_USER + "/anon", 226 (link.indexOf("/" + Profiler.PARAM_USER + "/anon") >0)); 227 228 assertTrue( "Verify link contains /" + Profiler.PARAM_PAGE + "/news", 229 (link.indexOf("/" + Profiler.PARAM_PAGE + "/news") >0)); 230 231 assertEquals( "Verify link does NOT contain /" + Profiler.PARAM_GROUP, -1, 232 link.indexOf("/" + Profiler.PARAM_GROUP )); 233 234 TurbineTestUtilities.generatePage(rundata); 236 TurbineTestUtilities.outputPage(rundata); 237 238 RunDataFactory.putRunData(rundata); 240 } 241 public void endPageLink(org.apache.cactus.WebResponse theResponse) 242 { 243 System.out.println("text = " + theResponse.getText().length()); 244 } 245 246 public void beginGroupPage(WebRequest theRequest) 247 { 248 theRequest.setURL(TEST_HOST, TEST_CONTEXT, TEST_SERVLET 249 , "/" + Profiler.PARAM_GROUP + "/apache/" + Profiler.PARAM_PAGE + "/news" , null); 250 System.out.println("post set URL = " + theRequest.getURL()); 251 } 252 253 257 public void testGroupPage() throws Exception 258 { 259 RunData rundata = RunDataFactory.getRunData( request, response, config ); 261 assertNotNull( "Got rundata", rundata); 262 TurbineTestUtilities.setupRunData(rundata); 263 264 Context context = TurbineVelocity.getContext(rundata); 266 assertNotNull( "Got context", context); 267 TurbinePull.populateContext( context, rundata); 268 269 JetspeedLink jsLink = (JetspeedLink) context.get("jslink"); 271 assertNotNull( "Got jslink from context", jsLink); 272 273 String link = jsLink.toString(); 275 System.out.println("Group/Page Link = " + link); 276 assertTrue( "Verifing base Link", 277 link.startsWith("http://" + TEST_HOST + TEST_CONTEXT + TEST_SERVLET)); 278 279 assertTrue( "Verify link contains /" + Profiler.PARAM_GROUP + "/apache", 280 (link.indexOf("/" + Profiler.PARAM_GROUP + "/apache") >0)); 281 282 assertEquals( "Verify link does NOT contain /" + Profiler.PARAM_USER, -1, 283 link.indexOf("/" + Profiler.PARAM_USER )); 284 285 assertTrue( "Verify link contains /" + Profiler.PARAM_PAGE + "/news", 286 (link.indexOf("/" + Profiler.PARAM_PAGE + "/news") >0)); 287 288 TurbineTestUtilities.generatePage(rundata); 290 TurbineTestUtilities.outputPage(rundata); 291 292 RunDataFactory.putRunData(rundata); 294 } 295 public void endGroupPage(org.apache.cactus.WebResponse theResponse) 296 { 297 System.out.println("text = " + theResponse.getText().length()); 298 } 299 300 public void beginGroupPage2(WebRequest theRequest) 301 { 302 theRequest.setURL(TEST_HOST, TEST_CONTEXT, TEST_SERVLET 303 , "/" + Profiler.PARAM_GROUP + "/apache/" + Profiler.PARAM_PAGE + "/news" , null); 304 System.out.println("post set URL = " + theRequest.getURL()); 305 } 306 307 311 public void testGroupPage2() throws Exception 312 { 313 JetspeedLink jetspeedLink = null; 314 315 RunData rundata = RunDataFactory.getRunData( request, response, config ); 317 assertNotNull( "Got rundata", rundata); 318 TurbineTestUtilities.setupRunData(rundata); 319 320 Context context = TurbineVelocity.getContext(rundata); 322 assertNotNull( "Got context", context); 323 TurbinePull.populateContext( context, rundata); 324 325 JetspeedLink jsLink = (JetspeedLink) context.get("jslink"); 327 assertNotNull( "Got jslink from context", jsLink); 328 329 String link = jsLink.toString(); 331 System.out.println("Group/Page Link = " + link); 332 333 jetspeedLink = JetspeedLinkFactory.getInstance(rundata); 335 System.out.println("Group/Page jetspeedLink = " + jetspeedLink.toString()); 336 assertEquals( "jsLink = jetspeedLink", link, jetspeedLink.toString()); 337 JetspeedLinkFactory.putInstance(jsLink); 338 339 jetspeedLink = JetspeedLinkFactory.getInstance(rundata); 341 assertEquals( "jsLink = jetspeedLink", jetspeedLink.toString(), jetspeedLink.toString()); 342 JetspeedLinkFactory.putInstance(jsLink); 343 344 TurbineTestUtilities.generatePage(rundata); 346 TurbineTestUtilities.outputPage(rundata); 347 348 RunDataFactory.putRunData(rundata); 350 } 351 public void endGroupPage2(org.apache.cactus.WebResponse theResponse) 352 { 353 System.out.println("text = " + theResponse.getText().length()); 354 } 355 356 357 public void beginGetLink(WebRequest theRequest) 358 { 359 theRequest.setURL(TEST_HOST, TEST_CONTEXT, TEST_SERVLET 360 , "/" + Profiler.PARAM_GROUP + "/apache/" + Profiler.PARAM_PAGE + "/news/" + JetspeedResources.PATH_PORTLETID_KEY + "/p_1234/" + JetspeedResources.PATH_TEMPLATE_KEY + "/Home/" + Profiler.PARAM_MEDIA_TYPE + "/html/" + Profiler.PARAM_LANGUAGE + "/en/" + Profiler.PARAM_COUNTRY + "/US" , null); 361 System.out.println("post set URL = " + theRequest.getURL()); 362 } 363 364 368 public void testGetLink() throws Exception 369 { 370 JetspeedLink jetspeedLink = null; 371 372 RunData rundata = RunDataFactory.getRunData( request, response, config ); 374 assertNotNull( "Got rundata", rundata); 375 TurbineTestUtilities.setupRunData(rundata); 376 377 Context context = TurbineVelocity.getContext(rundata); 379 assertNotNull( "Got context", context); 380 TurbinePull.populateContext( context, rundata); 381 382 JetspeedLink jsLink = (JetspeedLink) context.get("jslink"); 384 assertNotNull( "Got jslink from context", jsLink); 385 386 jetspeedLink = JetspeedLinkFactory.getInstance(rundata); 388 String baseLink = new String ("http://" + TEST_HOST + TEST_CONTEXT + TEST_SERVLET); 389 String currentLink = new String ( baseLink 390 + "/" + Profiler.PARAM_MEDIA_TYPE + "/" + jetspeedLink.getMediaType() 391 + "/" + Profiler.PARAM_GROUP + "/" + jetspeedLink.getGroupName() 392 + "/" + Profiler.PARAM_PAGE + "/" + jetspeedLink.getPageName()); 393 394 assertEquals( "Testing getGroupName()", "apache" , jetspeedLink.getGroupName() ); 395 assertEquals( "Testing getPageName()", "news.psml" , jetspeedLink.getPageName() ); 396 assertEquals( "Testing getPageName()", "html" , jetspeedLink.getMediaType() ); 397 assertNull( "Testing getRoleName()", jetspeedLink.getRoleName() ); 398 assertNull( "Testing getUserName()", jetspeedLink.getUserName() ); 399 400 assertEquals( "Testing getAction(actionName)", currentLink + "?" + JetspeedResources.PATH_ACTION_KEY + "=myAction", jetspeedLink.getAction("myAction").toString()); 402 assertEquals( "Testing getAction(actionName, peid)", currentLink + "/" + JetspeedResources.PATH_PORTLETID_KEY + "/actionpeid?" + JetspeedResources.PATH_ACTION_KEY + "=myAction1", jetspeedLink.getAction("myAction1","actionpeid").toString() ); 403 assertEquals( "Testing getGroup(groupName)", baseLink + "/" + Profiler.PARAM_MEDIA_TYPE + "/" + jetspeedLink.getMediaType()+ "/" + Profiler.PARAM_GROUP + "/myGroup", jetspeedLink.getGroup("myGroup").toString()); 404 assertEquals( "Testing getGroup(groupName,pageName)", baseLink + "/" + Profiler.PARAM_MEDIA_TYPE + "/" + jetspeedLink.getMediaType() + "/" + Profiler.PARAM_GROUP + "/myGroup1/" + Profiler.PARAM_PAGE + "/myGroupPage", jetspeedLink.getGroup("myGroup1","myGroupPage").toString()); 405 assertEquals( "Testing getHomePage()", baseLink , jetspeedLink.getHomePage().toString() ); 406 assertEquals( "Testing getRole(roleName)", baseLink + "/" + Profiler.PARAM_MEDIA_TYPE + "/" + jetspeedLink.getMediaType() + "/" + Profiler.PARAM_ROLE + "/myRole", jetspeedLink.getRole("myRole").toString()); 407 assertEquals( "Testing getRole(roleName,pageName)", baseLink + "/" + Profiler.PARAM_MEDIA_TYPE + "/" + jetspeedLink.getMediaType()+ "/" + Profiler.PARAM_ROLE + "/myRole1/" + Profiler.PARAM_PAGE + "/myRolePage", jetspeedLink.getRole("myRole1","myRolePage").toString()); 408 assertEquals( "Testing getTemplate(templateName)", currentLink + "/" + JetspeedResources.PATH_TEMPLATE_KEY + "/myTemplate", jetspeedLink.getTemplate("myTemplate").toString()); 409 assertEquals( "Testing getTemplate()", currentLink , jetspeedLink.getTemplate().toString() ); 410 assertEquals( "Testing getUser(userName)", baseLink + "/" + Profiler.PARAM_MEDIA_TYPE + "/" + jetspeedLink.getMediaType() + "/" + Profiler.PARAM_USER + "/myUser", jetspeedLink.getUser("myUser").toString()); 411 assertEquals( "Testing getUser(userName,PageName)", baseLink + "/" + Profiler.PARAM_MEDIA_TYPE + "/" + jetspeedLink.getMediaType() + "/" + Profiler.PARAM_USER + "/myUser1/" + Profiler.PARAM_PAGE + "/myUserPage", jetspeedLink.getUser("myUser1","myUserPage").toString()); 412 413 assertEquals( "Testing getLink() with default & nulls", 415 baseLink + 416 "/" + Profiler.PARAM_MEDIA_TYPE + 417 "/" + jetspeedLink.getMediaType() + 418 "/" + Profiler.PARAM_PAGE + 419 "/" + jetspeedLink.getPageName(), 420 jetspeedLink.getLink(JetspeedLink.DEFAULT, null, null, JetspeedLink.DEFAULT, null, null).toString() ); 421 422 assertEquals( "Testing getLink() with current & nulls", 423 baseLink + 424 "/" + Profiler.PARAM_MEDIA_TYPE + 425 "/" + jetspeedLink.getMediaType() + 426 "/" + Profiler.PARAM_GROUP + 427 "/" + jetspeedLink.getGroupName()+ 428 "/" + Profiler.PARAM_PAGE + 429 "/" + jetspeedLink.getPageName(), 430 jetspeedLink.getLink(JetspeedLink.CURRENT, null, null, JetspeedLink.CURRENT, null, null).toString() ); 431 432 assertEquals( "Testing getLink() with default & nulls + media/language/country", 433 baseLink + 434 "/" + Profiler.PARAM_PAGE + 435 "/" + jetspeedLink.getPageName() + 436 "/" + Profiler.PARAM_MEDIA_TYPE + 437 "/" + "test_html"+ 438 "/" + Profiler.PARAM_LANGUAGE + 439 "/" + "test_en" + 440 "/" + Profiler.PARAM_COUNTRY + 441 "/" + "test_US", 442 jetspeedLink.getLink(JetspeedLink.DEFAULT, null, null, JetspeedLink.DEFAULT, null, null, null, "test_html", "test_en", "test_US").toString() ); 443 444 JetspeedLinkFactory.putInstance(jsLink); 445 446 TurbineTestUtilities.generatePage(rundata); 448 TurbineTestUtilities.outputPage(rundata); 449 450 RunDataFactory.putRunData(rundata); 452 } 453 public void endGetLink(org.apache.cactus.WebResponse theResponse) 454 { 455 System.out.println("text = " + theResponse.getText().length()); 456 } 457 } 458 | Popular Tags |