lundi 19 août 2019

Integration testing a SOAP call in Spring Boot

I want to create an integration test in my spring boot app to test a SOAPUI call for getVersion. I want to imitate a SOAPUI call in spring boot and test if it hits but I am not sure how I should start it.

Some things that I have is the URI I have to hit:

https://127.0.0.1:28433/dave/ws/billingtool

This is on the left side of my SOAPUI getVersion (the envelope request input)

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://service.billing.nulogix.com">
   <soapenv:Header/>
   <soapenv:Body>
      <ser:getVersion/>
   </soapenv:Body>
</soapenv:Envelope>

The output I am expecting is the version returned in this class:

@Endpoint
public class GetVersionEndPoint {
    private static final Logger LOGGER = LoggerFactory.getLogger(GetVersionEndPoint.class);

    @Value("${billing.engine.api.version}")
    private String configApiVersion;

    @PostConstruct
    public void init() {
        LOGGER.debug("billing.engine.api.version=" + configApiVersion);
    }

    @PayloadRoot(namespace = "http://service.billing.dave.com", localPart = "getVersion")
    @ResponsePayload
    public GetVersionResponse doGetVersion(@RequestPayload GetVersion request) {
        LOGGER.info("Endpoint GetVersionEndPoint doGetVersion");

        ObjectFactory factory = new ObjectFactory();
        GetVersionResponse response = factory.createGetVersionResponse();
        response.setGetVersionReturn(configApiVersion);

        LOGGER.info("Endpoint sending GetVersionResponse='{}'", response.getGetVersionReturn());
        return response;
    }
}

I have a WSDL defined in my main/resources along with a request StudyDetailsSchema.xjb and .xsd and a response.xsd

This is my web service config

EnableWs
@Configuration
public class WebServiceConfig extends WsConfigurerAdapter {
      @Bean
      public ServletRegistrationBean<MessageDispatcherServlet> messageDispatcherServlet(ApplicationContext applicationContext) {
        MessageDispatcherServlet servlet = new MessageDispatcherServlet();
        servlet.setApplicationContext(applicationContext);

        return new ServletRegistrationBean<MessageDispatcherServlet>(servlet, "/nulogix/ws/*");
      }

      @Bean(name = "billingtool")
      public Wsdl11Definition defaultWsdl11Definition() {
        SimpleWsdl11Definition wsdl11Definition = new SimpleWsdl11Definition();
        wsdl11Definition.setWsdl(new ClassPathResource("/wsdl/BillingServiceImpl.wsdl"));

        return wsdl11Definition;
      }
}

I don't really know how I have to work it all together. Do I set up a simple HTTP request test?

So far I have this:

@Autowired
    private String studyDetailDemo;
    @Test
    public void soapTest() throws ClientProtocolException, IOException {
        String result = Request.Post("https://127.0.0.1:28433")
                .connectTimeout(2000)
                .socketTimeout(2000)
                .bodyString(studyDetailDemo, ContentType.TEXT_PLAIN)
                .execute().returnContent().asString();

    }

But I'm not sure if this is correct.

Aucun commentaire:

Enregistrer un commentaire