Search in sources :

Example 1 with Opportunity

use of com.netsuite.webservices.v2014_2.transactions.sales.Opportunity in project components by Talend.

the class NsObjectInputTransducerIT method testIncludeAllFields.

@Test
public void testIncludeAllFields() throws Exception {
    NetSuiteClientService<?> connection = webServiceTestFixture.getClientService();
    connection.login();
    TypeDesc basicTypeDesc = connection.getBasicMetaData().getTypeInfo("Opportunity");
    Schema schema = getDynamicSchema();
    NsObjectInputTransducer transducer = new NsObjectInputTransducer(connection, schema, basicTypeDesc.getTypeName());
    SearchResultSet<Record> rs = connection.newSearch().target(basicTypeDesc.getTypeName()).search();
    TypeDesc typeDesc = connection.getMetaDataSource().getTypeInfo(basicTypeDesc.getTypeName());
    int count = 0;
    while (count++ < connection.getSearchPageSize() && rs.next()) {
        Record record = rs.get();
        IndexedRecord indexedRecord = transducer.read(record);
        logger.debug("Indexed record: {}", indexedRecord);
        Schema recordSchema = indexedRecord.getSchema();
        assertEquals(typeDesc.getFields().size(), recordSchema.getFields().size());
        for (FieldDesc fieldDesc : typeDesc.getFields()) {
            String fieldName = fieldDesc.getName();
            Schema.Field field = recordSchema.getField(fieldName);
            assertNotNull(field);
            Object value = indexedRecord.get(field.pos());
        }
    }
    if (count == 0) {
        throw new IllegalStateException("No records");
    }
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) Schema(org.apache.avro.Schema) TypeDesc(org.talend.components.netsuite.client.model.TypeDesc) NsObjectInputTransducer(org.talend.components.netsuite.input.NsObjectInputTransducer) Record(com.netsuite.webservices.v2014_2.platform.core.Record) IndexedRecord(org.apache.avro.generic.IndexedRecord) FieldDesc(org.talend.components.netsuite.client.model.FieldDesc) Test(org.junit.Test)

Example 2 with Opportunity

use of com.netsuite.webservices.v2014_2.transactions.sales.Opportunity in project components by Talend.

the class NsObjectInputTransducerIT method testBasic.

@Test
public void testBasic() throws Exception {
    NetSuiteClientService<?> connection = webServiceTestFixture.getClientService();
    connection.login();
    TypeDesc typeDesc = connection.getMetaDataSource().getTypeInfo("Opportunity");
    Schema schema = NetSuiteDatasetRuntimeImpl.inferSchemaForType(typeDesc.getTypeName(), typeDesc.getFields());
    NsObjectInputTransducer transducer = new NsObjectInputTransducer(connection, schema, typeDesc.getTypeName());
    SearchResultSet<Record> rs = connection.newSearch().target(typeDesc.getTypeName()).search();
    if (!rs.next()) {
        throw new IllegalStateException("Not records");
    }
    Record record = rs.get();
    IndexedRecord indexedRecord = transducer.read(record);
    logger.debug("Indexed record: {}", indexedRecord);
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) Schema(org.apache.avro.Schema) TypeDesc(org.talend.components.netsuite.client.model.TypeDesc) NsObjectInputTransducer(org.talend.components.netsuite.input.NsObjectInputTransducer) Record(com.netsuite.webservices.v2014_2.platform.core.Record) IndexedRecord(org.apache.avro.generic.IndexedRecord) Test(org.junit.Test)

Example 3 with Opportunity

use of com.netsuite.webservices.v2014_2.transactions.sales.Opportunity in project components by Talend.

the class NetSuiteOutputWriterTest method testUpdate.

