use of com.netsuite.webservices.v2016_2.platform.messages.WriteResponse in project components by Talend.
the class NetSuiteOutputWriterIT method testUpdateWithCustomFields.
@Test
public void testUpdateWithCustomFields() throws Exception {
final NetSuiteClientService<NetSuitePortType> clientService = webServiceTestFixture.getClientService();
RuntimeContainer container = mock(RuntimeContainer.class);
NetSuiteOutputProperties properties = new NetSuiteOutputProperties("test");
properties.init();
properties.connection.endpoint.setValue(webServiceTestFixture.getEndpointUrl());
properties.connection.email.setValue(webServiceTestFixture.getCredentials().getEmail());
properties.connection.password.setValue(webServiceTestFixture.getCredentials().getPassword());
properties.connection.account.setValue(webServiceTestFixture.getCredentials().getAccount());
properties.connection.role.setValue(Integer.valueOf(webServiceTestFixture.getCredentials().getRoleId()));
properties.connection.applicationId.setValue(webServiceTestFixture.getCredentials().getApplicationId());
properties.module.moduleName.setValue(RecordTypeEnum.CONTACT.getTypeName());
properties.module.action.setValue(OutputAction.UPDATE);
NetSuiteRuntimeImpl runtime = new NetSuiteRuntimeImpl();
runtime.setClientFactory(clientFactory);
NetSuiteDatasetRuntime dataSetRuntime = runtime.getDatasetRuntime(properties.getConnectionProperties());
Schema schema = dataSetRuntime.getSchema(properties.module.moduleName.getValue());
properties.module.main.schema.setValue(schema);
SubsidiarySearch subsidiarySearch = new SubsidiarySearch();
SubsidiarySearchBasic subsidiarySearchBasic = new SubsidiarySearchBasic();
subsidiarySearch.setBasic(subsidiarySearchBasic);
NsSearchResult<Subsidiary> searchResult = clientService.search(subsidiarySearch);
assertTrue(searchResult.isSuccess());
assertNotNull(searchResult.getRecordList());
assertTrue(searchResult.getRecordList().size() > 0);
Subsidiary subsidiary = searchResult.getRecordList().get(0);
RecordRef subsidiaryRef = new RecordRef();
subsidiaryRef.setType(RecordType.SUBSIDIARY);
subsidiaryRef.setInternalId(subsidiary.getInternalId());
TypeDesc typeDesc = clientService.getMetaDataSource().getTypeInfo("Contact");
assertNotNull(typeDesc.getField("custentity_interest_bpm"));
List<Contact> recordsToAdd = makeContactRecords(5, subsidiaryRef, typeDesc.getFieldMap());
final List<RecordRef> refList = new ArrayList<>(recordsToAdd.size());
// Add records
List<NsWriteResponse<RecordRef>> writeResponseList = clientService.addList(recordsToAdd);
for (NsWriteResponse<RecordRef> writeResponse : writeResponseList) {
assertTrue("Add: " + writeResponse.getStatus(), writeResponse.getStatus().isSuccess());
assertNotNull(writeResponse.getRef());
refList.add(writeResponse.getRef());
}
// Read added records
List<Contact> recordList = new ArrayList<>(refList.size());
List<NsReadResponse<Contact>> readResponseList = clientService.execute(new NetSuiteClientService.PortOperation<List<NsReadResponse<Contact>>, NetSuitePortType>() {
@Override
public List<NsReadResponse<Contact>> execute(NetSuitePortType port) throws Exception {
GetListRequest request = new GetListRequest();
request.getBaseRef().addAll(refList);
return NetSuiteClientServiceImpl.toNsReadResponseList(port.getList(request).getReadResponseList());
}
});
for (NsReadResponse<Contact> readResponse : readResponseList) {
assertTrue(readResponse.getStatus().isSuccess());
recordList.add(readResponse.getRecord());
}
List<IndexedRecord> indexedRecordList = new ArrayList<>(refList.size());
for (Contact record : recordList) {
GenericRecord indexedRecord = new GenericData.Record(schema);
indexedRecord.put("InternalId", record.getInternalId());
// Updated fields
indexedRecord.put("custentity_interest_bpm", Boolean.FALSE);
indexedRecordList.add(indexedRecord);
}
// Update records
NetSuiteSink sink = new NetSuiteSinkImpl();
sink.setClientFactory(clientFactory);
sink.initialize(container, properties);
NetSuiteWriteOperation writeOperation = (NetSuiteWriteOperation) sink.createWriteOperation();
NetSuiteOutputWriter writer = (NetSuiteOutputWriter) writeOperation.createWriter(container);
writer.open(UUID.randomUUID().toString());
for (IndexedRecord indexedRecord : indexedRecordList) {
writer.write(indexedRecord);
}
Result writerResult = writer.close();
assertNotNull(writerResult);
assertEquals(indexedRecordList.size(), writerResult.totalCount);
assertEquals(indexedRecordList.size(), writerResult.successCount);
// Re-read updated records
readResponseList = clientService.execute(new NetSuiteClientService.PortOperation<List<NsReadResponse<Contact>>, NetSuitePortType>() {
@Override
public List<NsReadResponse<Contact>> execute(NetSuitePortType port) throws Exception {
GetListRequest request = new GetListRequest();
request.getBaseRef().addAll(refList);
return NetSuiteClientServiceImpl.toNsReadResponseList(port.getList(request).getReadResponseList());
}
});
for (NsReadResponse<Contact> readResponse : readResponseList) {
assertTrue(readResponse.getStatus().isSuccess());
Contact record = readResponse.getRecord();
CustomFieldList customFieldList = record.getCustomFieldList();
assertNotNull(customFieldList);
Map<String, CustomFieldRef> customFieldRefMap = new HashMap<>();
for (CustomFieldRef fieldRef : customFieldList.getCustomField()) {
customFieldRefMap.put(fieldRef.getScriptId(), fieldRef);
}
BooleanCustomFieldRef customFieldRef1 = (BooleanCustomFieldRef) customFieldRefMap.get("custentity_interest_bpm");
assertNotNull(customFieldRef1);
assertEquals(Boolean.FALSE, customFieldRef1.getValue());
}
clientService.deleteList(refList);
}
use of com.netsuite.webservices.v2016_2.platform.messages.WriteResponse in project components by Talend.
the class NetSuiteOutputWriterTest method testDelete.
@Test
public void testDelete() throws Exception {
final NetSuitePortType port = webServiceMockTestFixture.getPortMock();
final TypeDesc typeDesc = webServiceMockTestFixture.getClientService().getMetaDataSource().getTypeInfo(RecordTypeEnum.OPPORTUNITY.getTypeName());
final TypeDesc refTypeDesc = webServiceMockTestFixture.getClientService().getMetaDataSource().getTypeInfo(RefType.RECORD_REF.getTypeName());
properties.module.moduleName.setValue(typeDesc.getTypeName());
properties.module.action.setValue(OutputAction.DELETE);
final List<RecordRef> deletedRecordRefList = new ArrayList<>();
when(port.deleteList(any(DeleteListRequest.class))).then(new Answer<DeleteListResponse>() {
@Override
public DeleteListResponse answer(InvocationOnMock invocationOnMock) throws Throwable {
DeleteListRequest request = (DeleteListRequest) invocationOnMock.getArguments()[0];
DeleteListResponse response = new DeleteListResponse();
WriteResponseList writeResponseList = new WriteResponseList();
for (int i = 0; i < request.getBaseRef().size(); i++) {
RecordRef recordRef = (RecordRef) request.getBaseRef().get(i);
assertNotNull(recordRef);
assertNotNull(recordRef.getInternalId());
assertNotNull(recordRef.getType());
deletedRecordRefList.add(recordRef);
WriteResponse writeResponse = new WriteResponse();
writeResponse.setStatus(createSuccessStatus());
writeResponse.setBaseRef(recordRef);
writeResponseList.getWriteResponse().add(writeResponse);
}
response.setWriteResponseList(writeResponseList);
return response;
}
});
NetSuiteRuntime netSuiteRuntime = new NetSuiteRuntimeImpl();
NetSuiteDatasetRuntime dataSetRuntime = netSuiteRuntime.getDatasetRuntime(properties.getConnectionProperties());
Schema schema = dataSetRuntime.getSchema(RefType.RECORD_REF.getTypeName());
properties.module.main.schema.setValue(schema);
NetSuiteSink sink = new NetSuiteSinkImpl();
sink.initialize(mockTestFixture.getRuntimeContainer(), properties);
NetSuiteClientService<?> clientService = sink.getClientService();
NetSuiteWriteOperation writeOperation = (NetSuiteWriteOperation) sink.createWriteOperation();
NetSuiteOutputWriter writer = (NetSuiteOutputWriter) writeOperation.createWriter(mockTestFixture.getRuntimeContainer());
writer.open(UUID.randomUUID().toString());
List<IndexedRecord> indexedRecordList = makeIndexedRecords(clientService, schema, new RecordRefComposer<>(refTypeDesc.getTypeClass()), 150);
for (IndexedRecord record : indexedRecordList) {
writer.write(record);
}
Result writerResult = writer.close();
assertNotNull(writerResult);
assertEquals(indexedRecordList.size(), writerResult.totalCount);
verify(port, times(2)).deleteList(any(DeleteListRequest.class));
assertEquals(indexedRecordList.size(), deletedRecordRefList.size());
}
Aggregations