Questions tagged [struts2-junit-plugin]

The Struts 2 JUnit Plugin provides integration with JUnit.

The Struts 2 JUnit Plugin provides integration with the JUnit test framework.

This plugin provides a base StrutsTestCase class that can subclassed to test Struts 2 components.

It is used within Struts 2 itself to test core framework components and many bundled plugins.

StrutsSpringTestCase is also provided to support actions created by the Spring object factory.

20 questions
5
votes
1 answer

Struts 2.3.14 junit test

I'm using Struts 2.3.14 for my application... I need some unit test in my application... so I'm using junit4... but when I use ActionProxy in my test, it will show NullPointerException... my test code is: ActionProxy…
Hariprasath
  • 828
  • 4
  • 15
  • 41
4
votes
1 answer

ActionContext.getContext().getParameters() returns null during StrutsJUnit4TestCase

I am running a JUnit test via maven where a struts action java method is being tested that makes the following call: // Gets this from the "org.apache.struts2.util.TokenHelper" class in the struts2-core jar String token =…
3
votes
1 answer

No qualifying bean of type for a bean in the Action I'm testing

I work on a project on eclipse, using tomcat, maven, spring, hibernate and struts. We've got 2 apps: core that contains all the beans (services) and web with the actions views etc. I made the JUnit tests for the services and decided to try doing…
nebra
  • 55
  • 1
  • 11
3
votes
2 answers

StrutsTestCase implementation - Compilation error

I am using Struts 2 to create a web application. I am using StrutsTestCase for Junit test case to test the Action class. I have imported struts2-junit-plugin-2.3.4.jar as I am using struts2-core-2.3.4.jar. Inside the testcase method, when i tried to…
Jothi
  • 14,720
  • 22
  • 68
  • 93
2
votes
1 answer

How to test a file upload in a struts unit test?

In Struts 2, I can use request.setParameter() for testing normal form submissions. But, how can one test uploading a file? Is there an equivalent of request.setParameter() which lets you pass a file as the parameter value? I also have a setFile()…
Ali
  • 261,656
  • 265
  • 575
  • 769
2
votes
3 answers

Struts2.3.12 junit4 testcase request & session are null

I have already gone through this solution : Struts 2 JUnit Plugin v2.2.3: Test Class Extending StrutsTestCase; 'request' is null But I'm already not having struts2-spring plugin, and neither I'm using spring in my application. I have 3 test-cases,…
coding_idiot
  • 13,526
  • 10
  • 65
  • 116
2
votes
1 answer

how to post json in request in a struts2 junit4 testcase

The test looks like this : @Test public void testSave() throws Exception { request.setContent("{\"id\":\"1\",\"name\":\"nitin\"}".getBytes()); request.setContentType("application/json"); // request.setMethod("post"); …
coding_idiot
  • 13,526
  • 10
  • 65
  • 116
2
votes
1 answer

While running the test case in Struts 2 I'm getting the error

I'm new to writing the Struts 2 test cases. And while running the test case I'm getting this error java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/servlet/jsp/PageContext at…
2
votes
1 answer

struts2 junit 2.3.12 plugin - unable to write successful test in struts2 junit4

I'm using struts2 junit 2.3.12 plugin. If I run test directly, then I get : java.lang.NoClassDefFoundError: javax/servlet/ServletContext so I include javax
coding_idiot
  • 13,526
  • 10
  • 65
  • 116
2
votes
2 answers

Struts 2 JUnit plugin + Hibernate

I'm testing my Struts 2 web application using Struts 2 JUnit plugin, following Unit Testing. In my web application I use fullHibernateCore-plugin-1.4 to integrate Hibernate functionality. When I test an action that do some Hibernate stuff, it…
1
vote
1 answer

How to set spring active profile when testing Struts2

When testing an stand alone spring environment we can do: @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration({ "classpath:spring-*.xml" }) @ActiveProfiles( profiles = { "Prod","bsi"}) public class SampleTest When testing Struts 2 with…
Alireza Fattahi
  • 42,517
  • 14
  • 123
  • 173
1
vote
1 answer

StrutsSpringJUnit4TestCase freemarker result "Template not found for name"

We've been trying to use the StrutsSpringJunit4TestCase for Struts2, but when we run a basic test, we're getting a"Template not found for name" error for a file we know exists: SEVERE: [29:39.103] Template not found for name…
adam
  • 1,067
  • 11
  • 24
1
vote
1 answer

Struts2 JUnit ActionContext objects

Struts ActionContext is null during test. Using Struts2 JUnit plugin I have the following test: public class MainActionIT extends StrutsJUnit4TestCase { @Test public void testAction() { Map application = new HashMap
dingdingding
  • 1,411
  • 1
  • 15
  • 23
1
vote
1 answer

Struts2 Junit4 tests accumulate JSON responses with every action execution

I've written a few Junit4 tests, which looks like this : public class TestCampaignList extends StrutsJUnit4TestCase { public static final Logger LOG = Logger.getLogger(TestCampaignList.class.getName()); @Before public void…
coding_idiot
  • 13,526
  • 10
  • 65
  • 116
1
vote
2 answers

Null Pointer when running Junit4 with Struts 2.3.12 and Spring 3.1.1

I am trying to develop JUnit4 test scripts for our application that uses Spring 3.2.2 and Struts 2.3.12. I think I am close to getting this working but for some reason when executeAction is called or getActionProxy is called I am getting a null…
1
2