I have several instances of my spring boot app, which in parallel do some work with DB. Each instance is running in separate JVM.
Is it a way to write a test in Java for testing that on one JVM? Like following:
Each instance has its own context and classpath.
I think that I could achieve that with some shell script scenario but I'd like to make it in Java.
What would be the best approach here?
You can run them multiple times using different ports.
I did something similar
@RunWith(SpringJUnit4ClassRunner.class)
public class ServicesIntegrationTest {
private RestTemplate restTemplate = new RestTemplate();
@Test
public void runTest() throws Exception {
SpringApplicationBuilder uws = new SpringApplicationBuilder(UserWebApplication.class)
.properties("server.port=8081",
"server.contextPath=/UserService",
"SOA.ControllerFactory.enforceProxyCreation=true");
uws.run();
SpringApplicationBuilder pws = new SpringApplicationBuilder(ProjectWebApplication.class)
.properties("server.port=8082",
"server.contextPath=/ProjectService",
"SOA.ControllerFactory.enforceProxyCreation=true");
pws.run();
String url = "http://localhost:8081/UserService/users";
ResponseEntity<SimplePage<UserDTO>> response = restTemplate.exchange(
url,
HttpMethod.GET,
null,
new ParameterizedTypeReference<SimplePage<UserDTO>>() {
});
here the source.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With