Struts2 でを使用しようとしましたがStrutsSpringJunit4TestCase
、基本的なテストを実行すると、"Template not found for name"
存在することがわかっているファイルに対してエラーが発生します。
SEVERE: [29:39.103] Template not found for name "/WEB-INF/content/errors/error.ftl".
The name was interpreted by this TemplateLoader: org.apache.struts2.views.freemarker.FreemarkerThemeTemplateLoader@7c060680.
Dispatcher#sendError: 500
src/main/webapp/
適切なファイルが `src/main/webapp/WEB-INF/content/errors/error.ftlにあるため、テスト ケースでファイルが見つからないようです。
Struts2 または freemarker テンプレートの場所をテストに指示するために、何か追加する必要があることはありますか?
サンプル テスト:
@ContextConfiguration(classes = TdarWebAppConfiguration.class)
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@Transactional
public class IndexControllerITCase extends StrutsSpringJUnit4TestCase<HomepageSupportingController> {
protected final Logger logger = LoggerFactory.getLogger(getClass());
@Test
public void test() throws Exception {
ActionProxy proxy = getActionProxy("/robots");
HomepageSupportingController myAction = (HomepageSupportingController) proxy.getAction();
logger.debug(executeAction("/robots"));
String execute = myAction.execute();
finishExecution();
logger.debug(response.getContentType());
logger.debug(response.getContentAsString());
assertEquals("Error", ActionSupport.SUCCESS, execute);
}
}
完全なスタック トレース:
freemarker.template.TemplateNotFoundException: Template not found for name "/WEB-INF/content/errors/error.ftl".
The name was interpreted by this TemplateLoader: org.apache.struts2.views.freemarker.FreemarkerThemeTemplateLoader@7c060680.
at freemarker.template.Configuration.getTemplate(Configuration.java:1833)
at freemarker.template.Configuration.getTemplate(Configuration.java:1655)
at org.apache.struts2.views.freemarker.FreemarkerResult.doExecute(FreemarkerResult.java:181)
at org.apache.struts2.dispatcher.StrutsResultSupport.execute(StrutsResultSupport.java:191)
at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:369)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:273)
at org.tdar.struts.interceptor.HttpsInterceptor.doHttpIntercept(HttpsInterceptor.java:52)
at org.tdar.struts.interceptor.HttpsInterceptor.intercept(HttpsInterceptor.java:34)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
at org.tdar.struts.interceptor.CacheControlInterceptor.intercept(CacheControlInterceptor.java:40)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
at org.tdar.struts.interceptor.SessionSecurityInterceptor.intercept(SessionSecurityInterceptor.java:85)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
at org.tdar.struts.interceptor.ActivityLoggingInterceptor.intercept(ActivityLoggingInterceptor.java:69)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:189)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244)
at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:564)
at org.apache.struts2.StrutsJUnit4TestCase.executeAction(StrutsJUnit4TestCase.java:140)
at org.tdar.struts.action.IndexControllerITCase.test(IndexControllerITCase.java:31)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:85)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:86)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:241)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:87)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:180)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)