Search in sources :

Example 1 with InvalidSessionFault

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);
}
Also used : TypeDesc(org.talend.components.netsuite.client.model.TypeDesc) RecordRef(com.netsuite.webservices.test.platform.core.RecordRef) InvalidSessionFault(com.netsuite.webservices.test.platform.InvalidSessionFault) LoginRequest(com.netsuite.webservices.test.platform.messages.LoginRequest) StopWatch(org.apache.commons.lang3.time.StopWatch) DeleteResponse(com.netsuite.webservices.test.platform.messages.DeleteResponse) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InvocationOnMock(org.mockito.invocation.InvocationOnMock) DeleteRequest(com.netsuite.webservices.test.platform.messages.DeleteRequest) Test(org.junit.Test)

Aggregations

InvalidSessionFault (com.netsuite.webservices.test.platform.InvalidSessionFault)1 RecordRef (com.netsuite.webservices.test.platform.core.RecordRef)1 DeleteRequest (com.netsuite.webservices.test.platform.messages.DeleteRequest)1 DeleteResponse (com.netsuite.webservices.test.platform.messages.DeleteResponse)1 LoginRequest (com.netsuite.webservices.test.platform.messages.LoginRequest)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 StopWatch (org.apache.commons.lang3.time.StopWatch)1 Test (org.junit.Test)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 TypeDesc (org.talend.components.netsuite.client.model.TypeDesc)1