use of com.netsuite.webservices.test.platform.core.RecordRef in project components by Talend.
the class NetSuiteClientServiceTest method testGetList.
@Test
public void testGetList() throws Exception {
TypeDesc typeDesc = clientService.getMetaDataSource().getTypeInfo("PurchaseOrder");
TypeDesc refTypeDesc = clientService.getMetaDataSource().getTypeInfo("RecordRef");
List<PurchaseOrder> recordList = makeNsObjects(new NsObjectComposer<PurchaseOrder>(clientService.getMetaDataSource(), typeDesc), 10);
List<RecordRef> recordRefList = makeNsObjects(new NsObjectComposer<RecordRef>(clientService.getMetaDataSource(), refTypeDesc), 10);
GetListResponse response = new GetListResponse();
response.setReadResponseList(createSuccessReadResponseList(recordList));
when(port.getList(notNull(GetListRequest.class))).thenReturn(response);
clientService.getList(recordRefList);
verify(port, times(1)).login(notNull(LoginRequest.class));
verify(port, times(1)).getList(notNull(GetListRequest.class));
List<NsReadResponse<Record>> readResponses = clientService.getList(null);
assertTrue(readResponses.isEmpty());
}
use of com.netsuite.webservices.test.platform.core.RecordRef in project components by Talend.
the class ValueConverterTest method testJsonConverterNestedObjectConcreteType.
@Test
public void testJsonConverterNestedObjectConcreteType() throws Exception {
NsObjectInputTransducer transducer = new NsObjectInputTransducer(clientService, schema, typeDesc.getTypeName());
ObjectMapper objectMapper = new ObjectMapper();
RecordRef recordRef1 = new RecordRef();
recordRef1.setInternalId("12345");
recordRef1.setName("R&D");
ObjectNode recordRefNode1 = JsonNodeFactory.instance.objectNode();
recordRefNode1.set("name", JsonNodeFactory.instance.textNode("R&D"));
recordRefNode1.set("internalId", JsonNodeFactory.instance.textNode("12345"));
recordRefNode1.set("externalId", JsonNodeFactory.instance.nullNode());
recordRefNode1.set("type", JsonNodeFactory.instance.nullNode());
String recordRefJson1 = objectMapper.writer().writeValueAsString(recordRef1);
FieldDesc fieldDesc = typeDesc.getField("department");
AvroConverter<RecordRef, String> converter1 = (AvroConverter<RecordRef, String>) transducer.getValueConverter(fieldDesc);
String testRecordRefJson1 = converter1.convertToAvro(recordRef1);
assertNotNull(testRecordRefJson1);
JsonNode testRecordRefNode1 = objectMapper.reader().readTree(testRecordRefJson1);
assertTrue(testRecordRefNode1.has("name"));
assertTrue(testRecordRefNode1.has("internalId"));
assertTrue(testRecordRefNode1.has("externalId"));
assertTrue(testRecordRefNode1.has("type"));
assertEquals(recordRef1.getName(), testRecordRefNode1.get("name").asText());
assertEquals(recordRef1.getInternalId(), testRecordRefNode1.get("internalId").asText());
assertEquals(recordRef1.getExternalId(), testRecordRefNode1.get("externalId").asText(null));
assertNull(testRecordRefNode1.get("type").asText(null));
RecordRef testRecordRef1 = converter1.convertToDatum(recordRefJson1);
assertNotNull(testRecordRef1);
assertEquals(recordRef1.getName(), testRecordRef1.getName());
assertEquals(recordRef1.getInternalId(), testRecordRef1.getInternalId());
assertEquals(recordRef1.getExternalId(), testRecordRef1.getExternalId());
assertEquals(recordRef1.getType(), testRecordRef1.getType());
}
use of com.netsuite.webservices.test.platform.core.RecordRef in project components by Talend.
the class NetSuiteClientServiceTest method testDeleteList.
@Test
public void testDeleteList() throws Exception {
TypeDesc typeDesc = clientService.getMetaDataSource().getTypeInfo("RecordRef");
List<RecordRef> recordRefList = makeNsObjects(new NsObjectComposer<RecordRef>(clientService.getMetaDataSource(), typeDesc), 10);
DeleteListResponse response = new DeleteListResponse();
response.setWriteResponseList(createSuccessWriteResponseList(recordRefList.size()));
when(port.deleteList(notNull(DeleteListRequest.class))).thenReturn(response);
clientService.deleteList(recordRefList);
verify(port, times(1)).login(notNull(LoginRequest.class));
verify(port, times(1)).deleteList(notNull(DeleteListRequest.class));
List<NsWriteResponse<RecordRef>> writeResponses = clientService.deleteList(null);
assertTrue(writeResponses.isEmpty());
}
use of com.netsuite.webservices.test.platform.core.RecordRef 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 com.netsuite.webservices.test.platform.core.RecordRef 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