public void testStandardRule() throws Exception
{
assertNotNull("profiler service is null", profiler);
RequestContext request = new MockRequestContext("default-other");
request.setSubject(SecurityHelper.createSubject("anon"));
request.setLocale(new Locale("en", "US"));
request.setMediaType("HTML");
request.setMimeType("text/html");
Map params = request.getParameterMap();
params.put("page", "default-other");
params.put("path", "/sports/football/nfl/chiefs");
ProfileLocator locator = profiler.getProfile(request, ProfileLocator.PAGE_LOCATOR);
assertNotNull("rule test on getProfile returned null", locator);
String path = locator.getLocatorPath();
System.out.println("locator = " + path);
assertTrue("locator key value unexpected: " + path, path
.equals("page:default-other:user:anon:mediatype:HTML:language:en:country:US"));
// test fallback
Iterator fallback = locator.iterator();
int count = 0;
while (fallback.hasNext())
{
ProfileLocatorProperty[] locatorProperties = (ProfileLocatorProperty[]) fallback.next();
assertTrue("locatorProperties is not null", (locatorProperties != null));
String locatorPath = locator.getLocatorPath(locatorProperties);
switch (count)
{
case 0:
assertTrue("locatorPath[0]: " + locatorPath, locatorPath
.equals("page:default-other:user:anon:mediatype:HTML:language:en:country:US"));
break;
case 1:
assertTrue("locatorPath[1]: " + locatorPath, locatorPath
.equals("page:default-other:user:anon:mediatype:HTML:language:en"));
break;
case 2:
assertTrue("locatorPath[2]: " + locatorPath, locatorPath
.equals("page:default-other:user:anon:mediatype:HTML"));
break;
case 3:
assertTrue("locatorPath[3]: " + locatorPath, locatorPath.equals("page:default-other:user:anon"));
break;
}
count++;
System.out.println("path = " + locatorPath);
}
assertTrue("fallback count = 4, " + count, count == 4);
// create a Simple locator
RequestContext request2 = new MockRequestContext("/test");
ProfileLocator locator2 = profiler.createLocator(request2);
locator2.add("page", "test");
fallback = locator2.iterator();
count = 0;
while (fallback.hasNext())
{
ProfileLocatorProperty[] locatorProperties = (ProfileLocatorProperty[]) fallback.next();
assertTrue("locatorProperties is not null", (locatorProperties != null));
String locatorPath = locator.getLocatorPath(locatorProperties);
assertTrue("locatorPath: " + locatorPath, locatorPath.equals("page:test"));
System.out.println("Simple Test: path = " + locatorPath);
count++;
}
assertTrue("fallback count = 1, " + count, count == 1);
// create an empty locator
RequestContext request3 = new MockRequestContext("/");
ProfileLocator locator3 = profiler.createLocator(request3);
fallback = locator3.iterator();
count = 0;
while (fallback.hasNext())
{