Search in sources :

Example 11 with NetSuiteRuntimeImpl

use of org.talend.components.netsuite.v2016_2.NetSuiteRuntimeImpl in project components by Talend.

the class NetSuiteSearchInputReaderIT method testSearch.

@Test
public void testSearch() throws Exception {
    RuntimeContainer container = mock(RuntimeContainer.class);
    NetSuiteInputProperties properties = new NetSuiteInputProperties("test");
    properties.init();
    properties.connection.endpoint.setValue(webServiceTestFixture.getEndpointUrl());
    properties.connection.email.setValue(webServiceTestFixture.getCredentials().getEmail());
    properties.connection.password.setValue(webServiceTestFixture.getCredentials().getPassword());
    properties.connection.account.setValue(webServiceTestFixture.getCredentials().getAccount());
    properties.connection.role.setValue(Integer.valueOf(webServiceTestFixture.getCredentials().getRoleId()));
    properties.connection.applicationId.setValue(webServiceTestFixture.getCredentials().getApplicationId());
    properties.module.moduleName.setValue("Account");
    NetSuiteRuntimeImpl runtime = new NetSuiteRuntimeImpl();
    runtime.setClientFactory(clientFactory);
    NetSuiteDatasetRuntime dataSetRuntime = runtime.getDatasetRuntime(properties.getConnectionProperties());
    Schema schema = dataSetRuntime.getSchema(properties.module.moduleName.getValue());
    properties.module.main.schema.setValue(schema);
    properties.module.afterModuleName();
    properties.module.searchQuery.field.setValue(Arrays.asList("Type"));
    properties.module.searchQuery.operator.setValue(Arrays.asList("List.anyOf"));
    properties.module.searchQuery.value1.setValue(Arrays.<Object>asList("Bank"));
    properties.module.searchQuery.value2.setValue(Arrays.<Object>asList((String) null));
    NetSuiteSource source = new NetSuiteSourceImpl();
    source.initialize(container, properties);
    NetSuiteSearchInputReader reader = (NetSuiteSearchInputReader) source.createReader(container);
    boolean started = reader.start();
    assertTrue(started);
    IndexedRecord record = reader.getCurrent();
    assertNotNull(record);
    List<Schema.Field> fields = record.getSchema().getFields();
    for (int i = 0; i < fields.size(); i++) {
        Schema.Field typeField = getFieldByName(fields, "AcctType");
        Object value = record.get(typeField.pos());
        assertNotNull(value);
        assertEquals(AccountType.BANK.value(), value);
    }
}
Also used : NetSuiteInputProperties(org.talend.components.netsuite.input.NetSuiteInputProperties) NetSuiteSourceImpl(org.talend.components.netsuite.v2016_2.NetSuiteSourceImpl) IndexedRecord(org.apache.avro.generic.IndexedRecord) NetSuiteSearchInputReader(org.talend.components.netsuite.input.NetSuiteSearchInputReader) Schema(org.apache.avro.Schema) NetSuiteDatasetRuntime(org.talend.components.netsuite.NetSuiteDatasetRuntime) NetSuiteSource(org.talend.components.netsuite.NetSuiteSource) NetSuiteRuntimeImpl(org.talend.components.netsuite.v2016_2.NetSuiteRuntimeImpl) RuntimeContainer(org.talend.components.api.container.RuntimeContainer) Test(org.junit.Test)

Example 12 with NetSuiteRuntimeImpl

use of org.talend.components.netsuite.v2016_2.NetSuiteRuntimeImpl in project components by Talend.

the class NetSuiteOutputWriterTest method testDelete.

