Search in sources :

Example 31 with TypeDesc

use of org.talend.components.netsuite.client.model.TypeDesc in project components by Talend.

the class NetSuiteClientServiceTest method testLogin.

@Test
public void testLogin() throws Exception {
    clientService.login();
    verify(port, times(1)).login(argThat(new AssertMatcher<LoginRequest>() {

        @Override
        protected void doAssert(LoginRequest request) throws Exception {
            assertNotNull(request);
            Passport passport = request.getPassport();
            assertNotNull(passport);
        }
    }));
    // Verify that logging in not performed for already logged in client
    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(any(LoginRequest.class));
}
Also used : Passport(com.netsuite.webservices.test.platform.core.Passport) DeleteResponse(com.netsuite.webservices.test.platform.messages.DeleteResponse) TypeDesc(org.talend.components.netsuite.client.model.TypeDesc) RecordRef(com.netsuite.webservices.test.platform.core.RecordRef) LoginRequest(com.netsuite.webservices.test.platform.messages.LoginRequest) AssertMatcher(org.talend.components.netsuite.test.AssertMatcher) DeleteRequest(com.netsuite.webservices.test.platform.messages.DeleteRequest) Test(org.junit.Test)

Example 32 with TypeDesc

use of org.talend.components.netsuite.client.model.TypeDesc in project components by Talend.

the class NetSuiteClientServiceTest method testAdd.

@Test
public void testAdd() throws Exception {
    TypeDesc typeDesc = clientService.getMetaDataSource().getTypeInfo("PurchaseOrder");
    PurchaseOrder record = new NsObjectComposer<PurchaseOrder>(clientService.getMetaDataSource(), typeDesc).composeObject();
    AddResponse response = new AddResponse();
    response.setWriteResponse(createSuccessWriteResponse());
    when(port.add(notNull(AddRequest.class))).thenReturn(response);
    clientService.add(record);
    verify(port, times(1)).login(notNull(LoginRequest.class));
    verify(port, times(1)).add(notNull(AddRequest.class));
    NsWriteResponse writeResponse = clientService.add(null);
    assertNull(writeResponse.getStatus());
    assertNull(writeResponse.getRef());
}
Also used : AddRequest(com.netsuite.webservices.test.platform.messages.AddRequest) TypeDesc(org.talend.components.netsuite.client.model.TypeDesc) PurchaseOrder(com.netsuite.webservices.test.transactions.purchases.PurchaseOrder) LoginRequest(com.netsuite.webservices.test.platform.messages.LoginRequest) AddResponse(com.netsuite.webservices.test.platform.messages.AddResponse) Test(org.junit.Test)

Example 33 with TypeDesc

use of org.talend.components.netsuite.client.model.TypeDesc in project components by Talend.

the class NsObjectInputTransducerTest method testNonRecordObjects.

@Test
public void testNonRecordObjects() throws Exception {
    Collection<String> typeNames = Arrays.asList(RefType.RECORD_REF.getTypeName(), RefType.CUSTOMIZATION_REF.getTypeName());
    for (String typeName : typeNames) {
        TypeDesc typeDesc = clientService.getMetaDataSource().getTypeInfo(typeName);
        final List<?> nsObjects = makeNsObjects(new NsObjectComposer<>(clientService.getMetaDataSource(), typeDesc), 10);
        Schema schema = NetSuiteDatasetRuntimeImpl.inferSchemaForType(typeDesc.getTypeName(), typeDesc.getFields());
        NsObjectInputTransducer transducer = new NsObjectInputTransducer(clientService, schema, typeDesc.getTypeName());
        for (Object record : nsObjects) {
            IndexedRecord indexedRecord = transducer.read(record);
            assertIndexedRecord(typeDesc, indexedRecord);
        }
    }
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) NetSuiteWebServiceMockTestFixture.assertIndexedRecord(org.talend.components.netsuite.NetSuiteWebServiceMockTestFixture.assertIndexedRecord) Schema(org.apache.avro.Schema) TypeDesc(org.talend.components.netsuite.client.model.TypeDesc) Test(org.junit.Test)

Example 34 with TypeDesc

use of org.talend.components.netsuite.client.model.TypeDesc in project components by Talend.

the class NsObjectInputTransducerTest method testDynamicSchemaWithCustomRecordType.

