Reputation: 4158
I am writing an test class for Integration Testing using groovy file
My Groovy File :
@UseModules(value = [MiddleModule])
class MiddleServiceIT extends Specification{
@Inject
MiddleService middleService
@Rule
public WireMockRule Server = new WireMockRule(wireMockConfig().port(9090));
def 'validate config'() {
expect:
middleService != null
}
def 'validate get'() {
/* String urlPath = 'http://localhost:8889/middle/?acctID=80873000101&vodSource=ais&headendID=louis&activeOnly=true&limit=50&startDate=2014-10-09&inclNonSyncData=test' */
String urlPath = 'http://localhost:8889/middle/'
given:
Server.stubFor(get(urlPathEqualTo(urlPath)).willReturn(MiddleServiceStub.buildSuccess()))
when:
MiddleMessage response = middleService.get( '80873000101','ais', 'louis', 'true', '50', '2014-10-09', 'test')
then:
response != null
}
}
Here my requirement is when it hits that URL, it has to give the response which I mentioned in the stubFor call.
My Original Method :
@Override
public MiddleMessage get(String acctID, String vodSource, String headendID, String activeOnly, String limit, String startDate, String inclNonSyncData){
String url = rentalsMiddleBaseUrl + "/?acctID=" + acctID + "&vodSource=" + vodSource + "&headendID=" + headendID + "&activeOnly=" + activeOnly + "&limit=" + limit + "&startDate=" + startDate + "&inclNonSyncData=" + inclNonSyncData;
System.out.println("***** For Test URL "+url);
return (MiddleMessage) commandBuilder.build(url,MiddleMessage.class).execute();
}
My Stub Method in MiddleServiceStub Class:
public static ResponseDefinitionBuilder buildSuccess() throws JsonProcessingException {
ObjectMapper mapper = new ObjectMapper();
MiddleSet middleSet = new MiddleSet();
MiddleMessage middleMessage = new MiddleMessage();
middleMessage.setMiddleSet(middleSet);
String json = mapper.writeValueAsString(middleMessage);
ResponseDefinitionBuilder responseDefinitionBuilder = ResponseDefinitionBuilder.like(ResponseDefinition.created()).withBody(json);
return responseDefinitionBuilder;
}
When I run the above code using maven command "clean install" it is giving the following exception
validate get(com.config.MiddleServiceTest) Time elapsed: 1.918 sec <<< ERROR!
com.netflix.hystrix.exception.HystrixRuntimeException: execute timed-out and no fallback available.
at com.netflix.hystrix.HystrixCommand.getFallbackOrThrowException(HystrixCommand.java:1646)
at com.netflix.hystrix.HystrixCommand.access$1900(HystrixCommand.java:103)
at com.netflix.hystrix.HystrixCommand$TimeoutObservable$1$1.run(HystrixCommand.java:1023)
at com.netflix.hystrix.strategy.concurrency.HystrixContextRunnable$1.call(HystrixContextRunnable.java:41)
at com.netflix.hystrix.strategy.concurrency.HystrixContextRunnable$1.call(HystrixContextRunnable.java:37)
at com.netflix.hystrix.strategy.concurrency.HystrixContextRunnable.run(HystrixContextRunnable.java:57)
at com.netflix.hystrix.HystrixCommand$TimeoutObservable$1$2.tick(HystrixCommand.java:1047)
at com.netflix.hystrix.HystrixCommand$1.performBlockingGetWithTimeout(HystrixCommand.java:627)
at com.netflix.hystrix.HystrixCommand$1.get(HystrixCommand.java:522)
at com.netflix.hystrix.HystrixCommand.execute(HystrixCommand.java:431)
at com.client.MiddleService.get(MiddleService.java:72)
at com.config.MiddleServiceTest.validate get(MiddleServiceTest.groovy:22)
Caused by: java.util.concurrent.TimeoutException
Upvotes: 1
Views: 8594
Reputation: 4149
The parameter you pass to urlPathEqualTo(...)
should be a relative URL, not absolute.
I don't know if this is what's causing the exception you've pasted, but WireMock will return a 404 given your current setup, which I suspect isn't what you want.
Upvotes: 1