You need to sign in to do that
Don't have an account?
the_wolf
URL Rewriter - How to test it?!
Hi all,
I tried in my sandbox the new feature of summer '10, the url rewriter, illustrated in the following blog:
http://blog.sforce.com/sforce/2010/05/url-rewriting-for-your-customizing-your-site-urls.html
Now I want to copy it on production, but needs testing.
So, I create a class similar to that shown in the blog, and my initial test code is:
static testMethod void testURLrewriter(){
// I try to create the internal saleforce pageReference
pageReference myPage = new pageReference('/apex/myPage');
Test.setCurrentPage(myPage);
myPage.setRedirect(true);
List<PageReference> res = new List<PageReference>();
res.add(myPage);
res.add(new PageReference('/apex/myPage2' ));
// now call the methods
ClassUrlRewriter urlClass = new ClassUrlRewriter();
urlClass.mapRequestUrl(myPage);
urlClass.generateUrlFor(res);
}
Calling methods, the code coverage stops at the first if (where it controls the site.getUrl) How can I test a getUrl of a site, knowing that this class will be moved to the production ?
Thanks in advance!
Thanks Ryan for reply !
I used the method System.assert illustrated in your post, and I completed the test with 90% of code coverage!
My problem was in string of PageReference ( I deleted the string " /apex/ " and I used getUrl() correctly ).
Thanks again.
All Answers
Can't you just test with different types of PageReferences (URLs) and make sure that they get transformed correctly? In my tests I have been doing something like the following:
and then I usually add a test case for when the URL shouldn't get rewritten as well:
Thanks Ryan for reply !
I used the method System.assert illustrated in your post, and I completed the test with 90% of code coverage!
My problem was in string of PageReference ( I deleted the string " /apex/ " and I used getUrl() correctly ).
Thanks again.