@Test
public void testDynamicSchemaWithCustomRecordType() throws Exception {
    CustomMetaDataSource customMetaDataSource = new TestCustomMetaDataSource(clientService);
    clientService.getMetaDataSource().setCustomMetaDataSource(customMetaDataSource);
    TypeDesc typeDesc = clientService.getMetaDataSource().getTypeInfo("custom_record_type_1");
    final List<CustomRecord> recordList = makeNsObjects(new NsObjectComposer<CustomRecord>(clientService.getMetaDataSource(), typeDesc), 10);
    mockSearchRequestResults(recordList, 100);
    Schema schema = getDynamicSchema();
    NsObjectInputTransducer transducer = new NsObjectInputTransducer(clientService, schema, typeDesc.getTypeName());
    SearchResultSet<CustomRecord> rs = clientService.newSearch().target(typeDesc.getTypeName()).search();
    while (rs.next()) {
        CustomRecord record = rs.get();
        IndexedRecord indexedRecord = transducer.read(record);
        assertIndexedRecord(typeDesc, indexedRecord);
    }
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) NetSuiteWebServiceMockTestFixture.assertIndexedRecord(org.talend.components.netsuite.NetSuiteWebServiceMockTestFixture.assertIndexedRecord) CustomMetaDataSource(org.talend.components.netsuite.client.CustomMetaDataSource) Schema(org.apache.avro.Schema) TypeDesc(org.talend.components.netsuite.client.model.TypeDesc) CustomRecord(com.netsuite.webservices.test.setup.customization.CustomRecord) Test(org.junit.Test)

Example 35 with TypeDesc

use of org.talend.components.netsuite.client.model.TypeDesc in project components by Talend.

the class NsObjectInputTransducerTest method testGetApiVersion.

@Test
public void testGetApiVersion() throws Exception {
    TypeDesc typeDesc = clientService.getMetaDataSource().getTypeInfo("Opportunity");
    Schema schema = NetSuiteDatasetRuntimeImpl.inferSchemaForType(typeDesc.getTypeName(), typeDesc.getFields());
    NsObjectInputTransducer transducer = new NsObjectInputTransducer(clientService, schema, typeDesc.getTypeName());
    transducer.setApiVersion("2016.2");
    assertNull(transducer.getPicklistClass());
}
Also used : Schema(org.apache.avro.Schema) TypeDesc(org.talend.components.netsuite.client.model.TypeDesc) Test(org.junit.Test)

Aggregations

TypeDesc (org.talend.components.netsuite.client.model.TypeDesc)48 Test (org.junit.Test)41 Schema (org.apache.avro.Schema)31 IndexedRecord (org.apache.avro.generic.IndexedRecord)23 ArrayList (java.util.ArrayList)14 NetSuiteDatasetRuntime (org.talend.components.netsuite.NetSuiteDatasetRuntime)13 LoginRequest (com.netsuite.webservices.test.platform.messages.LoginRequest)12 NetSuiteRuntime (org.talend.components.netsuite.NetSuiteRuntime)10 FieldDesc (org.talend.components.netsuite.client.model.FieldDesc)10 RecordTypeDesc (org.talend.components.netsuite.client.model.RecordTypeDesc)10 SearchRecordTypeDesc (org.talend.components.netsuite.client.model.SearchRecordTypeDesc)10 CustomFieldDesc (org.talend.components.netsuite.client.model.CustomFieldDesc)9 PurchaseOrder (com.netsuite.webservices.test.transactions.purchases.PurchaseOrder)8 NetSuiteWebServiceMockTestFixture.assertIndexedRecord (org.talend.components.netsuite.NetSuiteWebServiceMockTestFixture.assertIndexedRecord)8 RecordTypeInfo (org.talend.components.netsuite.client.model.RecordTypeInfo)8 RecordRef (com.netsuite.webservices.test.platform.core.RecordRef)7 CustomRecord (com.netsuite.webservices.test.setup.customization.CustomRecord)7 NetSuiteException (org.talend.components.netsuite.client.NetSuiteException)6 CustomRecordTypeInfo (org.talend.components.netsuite.client.model.CustomRecordTypeInfo)6 InvocationOnMock (org.mockito.invocation.InvocationOnMock)4