use of org.hamcrest.text.StringStartsWith in project sling by apache.
the class FormAuthenticationHandlerTest method test_getTokenFile.
@Test
public void test_getTokenFile() {
final File root = new File("bundle999").getAbsoluteFile();
final SlingHomeAction slingHome = new SlingHomeAction();
slingHome.setSlingHome(new File("sling").getAbsolutePath());
Mockery context = new Mockery();
final BundleContext bundleContext = context.mock(BundleContext.class);
context.checking(new Expectations() {
{
// mock access to sling.home framework property
allowing(bundleContext).getProperty("sling.home");
will(slingHome);
// mock no data file support with file names starting with sl
allowing(bundleContext).getDataFile(with(new StringStartsWith("sl")));
will(returnValue(null));
// mock data file support for any other name
allowing(bundleContext).getDataFile(with(any(String.class)));
will(new RVA(root));
}
});
final FormAuthenticationHandler handler = new FormAuthenticationHandler();
// test files relative to bundle context
File relFile0 = handler.getTokenFile("", bundleContext);
assertEquals(root, relFile0);
String relName1 = "rel/path";
File relFile1 = handler.getTokenFile(relName1, bundleContext);
assertEquals(new File(root, relName1), relFile1);
// test file relative to sling.home if no data file support
String relName2 = "sl/rel_to_sling.home";
File relFile2 = handler.getTokenFile(relName2, bundleContext);
assertEquals(new File(slingHome.getSlingHome(), relName2), relFile2);
// test file relative to current working directory
String relName3 = "sl/test";
slingHome.setSlingHome(null);
File relFile3 = handler.getTokenFile(relName3, bundleContext);
assertEquals(new File(relName3).getAbsoluteFile(), relFile3);
// test absolute file return
File absFile = new File("test").getAbsoluteFile();
File absFile0 = handler.getTokenFile(absFile.getPath(), bundleContext);
assertEquals(absFile, absFile0);
}
Aggregations