Search code examples
javaspring-bootsoapspring-testspring-ws

Soap integration tests load only the tested endpoint not all Endpoints


I have a qustion: what would be the right configuraiton to load only the Enpoint class that I want to test in that integration test and not the full Application context (not All the Enpoint Classes)? Right now I have:

@RunWith(SpringRunner.class)
@SpringBootTest(classes = {WebServiceConfigTest.class}, properties = {"application.address=http://hostname:port/context"})
public class MyEndpointTest {

@Autowired
private ApplicationContext applicationContext;

private MockWebServiceClient mockClient;


@Before
public void init() {
    mockClient = MockWebServiceClient.createClient(applicationContext);
    MockitoAnnotations.initMocks(this);
}
@Test
public void test1(){}
....
}

in WebServiceConfigTest is:

@ComponentScan("mypackages.soap")
@ContextConfiguration(classes = SoapApplication.class)
@MockBean(classes = {MyService.class})
public class WebServiceConfigTest {
}

SoapApplication is:

@ComponentScan({"mypackages"})
@SpringBootApplication
public class SoapApplication extends SpringBootServletInitializer implements WebApplicationInitializer {

 public static void main(String[] args) {
     SpringApplication.run(SoapApplication.class, args);
 }
}

The reason is that in Soap module I have a dependency of Service module which has other dependencies as well and so on. If i load the whole ApplicaitonContext then:

  • either I need to mock the full list of services that I use in Soap module
  • or to mock the underneath dependencies of Service module, such as DataSource, Queues etc.

If I do the second will make Soap module aware of things it should not be. If I do the first I am forced to mock and maintain in the config test file the full list of used Services which can be long.

Any advices here?


Solution

  • After long searches and trials i found the solution. As you can ask Spring on REST to loaad only 1 Controller into the context with

    @WebMvcTest(MyController.class) 
    

    the same thign you can do for Soap with

    @SpringBootTest(classes = {MyEndpoint.class}) 
    

    It will load only the Endpoint you want and you can mock the the Services you use inside that or you can go all the way till the Repository o whatever your Application Bussiness logic is doing there.