@Test
public void testUpdate() throws Exception {
    final NetSuitePortType port = webServiceMockTestFixture.getPortMock();
    final TypeDesc typeDesc = webServiceMockTestFixture.getClientService().getMetaDataSource().getTypeInfo(RecordTypeEnum.OPPORTUNITY.getTypeName());
    mockGetListRequestResults(null);
    final List<Opportunity> updatedRecordList = new ArrayList<>();
    when(port.updateList(any(UpdateListRequest.class))).then(new Answer<UpdateListResponse>() {

        @Override
        public UpdateListResponse answer(InvocationOnMock invocationOnMock) throws Throwable {
            UpdateListRequest request = (UpdateListRequest) invocationOnMock.getArguments()[0];
            assertFalse(request.getRecord().isEmpty());
            UpdateListResponse response = new UpdateListResponse();
            WriteResponseList writeResponseList = new WriteResponseList();
            writeResponseList.setStatus(createSuccessStatus());
            for (int i = 0; i < request.getRecord().size(); i++) {
                Opportunity record = (Opportunity) request.getRecord().get(i);
                assertNotNull(record);
                assertNotNull(record.getInternalId());
                RecordRef recordRef = new RecordRef();
                recordRef.setInternalId(record.getInternalId());
                recordRef.setType(RecordType.OPPORTUNITY);
                updatedRecordList.add(record);
                WriteResponse writeResponse = new WriteResponse();
                writeResponse.setStatus(createSuccessStatus());
                writeResponse.setBaseRef(recordRef);
                writeResponseList.getWriteResponse().add(writeResponse);
            }
            response.setWriteResponseList(writeResponseList);
            return response;
        }
    });
    properties.module.moduleName.setValue(typeDesc.getTypeName());
    properties.module.action.setValue(OutputAction.UPDATE);
    NetSuiteRuntime netSuiteRuntime = new NetSuiteRuntimeImpl();
    NetSuiteDatasetRuntime dataSetRuntime = netSuiteRuntime.getDatasetRuntime(properties.getConnectionProperties());
    Schema schema = dataSetRuntime.getSchema(properties.module.moduleName.getValue());
    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 SimpleObjectComposer<>(typeDesc.getTypeClass()), 150);
    for (IndexedRecord record : indexedRecordList) {
        writer.write(record);
    }
    Result writerResult = writer.close();
    assertNotNull(writerResult);
    assertEquals(indexedRecordList.size(), writerResult.totalCount);
    verify(port, times(2)).updateList(any(UpdateListRequest.class));
    assertEquals(indexedRecordList.size(), updatedRecordList.size());
}
Also used : NetSuiteSinkImpl(org.talend.components.netsuite.v2016_2.NetSuiteSinkImpl) IndexedRecord(org.apache.avro.generic.IndexedRecord) Schema(org.apache.avro.Schema) TypeDesc(org.talend.components.netsuite.client.model.TypeDesc) ArrayList(java.util.ArrayList) RecordRef(com.netsuite.webservices.v2016_2.platform.core.RecordRef) NetSuiteDatasetRuntime(org.talend.components.netsuite.NetSuiteDatasetRuntime) NetSuiteWriteOperation(org.talend.components.netsuite.output.NetSuiteWriteOperation) NetSuiteRuntimeImpl(org.talend.components.netsuite.v2016_2.NetSuiteRuntimeImpl) Result(org.talend.components.api.component.runtime.Result) UpdateListRequest(com.netsuite.webservices.v2016_2.platform.messages.UpdateListRequest) Opportunity(com.netsuite.webservices.v2016_2.transactions.sales.Opportunity) UpdateListResponse(com.netsuite.webservices.v2016_2.platform.messages.UpdateListResponse) NetSuiteRuntime(org.talend.components.netsuite.NetSuiteRuntime) NetSuiteOutputWriter(org.talend.components.netsuite.output.NetSuiteOutputWriter) WriteResponse(com.netsuite.webservices.v2016_2.platform.messages.WriteResponse) NetSuitePortType(com.netsuite.webservices.v2016_2.platform.NetSuitePortType) WriteResponseList(com.netsuite.webservices.v2016_2.platform.messages.WriteResponseList) InvocationOnMock(org.mockito.invocation.InvocationOnMock) NetSuiteSink(org.talend.components.netsuite.NetSuiteSink) Test(org.junit.Test)

Example 4 with Opportunity

use of com.netsuite.webservices.v2014_2.transactions.sales.Opportunity in project components by Talend.

the class NetSuiteOutputWriterTest method testUpdate.

