Search in sources :

Example 1 with RecordRef

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());
    }
}
Also used : AbstractNetSuiteTestBase(org.talend.components.netsuite.AbstractNetSuiteTestBase) IndexedRecord(org.apache.avro.generic.IndexedRecord) NetSuiteRuntime(org.talend.components.netsuite.NetSuiteRuntime) Schema(org.apache.avro.Schema) TypeDesc(org.talend.components.netsuite.client.model.TypeDesc) RecordRef(com.netsuite.webservices.test.platform.core.RecordRef) CustomRecordRef(com.netsuite.webservices.test.platform.core.CustomRecordRef) NetSuiteDatasetRuntime(org.talend.components.netsuite.NetSuiteDatasetRuntime) NetSuiteWebServiceMockTestFixture.assertNsObject(org.talend.components.netsuite.NetSuiteWebServiceMockTestFixture.assertNsObject) TestNetSuiteRuntimeImpl(org.talend.components.netsuite.TestNetSuiteRuntimeImpl) Test(org.junit.Test)

Example 2 with RecordRef

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;
}
Also used : Passport(com.netsuite.webservices.test.platform.core.Passport) RecordRef(com.netsuite.webservices.test.platform.core.RecordRef)

Example 3 with RecordRef

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());
}
Also used : RecordRef(com.netsuite.webservices.test.platform.core.RecordRef) CustomRecordRef(com.netsuite.webservices.test.platform.core.CustomRecordRef) NsRef(org.talend.components.netsuite.client.NsRef) Test(org.junit.Test)

Example 4 with RecordRef

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));
    }
}
Also used : RecordRef(com.netsuite.webservices.test.platform.core.RecordRef) NsObjectInputTransducer(org.talend.components.netsuite.input.NsObjectInputTransducer) NetSuiteException(org.talend.components.netsuite.client.NetSuiteException) AvroConverter(org.talend.daikon.avro.converter.AvroConverter) NetSuiteException(org.talend.components.netsuite.client.NetSuiteException) FieldDesc(org.talend.components.netsuite.client.model.FieldDesc) Test(org.junit.Test)

Example 5 with RecordRef

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);
}
Also used : RecordRefList(com.netsuite.webservices.test.platform.core.RecordRefList) Account(com.netsuite.webservices.test.lists.accounting.Account) RecordRef(com.netsuite.webservices.test.platform.core.RecordRef) BooleanCustomFieldRef(com.netsuite.webservices.test.platform.core.BooleanCustomFieldRef) NsObjectInputTransducer(org.talend.components.netsuite.input.NsObjectInputTransducer) CustomFieldList(com.netsuite.webservices.test.platform.core.CustomFieldList) StringCustomFieldRef(com.netsuite.webservices.test.platform.core.StringCustomFieldRef) AvroConverter(org.talend.daikon.avro.converter.AvroConverter) Test(org.junit.Test)

Aggregations

RecordRef (com.netsuite.webservices.test.platform.core.RecordRef)13 Test (org.junit.Test)11 TypeDesc (org.talend.components.netsuite.client.model.TypeDesc)7 LoginRequest (com.netsuite.webservices.test.platform.messages.LoginRequest)6 DeleteRequest (com.netsuite.webservices.test.platform.messages.DeleteRequest)3 DeleteResponse (com.netsuite.webservices.test.platform.messages.DeleteResponse)3 NsObjectInputTransducer (org.talend.components.netsuite.input.NsObjectInputTransducer)3 AvroConverter (org.talend.daikon.avro.converter.AvroConverter)3 CustomRecordRef (com.netsuite.webservices.test.platform.core.CustomRecordRef)2 Passport (com.netsuite.webservices.test.platform.core.Passport)2 PurchaseOrder (com.netsuite.webservices.test.transactions.purchases.PurchaseOrder)2 FieldDesc (org.talend.components.netsuite.client.model.FieldDesc)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Account (com.netsuite.webservices.test.lists.accounting.Account)1 InvalidSessionFault (com.netsuite.webservices.test.platform.InvalidSessionFault)1 BooleanCustomFieldRef (com.netsuite.webservices.test.platform.core.BooleanCustomFieldRef)1 CustomFieldList (com.netsuite.webservices.test.platform.core.CustomFieldList)1 RecordRefList (com.netsuite.webservices.test.platform.core.RecordRefList)1