Search in sources :

Example 1 with DeleteResponse

use of com.netsuite.webservices.test.platform.messages.DeleteResponse 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)

Example 2 with DeleteResponse

use of com.netsuite.webservices.test.platform.messages.DeleteResponse in project components by Talend.

the class NetSuiteClientServiceTest method testDelete.

@Test
public void testDelete() throws Exception {
    TypeDesc typeDesc = clientService.getMetaDataSource().getTypeInfo("RecordRef");
    RecordRef recordRef = new NsObjectComposer<RecordRef>(clientService.getMetaDataSource(), typeDesc).composeObject();
    DeleteResponse response = new DeleteResponse();
    response.setWriteResponse(createSuccessWriteResponse());
    when(port.delete(notNull(DeleteRequest.class))).thenReturn(response);
    clientService.delete(recordRef);
    verify(port, times(1)).login(notNull(LoginRequest.class));
    verify(port, times(1)).delete(notNull(DeleteRequest.class));
    NsWriteResponse writeResponse = clientService.delete(null);
    assertNull(writeResponse.getStatus());
    assertNull(writeResponse.getRef());
}
Also used : DeleteResponse(com.netsuite.webservices.test.platform.messages.DeleteResponse) TypeDesc(org.talend.components.netsuite.client.model.TypeDesc) RecordRef(com.netsuite.webservices.test.platform.core.RecordRef) LoginRequest(com.netsuite.webservices.test.platform.messages.LoginRequest) DeleteRequest(com.netsuite.webservices.test.platform.messages.DeleteRequest) Test(org.junit.Test)

Example 3 with DeleteResponse

use of com.netsuite.webservices.test.platform.messages.DeleteResponse in project components by Talend.

the class NetSuiteClientServiceTest method testLogin.

@Test
public void testLogin() throws Exception {
    clientService.login();
    verify(port, times(1)).login(argThat(new AssertMatcher<LoginRequest>() {

        @Override
        protected void doAssert(LoginRequest request) throws Exception {
            assertNotNull(request);
            Passport passport = request.getPassport();
            assertNotNull(passport);
        }
    }));
    // Verify that logging in not performed for already logged in client
    TypeDesc typeDesc = clientService.getMetaDataSource().getTypeInfo("RecordRef");
    RecordRef recordRef = new NsObjectComposer<RecordRef>(clientService.getMetaDataSource(), typeDesc).composeObject();
    DeleteResponse response = new DeleteResponse();
    response.setWriteResponse(createSuccessWriteResponse());
    when(port.delete(notNull(DeleteRequest.class))).thenReturn(response);
    clientService.delete(recordRef);
    verify(port, times(1)).login(any(LoginRequest.class));
}
Also used : Passport(com.netsuite.webservices.test.platform.core.Passport) DeleteResponse(com.netsuite.webservices.test.platform.messages.DeleteResponse) TypeDesc(org.talend.components.netsuite.client.model.TypeDesc) RecordRef(com.netsuite.webservices.test.platform.core.RecordRef) LoginRequest(com.netsuite.webservices.test.platform.messages.LoginRequest) AssertMatcher(org.talend.components.netsuite.test.AssertMatcher) DeleteRequest(com.netsuite.webservices.test.platform.messages.DeleteRequest) Test(org.junit.Test)

Aggregations

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