Search in sources :

Example 1 with BooleanCustomFieldRef

use of com.netsuite.webservices.test.platform.core.BooleanCustomFieldRef 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)

Example 2 with BooleanCustomFieldRef

use of com.netsuite.webservices.test.platform.core.BooleanCustomFieldRef in project components by Talend.

the class ValueConverterTest method testJsonConverterNestedObjectPolymorphicType.

@Test
public void testJsonConverterNestedObjectPolymorphicType() throws Exception {
    NsObjectInputTransducer transducer = new NsObjectInputTransducer(clientService, schema, typeDesc.getTypeName());
    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);
    FieldDesc fieldDesc = typeDesc.getField("customFieldList");
    AvroConverter<CustomFieldList, String> converter1 = (AvroConverter<CustomFieldList, String>) transducer.getValueConverter(fieldDesc);
    String testJson1 = converter1.convertToAvro(customFieldList);
    assertNotNull(testJson1);
    ObjectNode node1 = JsonNodeFactory.instance.objectNode();
    ArrayNode list1 = JsonNodeFactory.instance.arrayNode();
    node1.set("customField", list1);
    ObjectNode customFieldNode1 = JsonNodeFactory.instance.objectNode();
    customFieldNode1.set(NsTypeResolverBuilder.TYPE_PROPERTY_NAME, JsonNodeFactory.instance.textNode("BooleanCustomFieldRef"));
    customFieldNode1.set("internalId", JsonNodeFactory.instance.textNode("100001"));
    customFieldNode1.set("scriptId", JsonNodeFactory.instance.textNode("custentity_field1"));
    customFieldNode1.set("value", JsonNodeFactory.instance.booleanNode(true));
    list1.add(customFieldNode1);
    ObjectNode customFieldNode2 = JsonNodeFactory.instance.objectNode();
    customFieldNode2.set(NsTypeResolverBuilder.TYPE_PROPERTY_NAME, JsonNodeFactory.instance.textNode("StringCustomFieldRef"));
    customFieldNode2.set("internalId", JsonNodeFactory.instance.textNode("100002"));
    customFieldNode2.set("scriptId", JsonNodeFactory.instance.textNode("custentity_field2"));
    customFieldNode2.set("value", JsonNodeFactory.instance.textNode("test123"));
    list1.add(customFieldNode2);
    CustomFieldList testCustomFieldList = converter1.convertToDatum(node1.toString());
    assertNotNull(testCustomFieldList);
    assertEquals(2, testCustomFieldList.getCustomField().size());
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) BooleanCustomFieldRef(com.netsuite.webservices.test.platform.core.BooleanCustomFieldRef) NsObjectInputTransducer(org.talend.components.netsuite.input.NsObjectInputTransducer) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) CustomFieldList(com.netsuite.webservices.test.platform.core.CustomFieldList) StringCustomFieldRef(com.netsuite.webservices.test.platform.core.StringCustomFieldRef) AvroConverter(org.talend.daikon.avro.converter.AvroConverter) FieldDesc(org.talend.components.netsuite.client.model.FieldDesc) Test(org.junit.Test)

Aggregations

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 Test (org.junit.Test)2 NsObjectInputTransducer (org.talend.components.netsuite.input.NsObjectInputTransducer)2 AvroConverter (org.talend.daikon.avro.converter.AvroConverter)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Account (com.netsuite.webservices.test.lists.accounting.Account)1 RecordRef (com.netsuite.webservices.test.platform.core.RecordRef)1 RecordRefList (com.netsuite.webservices.test.platform.core.RecordRefList)1 FieldDesc (org.talend.components.netsuite.client.model.FieldDesc)1