Search in sources :

Example 6 with TypeDesc

use of org.talend.components.netsuite.client.model.TypeDesc 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 7 with TypeDesc

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

the class NetSuiteSearchInputReaderTest method testBasic.

@Test
public void testBasic() throws Exception {
    properties.module.moduleName.setValue("Account");
    properties.module.searchQuery.field.setValue(Lists.newArrayList("type", "generalRateType"));
    properties.module.searchQuery.operator.setValue(Lists.newArrayList("List.anyOf", "List.anyOf"));
    properties.module.searchQuery.value1.setValue(Lists.newArrayList((Object) Arrays.asList("bank", "otherAsset"), (Object) Arrays.asList("current", "historical")));
    properties.module.searchQuery.value2.setValue(Lists.newArrayList(null, null));
    NetSuiteRuntime netSuiteRuntime = new NetSuiteRuntimeImpl();
    NetSuiteDatasetRuntime dataSetRuntime = netSuiteRuntime.getDatasetRuntime(properties.getConnectionProperties());
    Schema schema = dataSetRuntime.getSchema(properties.module.moduleName.getValue());
    properties.module.main.schema.setValue(schema);
    NetSuiteSource source = new NetSuiteSourceImpl();
    source.initialize(mockTestFixture.getRuntimeContainer(), properties);
    List<Account> recordList = makeNsObjects(new SimpleObjectComposer<>(Account.class), 150);
    mockSearchRequestResults(recordList, 100);
    NetSuiteClientService<?> clientService = source.getClientService();
    TypeDesc typeDesc = clientService.getMetaDataSource().getTypeInfo(Account.class);
    NetSuiteSearchInputReader reader = (NetSuiteSearchInputReader) source.createReader(mockTestFixture.getRuntimeContainer());
    boolean started = reader.start();
    assertTrue(started);
    IndexedRecord record = reader.getCurrent();
    assertNotNull(record);
    while (reader.advance()) {
        record = reader.getCurrent();
        assertIndexedRecord(typeDesc, record);
    }
    Map<String, Object> readerResult = reader.getReturnValues();
    assertNotNull(readerResult);
    assertEquals(150, readerResult.get(ComponentDefinition.RETURN_TOTAL_RECORD_COUNT));
}
Also used : Account(com.netsuite.webservices.v2016_2.lists.accounting.Account) NetSuiteSourceImpl(org.talend.components.netsuite.v2016_2.NetSuiteSourceImpl) IndexedRecord(org.apache.avro.generic.IndexedRecord) NetSuiteWebServiceMockTestFixture.assertIndexedRecord(org.talend.components.netsuite.NetSuiteWebServiceMockTestFixture.assertIndexedRecord) NetSuiteSearchInputReader(org.talend.components.netsuite.input.NetSuiteSearchInputReader) NetSuiteRuntime(org.talend.components.netsuite.NetSuiteRuntime) Schema(org.apache.avro.Schema) TypeDesc(org.talend.components.netsuite.client.model.TypeDesc) NetSuiteDatasetRuntime(org.talend.components.netsuite.NetSuiteDatasetRuntime) NetSuiteSource(org.talend.components.netsuite.NetSuiteSource) NetSuiteRuntimeImpl(org.talend.components.netsuite.v2016_2.NetSuiteRuntimeImpl) Test(org.junit.Test)

Example 8 with TypeDesc

use of org.talend.components.netsuite.client.model.TypeDesc 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 9 with TypeDesc

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

the class NetSuiteDatasetRuntimeTest method testGetSchemaForRecordBasic.

@Test
public void testGetSchemaForRecordBasic() throws Exception {
    TypeDesc typeDesc = clientService.getBasicMetaData().getTypeInfo("Account");
    Schema s = NetSuiteDatasetRuntimeImpl.inferSchemaForType(typeDesc.getTypeName(), typeDesc.getFields());
    assertThat(s.getType(), is(Schema.Type.RECORD));
    assertThat(s.getName(), is("Account"));
    assertThat(s.getFields(), hasSize(typeDesc.getFields().size()));
    assertThat(s.getObjectProps().keySet(), empty());
    FieldDesc fieldDesc = typeDesc.getField("acctType");
    Schema.Field f = getNsFieldByName(s, fieldDesc.getName());
    assertUnionType(f.schema(), Arrays.asList(Schema.Type.STRING, Schema.Type.NULL));
    assertThat(f.getObjectProps().keySet(), containsInAnyOrder(SchemaConstants.TALEND_COLUMN_DB_COLUMN_NAME, SchemaConstants.TALEND_COLUMN_DB_TYPE));
    assertThat(f.getProp(SchemaConstants.TALEND_COLUMN_DB_COLUMN_NAME), is(fieldDesc.getName()));
    assertThat(f.schema().getObjectProps().keySet(), empty());
    fieldDesc = typeDesc.getField("acctName");
    f = getNsFieldByName(s, fieldDesc.getName());
    assertUnionType(f.schema(), Arrays.asList(Schema.Type.STRING, Schema.Type.NULL));
    assertThat(f.getObjectProps().keySet(), containsInAnyOrder(SchemaConstants.TALEND_COLUMN_DB_COLUMN_NAME, SchemaConstants.TALEND_COLUMN_DB_TYPE));
    assertThat(f.getProp(SchemaConstants.TALEND_COLUMN_DB_COLUMN_NAME), is(fieldDesc.getName()));
    assertThat(f.schema().getObjectProps().keySet(), empty());
    fieldDesc = typeDesc.getField("inventory");
    f = getNsFieldByName(s, fieldDesc.getName());
    assertUnionType(f.schema(), Arrays.asList(Schema.Type.BOOLEAN, Schema.Type.NULL));
    assertThat(f.getObjectProps().keySet(), containsInAnyOrder(SchemaConstants.TALEND_COLUMN_DB_COLUMN_NAME, SchemaConstants.TALEND_COLUMN_DB_TYPE));
    assertThat(f.getProp(SchemaConstants.TALEND_COLUMN_DB_COLUMN_NAME), is(fieldDesc.getName()));
    assertThat(f.schema().getObjectProps().keySet(), empty());
    fieldDesc = typeDesc.getField("tranDate");
    f = getNsFieldByName(s, fieldDesc.getName());
    assertUnionType(f.schema(), Arrays.asList(Schema.Type.LONG, Schema.Type.NULL));
    assertThat(f.getObjectProps().keySet(), containsInAnyOrder(SchemaConstants.TALEND_COLUMN_PATTERN, SchemaConstants.TALEND_COLUMN_DB_COLUMN_NAME, SchemaConstants.TALEND_COLUMN_DB_TYPE));
    assertThat(f.getProp(SchemaConstants.TALEND_COLUMN_PATTERN), is("yyyy-MM-dd'T'HH:mm:ss'.000Z'"));
    assertThat(f.getProp(SchemaConstants.TALEND_COLUMN_DB_COLUMN_NAME), is(fieldDesc.getName()));
}
Also used : Schema(org.apache.avro.Schema) TypeDesc(org.talend.components.netsuite.client.model.TypeDesc) CustomFieldDesc(org.talend.components.netsuite.client.model.CustomFieldDesc) FieldDesc(org.talend.components.netsuite.client.model.FieldDesc) Test(org.junit.Test)

