Spring WS - Unit Test Client



In this chapter, we will learn how to unit test a client created in the Spring WS - Writing Client for the web application server created in chapter Spring WS - Writing Server using Spring WS.

Step Description
1 Update the project leaveService under theleaveService under a package com.tutorialspoint as explained in the Spring WS - Write Client chapter.
2 Create CountryServiceClientTest.java under the package com.tutorialspoint under folder src → Test → Java as explained in steps given below.

CountryServiceClientTest.java

package com.tutorialspoint;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.oxm.jaxb.Jaxb2Marshaller;

import com.tutorialspoint.client.CountryServiceClient;

public class CountryServiceClientTest {
   CountryServiceClient client;
   
   @BeforeEach
   public void setUp() throws Exception {
      client = new CountryServiceClient();
      Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
      marshaller.setContextPath("com.tutorialspoint");
      client.setMarshaller(marshaller);
      client.setUnmarshaller(marshaller);
   }
   @Test
   public void test() {
      GetCountryResponse response = client.getCountryDetails("United States");
      Country expectedCountry = new Country();
      expectedCountry.setCapital("Washington");
      Country actualCountry = response.getCountry();
      Assertions.assertEquals(expectedCountry.getCapital(), actualCountry.getCapital());
   }
}

Unit Test Web Service Client

Run the mvn test

command from eclipse Run As option to run and validate the test cases.
[INFO] Scanning for projects...
[INFO] 
[INFO] [1m-----------------< [0;36mcom.tutorialspoint.hr:leaveservice[0;1m >-----------------[m
[INFO] [1mBuilding leaveService Spring-WS Application 0.0.1-SNAPSHOT[m
[INFO]   from pom.xml
[INFO] [1m--------------------------------[ war ]---------------------------------[m
[INFO] 
[INFO] [1m--- [0;32mresources:3.3.1:resources[m [1m(default-resources)[m @ [36mleaveservice[0;1m ---[m
[INFO] Copying 2 resources from src\main\resources to target\classes
[INFO] 
[INFO] [1m--- [0;32mcompiler:3.13.0:compile[m [1m(default-compile)[m @ [36mleaveservice[0;1m ---[m
[INFO] Nothing to compile - all classes are up to date.
[INFO] 
[INFO] [1m--- [0;32mresources:3.3.1:testResources[m [1m(default-testResources)[m @ [36mleaveservice[0;1m ---[m
[INFO] skip non existing resourceDirectory C:\Users\mahes\eclipse-workspace\leaveservice\src\test\resources
[INFO] 
[INFO] [1m--- [0;32mcompiler:3.13.0:testCompile[m [1m(default-testCompile)[m @ [36mleaveservice[0;1m ---[m
[INFO] Nothing to compile - all classes are up to date.
[INFO] 
[INFO] [1m--- [0;32msurefire:3.3.0:test[m [1m(default-test)[m @ [36mleaveservice[0;1m ---[m
[INFO] Using auto detected provider org.apache.maven.surefire.junitplatform.JUnitPlatformProvider
[INFO] 
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.tutorialspoint.[1mCountryServiceClientTest[m
Oct 19, 2025 4:07:54 PM org.springframework.ws.soap.saaj.SaajSoapMessageFactory afterPropertiesSet
INFO: Creating SAAJ 1.3 MessageFactory with SOAP 1.1 Protocol
[INFO] [1;32mTests run: [0;1;32m1[m, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.489 s -- in com.tutorialspoint.[1mCountryServiceClientTest[m
[INFO] Running com.tutorialspoint.ws.[1mCustomerEndPointTest[m
Oct 19, 2025 4:07:55 PM org.springframework.ws.soap.addressing.server.AbstractAddressingEndpointMapping afterPropertiesSet
INFO: Supporting [WS-Addressing August 2004, WS-Addressing 1.0]
Oct 19, 2025 4:07:55 PM org.springframework.ws.soap.saaj.SaajSoapMessageFactory afterPropertiesSet
INFO: Creating SAAJ 1.3 MessageFactory with SOAP 1.1 Protocol
[INFO] [1;32mTests run: [0;1;32m1[m, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.651 s -- in com.tutorialspoint.ws.[1mCustomerEndPointTest[m
[INFO] 
[INFO] Results:
[INFO] 
[INFO] [1;32mTests run: 2, Failures: 0, Errors: 0, Skipped: 0[m
[INFO] 
[INFO] [1m------------------------------------------------------------------------[m
[INFO] [1;32mBUILD SUCCESS[m
[INFO] [1m------------------------------------------------------------------------[m
[INFO] Total time:  3.083 s
[INFO] Finished at: 2025-10-19T16:07:55+05:30
[INFO] [1m------------------------------------------------------------------------[m
Advertisements