@Test
public void testDelete() throws Exception {
    final NetSuitePortType port = webServiceMockTestFixture.getPortMock();
    final TypeDesc typeDesc = webServiceMockTestFixture.getClientService().getMetaDataSource().getTypeInfo(RecordTypeEnum.OPPORTUNITY.getTypeName());
    final TypeDesc refTypeDesc = webServiceMockTestFixture.getClientService().getMetaDataSource().getTypeInfo(RefType.RECORD_REF.getTypeName());
    properties.module.moduleName.setValue(typeDesc.getTypeName());
    properties.module.action.setValue(OutputAction.DELETE);
    final List<RecordRef> deletedRecordRefList = new ArrayList<>();
    when(port.deleteList(any(DeleteListRequest.class))).then(new Answer<DeleteListResponse>() {

        @Override
        public DeleteListResponse answer(InvocationOnMock invocationOnMock) throws Throwable {
            DeleteListRequest request = (DeleteListRequest) invocationOnMock.getArguments()[0];
            DeleteListResponse response = new DeleteListResponse();
            WriteResponseList writeResponseList = new WriteResponseList();
            for (int i = 0; i < request.getBaseRef().size(); i++) {
                RecordRef recordRef = (RecordRef) request.getBaseRef().get(i);
                assertNotNull(recordRef);
                assertNotNull(recordRef.getInternalId());
                assertNotNull(recordRef.getType());
                deletedRecordRefList.add(recordRef);
                WriteResponse writeResponse = new WriteResponse();
                writeResponse.setStatus(createSuccessStatus());
                writeResponse.setBaseRef(recordRef);
                writeResponseList.getWriteResponse().add(writeResponse);
            }
            response.setWriteResponseList(writeResponseList);
            return response;
        }
    });
    NetSuiteRuntime netSuiteRuntime = new NetSuiteRuntimeImpl();
    NetSuiteDatasetRuntime dataSetRuntime = netSuiteRuntime.getDatasetRuntime(properties.getConnectionProperties());
    Schema schema = dataSetRuntime.getSchema(RefType.RECORD_REF.getTypeName());
    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 RecordRefComposer<>(refTypeDesc.getTypeClass()), 150);
    for (IndexedRecord record : indexedRecordList) {
        writer.write(record);
    }
    Result writerResult = writer.close();
    assertNotNull(writerResult);
    assertEquals(indexedRecordList.size(), writerResult.totalCount);
    verify(port, times(2)).deleteList(any(DeleteListRequest.class));
    assertEquals(indexedRecordList.size(), deletedRecordRefList.size());
}
Also used : DeleteListRequest(com.netsuite.webservices.v2016_2.platform.messages.DeleteListRequest) NetSuiteSinkImpl(org.talend.components.netsuite.v2016_2.NetSuiteSinkImpl) IndexedRecord(org.apache.avro.generic.IndexedRecord) DeleteListResponse(com.netsuite.webservices.v2016_2.platform.messages.DeleteListResponse) Schema(org.apache.avro.Schema) TypeDesc(org.talend.components.netsuite.client.model.TypeDesc) RecordRef(com.netsuite.webservices.v2016_2.platform.core.RecordRef) ArrayList(java.util.ArrayList) 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) 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)

Aggregations

Schema (org.apache.avro.Schema)12 IndexedRecord (org.apache.avro.generic.IndexedRecord)12 Test (org.junit.Test)12 NetSuiteDatasetRuntime (org.talend.components.netsuite.NetSuiteDatasetRuntime)12 ArrayList (java.util.ArrayList)8 Result (org.talend.components.api.component.runtime.Result)8 NetSuiteSink (org.talend.components.netsuite.NetSuiteSink)8 NetSuiteOutputWriter (org.talend.components.netsuite.output.NetSuiteOutputWriter)8 NetSuiteWriteOperation (org.talend.components.netsuite.output.NetSuiteWriteOperation)8 NetSuiteRuntimeImpl (org.talend.components.netsuite.v2016_2.NetSuiteRuntimeImpl)8 TypeDesc (org.talend.components.netsuite.client.model.TypeDesc)7 NetSuitePortType (com.netsuite.webservices.v2016_2.platform.NetSuitePortType)6 RuntimeContainer (org.talend.components.api.container.RuntimeContainer)6 NetSuiteRuntime (org.talend.components.netsuite.NetSuiteRuntime)6 NetSuiteSinkImpl (org.talend.components.netsuite.v2016_2.NetSuiteSinkImpl)6 RecordRef (com.netsuite.webservices.v2016_2.platform.core.RecordRef)5 CustomFieldList (com.netsuite.webservices.v2016_2.platform.core.CustomFieldList)4 CustomRecordRef (com.netsuite.webservices.v2016_2.platform.core.CustomRecordRef)4 RecordRefList (com.netsuite.webservices.v2016_2.platform.core.RecordRefList)4 GetListRequest (com.netsuite.webservices.v2016_2.platform.messages.GetListRequest)4