I'm new to Spring. I have a Spring MVC application that is handled by DispatcherServlet. The servlet mapping is defined in web.xml and beans are defined in myapp-servlet.xml as per the documentation. The app itself works fine when deployed. What I'm attempting to do is write some integration tests for it.
How the app works is it has a server-side component and a client-side component. Clients use MyAppInterface (an HttpInvokerServiceExporter) to send requests to the app. The requests are routed to the correct implementation by Spring.
I would like to create integration tests that use the same client and service that are defined in xml to remotely invoke methods and assert that they return the correct results. This means I need to gain an instance of my client (which I've successfully done using context.getBean("myAppClient");) and I need to spin up an instance of the server-side component to receive these requests.
How do I create (programmatically, in unit tests) an instance of the server-side component that uses my current xml configuration? eg. I don't want to configure it programmatically, I just want to get an instance of the server.
Example:
// Here is the client I am going to use to invoke methods final ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("com/example/myapp/myapp-servlet.xml"); (MyAppInterface) myAppClient = context.getBean("myAppClient"); // Here I start an instance of the server to receive the requests MyAppServer server = Spring.someMagicMethod().startMyAppServer(); // Do tests... assertEquals("expected result", myAppClient.invokeAMethod()); // Clean up server.shutDown();
No comments:
Post a Comment