Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7833025
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T12:32:19+00:00 2026-06-02T12:32:19+00:00

i want to unit test my validation defined with annotation. but it should be

  • 0

i want to unit test my validation defined with annotation. but it should be light. without loading any configuration files. i’m rather new to struts2 so i’m not sure if it is even possible. i have MyAction with method:

@Validations(...)
public String submit() {...}

and what i want is something like:

@Test
public void submitTest() {
  MyAction myAction = createInitializedMyAction(); //new MyAction, setXXX
  Map<String, String> httpRequestParams = prepareHttpRequestParams();
  TestHelperINeed testHelper = createTestHelper(myAction); // maybe some proxy???
  testHelper.execute("submit", httpRequestParams);

  assertErrors(testHelper.getErrors());
  assertResult(testHelper.getResult());

every solution i found requires configuration files of struts and spring. why do i need them if all the code i want to test is located in a single java file?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T12:32:20+00:00Added an answer on June 2, 2026 at 12:32 pm

    i found a solution there: http://bloodredsun.com/2009/10/21/unit-testing-struts2-actions-with-annotation-based-validation/

    it requires small refactoring to make it more useful but it works. at least with Struts 2.1.6. i also added some changes to make it works as my production struts:

    builder.constant("devMode", "false");
    builder.constant("objectFactory.classloader", ActionAnnotationValidatorFactory.class.getClassLoader().getClass());
    
    Container container = builder.create(true);
    ValueStackFactory ognlValueStackFactory = container.getInstance(ValueStackFactory.class);
    ((OgnlValueStackFactory) ognlValueStackFactory).setAllowStaticMethodAccess("true");
    

    it requires small changes to work with struts 2.1.8.1. before calling validate i do something like this:

    ActionInvocation actionInvocation = Mockito.mock(ActionInvocation.class, Mockito.RETURNS_DEEP_STUBS);
    ActionContext.getContext().setActionInvocation(actionInvocation);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to Unit Test my application which use MSMQ but i found no
I want to create a unit test for integration testing. What class should I
HI, I want to have set configuration settings for a unit test project that
I want to unit test my code without a dependency on having the back
I want to unit test a class, Class A , but it has a
I want to unit test a RESTful interface written with Apache CXF. I use
I have a method CreateAccount(...) that I want to unit test. Basically it creates
I want to write a unit test for a Django manage.py command that does
For a unit test I want to use the Range attribute from NUnit to
I want to run a single unit test and collect its profiling information: how

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.