use of com.netsuite.webservices.test.platform.core.RecordRef in project components by Talend.
the class NetSuiteOutputTransducerTest method testRecordRef.
@Test
public void testRecordRef() throws Exception {
NetSuiteRuntime netSuiteRuntime = new TestNetSuiteRuntimeImpl(webServiceMockTestFixture.getClientFactory());
NetSuiteDatasetRuntime dataSetRuntime = netSuiteRuntime.getDatasetRuntime(mockTestFixture.getConnectionProperties());
TypeDesc typeDesc = clientService.getMetaDataSource().getTypeInfo(RefType.RECORD_REF.getTypeName());
TypeDesc referencedTypeDesc = clientService.getMetaDataSource().getTypeInfo("Opportunity");
Schema schema = dataSetRuntime.getSchema(typeDesc.getTypeName());
NsObjectOutputTransducer transducer = new NsObjectOutputTransducer(webServiceMockTestFixture.getClientService(), referencedTypeDesc.getTypeName());
transducer.setReference(true);
List<IndexedRecord> indexedRecordList = makeIndexedRecords(clientService, schema, new AbstractNetSuiteTestBase.SimpleObjectComposer<>(typeDesc.getTypeClass()), 10);
for (IndexedRecord indexedRecord : indexedRecordList) {
Object nsObject = transducer.write(indexedRecord);
assertNsObject(typeDesc, nsObject);
RecordRef ref = (RecordRef) nsObject;
assertEquals(RecordType.OPPORTUNITY, ref.getType());
}
}
use of com.netsuite.webservices.test.platform.core.RecordRef in project components by Talend.
the class TestNetSuiteClientService method createNativePassport.
@Override
protected Passport createNativePassport(NetSuiteCredentials nsCredentials) {
RecordRef roleRecord = new RecordRef();
roleRecord.setInternalId(nsCredentials.getRoleId());
final Passport passport = new Passport();
passport.setEmail(nsCredentials.getEmail());
passport.setPassword(nsCredentials.getPassword());
passport.setRole(roleRecord);
passport.setAccount(nsCredentials.getAccount());
return passport;
}
use of com.netsuite.webservices.test.platform.core.RecordRef in project components by Talend.
the class NsRefTest method testRecordRef.
@Test
public void testRecordRef() {
NsRef ref1 = new NsRef(RefType.RECORD_REF);
ref1.setType(RecordType.ACCOUNT.value());
ref1.setInternalId("10001");
ref1.setExternalId(UUID.randomUUID().toString());
RecordRef recordRef = (RecordRef) ref1.toNativeRef(basicMetaData);
assertNotNull(recordRef);
assertEquals(RecordType.ACCOUNT, recordRef.getType());
assertEquals(ref1.getInternalId(), recordRef.getInternalId());
assertEquals(ref1.getExternalId(), recordRef.getExternalId());
NsRef ref2 = NsRef.fromNativeRef(recordRef);
assertNotNull(ref2);
assertEquals(RecordType.ACCOUNT.value(), ref2.getType());
assertEquals(recordRef.getInternalId(), ref2.getInternalId());
assertEquals(recordRef.getExternalId(), ref2.getExternalId());
}
use of com.netsuite.webservices.test.platform.core.RecordRef in project components by Talend.
the class ValueConverterTest method testJsonConverterError.
@Test
public void testJsonConverterError() throws Exception {
NsObjectInputTransducer transducer = new NsObjectInputTransducer(clientService, schema, typeDesc.getTypeName());
FieldDesc fieldDesc = typeDesc.getField("department");
AvroConverter<RecordRef, String> converter1 = (AvroConverter<RecordRef, String>) transducer.getValueConverter(fieldDesc);
try {
converter1.convertToDatum("{name:'R&D',internalId:'12345',externalId:null,type:null}");
fail("NetSuiteException expected");
} catch (Exception e) {
assertThat(e, instanceOf(NetSuiteException.class));
NetSuiteException nsException = (NetSuiteException) e;
assertNotNull(nsException.getCode());
assertNotNull(nsException.getContext());
assertNotNull(nsException.getContext().get(ExceptionContext.KEY_MESSAGE));
}
}
use of com.netsuite.webservices.test.platform.core.RecordRef in project components by Talend.
the class ValueConverterTest method testJsonConverterComplexObject.
@Test
public void testJsonConverterComplexObject() throws Exception {
NsObjectInputTransducer transducer = new NsObjectInputTransducer(clientService, schema, typeDesc.getTypeName());
Account account1 = new SimpleObjectComposer<>(Account.class).composeObject();
RecordRef recordRef1 = new RecordRef();
recordRef1.setInternalId("120001");
recordRef1.setName("Talend France");
RecordRef recordRef2 = new RecordRef();
recordRef2.setInternalId("120002");
recordRef2.setName("Talend China");
RecordRefList recordRefList1 = new RecordRefList();
recordRefList1.getRecordRef().add(recordRef1);
recordRefList1.getRecordRef().add(recordRef2);
account1.setSubsidiaryList(recordRefList1);
BooleanCustomFieldRef customFieldRef1 = new BooleanCustomFieldRef();
customFieldRef1.setInternalId("100001");
customFieldRef1.setScriptId("custentity_field1");
customFieldRef1.setValue(true);
StringCustomFieldRef customFieldRef2 = new StringCustomFieldRef();
customFieldRef2.setInternalId("100002");
customFieldRef2.setScriptId("custentity_field2");
customFieldRef2.setValue("test123");
CustomFieldList customFieldList = new CustomFieldList();
customFieldList.getCustomField().add(customFieldRef1);
customFieldList.getCustomField().add(customFieldRef2);
account1.setCustomFieldList(customFieldList);
AvroConverter<Account, String> converter1 = (AvroConverter<Account, String>) transducer.getValueConverter(account1.getClass());
assertEquals(AvroUtils._string(), converter1.getSchema());
assertEquals(account1.getClass(), converter1.getDatumClass());
String testJson1 = converter1.convertToAvro(account1);
assertNotNull(testJson1);
Account testAccount1 = converter1.convertToDatum(testJson1);
assertNotNull(testAccount1);
}
Aggregations