Search in sources :

Example 26 with TypeDesc

use of org.talend.components.netsuite.client.model.TypeDesc in project components by Talend.

the class NetSuiteClientServiceTest method testUpsert.

@Test
public void testUpsert() throws Exception {
    TypeDesc typeDesc = clientService.getMetaDataSource().getTypeInfo("PurchaseOrder");
    PurchaseOrder record = new NsObjectComposer<PurchaseOrder>(clientService.getMetaDataSource(), typeDesc).composeObject();
    UpsertResponse response = new UpsertResponse();
    response.setWriteResponse(createSuccessWriteResponse());
    when(port.upsert(notNull(UpsertRequest.class))).thenReturn(response);
    clientService.upsert(record);
    verify(port, times(1)).login(notNull(LoginRequest.class));
    verify(port, times(1)).upsert(notNull(UpsertRequest.class));
    NsWriteResponse writeResponse = clientService.upsert(null);
    assertNull(writeResponse.getStatus());
    assertNull(writeResponse.getRef());
}
Also used : UpsertResponse(com.netsuite.webservices.test.platform.messages.UpsertResponse) TypeDesc(org.talend.components.netsuite.client.model.TypeDesc) UpsertRequest(com.netsuite.webservices.test.platform.messages.UpsertRequest) PurchaseOrder(com.netsuite.webservices.test.transactions.purchases.PurchaseOrder) LoginRequest(com.netsuite.webservices.test.platform.messages.LoginRequest) Test(org.junit.Test)

Example 27 with TypeDesc

use of org.talend.components.netsuite.client.model.TypeDesc in project components by Talend.

the class NetSuiteClientServiceTest method testGet.

@Test
public void testGet() throws Exception {
    TypeDesc typeDesc = clientService.getMetaDataSource().getTypeInfo("PurchaseOrder");
    TypeDesc refTypeDesc = clientService.getMetaDataSource().getTypeInfo("RecordRef");
    PurchaseOrder record = new NsObjectComposer<PurchaseOrder>(clientService.getMetaDataSource(), typeDesc).composeObject();
    RecordRef recordRef = new NsObjectComposer<RecordRef>(clientService.getMetaDataSource(), refTypeDesc).composeObject();
    GetResponse response = new GetResponse();
    response.setReadResponse(createSuccessReadResponse(record));
    when(port.get(notNull(GetRequest.class))).thenReturn(response);
    clientService.get(recordRef);
    verify(port, times(1)).login(notNull(LoginRequest.class));
    verify(port, times(1)).get(notNull(GetRequest.class));
    NsReadResponse readResponse = clientService.get(null);
    assertNull(readResponse.getStatus());
    assertNull(readResponse.getRecord());
}
Also used : GetRequest(com.netsuite.webservices.test.platform.messages.GetRequest) TypeDesc(org.talend.components.netsuite.client.model.TypeDesc) RecordRef(com.netsuite.webservices.test.platform.core.RecordRef) PurchaseOrder(com.netsuite.webservices.test.transactions.purchases.PurchaseOrder) LoginRequest(com.netsuite.webservices.test.platform.messages.LoginRequest) GetResponse(com.netsuite.webservices.test.platform.messages.GetResponse) Test(org.junit.Test)

Example 28 with TypeDesc

use of org.talend.components.netsuite.client.model.TypeDesc 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 29 with TypeDesc

use of org.talend.components.netsuite.client.model.TypeDesc 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 30 with TypeDesc

use of org.talend.components.netsuite.client.model.TypeDesc in project components by Talend.

the class NetSuiteClientServiceTest method testAddList.

@Test
public void testAddList() throws Exception {
    TypeDesc typeDesc = clientService.getMetaDataSource().getTypeInfo("PurchaseOrder");
    List<PurchaseOrder> recordList = makeNsObjects(new NsObjectComposer<PurchaseOrder>(clientService.getMetaDataSource(), typeDesc), 10);
    AddListResponse response = new AddListResponse();
    response.setWriteResponseList(createSuccessWriteResponseList(recordList.size()));
    when(port.addList(notNull(AddListRequest.class))).thenReturn(response);
    clientService.addList(recordList);
    verify(port, times(1)).login(notNull(LoginRequest.class));
    verify(port, times(1)).addList(notNull(AddListRequest.class));
    List<NsWriteResponse<RecordRef>> writeResponses = clientService.addList(null);
    assertTrue(writeResponses.isEmpty());
}
Also used : AddListResponse(com.netsuite.webservices.test.platform.messages.AddListResponse) AddListRequest(com.netsuite.webservices.test.platform.messages.AddListRequest) TypeDesc(org.talend.components.netsuite.client.model.TypeDesc) PurchaseOrder(com.netsuite.webservices.test.transactions.purchases.PurchaseOrder) LoginRequest(com.netsuite.webservices.test.platform.messages.LoginRequest) Test(org.junit.Test)

Aggregations

TypeDesc (org.talend.components.netsuite.client.model.TypeDesc)48 Test (org.junit.Test)41 Schema (org.apache.avro.Schema)31 IndexedRecord (org.apache.avro.generic.IndexedRecord)23 ArrayList (java.util.ArrayList)14 NetSuiteDatasetRuntime (org.talend.components.netsuite.NetSuiteDatasetRuntime)13 LoginRequest (com.netsuite.webservices.test.platform.messages.LoginRequest)12 NetSuiteRuntime (org.talend.components.netsuite.NetSuiteRuntime)10 FieldDesc (org.talend.components.netsuite.client.model.FieldDesc)10 RecordTypeDesc (org.talend.components.netsuite.client.model.RecordTypeDesc)10 SearchRecordTypeDesc (org.talend.components.netsuite.client.model.SearchRecordTypeDesc)10 CustomFieldDesc (org.talend.components.netsuite.client.model.CustomFieldDesc)9 PurchaseOrder (com.netsuite.webservices.test.transactions.purchases.PurchaseOrder)8 NetSuiteWebServiceMockTestFixture.assertIndexedRecord (org.talend.components.netsuite.NetSuiteWebServiceMockTestFixture.assertIndexedRecord)8 RecordTypeInfo (org.talend.components.netsuite.client.model.RecordTypeInfo)8 RecordRef (com.netsuite.webservices.test.platform.core.RecordRef)7 CustomRecord (com.netsuite.webservices.test.setup.customization.CustomRecord)7 NetSuiteException (org.talend.components.netsuite.client.NetSuiteException)6 CustomRecordTypeInfo (org.talend.components.netsuite.client.model.CustomRecordTypeInfo)6 InvocationOnMock (org.mockito.invocation.InvocationOnMock)4