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

spring-retry with MockWebServiceServer error: 'webServiceTemplate' must not be null #11920

Closed
mhewedy opened this issue Feb 6, 2018 · 6 comments
Labels
for: stackoverflow A question that's better suited to stackoverflow.com status: invalid An issue that we don't feel is valid

Comments

@mhewedy
Copy link
Contributor

mhewedy commented Feb 6, 2018

I'm using spring-boot 1.5.7.RELEASE and I'm having trouble when I have a mocked WebServiceGatewaySupport which has @retryable annotations in the subclass of that class. When I call Mockito.verify() I get an UnfinishedVerificationException exception.

I find a workaround like #6828 and #5837

if (client instanceof Advised) {
	client = (MySubClassOfWebServiceGatewaySupport) ((Advised) client).getTargetSource().getTarget();
}
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 6, 2018
@wilkinsona
Copy link
Member

Are you using @MockBean or creating the mock yourself? As noted in #6828, there's not much we can do if it's the latter. If it's the former, please provide a small sample that reproduces the problem and we can take a look.

@wilkinsona wilkinsona added the status: waiting-for-feedback We need additional information before we can continue label Feb 6, 2018
@mhewedy
Copy link
Contributor Author

mhewedy commented Feb 6, 2018

I am using something similar to the example in the documentation here

Here's what I am doing:

@RunWith(SpringRunner.class)
@SpringBootTest(classes = MyApp.class)
@Import(MyConfiguration.class)
public class MySubClassOfWebServiceGatewaySupportIntTest {

    @Autowired
    private MySubClassOfWebServiceGatewaySupport client;

    private MockWebServiceServer mockServer;

  
    @Before
    public void createServer() throws Exception {
        mockServer = MockWebServiceServer.createServer(client); // fails here with 'webServiceTemplate' must not be null
    }
	
	// ......
}

When I inspect the client object itself i got:

CGLIB$BOUND = false
CGLIB$CALLBACK_0 = {CglibAopProxy$DynamicAdvisedInterceptor@14886} 
CGLIB$CALLBACK_1 = {CglibAopProxy$StaticUnadvisedInterceptor@14887} 
CGLIB$CALLBACK_2 = {CglibAopProxy$SerializableNoOp@14888} 
CGLIB$CALLBACK_3 = {CglibAopProxy$StaticDispatcher@14889} 
CGLIB$CALLBACK_4 = {CglibAopProxy$AdvisedDispatcher@14890} 
CGLIB$CALLBACK_5 = {CglibAopProxy$EqualsInterceptor@14891} 
CGLIB$CALLBACK_6 = {CglibAopProxy$HashCodeInterceptor@14892} 
logger = null
webServiceTemplate = null

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Feb 6, 2018
@wilkinsona
Copy link
Member

Thanks, but that's not enough information for us to figure out what's going on here. For example, you mentioned Mockito in the title and original description but I can't see any sign of it being used in the code above. If you'd like us to spend some more time on this, please take the time to provide a small, complete sample that reproduces the problem.

@wilkinsona wilkinsona added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Feb 6, 2018
@mhewedy mhewedy changed the title Mockito fails to verify mocked WebServiceGatewaySupport when contains @Retryable methods spring-retry with MockWebServiceServer error: 'webServiceTemplate' must not be null Feb 6, 2018
@mhewedy
Copy link
Contributor Author

mhewedy commented Feb 6, 2018

Title updated, sorry it was copy-n-paste.

I'll work on a complete example and upload here.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Feb 6, 2018
@wilkinsona wilkinsona added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Feb 6, 2018
@mhewedy
Copy link
Contributor Author

mhewedy commented Feb 8, 2018

Demo spring boot app to reproduce the issue
demo.zip

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Feb 8, 2018
@wilkinsona
Copy link
Member

wilkinsona commented Feb 9, 2018

Thanks. This isn't a Spring Boot problem. It's a problem with Spring Retry proxying QuoteClient due to its @Retryable method and MockWebServiceServer.createServer being unable to correctly consume that proxy. You can avoid the problem by unwrapping the proxy before passing it into createServer:

@Before
public void before() {
    mockServer = MockWebServiceServer.createServer((QuoteClient)AopTestUtils.getUltimateTargetObject(quoteClient));
}

@wilkinsona wilkinsona added status: invalid An issue that we don't feel is valid for: stackoverflow A question that's better suited to stackoverflow.com and removed status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged labels Feb 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: stackoverflow A question that's better suited to stackoverflow.com status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

3 participants