My JUnit is not working as expected. I am following this link Below is the my code:
StrutsTest.java:
package com.test.action;
import org.apache.struts2.StrutsSpringTestCase;
import org.junit.Assert;
import org.junit.Test;
import com.opensymphony.xwork2.ActionProxy;
public class StrutsTest extends StrutsSpringTestCase {
public void testHomePage() {
System.out.println("Inside the method!");
ActionProxy actionProxy = getActionProxy("hello/index.action");
System.out.println("Right here!");
try {
Assert.assertEquals("Two are equal", 0, 0);
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
protected String[] getContextLocations() {
return new String[] { "classpath*:test-applicationContext.xml" };
}
}
test-applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://ift.tt/ra1lAU"
xmlns:context="http://ift.tt/GArMu7" xmlns="http://ift.tt/GArMu6"
xmlns:cache="http://ift.tt/LO4PtR"
xsi:schemaLocation="http://ift.tt/GArMu6 http://ift.tt/18sW2ax
http://ift.tt/GArMu7 http://ift.tt/1bGeTcI
http://ift.tt/LO4PtR http://ift.tt/1Gvmjlz"
default-autowire="byName">
<import resource="classpath:applicationContext-api.xml" />
<bean id='homeAction'
class='com.action.HomePageAction'
scope='prototype'>
</bean>
Struts.xml snippet:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://ift.tt/1iwXH3l">
<struts>
<constant name="struts.devMode" value="true" />
<package name='mypackage' extends='struts-default' namespace='/hello'>
<default-action-ref name="index" />
<action name='index' class='homeAction'>
<result name='success'>/WEB-INF/jsp/home/main.jsp</result>
</action>
</package>
</struts>
pom.xml:
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-junit-plugin</artifactId>
<version>${struts.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-spring-plugin</artifactId>
<version>${struts.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jsp-api</artifactId>
<version>2.0</version>
<scope>test</scope>
</dependency>
Exception:
java.lang.RuntimeException: Unable to load bean org.apache.struts2.dispatcher.mapper.ActionMapper (globalActionMapper) - [unknown location] at com.opensymphony.xwork2.inject.ContainerBuilder$4.create(ContainerBuilder.java:132) at com.opensymphony.xwork2.inject.Scope$2$1.create(Scope.java:51) at com.opensymphony.xwork2.inject.ContainerImpl.getInstance(ContainerImpl.java:514) at com.opensymphony.xwork2.inject.ContainerImpl.getInstance(ContainerImpl.java:524) at com.opensymphony.xwork2.inject.ContainerImpl$9.call(ContainerImpl.java:555) at com.opensymphony.xwork2.inject.ContainerImpl.callInContext(ContainerImpl.java:584) at com.opensymphony.xwork2.inject.ContainerImpl.getInstance(ContainerImpl.java:553) at org.apache.struts2.StrutsTestCase.getActionMapping(StrutsTestCase.java:180) at org.apache.struts2.StrutsTestCase.getActionProxy(StrutsTestCase.java:131) at com.test.action.StrutsTest.testHomePage(StrutsTest.java:15) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at junit.framework.TestCase.runTest(TestCase.java:176) at junit.framework.TestCase.runBare(TestCase.java:141) at junit.framework.TestResult$1.protect(TestResult.java:122) at junit.framework.TestResult.runProtected(TestResult.java:142) at junit.framework.TestResult.run(TestResult.java:125) at junit.framework.TestCase.run(TestCase.java:129) at junit.framework.TestSuite.runTest(TestSuite.java:255) at junit.framework.TestSuite.run(TestSuite.java:250) at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:84) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) 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) Caused by: Unable to load bean org.apache.struts2.dispatcher.mapper.ActionMapper (globalActionMapper) - [unknown location] at org.apache.struts2.config.AbstractBeanSelectionProvider$ObjectFactoryDelegateFactory.create(AbstractBeanSelectionProvider.java:109) at com.opensymphony.xwork2.inject.ContainerBuilder$4.create(ContainerBuilder.java:130) ... 28 more
Not sure what may be causing it. Can you provide any feedback? Also, I want to have a separate struts file for test. Is it possible to do that? if yes, How?
Aucun commentaire:
Enregistrer un commentaire