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 8345535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:42:25+00:00 2026-06-09T06:42:25+00:00

How do I test a resource in a Spring Controller: @RequestMapping(value = /{query}, method

  • 0

How do I test a “resource” in a Spring Controller:

@RequestMapping(value = "/{query}", method = RequestMethod.GET)
public @ResponseBody String getResource(
        HttpServletRequest req, 
        HttpServletResponse res,
        @PathVariable String query,
        @RequestParam(value="param1", required = false) String param1,
        @RequestParam(value="param2", required = false) String param2) throws SomeException{
    return service.read(query);
}

And since I am developing with App Engine I have a JUnit scaffolding like this:

@ContextConfiguration(locations = { "classpath:service/client-config.xml" })
@RunWith(SpringJUnit4ClassRunner.class)
public class LocalDatastoreTest {
    private final LocalServiceTestHelper helper =
            new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig());  

    @Before
    public void setUp() {
        helper.setUp();
    }

    @After
    public void tearDown() {
        helper.tearDown();
    }   

    @Test
    public void test() {

    }

}
  • 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-09T06:42:26+00:00Added an answer on June 9, 2026 at 6:42 am

    If you have a test server up and running,
    try using Spring RestTemplate in your test method

    something like:

    RestTemplate restTemplate = new RestTemplate();
    String result = restTemplate.getForObject("YOUR_URL/{query}", String.class,"myQuery");
    

    See more here.

    If you don’t have a server and need basic unit testing, try mocking one.
    More info on another stackoverflow question.

    Or try using https://github.com/SpringSource/spring-test-mvc

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I trying @RequestMapping(value = /test, method = RequestMethod.POST) but is error Code is @Controller
I trying spring 3 mvc this package is org.spring.test and code is @Controller @RequestMapping(/welcome)
To test what happens when I try to load a non-existent resource (on the
I have project asp.net with namespace test and I'm using resources (files Resource.resx and
I just have a test. Config jndi in $CATALINA_HOME/conf/context.xml like below: <Resource name=jdbc/db auth=Container
I try to setup a project with spring-test using TestNg in Maven. The code
I've got the default route set-up: public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute({resource}.axd/{*pathInfo}); routes.MapRoute(
I am developing a web application using Spring and Tomcat 7.0. When I test
I cannot seem to get a simple REST client integration test going. I am
I am trying ot write an integration test for one of my controller classes

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.