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());
}
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());
}
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);
}
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());
}
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());
}
Aggregations