use of com.netsuite.webservices.test.platform.InvalidSessionFault in project components by Talend.
the class NetSuiteClientServiceTest method testRetrying.
@Test
public void testRetrying() throws Exception {
clientService.setRetryCount(3);
clientService.setRetryInterval(1);
clientService.login();
TypeDesc typeDesc = clientService.getMetaDataSource().getTypeInfo("RecordRef");
RecordRef recordRef = new NsObjectComposer<RecordRef>(clientService.getMetaDataSource(), typeDesc).composeObject();
final DeleteResponse response = new DeleteResponse();
response.setWriteResponse(createSuccessWriteResponse());
final AtomicInteger counter = new AtomicInteger(3);
when(port.delete(notNull(DeleteRequest.class))).thenAnswer(new Answer<DeleteResponse>() {
@Override
public DeleteResponse answer(InvocationOnMock invocation) throws Throwable {
if (counter.decrementAndGet() > 0) {
com.netsuite.webservices.test.platform.faults.InvalidSessionFault faultInfo = new com.netsuite.webservices.test.platform.faults.InvalidSessionFault();
faultInfo.setCode(FaultCodeType.SESSION_TIMED_OUT);
faultInfo.setMessage("Session timed out");
InvalidSessionFault fault = new InvalidSessionFault(faultInfo.getMessage(), faultInfo);
throw fault;
}
return response;
}
});
StopWatch stopWatch = new StopWatch();
stopWatch.start();
clientService.delete(recordRef);
stopWatch.stop();
verify(port, times(3)).login(notNull(LoginRequest.class));
verify(port, times(3)).delete(notNull(DeleteRequest.class));
assertTrue(stopWatch.getTime() >= 3 * clientService.getRetryInterval() * 1000);
}
Aggregations