@Test
public void testUpdate() throws Exception {
    final NetSuitePortType port = webServiceMockTestFixture.getPortMock();
    final TypeDesc typeDesc = webServiceMockTestFixture.getClientService().getMetaDataSource().getTypeInfo(RecordTypeEnum.OPPORTUNITY.getTypeName());
    mockGetListRequestResults(null);
    final List<Opportunity> updatedRecordList = new ArrayList<>();
    when(port.updateList(any(UpdateListRequest.class))).then(new Answer<UpdateListResponse>() {

        @Override
        public UpdateListResponse answer(InvocationOnMock invocationOnMock) throws Throwable {
            UpdateListRequest request = (UpdateListRequest) invocationOnMock.getArguments()[0];
            assertFalse(request.getRecord().isEmpty());
            UpdateListResponse response = new UpdateListResponse();
            WriteResponseList writeResponseList = new WriteResponseList();
            writeResponseList.setStatus(createSuccessStatus());
            for (int i = 0; i < request.getRecord().size(); i++) {
                Opportunity record = (Opportunity) request.getRecord().get(i);
                assertNotNull(record);
                assertNotNull(record.getInternalId());
                RecordRef recordRef = new RecordRef();
                recordRef.setInternalId(record.getInternalId());
                recordRef.setType(RecordType.OPPORTUNITY);
                updatedRecordList.add(record);
                WriteResponse writeResponse = new WriteResponse();
                writeResponse.setStatus(createSuccessStatus());
                writeResponse.setBaseRef(recordRef);
                writeResponseList.getWriteResponse().add(writeResponse);
            }
            response.setWriteResponseList(writeResponseList);
            return response;
        }
    });
    properties.module.moduleName.setValue(typeDesc.getTypeName());
    properties.module.action.setValue(OutputAction.UPDATE);
    NetSuiteRuntime netSuiteRuntime = new NetSuiteRuntimeImpl();
    NetSuiteDatasetRuntime dataSetRuntime = netSuiteRuntime.getDatasetRuntime(properties.getConnectionProperties());
    Schema schema = dataSetRuntime.getSchema(properties.module.moduleName.getValue());
    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 SimpleObjectComposer<>(typeDesc.getTypeClass()), 150);
    for (IndexedRecord record : indexedRecordList) {
        writer.write(record);
    }
    Result writerResult = writer.close();
    assertNotNull(writerResult);
    assertEquals(indexedRecordList.size(), writerResult.totalCount);
    verify(port, times(2)).updateList(any(UpdateListRequest.class));
    assertEquals(indexedRecordList.size(), updatedRecordList.size());
}
Also used : NetSuiteSinkImpl(org.talend.components.netsuite.v2014_2.NetSuiteSinkImpl) IndexedRecord(org.apache.avro.generic.IndexedRecord) Schema(org.apache.avro.Schema) TypeDesc(org.talend.components.netsuite.client.model.TypeDesc) ArrayList(java.util.ArrayList) RecordRef(com.netsuite.webservices.v2014_2.platform.core.RecordRef) NetSuiteDatasetRuntime(org.talend.components.netsuite.NetSuiteDatasetRuntime) NetSuiteWriteOperation(org.talend.components.netsuite.output.NetSuiteWriteOperation) NetSuiteRuntimeImpl(org.talend.components.netsuite.v2014_2.NetSuiteRuntimeImpl) Result(org.talend.components.api.component.runtime.Result) UpdateListRequest(com.netsuite.webservices.v2014_2.platform.messages.UpdateListRequest) Opportunity(com.netsuite.webservices.v2014_2.transactions.sales.Opportunity) UpdateListResponse(com.netsuite.webservices.v2014_2.platform.messages.UpdateListResponse) NetSuiteRuntime(org.talend.components.netsuite.NetSuiteRuntime) NetSuiteOutputWriter(org.talend.components.netsuite.output.NetSuiteOutputWriter) WriteResponse(com.netsuite.webservices.v2014_2.platform.messages.WriteResponse) NetSuitePortType(com.netsuite.webservices.v2014_2.platform.NetSuitePortType) WriteResponseList(com.netsuite.webservices.v2014_2.platform.messages.WriteResponseList) InvocationOnMock(org.mockito.invocation.InvocationOnMock) NetSuiteSink(org.talend.components.netsuite.NetSuiteSink) Test(org.junit.Test)

Aggregations

Schema (org.apache.avro.Schema)4 IndexedRecord (org.apache.avro.generic.IndexedRecord)4 Test (org.junit.Test)4 TypeDesc (org.talend.components.netsuite.client.model.TypeDesc)4 Record (com.netsuite.webservices.v2014_2.platform.core.Record)2 ArrayList (java.util.ArrayList)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Result (org.talend.components.api.component.runtime.Result)2 NetSuiteDatasetRuntime (org.talend.components.netsuite.NetSuiteDatasetRuntime)2 NetSuiteRuntime (org.talend.components.netsuite.NetSuiteRuntime)2 NetSuiteSink (org.talend.components.netsuite.NetSuiteSink)2 NsObjectInputTransducer (org.talend.components.netsuite.input.NsObjectInputTransducer)2 NetSuiteOutputWriter (org.talend.components.netsuite.output.NetSuiteOutputWriter)2 NetSuiteWriteOperation (org.talend.components.netsuite.output.NetSuiteWriteOperation)2 NetSuitePortType (com.netsuite.webservices.v2014_2.platform.NetSuitePortType)1 RecordRef (com.netsuite.webservices.v2014_2.platform.core.RecordRef)1 UpdateListRequest (com.netsuite.webservices.v2014_2.platform.messages.UpdateListRequest)1 UpdateListResponse (com.netsuite.webservices.v2014_2.platform.messages.UpdateListResponse)1 WriteResponse (com.netsuite.webservices.v2014_2.platform.messages.WriteResponse)1 WriteResponseList (com.netsuite.webservices.v2014_2.platform.messages.WriteResponseList)1