Search in sources :

Example 1 with NsObjectInputTransducer

use of org.talend.components.netsuite.input.NsObjectInputTransducer 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 NsObjectInputTransducer

use of org.talend.components.netsuite.input.NsObjectInputTransducer 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 NsObjectInputTransducer

use of org.talend.components.netsuite.input.NsObjectInputTransducer in project components by Talend.

the class NetSuiteMockTestBase method makeIndexedRecords.

public static <T> List<IndexedRecord> makeIndexedRecords(NetSuiteClientService<?> clientService, Schema schema, ObjectComposer<T> objectComposer, int count) throws Exception {
    NsObjectInputTransducer transducer = new NsObjectInputTransducer(clientService, schema, schema.getName());
    List<IndexedRecord> recordList = new ArrayList<>();
    while (count > 0) {
        T nsRecord = objectComposer.composeObject();
        IndexedRecord convertedRecord = transducer.read(nsRecord);
        Schema recordSchema = convertedRecord.getSchema();
        GenericRecord record = new GenericData.Record(recordSchema);
        for (Schema.Field field : schema.getFields()) {
            Object value = convertedRecord.get(field.pos());
            record.put(field.pos(), value);
        }
        recordList.add(record);
        count--;
    }
    return recordList;
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) Schema(org.apache.avro.Schema) ArrayList(java.util.ArrayList) NsObjectInputTransducer(org.talend.components.netsuite.input.NsObjectInputTransducer) Record(com.netsuite.webservices.v2016_2.platform.core.Record) IndexedRecord(org.apache.avro.generic.IndexedRecord) GenericRecord(org.apache.avro.generic.GenericRecord) GenericRecord(org.apache.avro.generic.GenericRecord)

Example 4 with NsObjectInputTransducer

use of org.talend.components.netsuite.input.NsObjectInputTransducer in project components by Talend.

the class ValueConverterTest method testIdentityConverters.

@Test
public void testIdentityConverters() throws Exception {
    NsObjectInputTransducer transducer = new NsObjectInputTransducer(clientService, schema, typeDesc.getTypeName());
    FieldDesc fieldDesc = typeDesc.getField("isInactive");
    AvroConverter<Boolean, Boolean> converter1 = (AvroConverter<Boolean, Boolean>) transducer.getValueConverter(fieldDesc);
    assertEquals(Boolean.TRUE, converter1.convertToAvro(Boolean.TRUE));
    assertEquals(Boolean.FALSE, converter1.convertToDatum(Boolean.FALSE));
    fieldDesc = typeDesc.getField("openingBalance");
    AvroConverter<Double, Double> converter2 = (AvroConverter<Double, Double>) transducer.getValueConverter(fieldDesc);
    assertEquals(Double.valueOf(12345.6789), converter2.convertToAvro(Double.valueOf(12345.6789)));
    assertEquals(Double.valueOf(98765.4321), converter2.convertToDatum(Double.valueOf(98765.4321)));
}
Also used : NsObjectInputTransducer(org.talend.components.netsuite.input.NsObjectInputTransducer) AvroConverter(org.talend.daikon.avro.converter.AvroConverter) FieldDesc(org.talend.components.netsuite.client.model.FieldDesc) Test(org.junit.Test)

Example 5 with NsObjectInputTransducer

use of org.talend.components.netsuite.input.NsObjectInputTransducer in project components by Talend.

the class ValueConverterTest method testEnumConverter.

@Test
public void testEnumConverter() throws Exception {
    NsObjectInputTransducer transducer = new NsObjectInputTransducer(clientService, schema, typeDesc.getTypeName());
    FieldDesc fieldDesc = typeDesc.getField("acctType");
    AvroConverter<Enum<AccountType>, String> converter1 = (AvroConverter<Enum<AccountType>, String>) transducer.getValueConverter(fieldDesc);
    assertEquals(AvroUtils._string(), converter1.getSchema());
    assertEquals(AccountType.class, converter1.getDatumClass());
    assertEquals(AccountType.ACCOUNTS_PAYABLE.value(), converter1.convertToAvro(AccountType.ACCOUNTS_PAYABLE));
    assertEquals(AccountType.ACCOUNTS_PAYABLE, converter1.convertToDatum(AccountType.ACCOUNTS_PAYABLE.value()));
    assertEquals(AccountType.ACCOUNTS_PAYABLE, converter1.convertToDatum(AccountType.ACCOUNTS_PAYABLE.name()));
    fieldDesc = typeDesc.getField("generalRate");
    assertNotNull(fieldDesc);
    AvroConverter<Enum<ConsolidatedRate>, String> converter2 = (AvroConverter<Enum<ConsolidatedRate>, String>) transducer.getValueConverter(fieldDesc);
    assertEquals(ConsolidatedRate.HISTORICAL.value(), converter2.convertToAvro(ConsolidatedRate.HISTORICAL));
    assertEquals(ConsolidatedRate.HISTORICAL, converter2.convertToDatum(ConsolidatedRate.HISTORICAL.value()));
}
Also used : ConsolidatedRate(com.netsuite.webservices.test.lists.accounting.types.ConsolidatedRate) NsObjectInputTransducer(org.talend.components.netsuite.input.NsObjectInputTransducer) AccountType(com.netsuite.webservices.test.lists.accounting.types.AccountType) AvroConverter(org.talend.daikon.avro.converter.AvroConverter) FieldDesc(org.talend.components.netsuite.client.model.FieldDesc) Test(org.junit.Test)

Aggregations

NsObjectInputTransducer (org.talend.components.netsuite.input.NsObjectInputTransducer)14 Test (org.junit.Test)11 FieldDesc (org.talend.components.netsuite.client.model.FieldDesc)8 Schema (org.apache.avro.Schema)7 IndexedRecord (org.apache.avro.generic.IndexedRecord)7 AvroConverter (org.talend.daikon.avro.converter.AvroConverter)7 TypeDesc (org.talend.components.netsuite.client.model.TypeDesc)4 RecordRef (com.netsuite.webservices.test.platform.core.RecordRef)3 Record (com.netsuite.webservices.v2014_2.platform.core.Record)3 Record (com.netsuite.webservices.v2016_2.platform.core.Record)3 ArrayList (java.util.ArrayList)3 GenericRecord (org.apache.avro.generic.GenericRecord)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 BooleanCustomFieldRef (com.netsuite.webservices.test.platform.core.BooleanCustomFieldRef)2 CustomFieldList (com.netsuite.webservices.test.platform.core.CustomFieldList)2 StringCustomFieldRef (com.netsuite.webservices.test.platform.core.StringCustomFieldRef)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 Account (com.netsuite.webservices.test.lists.accounting.Account)1