File |
Line |
org/apache/myfaces/test/base/AbstractJsfTestCase.java |
91 |
org/apache/myfaces/test/jmock/AbstractJmockJsfTestCase.java |
90 |
setName(name);
}
// ---------------------------------------------------- Overall Test Methods
/**
* <p>Set up instance variables required by this test case.</p>
*/
protected void setUp() throws Exception
{
// Set up a new thread context class loader
setUpClassloader();
// Set up Servlet API Objects
setUpServletObjects();
// Set up JSF API Objects
FactoryFinder.releaseFactories();
setFactories();
setUpJSFObjects();
}
/**
* Set up the thread context classloader. JSF uses the this classloader
* in order to find related factory classes and other resources, but in
* some selected cases, the default classloader cannot be properly set.
*
* @throws Exception
*/
protected void setUpClassloader() throws Exception
{
threadContextClassLoader = Thread.currentThread()
.getContextClassLoader();
Thread.currentThread()
.setContextClassLoader(
new URLClassLoader(new URL[0], this.getClass()
.getClassLoader()));
classLoaderSet = true;
}
/**
* <p>Setup JSF object used for the test. By default it calls to the following
* methods in this order:</p>
*
* <ul>
* <li><code>setUpExternalContext();</code></li>
* <li><code>setUpLifecycle();</code></li>
* <li><code>setUpFacesContext();</code></li>
* <li><code>setUpView();</code></li>
* <li><code>setUpApplication();</code></li>
* <li><code>setUpRenderKit();</code></li>
* </ul>
*
* @throws Exception
*/
protected void setUpJSFObjects() throws Exception
{
setUpExternalContext();
setUpLifecycle();
setUpFacesContext();
setUpView();
setUpApplication();
setUpRenderKit();
}
/**
* <p>Setup servlet objects that will be used for the test:</p>
*
* <ul>
* <li><code>config</code> (<code>MockServletConfig</code>)</li>
* <li><code>servletContext</code> (<code>MockServletContext</code>)</li>
* <li><code>request</code> (<code>MockHttpServletRequest</code></li>
* <li><code>response</code> (<code>MockHttpServletResponse</code>)</li>
* <li><code>session</code> (<code>MockHttpSession</code>)</li>
* </ul>
*
* @throws Exception
*/
protected void setUpServletObjects() throws Exception
{
servletContext = new MockServletContext();
config = new MockServletConfig(servletContext);
session = new MockHttpSession();
session.setServletContext(servletContext);
request = new MockHttpServletRequest(session);
request.setServletContext(servletContext);
response = new MockHttpServletResponse();
}
/**
* <p>Set JSF factories using FactoryFinder method setFactory.</p>
*
* @throws Exception
*/
protected void setFactories() throws Exception
{
FactoryFinder.setFactory(FactoryFinder.APPLICATION_FACTORY,
"org.apache.myfaces.test.mock.MockApplicationFactory");
FactoryFinder.setFactory(FactoryFinder.FACES_CONTEXT_FACTORY,
"org.apache.myfaces.test.mock.MockFacesContextFactory");
FactoryFinder.setFactory(FactoryFinder.LIFECYCLE_FACTORY,
"org.apache.myfaces.test.mock.lifecycle.MockLifecycleFactory");
FactoryFinder.setFactory(FactoryFinder.RENDER_KIT_FACTORY,
"org.apache.myfaces.test.mock.MockRenderKitFactory");
FactoryFinder.setFactory(FactoryFinder.EXCEPTION_HANDLER_FACTORY,
"org.apache.myfaces.test.mock.MockExceptionHandlerFactory");
FactoryFinder.setFactory(FactoryFinder.PARTIAL_VIEW_CONTEXT_FACTORY,
"org.apache.myfaces.test.mock.MockPartialViewContextFactory");
FactoryFinder.setFactory(FactoryFinder.VISIT_CONTEXT_FACTORY,
"org.apache.myfaces.test.mock.visit.MockVisitContextFactory");
}
/**
* Setup the <code>externalContext</code> variable, using the
* servlet variables already initialized.
*
* @throws Exception
*/
protected void setUpExternalContext() throws Exception
{
externalContext = new MockExternalContext(servletContext, request,
response);
}
/**
* Setup the <code>lifecycle</code> and <code>lifecycleFactory</code>
* variables.
*
* @throws Exception
*/
protected void setUpLifecycle() throws Exception
{
lifecycleFactory = (MockLifecycleFactory) FactoryFinder
.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
lifecycle = (MockLifecycle) lifecycleFactory
.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
}
/**
* Setup the <code>facesContextFactory</code> and <code>facesContext</code>
* variable. Before end, by default it override <code>externalContext</code>
* variable from the value retrieved from facesContext.getExternalContext(),
* because sometimes it is possible facesContext overrides externalContext
* internally.
*
* @throws Exception
*/
protected void setUpFacesContext() throws Exception
{
facesContextFactory = (MockFacesContextFactory) FactoryFinder
.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
facesContext = (MockFacesContext) facesContextFactory.getFacesContext(
servletContext, request, response, lifecycle);
if (facesContext.getExternalContext() != null)
{
externalContext = (MockExternalContext) facesContext
.getExternalContext();
}
}
/**
* By default, create an instance of UIViewRoot, set its viewId as "/viewId"
* and assign it to the current facesContext.
*
* @throws Exception
*/
protected void setUpView() throws Exception
{
UIViewRoot root = new UIViewRoot();
root.setViewId("/viewId");
root.setRenderKitId(RenderKitFactory.HTML_BASIC_RENDER_KIT);
facesContext.setViewRoot(root);
}
/**
* Setup the <code>application</code> variable and before
* the end by default it is assigned to the <code>facesContext</code>
* variable, calling <code>facesContext.setApplication(application)</code>
*
* @throws Exception
*/
protected void setUpApplication() throws Exception
{
ApplicationFactory applicationFactory = (ApplicationFactory) FactoryFinder
.getFactory(FactoryFinder.APPLICATION_FACTORY);
application = (MockApplication) applicationFactory.getApplication();
facesContext.setApplication(application);
}
/**
* Setup the <code>renderKit</code> variable. This is a good place to use
* <code>ConfigParser</code> to register converters, validators, components
* or renderkits.
*
* @throws Exception
*/
protected void setUpRenderKit() throws Exception
{
RenderKitFactory renderKitFactory = (RenderKitFactory) FactoryFinder
.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
renderKit = new MockRenderKit();
renderKitFactory.addRenderKit(RenderKitFactory.HTML_BASIC_RENDER_KIT,
renderKit);
}
/**
* <p>Tear down instance variables required by this test case.</p>
*/
protected void tearDown() throws Exception
{
application = null;
config = null;
externalContext = null;
if (facesContext != null)
{
facesContext.release();
}
facesContext = null;
lifecycle = null;
lifecycleFactory = null;
renderKit = null;
request = null;
response = null;
servletContext = null;
session = null;
FactoryFinder.releaseFactories();
ResourceBundleVarNames.resetNames();
tearDownClassloader();
}
protected void tearDownClassloader() throws Exception
{
if (classLoaderSet)
{
Thread.currentThread().setContextClassLoader(threadContextClassLoader);
threadContextClassLoader = null;
classLoaderSet = false;
}
}
// ------------------------------------------------------ Instance Variables
// Mock object instances for our tests
protected MockApplication application = null;
protected MockServletConfig config = null;
protected MockExternalContext externalContext = null;
protected MockFacesContext facesContext = null;
protected MockFacesContextFactory facesContextFactory = null;
protected MockLifecycle lifecycle = null;
protected MockLifecycleFactory lifecycleFactory = null;
protected MockRenderKit renderKit = null;
protected MockHttpServletRequest request = null;
protected MockHttpServletResponse response = null;
protected MockServletContext servletContext = null;
protected MockHttpSession session = null;
// Thread context class loader saved and restored after each test
private ClassLoader threadContextClassLoader = null;
private boolean classLoaderSet = false;
} |
File |
Line |
org/apache/myfaces/test/base/AbstractJsfTestCase.java |
99 |
org/apache/myfaces/test/base/junit4/AbstractJsfTestCase.java |
99 |
public void setUp() throws Exception
{
// Set up a new thread context class loader
setUpClassloader();
// Set up Servlet API Objects
setUpServletObjects();
// Set up JSF API Objects
FactoryFinder.releaseFactories();
setFactories();
setUpJSFObjects();
}
/**
* Set up the thread context classloader. JSF uses the this classloader
* in order to find related factory classes and other resources, but in
* some selected cases, the default classloader cannot be properly set.
*
* @throws Exception
*/
protected void setUpClassloader() throws Exception
{
threadContextClassLoader = Thread.currentThread()
.getContextClassLoader();
Thread.currentThread()
.setContextClassLoader(
new URLClassLoader(new URL[0], this.getClass()
.getClassLoader()));
classLoaderSet = true;
}
/**
* <p>Setup JSF object used for the test. By default it calls to the following
* methods in this order:</p>
*
* <ul>
* <li><code>setUpExternalContext();</code></li>
* <li><code>setUpLifecycle();</code></li>
* <li><code>setUpFacesContext();</code></li>
* <li><code>setUpView();</code></li>
* <li><code>setUpApplication();</code></li>
* <li><code>setUpRenderKit();</code></li>
* </ul>
*
* @throws Exception
*/
protected void setUpJSFObjects() throws Exception
{
setUpExternalContext();
setUpLifecycle();
setUpFacesContext();
setUpView();
setUpApplication();
setUpRenderKit();
}
/**
* <p>Setup servlet objects that will be used for the test:</p>
*
* <ul>
* <li><code>config</code> (<code>MockServletConfig</code>)</li>
* <li><code>servletContext</code> (<code>MockServletContext</code>)</li>
* <li><code>request</code> (<code>MockHttpServletRequest</code></li>
* <li><code>response</code> (<code>MockHttpServletResponse</code>)</li>
* <li><code>session</code> (<code>MockHttpSession</code>)</li>
* </ul>
*
* @throws Exception
*/
protected void setUpServletObjects() throws Exception
{
servletContext = new MockServletContext();
config = new MockServletConfig(servletContext);
session = new MockHttpSession();
session.setServletContext(servletContext);
request = new MockHttpServletRequest(session);
request.setServletContext(servletContext);
response = new MockHttpServletResponse();
}
/**
* <p>Set JSF factories using FactoryFinder method setFactory.</p>
*
* @throws Exception
*/
protected void setFactories() throws Exception
{
FactoryFinder.setFactory(FactoryFinder.APPLICATION_FACTORY,
"org.apache.myfaces.test.mock.MockApplicationFactory");
FactoryFinder.setFactory(FactoryFinder.FACES_CONTEXT_FACTORY,
"org.apache.myfaces.test.mock.MockFacesContextFactory");
FactoryFinder.setFactory(FactoryFinder.LIFECYCLE_FACTORY,
"org.apache.myfaces.test.mock.lifecycle.MockLifecycleFactory");
FactoryFinder.setFactory(FactoryFinder.RENDER_KIT_FACTORY,
"org.apache.myfaces.test.mock.MockRenderKitFactory");
FactoryFinder.setFactory(FactoryFinder.EXCEPTION_HANDLER_FACTORY,
"org.apache.myfaces.test.mock.MockExceptionHandlerFactory");
FactoryFinder.setFactory(FactoryFinder.PARTIAL_VIEW_CONTEXT_FACTORY,
"org.apache.myfaces.test.mock.MockPartialViewContextFactory");
FactoryFinder.setFactory(FactoryFinder.VISIT_CONTEXT_FACTORY,
"org.apache.myfaces.test.mock.visit.MockVisitContextFactory");
}
/**
* Setup the <code>externalContext</code> variable, using the
* servlet variables already initialized.
*
* @throws Exception
*/
protected void setUpExternalContext() throws Exception
{
externalContext = new MockExternalContext(servletContext, request,
response);
}
/**
* Setup the <code>lifecycle</code> and <code>lifecycleFactory</code>
* variables.
*
* @throws Exception
*/
protected void setUpLifecycle() throws Exception
{
lifecycleFactory = (MockLifecycleFactory) FactoryFinder
.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
lifecycle = (MockLifecycle) lifecycleFactory
.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
}
/**
* Setup the <code>facesContextFactory</code> and <code>facesContext</code>
* variable. Before end, by default it override <code>externalContext</code>
* variable from the value retrieved from facesContext.getExternalContext(),
* because sometimes it is possible facesContext overrides externalContext
* internally.
*
* @throws Exception
*/
protected void setUpFacesContext() throws Exception
{
facesContextFactory = (MockFacesContextFactory) FactoryFinder
.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
facesContext = (MockFacesContext) facesContextFactory.getFacesContext(
servletContext, request, response, lifecycle);
if (facesContext.getExternalContext() != null)
{
externalContext = (MockExternalContext) facesContext
.getExternalContext();
}
}
/**
* By default, create an instance of UIViewRoot, set its viewId as "/viewId"
* and assign it to the current facesContext.
*
* @throws Exception
*/
protected void setUpView() throws Exception
{
UIViewRoot root = new UIViewRoot();
root.setViewId("/viewId");
root.setRenderKitId(RenderKitFactory.HTML_BASIC_RENDER_KIT);
facesContext.setViewRoot(root);
}
/**
* Setup the <code>application</code> variable and before
* the end by default it is assigned to the <code>facesContext</code>
* variable, calling <code>facesContext.setApplication(application)</code>
*
* @throws Exception
*/
protected void setUpApplication() throws Exception
{
ApplicationFactory applicationFactory = (ApplicationFactory) FactoryFinder
.getFactory(FactoryFinder.APPLICATION_FACTORY);
application = (MockApplication) applicationFactory.getApplication();
facesContext.setApplication(application);
}
/**
* Setup the <code>renderKit</code> variable. This is a good place to use
* <code>ConfigParser</code> to register converters, validators, components
* or renderkits.
*
* @throws Exception
*/
protected void setUpRenderKit() throws Exception
{
RenderKitFactory renderKitFactory = (RenderKitFactory) FactoryFinder
.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
renderKit = new MockRenderKit();
renderKitFactory.addRenderKit(RenderKitFactory.HTML_BASIC_RENDER_KIT,
renderKit);
} |
File |
Line |
org/apache/myfaces/test/base/junit4/AbstractJsfConfigurableMockTestCase.java |
91 |
org/apache/myfaces/test/base/junit4/AbstractJsfTestCase.java |
89 |
public AbstractJsfTestCase()
{
}
// ---------------------------------------------------- Overall Test Methods
/**
* <p>Set up instance variables required by this test case.</p>
*/
@Before
public void setUp() throws Exception
{
// Set up a new thread context class loader
setUpClassloader();
// Set up Servlet API Objects
setUpServletObjects();
// Set up JSF API Objects
FactoryFinder.releaseFactories();
setFactories();
setUpJSFObjects();
}
/**
* Set up the thread context classloader. JSF uses the this classloader
* in order to find related factory classes and other resources, but in
* some selected cases, the default classloader cannot be properly set.
*
* @throws Exception
*/
protected void setUpClassloader() throws Exception
{
threadContextClassLoader = Thread.currentThread()
.getContextClassLoader();
Thread.currentThread()
.setContextClassLoader(
new URLClassLoader(new URL[0], this.getClass()
.getClassLoader()));
classLoaderSet = true;
}
/**
* <p>Setup JSF object used for the test. By default it calls to the following
* methods in this order:</p>
*
* <ul>
* <li><code>setUpExternalContext();</code></li>
* <li><code>setUpLifecycle();</code></li>
* <li><code>setUpFacesContext();</code></li>
* <li><code>setUpView();</code></li>
* <li><code>setUpApplication();</code></li>
* <li><code>setUpRenderKit();</code></li>
* </ul>
*
* @throws Exception
*/
protected void setUpJSFObjects() throws Exception
{
setUpExternalContext();
setUpLifecycle();
setUpFacesContext();
setUpView();
setUpApplication();
setUpRenderKit();
}
/**
* <p>Setup servlet objects that will be used for the test:</p>
*
* <ul>
* <li><code>config</code> (<code>MockServletConfig</code>)</li>
* <li><code>servletContext</code> (<code>MockServletContext</code>)</li>
* <li><code>request</code> (<code>MockHttpServletRequest</code></li>
* <li><code>response</code> (<code>MockHttpServletResponse</code>)</li>
* <li><code>session</code> (<code>MockHttpSession</code>)</li>
* </ul>
*
* @throws Exception
*/
protected void setUpServletObjects() throws Exception
{
servletContext = new MockServletContext();
config = new MockServletConfig(servletContext);
session = new MockHttpSession();
session.setServletContext(servletContext);
request = new MockHttpServletRequest(session);
request.setServletContext(servletContext);
response = new MockHttpServletResponse();
}
/**
* <p>Set JSF factories using FactoryFinder method setFactory.</p>
*
* @throws Exception
*/
protected void setFactories() throws Exception
{
FactoryFinder.setFactory(FactoryFinder.APPLICATION_FACTORY,
"org.apache.myfaces.test.mock.MockApplicationFactory");
FactoryFinder.setFactory(FactoryFinder.FACES_CONTEXT_FACTORY,
"org.apache.myfaces.test.mock.MockFacesContextFactory");
FactoryFinder.setFactory(FactoryFinder.LIFECYCLE_FACTORY,
"org.apache.myfaces.test.mock.lifecycle.MockLifecycleFactory");
FactoryFinder.setFactory(FactoryFinder.RENDER_KIT_FACTORY,
"org.apache.myfaces.test.mock.MockRenderKitFactory");
FactoryFinder.setFactory(FactoryFinder.EXCEPTION_HANDLER_FACTORY,
"org.apache.myfaces.test.mock.MockExceptionHandlerFactory");
FactoryFinder.setFactory(FactoryFinder.PARTIAL_VIEW_CONTEXT_FACTORY,
"org.apache.myfaces.test.mock.MockPartialViewContextFactory");
FactoryFinder.setFactory(FactoryFinder.VISIT_CONTEXT_FACTORY,
"org.apache.myfaces.test.mock.visit.MockVisitContextFactory");
}
/**
* Setup the <code>externalContext</code> variable, using the
* servlet variables already initialized.
*
* @throws Exception
*/
protected void setUpExternalContext() throws Exception
{
externalContext = new MockExternalContext(servletContext, request,
response);
}
/**
* Setup the <code>lifecycle</code> and <code>lifecycleFactory</code>
* variables.
*
* @throws Exception
*/
protected void setUpLifecycle() throws Exception
{
lifecycleFactory = (MockLifecycleFactory) FactoryFinder |
File |
Line |
org/apache/myfaces/test/base/AbstractJsfTestCase.java |
99 |
org/apache/myfaces/test/base/junit4/AbstractJsfConfigurableMockTestCase.java |
101 |
public void setUp() throws Exception
{
// Set up a new thread context class loader
setUpClassloader();
// Set up Servlet API Objects
setUpServletObjects();
// Set up JSF API Objects
FactoryFinder.releaseFactories();
setFactories();
setUpJSFObjects();
}
/**
* Set up the thread context classloader. JSF uses the this classloader
* in order to find related factory classes and other resources, but in
* some selected cases, the default classloader cannot be properly set.
*
* @throws Exception
*/
protected void setUpClassloader() throws Exception
{
threadContextClassLoader = Thread.currentThread()
.getContextClassLoader();
Thread.currentThread()
.setContextClassLoader(
new URLClassLoader(new URL[0], this.getClass()
.getClassLoader()));
classLoaderSet = true;
}
/**
* <p>Setup JSF object used for the test. By default it calls to the following
* methods in this order:</p>
*
* <ul>
* <li><code>setUpExternalContext();</code></li>
* <li><code>setUpLifecycle();</code></li>
* <li><code>setUpFacesContext();</code></li>
* <li><code>setUpView();</code></li>
* <li><code>setUpApplication();</code></li>
* <li><code>setUpRenderKit();</code></li>
* </ul>
*
* @throws Exception
*/
protected void setUpJSFObjects() throws Exception
{
setUpExternalContext();
setUpLifecycle();
setUpFacesContext();
setUpView();
setUpApplication();
setUpRenderKit();
}
/**
* <p>Setup servlet objects that will be used for the test:</p>
*
* <ul>
* <li><code>config</code> (<code>MockServletConfig</code>)</li>
* <li><code>servletContext</code> (<code>MockServletContext</code>)</li>
* <li><code>request</code> (<code>MockHttpServletRequest</code></li>
* <li><code>response</code> (<code>MockHttpServletResponse</code>)</li>
* <li><code>session</code> (<code>MockHttpSession</code>)</li>
* </ul>
*
* @throws Exception
*/
protected void setUpServletObjects() throws Exception
{
servletContext = new MockServletContext();
config = new MockServletConfig(servletContext);
session = new MockHttpSession();
session.setServletContext(servletContext);
request = new MockHttpServletRequest(session);
request.setServletContext(servletContext);
response = new MockHttpServletResponse();
}
/**
* <p>Set JSF factories using FactoryFinder method setFactory.</p>
*
* @throws Exception
*/
protected void setFactories() throws Exception
{
FactoryFinder.setFactory(FactoryFinder.APPLICATION_FACTORY,
"org.apache.myfaces.test.mock.MockApplicationFactory");
FactoryFinder.setFactory(FactoryFinder.FACES_CONTEXT_FACTORY,
"org.apache.myfaces.test.mock.MockFacesContextFactory");
FactoryFinder.setFactory(FactoryFinder.LIFECYCLE_FACTORY,
"org.apache.myfaces.test.mock.lifecycle.MockLifecycleFactory");
FactoryFinder.setFactory(FactoryFinder.RENDER_KIT_FACTORY,
"org.apache.myfaces.test.mock.MockRenderKitFactory");
FactoryFinder.setFactory(FactoryFinder.EXCEPTION_HANDLER_FACTORY,
"org.apache.myfaces.test.mock.MockExceptionHandlerFactory");
FactoryFinder.setFactory(FactoryFinder.PARTIAL_VIEW_CONTEXT_FACTORY,
"org.apache.myfaces.test.mock.MockPartialViewContextFactory");
FactoryFinder.setFactory(FactoryFinder.VISIT_CONTEXT_FACTORY,
"org.apache.myfaces.test.mock.visit.MockVisitContextFactory");
}
/**
* Setup the <code>externalContext</code> variable, using the
* servlet variables already initialized.
*
* @throws Exception
*/
protected void setUpExternalContext() throws Exception
{
externalContext = new MockExternalContext(servletContext, request,
response);
}
/**
* Setup the <code>lifecycle</code> and <code>lifecycleFactory</code>
* variables.
*
* @throws Exception
*/
protected void setUpLifecycle() throws Exception
{
lifecycleFactory = (LifecycleFactory) FactoryFinder |
File |
Line |
org/apache/myfaces/test/mock/resource/MockResourceLoader.java |
87 |
org/apache/myfaces/test/mock/resource/MockSimpleResourceHandler.java |
314 |
private int compareVersion(String s1, String s2)
{
int n1 = 0;
int n2 = 0;
String o1 = s1;
String o2 = s2;
boolean p1 = true;
boolean p2 = true;
while (n1 == n2 && (p1 || p2))
{
int i1 = o1.indexOf('_');
int i2 = o2.indexOf('_');
if (i1 < 0)
{
if (o1.length() > 0)
{
p1 = false;
n1 = Integer.valueOf(o1);
o1 = "";
}
else
{
p1 = false;
n1 = 0;
}
}
else
{
n1 = Integer.valueOf(o1.substring(0, i1));
o1 = o1.substring(i1 + 1);
}
if (i2 < 0)
{
if (o2.length() > 0)
{
p2 = false;
n2 = Integer.valueOf(o2);
o2 = "";
}
else
{
p2 = false;
n2 = 0;
}
}
else
{
n2 = Integer.valueOf(o2.substring(0, i2));
o2 = o2.substring(i2 + 1);
}
}
if (n1 == n2)
{
return s1.length() - s2.length();
}
return n1 - n2;
} |
File |
Line |
org/apache/myfaces/test/base/AbstractJsfTestCase.java |
177 |
org/apache/myfaces/test/base/junit4/AbstractJsfConfigurableMultipleRequestsTestCase.java |
199 |
request = new MockHttpServletRequest(session);
request.setServletContext(servletContext);
response = new MockHttpServletResponse();
}
/**
* <p>Set JSF factories using FactoryFinder method setFactory.</p>
*
* @throws Exception
*/
protected void setFactories() throws Exception
{
FactoryFinder.setFactory(FactoryFinder.APPLICATION_FACTORY,
"org.apache.myfaces.test.mock.MockApplicationFactory");
FactoryFinder.setFactory(FactoryFinder.FACES_CONTEXT_FACTORY,
"org.apache.myfaces.test.mock.MockFacesContextFactory");
FactoryFinder.setFactory(FactoryFinder.LIFECYCLE_FACTORY,
"org.apache.myfaces.test.mock.lifecycle.MockLifecycleFactory");
FactoryFinder.setFactory(FactoryFinder.RENDER_KIT_FACTORY,
"org.apache.myfaces.test.mock.MockRenderKitFactory");
FactoryFinder.setFactory(FactoryFinder.EXCEPTION_HANDLER_FACTORY,
"org.apache.myfaces.test.mock.MockExceptionHandlerFactory");
FactoryFinder.setFactory(FactoryFinder.PARTIAL_VIEW_CONTEXT_FACTORY,
"org.apache.myfaces.test.mock.MockPartialViewContextFactory");
FactoryFinder.setFactory(FactoryFinder.VISIT_CONTEXT_FACTORY,
"org.apache.myfaces.test.mock.visit.MockVisitContextFactory");
}
/**
* Setup the <code>externalContext</code> variable, using the
* servlet variables already initialized.
*
* @throws Exception
*/
protected void setUpExternalContext() throws Exception
{
externalContext = new MockExternalContext(servletContext, request,
response);
}
/**
* Setup the <code>lifecycle</code> and <code>lifecycleFactory</code>
* variables.
*
* @throws Exception
*/
protected void setUpLifecycle() throws Exception
{
lifecycleFactory = (MockLifecycleFactory) FactoryFinder
.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
lifecycle = (MockLifecycle) lifecycleFactory
.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);
}
/**
* Setup the <code>facesContextFactory</code> and <code>facesContext</code>
* variable. Before end, by default it override <code>externalContext</code>
* variable from the value retrieved from facesContext.getExternalContext(),
* because sometimes it is possible facesContext overrides externalContext
* internally.
*
* @throws Exception
*/
protected void setUpFacesContext() throws Exception
{
facesContextFactory = (MockFacesContextFactory) FactoryFinder
.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
facesContext = (MockFacesContext) facesContextFactory.getFacesContext(
servletContext, request, response, lifecycle);
if (facesContext.getExternalContext() != null)
{
externalContext = (MockExternalContext) facesContext
.getExternalContext();
} |
File |
Line |
org/apache/myfaces/test/mock/resource/MockResourceHandler.java |
284 |
org/apache/myfaces/test/mock/resource/MockSimpleResourceHandler.java |
180 |
}
@Override
public boolean libraryExists(String libraryName)
{
String localePrefix = getLocalePrefixForLocateResource();
String pathToLib;
if (localePrefix != null)
{
//Check with locale
pathToLib = localePrefix + '/' + libraryName;
}
else
{
pathToLib = libraryName;
}
try
{
URL url = FacesContext.getCurrentInstance().getExternalContext()
.getResource("/" + pathToLib);
return (url != null);
}
catch (MalformedURLException e)
{
return false;
}
}
protected String getLocalePrefixForLocateResource()
{
String localePrefix = null;
FacesContext context = FacesContext.getCurrentInstance();
String bundleName = context.getApplication().getMessageBundle();
if (null != bundleName)
{
Locale locale = context.getApplication().getViewHandler()
.calculateLocale(context);
ResourceBundle bundle = ResourceBundle.getBundle(bundleName,
locale, getContextClassLoader());
if (bundle != null)
{
try
{
localePrefix = bundle
.getString(ResourceHandler.LOCALE_PREFIX);
}
catch (MissingResourceException e)
{
// Ignore it and return null
}
}
}
return localePrefix;
} |
File |
Line |
org/apache/myfaces/test/base/AbstractJsfTestCase.java |
301 |
org/apache/myfaces/test/base/junit4/AbstractJsfTestCase.java |
303 |
public void tearDown() throws Exception
{
application = null;
config = null;
externalContext = null;
if (facesContext != null)
{
facesContext.release();
}
facesContext = null;
lifecycle = null;
lifecycleFactory = null;
renderKit = null;
request = null;
response = null;
servletContext = null;
session = null;
FactoryFinder.releaseFactories();
ResourceBundleVarNames.resetNames();
tearDownClassloader();
}
protected void tearDownClassloader() throws Exception
{
if (classLoaderSet)
{
Thread.currentThread().setContextClassLoader(threadContextClassLoader);
threadContextClassLoader = null;
classLoaderSet = false;
}
}
// ------------------------------------------------------ Instance Variables
// Mock object instances for our tests
protected MockApplication application = null;
protected MockServletConfig config = null;
protected MockExternalContext externalContext = null;
protected MockFacesContext facesContext = null;
protected MockFacesContextFactory facesContextFactory = null;
protected MockLifecycle lifecycle = null;
protected MockLifecycleFactory lifecycleFactory = null;
protected MockRenderKit renderKit = null;
protected MockHttpServletRequest request = null;
protected MockHttpServletResponse response = null;
protected MockServletContext servletContext = null;
protected MockHttpSession session = null;
// Thread context class loader saved and restored after each test
private ClassLoader threadContextClassLoader = null;
private boolean classLoaderSet = false;
} |
File |
Line |
org/apache/myfaces/test/mock/resource/MockResourceMeta.java |
74 |
org/apache/myfaces/test/mock/resource/MockSimpleResource.java |
152 |
builder.append('/');
boolean firstSlashAdded = false;
if (_prefix != null && _prefix.length() > 0)
{
builder.append(_prefix);
firstSlashAdded = true;
}
if (_libraryName != null)
{
if (firstSlashAdded)
{
builder.append('/');
}
builder.append(_libraryName);
firstSlashAdded = true;
}
if (_libraryVersion != null)
{
if (firstSlashAdded)
{
builder.append('/');
}
builder.append(_libraryVersion);
firstSlashAdded = true;
}
if (_resourceName != null)
{
if (firstSlashAdded)
{
builder.append('/');
}
builder.append(_resourceName);
firstSlashAdded = true;
}
if (_resourceVersion != null)
{
if (firstSlashAdded)
{
builder.append('/');
}
builder.append(_resourceVersion);
builder.append(_resourceName.substring(_resourceName
.lastIndexOf('.'))); |
File |
Line |
org/apache/myfaces/test/base/junit4/AbstractJsfConfigurableMockTestCase.java |
280 |
org/apache/myfaces/test/base/junit4/AbstractJsfTestCase.java |
280 |
facesContext.setApplication(application);
}
/**
* Setup the <code>renderKit</code> variable. This is a good place to use
* <code>ConfigParser</code> to register converters, validators, components
* or renderkits.
*
* @throws Exception
*/
protected void setUpRenderKit() throws Exception
{
RenderKitFactory renderKitFactory = (RenderKitFactory) FactoryFinder
.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
renderKit = new MockRenderKit();
renderKitFactory.addRenderKit(RenderKitFactory.HTML_BASIC_RENDER_KIT,
renderKit);
}
/**
* <p>Tear down instance variables required by this test case.</p>
*/
@After
public void tearDown() throws Exception
{
application = null;
config = null;
externalContext = null;
if (facesContext != null)
{
facesContext.release();
}
facesContext = null;
lifecycle = null;
lifecycleFactory = null;
renderKit = null;
request = null;
response = null;
servletContext = null;
session = null;
FactoryFinder.releaseFactories();
ResourceBundleVarNames.resetNames();
tearDownClassloader();
}
protected void tearDownClassloader() throws Exception
{
if (classLoaderSet)
{
Thread.currentThread().setContextClassLoader(threadContextClassLoader);
threadContextClassLoader = null;
classLoaderSet = false;
}
}
// ------------------------------------------------------ Instance Variables
// Mock object instances for our tests
protected MockApplication application = null; |
File |
Line |
org/apache/myfaces/test/base/junit4/AbstractJsfConfigurableMockTestCase.java |
280 |
org/apache/myfaces/test/base/junit4/AbstractJsfConfigurableMultipleRequestsTestCase.java |
304 |
application = applicationFactory.getApplication();
}
/**
* Setup the <code>renderKit</code> variable. This is a good place to use
* <code>ConfigParser</code> to register converters, validators, components
* or renderkits.
*
* @throws Exception
*/
protected void setUpRenderKit() throws Exception
{
RenderKitFactory renderKitFactory = (RenderKitFactory) FactoryFinder
.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
renderKit = new MockRenderKit();
renderKitFactory.addRenderKit(RenderKitFactory.HTML_BASIC_RENDER_KIT,
renderKit);
}
/**
* <p>Tear down instance variables required by this test case.</p>
*/
@After
public void tearDown() throws Exception
{
application = null;
config = null;
externalContext = null;
if (facesContext != null)
{
facesContext.release();
}
facesContext = null;
lifecycle = null;
lifecycleFactory = null;
renderKit = null;
request = null;
response = null;
servletContext = null;
session = null;
FactoryFinder.releaseFactories();
ResourceBundleVarNames.resetNames();
tearDownClassloader();
}
protected void tearDownClassloader() throws Exception
{
if (classLoaderSet)
{
Thread.currentThread().setContextClassLoader(threadContextClassLoader);
threadContextClassLoader = null;
classLoaderSet = false;
}
} |
File |
Line |
org/apache/myfaces/test/base/junit4/AbstractJsfConfigurableMockTestCase.java |
179 |
org/apache/myfaces/test/base/junit4/AbstractJsfConfigurableMultipleRequestsTestCase.java |
199 |
request = new MockHttpServletRequest(session);
request.setServletContext(servletContext);
response = new MockHttpServletResponse();
}
/**
* <p>Set JSF factories using FactoryFinder method setFactory.</p>
*
* @throws Exception
*/
protected void setFactories() throws Exception
{
FactoryFinder.setFactory(FactoryFinder.APPLICATION_FACTORY,
"org.apache.myfaces.test.mock.MockApplicationFactory");
FactoryFinder.setFactory(FactoryFinder.FACES_CONTEXT_FACTORY,
"org.apache.myfaces.test.mock.MockFacesContextFactory");
FactoryFinder.setFactory(FactoryFinder.LIFECYCLE_FACTORY,
"org.apache.myfaces.test.mock.lifecycle.MockLifecycleFactory");
FactoryFinder.setFactory(FactoryFinder.RENDER_KIT_FACTORY,
"org.apache.myfaces.test.mock.MockRenderKitFactory");
FactoryFinder.setFactory(FactoryFinder.EXCEPTION_HANDLER_FACTORY,
"org.apache.myfaces.test.mock.MockExceptionHandlerFactory");
FactoryFinder.setFactory(FactoryFinder.PARTIAL_VIEW_CONTEXT_FACTORY,
"org.apache.myfaces.test.mock.MockPartialViewContextFactory");
FactoryFinder.setFactory(FactoryFinder.VISIT_CONTEXT_FACTORY,
"org.apache.myfaces.test.mock.visit.MockVisitContextFactory");
}
/**
* Setup the <code>externalContext</code> variable, using the
* servlet variables already initialized.
*
* @throws Exception
*/
protected void setUpExternalContext() throws Exception
{
externalContext = new MockExternalContext(servletContext, request,
response);
}
/**
* Setup the <code>lifecycle</code> and <code>lifecycleFactory</code>
* variables.
*
* @throws Exception
*/
protected void setUpLifecycle() throws Exception
{
lifecycleFactory = (MockLifecycleFactory) FactoryFinder |