Example 10 with TypeDesc

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

the class NetSuiteDatasetRuntimeTest method testGetSchemaForRecordWithCustomFields.

@Test
public void testGetSchemaForRecordWithCustomFields() throws Exception {
    final CustomMetaDataSource customMetaDataSource = new EmptyCustomMetaDataSource() {

        @Override
        public Map<String, CustomFieldDesc> getCustomFields(RecordTypeInfo recordTypeInfo) {
            try {
                if (recordTypeInfo.getName().equals("Account")) {
                    JsonNode fieldListNode = objectMapper.readTree(NetSuiteDatasetRuntimeTest.class.getResource("/test-data/customFields-1.json"));
                    Map<String, CustomFieldDesc> customFieldDescMap = TestUtils.readCustomFields(fieldListNode);
                    return customFieldDescMap;
                }
                return null;
            } catch (IOException e) {
                throw new NetSuiteException(e.getMessage(), e);
            }
        }
    };
    MetaDataSource metaDataSource = clientService.createDefaultMetaDataSource();
    metaDataSource.setCustomMetaDataSource(customMetaDataSource);
    NetSuiteDatasetRuntimeImpl datasetRuntime = new NetSuiteDatasetRuntimeImpl(metaDataSource);
    TypeDesc typeDesc = metaDataSource.getTypeInfo("Account");
    Schema s = datasetRuntime.getSchema(typeDesc.getTypeName());
    assertThat(s.getType(), is(Schema.Type.RECORD));
    assertThat(s.getName(), is("Account"));
    assertThat(s.getFields(), hasSize(typeDesc.getFields().size()));
    assertThat(s.getObjectProps().keySet(), Matchers.<String>empty());
    CustomFieldDesc fieldDesc = (CustomFieldDesc) typeDesc.getField("custom_field_1");
    Schema.Field f = getNsFieldByName(s, fieldDesc.getName());
    assertUnionType(f.schema(), Arrays.asList(Schema.Type.STRING, Schema.Type.NULL));
    assertThat(f.getObjectProps().keySet(), containsInAnyOrder(SchemaConstants.TALEND_COLUMN_DB_COLUMN_NAME, SchemaConstants.TALEND_COLUMN_DB_TYPE, NetSuiteSchemaConstants.NS_CUSTOM_FIELD, NetSuiteSchemaConstants.NS_CUSTOM_FIELD_SCRIPT_ID, NetSuiteSchemaConstants.NS_CUSTOM_FIELD_INTERNAL_ID, NetSuiteSchemaConstants.NS_CUSTOM_FIELD_CUSTOMIZATION_TYPE, NetSuiteSchemaConstants.NS_CUSTOM_FIELD_TYPE));
    assertThat(f.getProp(SchemaConstants.TALEND_COLUMN_DB_COLUMN_NAME), is(fieldDesc.getName()));
    CustomFieldDesc customFieldDesc = NetSuiteDatasetRuntimeImpl.readCustomField(f);
    assertThat(customFieldDesc.getName(), is(fieldDesc.getName()));
}
Also used : EmptyCustomMetaDataSource(org.talend.components.netsuite.client.EmptyCustomMetaDataSource) CustomMetaDataSource(org.talend.components.netsuite.client.CustomMetaDataSource) Schema(org.apache.avro.Schema) TypeDesc(org.talend.components.netsuite.client.model.TypeDesc) JsonNode(com.fasterxml.jackson.databind.JsonNode) NetSuiteException(org.talend.components.netsuite.client.NetSuiteException) IOException(java.io.IOException) EmptyCustomMetaDataSource(org.talend.components.netsuite.client.EmptyCustomMetaDataSource) MetaDataSource(org.talend.components.netsuite.client.MetaDataSource) EmptyCustomMetaDataSource(org.talend.components.netsuite.client.EmptyCustomMetaDataSource) CustomMetaDataSource(org.talend.components.netsuite.client.CustomMetaDataSource) RecordTypeInfo(org.talend.components.netsuite.client.model.RecordTypeInfo) CustomFieldDesc(org.talend.components.netsuite.client.model.CustomFieldDesc) 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