Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add @WebServiceClientTest annotation that can be used when testing SOAP clients #17274

Closed
wants to merge 1 commit into from

Conversation

nosan
Copy link
Contributor

@nosan nosan commented Jun 20, 2019

Add a slice @WebServiceClientTest annotation that can be used when testing SOAP clients.

The implementation is quite similar to @RestClientTest but for WebServiceTemplateBuilder.
PR is not ready yet, it is just a concept of how it could be.

Here is a small example of usage:

@WebServiceClientTest(ExampleWebServiceClient.class)
class WebServiceClientIntegrationTests {

	@Autowired
	private MockWebServiceServers servers;

	@Autowired
	private ExampleWebServiceClient client;

	@Test
	void mockServerCall() {
		this.servers.expect(RequestMatchers.payload(new StringSource("<request/>"))).andRespond(
				ResponseCreators.withPayload(new StringSource("<response><status>200</status></response>")));
		assertThat(this.client.test()).extracting(Response::getStatus).isEqualTo(200);
	}

	@Test
	void mockServerCall1() {
		this.servers.expect(RequestMatchers.connectionTo("https://example1"))
				.andRespond(ResponseCreators.withPayload(new StringSource("<response/>")));
		assertThatExceptionOfType(SourceAssertionError.class).isThrownBy(this.client::test)
				.withMessageContaining("Unexpected connection expected");
	}
}

If you are interested in this feature I will add more tests and documentation.

Also, pay attention to https://github.com/spring-projects/spring-boot/compare/master...nosan:webservice-client-test?expand=1#diff-a0ae2b770ccb1b5cc0b45d9966df843aR66 it would be nice to have reset() functionality in MockWebServiceServer class. Is it possible to add?

Let me know what you think and thanks in advance.

P.S. Work-in-Progress

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 20, 2019
@philwebb philwebb added for: team-attention An issue we'd like other members of the team to review and removed for: team-attention An issue we'd like other members of the team to review labels Jun 20, 2019
@philwebb
Copy link
Member

@nosan This looks like a really nice addition to the existing test slice support and would be great to add it in 2.2.x. The one things we're not totally sure about is the MockWebServiceServers class. I think we'd rather not introduce that in Boot and instead just support a single MockWebServiceServer (similar to the way we support MockRestServiceServer).

it would be nice to have reset() functionality in MockWebServiceServer class. Is it possible to add?

@gregturn Can probably help answer that. I'd certainly like to keep a clean separation and have the general use Mock code in spring-ws and keep the Boot code specific to our slice concepts.

@nosan
Copy link
Contributor Author

nosan commented Jun 27, 2019

Thank you @philwebb,
I have added MockWebServiceServers because I have not found a way to customize MockWebServiceServer with a custom MockWebServiceMessageSender to create a deferred MockWebServiceServer since MockWebServiceMessageSender has a package private modifier.

If adding support for a slice @WebServiceClientTest annotation is desired, then the possibility to reset MockWebServiceServer after each test should be added. Also, a public modifier to MockWebServiceMessageSender class should be added as well.

@nosan
Copy link
Contributor Author

nosan commented Jun 27, 2019

@philwebb I've updated PR fc53f37 to support only a single WebServiceTemplate.

This approach is quite messy with Reflection for me. I would rather not to add @WebServiceClientTest annotation at all than using this way.

I am hoping that spring-ws team could help here.

@philwebb
Copy link
Member

@nosan I totally agree, we'll really need some upstream changes I think.

@wilkinsona
Copy link
Member

@gregturn can you please review the discussion above? As currently proposed, there's quite a bit of reflection when interacting with Spring Web Services which we'd like to avoid.

@wilkinsona wilkinsona added status: blocked An issue that's blocked on an external project change type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 18, 2020
@gregturn
Copy link
Contributor

I don't see why we can't alter the visibility of MockWebServiceServer(MockWebServiceMessageSender). Looks like a valid use case to open it up for public usage.

I opened https://jira.spring.io/browse/SWS-1085.

@gregturn
Copy link
Contributor

You can test out these changes using 2.4.7.BUILD-SNAPSHOT or 3.0.9.BUILD-SNAPSHOT (until a release is made).

@gregturn
Copy link
Contributor

If @nosan wishes to retool the PR using these modifications, so be it.

@nosan
Copy link
Contributor Author

nosan commented Mar 19, 2020

Thanks for your feedback and changes, @gregturn

I checked 3.0.9.BUILD-SNAPSHOT and unfortunately, those changes are not enough to avoid reflection at all.

Could you please add the following changes?

  • MockWebServiceMessageSender must be public as well.
  • Add reset method to MockWebServiceServer, similar to verify but for reset.

'reset' just clearsexpectedConnections and sets connectionIterator to null.

Ideally, this class should be removed.

Thanks in advance

@gregturn
Copy link
Contributor

gregturn commented Mar 19, 2020

I can extend the surface API to support a reset, but are you sure you can't just create a new instance for each test case?

@wilkinsona
Copy link
Member

@gregturn In the proposed changes, MockWebServiceServer is being used as a bean. Requiring a new instance per test would mean that we needed a new application context per test, making the test framework's context cache redundant and slowing down overall test execution.

@gregturn
Copy link
Contributor

@nosan Okay, the additional changes you requested have been applied. Again, check the latest snapshots and see if they are suitable.

@nosan
Copy link
Contributor Author

nosan commented Mar 23, 2020

Thanks @gregturn

PR has been updated

@philwebb philwebb added the for: team-attention An issue we'd like other members of the team to review label Apr 15, 2020
@gregturn
Copy link
Contributor

gregturn commented Apr 17, 2020

Spring WS 3.0.9.RELEASE has been released.

@wilkinsona wilkinsona removed the status: blocked An issue that's blocked on an external project change label Apr 20, 2020
@philwebb philwebb added this to the 2.4.x milestone May 13, 2020
@philwebb philwebb removed the for: team-attention An issue we'd like other members of the team to review label May 13, 2020
@philwebb philwebb self-assigned this May 13, 2020
philwebb pushed a commit to philwebb/spring-boot that referenced this pull request May 14, 2020
Add `@WebServiceClientTest` and related test auto-configuration to allow
slice testing of Spring Web Service client applications.

See spring-projectsgh-17274
philwebb added a commit to philwebb/spring-boot that referenced this pull request May 14, 2020
@philwebb philwebb modified the milestones: 2.4.x, 2.3.0 May 14, 2020
philwebb pushed a commit that referenced this pull request May 14, 2020
Add `@WebServiceClientTest` and related test auto-configuration to allow
slice testing of Spring Web Service client applications.

See gh-17274
@philwebb philwebb closed this in a2187bb May 14, 2020
@wilkinsona
Copy link
Member

Re-opening to address the CI failures on JDK 11 and 14.

@wilkinsona wilkinsona reopened this May 14, 2020
@snicoll snicoll self-assigned this May 14, 2020
@snicoll snicoll closed this in e6376fc May 14, 2020
@nosan nosan deleted the webservice-client-test branch May 14, 2020 09:25
@nosan
Copy link
Contributor Author

nosan commented May 14, 2020

Thanks a lot! 👍

@wilkinsona wilkinsona changed the title Add @WebServiceClientTest annotation that can be used when testing SOAP clients. Add @WebServiceClientTest annotation that can be used when testing SOAP clients May 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants