Search in sources :

Example 1 with ReadResponse

use of com.netsuite.webservices.v2016_2.platform.messages.ReadResponse in project components by Talend.

the class NetSuiteMockTestBase method mockGetRequestResults.

protected <T extends Record> void mockGetRequestResults(final T record) throws Exception {
    final NetSuitePortType port = webServiceMockTestFixture.getPortMock();
    when(port.get(any(GetRequest.class))).then(new Answer<GetResponse>() {

        @Override
        public GetResponse answer(InvocationOnMock invocationOnMock) throws Throwable {
            GetResponse response = new GetResponse();
            ReadResponse readResponse = new ReadResponse();
            readResponse.setStatus(createSuccessStatus());
            readResponse.setRecord(record);
            response.setReadResponse(readResponse);
            return response;
        }
    });
}
Also used : NetSuitePortType(com.netsuite.webservices.v2014_2.platform.NetSuitePortType) ReadResponse(com.netsuite.webservices.v2014_2.platform.messages.ReadResponse) InvocationOnMock(org.mockito.invocation.InvocationOnMock) GetRequest(com.netsuite.webservices.v2014_2.platform.messages.GetRequest) GetResponse(com.netsuite.webservices.v2014_2.platform.messages.GetResponse)

Example 2 with ReadResponse

use of com.netsuite.webservices.v2016_2.platform.messages.ReadResponse in project components by Talend.

the class NetSuiteMockTestBase method mockCustomizationRequestResults.

protected void mockCustomizationRequestResults(final Map<String, CustomFieldSpec<RecordType, CustomizationFieldType>> customFieldSpecs) throws Exception {
    final NetSuitePortType port = webServiceMockTestFixture.getPortMock();
    when(port.getCustomizationId(any(GetCustomizationIdRequest.class))).then(new Answer<GetCustomizationIdResponse>() {

        @Override
        public GetCustomizationIdResponse answer(InvocationOnMock invocationOnMock) throws Throwable {
            GetCustomizationIdRequest request = (GetCustomizationIdRequest) invocationOnMock.getArguments()[0];
            CustomizationType customizationType = request.getCustomizationType();
            GetCustomizationIdResult result = new GetCustomizationIdResult();
            result.setCustomizationRefList(new CustomizationRefList());
            result.setStatus(createSuccessStatus());
            Map<String, CustomizationRef> customizationRefMap = createCustomFieldCustomizationRefs(customFieldSpecs);
            for (String scriptId : customFieldSpecs.keySet()) {
                RecordType recordType = RecordType.fromValue(customizationType.getGetCustomizationType().value());
                CustomizationRef customizationRef = customizationRefMap.get(scriptId);
                if (recordType == customizationRef.getType()) {
                    result.getCustomizationRefList().getCustomizationRef().add(customizationRef);
                }
            }
            result.setTotalRecords(result.getCustomizationRefList().getCustomizationRef().size());
            GetCustomizationIdResponse response = new GetCustomizationIdResponse();
            response.setGetCustomizationIdResult(result);
            return response;
        }
    });
    when(port.getList(any(GetListRequest.class))).then(new Answer<GetListResponse>() {

        @Override
        public GetListResponse answer(InvocationOnMock invocationOnMock) throws Throwable {
            GetListRequest request = (GetListRequest) invocationOnMock.getArguments()[0];
            ReadResponseList readResponseList = new ReadResponseList();
            readResponseList.setStatus(createSuccessStatus());
            Map<String, CustomFieldType> customFieldTypeMap = createCustomFieldTypes(customFieldSpecs);
            for (BaseRef ref : request.getBaseRef()) {
                if (ref instanceof CustomizationRef) {
                    CustomizationRef customizationRef = (CustomizationRef) ref;
                    if (customFieldTypeMap.containsKey(customizationRef.getScriptId())) {
                        CustomFieldType fieldType = customFieldTypeMap.get(customizationRef.getScriptId());
                        ReadResponse readResponse = new ReadResponse();
                        readResponse.setRecord(fieldType);
                        readResponse.setStatus(createSuccessStatus());
                        readResponseList.getReadResponse().add(readResponse);
                    }
                }
            }
            GetListResponse response = new GetListResponse();
            response.setReadResponseList(readResponseList);
            return response;
        }
    });
}
Also used : GetListResponse(com.netsuite.webservices.v2016_2.platform.messages.GetListResponse) ReadResponseList(com.netsuite.webservices.v2016_2.platform.messages.ReadResponseList) BaseRef(com.netsuite.webservices.v2016_2.platform.core.BaseRef) CustomFieldType(com.netsuite.webservices.v2016_2.setup.customization.CustomFieldType) GetCustomizationIdResult(com.netsuite.webservices.v2016_2.platform.core.GetCustomizationIdResult) NetSuitePortType(com.netsuite.webservices.v2016_2.platform.NetSuitePortType) GetCustomizationIdRequest(com.netsuite.webservices.v2016_2.platform.messages.GetCustomizationIdRequest) RecordType(com.netsuite.webservices.v2016_2.platform.core.types.RecordType) ReadResponse(com.netsuite.webservices.v2016_2.platform.messages.ReadResponse) InvocationOnMock(org.mockito.invocation.InvocationOnMock) CustomizationRefList(com.netsuite.webservices.v2016_2.platform.core.CustomizationRefList) CustomizationType(com.netsuite.webservices.v2016_2.platform.core.CustomizationType) CustomizationRef(com.netsuite.webservices.v2016_2.platform.core.CustomizationRef) GetCustomizationIdResponse(com.netsuite.webservices.v2016_2.platform.messages.GetCustomizationIdResponse) Map(java.util.Map) HashMap(java.util.HashMap) GetListRequest(com.netsuite.webservices.v2016_2.platform.messages.GetListRequest)

Example 3 with ReadResponse

use of com.netsuite.webservices.v2016_2.platform.messages.ReadResponse in project components by Talend.

the class NetSuiteMockTestBase method mockGetListRequestResults.

protected <T extends Record> void mockGetListRequestResults(final List<T> records) throws Exception {
    final NetSuitePortType port = webServiceMockTestFixture.getPortMock();
    when(port.getList(any(GetListRequest.class))).then(new Answer<GetListResponse>() {

        @Override
        public GetListResponse answer(InvocationOnMock invocationOnMock) throws Throwable {
            GetListRequest request = (GetListRequest) invocationOnMock.getArguments()[0];
            GetListResponse response = new GetListResponse();
            ReadResponseList readResponseList = new ReadResponseList();
            int count = request.getBaseRef().size();
            for (int i = 0; i < count; i++) {
                ReadResponse readResponse = new ReadResponse();
                T record = records != null ? records.get(i) : null;
                if (record != null) {
                    readResponse.setStatus(createSuccessStatus());
                } else {
                    readResponse.setStatus(createNotFoundStatus());
                }
                readResponse.setRecord(record);
                readResponseList.getReadResponse().add(readResponse);
            }
            response.setReadResponseList(readResponseList);
            return response;
        }
    });
}
Also used : NetSuitePortType(com.netsuite.webservices.v2016_2.platform.NetSuitePortType) GetListResponse(com.netsuite.webservices.v2016_2.platform.messages.GetListResponse) ReadResponse(com.netsuite.webservices.v2016_2.platform.messages.ReadResponse) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ReadResponseList(com.netsuite.webservices.v2016_2.platform.messages.ReadResponseList) GetListRequest(com.netsuite.webservices.v2016_2.platform.messages.GetListRequest)

Example 4 with ReadResponse

use of com.netsuite.webservices.v2016_2.platform.messages.ReadResponse in project components by Talend.

the class NetSuiteOutputWriterIT method testDelete.

@Test
public void testDelete() throws Exception {
    NetSuiteClientService<NetSuitePortType> clientService = webServiceTestFixture.getClientService();
    clientService.getMetaDataSource().setCustomizationEnabled(false);
    RuntimeContainer container = mock(RuntimeContainer.class);
    NetSuiteOutputProperties properties = new NetSuiteOutputProperties("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(RecordTypeEnum.MESSAGE.getTypeName());
    properties.module.action.setValue(OutputAction.DELETE);
    NetSuiteRuntimeImpl runtime = new NetSuiteRuntimeImpl();
    runtime.setClientFactory(clientFactory);
    NetSuiteDatasetRuntime dataSetRuntime = runtime.getDatasetRuntime(properties.getConnectionProperties());
    Schema schema = dataSetRuntime.getSchema(RefType.RECORD_REF.getTypeName());
    properties.module.main.schema.setValue(schema);
    List<Message> recordsToAdd = makeMessageRecords(5);
    final List<RecordRef> refList = new ArrayList<>(recordsToAdd.size());
    List<NsWriteResponse<RecordRef>> writeResponseList = clientService.addList(recordsToAdd);
    for (NsWriteResponse<RecordRef> writeResponse : writeResponseList) {
        assertTrue(writeResponse.getStatus().isSuccess());
        assertNotNull(writeResponse.getRef());
        refList.add(writeResponse.getRef());
    }
    List<IndexedRecord> indexedRecordList = makeRecordRefIndexedRecords(schema, refList);
    NetSuiteSink sink = new NetSuiteSinkImpl();
    sink.setClientFactory(new NetSuiteClientFactoryImpl() {

        @Override
        public NetSuiteClientService<NetSuitePortType> createClient() throws NetSuiteException {
            NetSuiteClientService<NetSuitePortType> service = super.createClient();
            service.getMetaDataSource().setCustomizationEnabled(webServiceTestFixture.getClientService().getMetaDataSource().isCustomizationEnabled());
            return service;
        }
    });
    sink.initialize(container, properties);
    NetSuiteWriteOperation writeOperation = (NetSuiteWriteOperation) sink.createWriteOperation();
    NetSuiteOutputWriter writer = (NetSuiteOutputWriter) writeOperation.createWriter(container);
    writer.open(UUID.randomUUID().toString());
    for (IndexedRecord indexedRecord : indexedRecordList) {
        writer.write(indexedRecord);
    }
    Result writerResult = writer.close();
    assertNotNull(writerResult);
    assertEquals(indexedRecordList.size(), writerResult.totalCount);
    assertEquals(indexedRecordList.size(), writerResult.successCount);
    List<NsReadResponse<Message>> readResponseList = clientService.execute(new NetSuiteClientService.PortOperation<List<NsReadResponse<Message>>, NetSuitePortType>() {

        @Override
        public List<NsReadResponse<Message>> execute(NetSuitePortType port) throws Exception {
            GetListRequest request = new GetListRequest();
            request.getBaseRef().addAll(refList);
            return NetSuiteClientServiceImpl.toNsReadResponseList(port.getList(request).getReadResponseList());
        }
    });
    for (NsReadResponse<Message> readResponse : readResponseList) {
        // success=false means that NetSuite Record was not found because it was deleted
        assertFalse(readResponse.getStatus().isSuccess());
    }
}
Also used : NetSuiteSinkImpl(org.talend.components.netsuite.v2016_2.NetSuiteSinkImpl) Message(com.netsuite.webservices.v2016_2.general.communication.Message) IndexedRecord(org.apache.avro.generic.IndexedRecord) Schema(org.apache.avro.Schema) NetSuiteClientFactoryImpl(org.talend.components.netsuite.v2016_2.client.NetSuiteClientFactoryImpl) RecordRef(com.netsuite.webservices.v2016_2.platform.core.RecordRef) CustomRecordRef(com.netsuite.webservices.v2016_2.platform.core.CustomRecordRef) ArrayList(java.util.ArrayList) NetSuiteDatasetRuntime(org.talend.components.netsuite.NetSuiteDatasetRuntime) NetSuiteWriteOperation(org.talend.components.netsuite.output.NetSuiteWriteOperation) NsReadResponse(org.talend.components.netsuite.client.NsReadResponse) NetSuiteRuntimeImpl(org.talend.components.netsuite.v2016_2.NetSuiteRuntimeImpl) Result(org.talend.components.api.component.runtime.Result) NsSearchResult(org.talend.components.netsuite.client.NsSearchResult) CustomFieldList(com.netsuite.webservices.v2016_2.platform.core.CustomFieldList) List(java.util.List) ArrayList(java.util.ArrayList) RecordRefList(com.netsuite.webservices.v2016_2.platform.core.RecordRefList) NsWriteResponse(org.talend.components.netsuite.client.NsWriteResponse) NetSuiteOutputWriter(org.talend.components.netsuite.output.NetSuiteOutputWriter) NetSuiteClientService(org.talend.components.netsuite.client.NetSuiteClientService) NetSuiteException(org.talend.components.netsuite.client.NetSuiteException) NetSuiteOutputProperties(org.talend.components.netsuite.output.NetSuiteOutputProperties) NetSuiteException(org.talend.components.netsuite.client.NetSuiteException) NetSuitePortType(com.netsuite.webservices.v2016_2.platform.NetSuitePortType) NetSuiteSink(org.talend.components.netsuite.NetSuiteSink) GetListRequest(com.netsuite.webservices.v2016_2.platform.messages.GetListRequest) RuntimeContainer(org.talend.components.api.container.RuntimeContainer) Test(org.junit.Test)

Example 5 with ReadResponse

use of com.netsuite.webservices.v2016_2.platform.messages.ReadResponse in project components by Talend.

the class NetSuiteOutputWriterIT method testUpdate.

@Test
public void testUpdate() throws Exception {
    final NetSuiteClientService<NetSuitePortType> clientService = webServiceTestFixture.getClientService();
    clientService.getMetaDataSource().setCustomizationEnabled(false);
    RuntimeContainer container = mock(RuntimeContainer.class);
    NetSuiteOutputProperties properties = new NetSuiteOutputProperties("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(RecordTypeEnum.ACCOUNT.getTypeName());
    properties.module.action.setValue(OutputAction.UPDATE);
    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);
    SubsidiarySearch subsidiarySearch = new SubsidiarySearch();
    SubsidiarySearchBasic subsidiarySearchBasic = new SubsidiarySearchBasic();
    subsidiarySearch.setBasic(subsidiarySearchBasic);
    NsSearchResult<Subsidiary> searchResult = clientService.search(subsidiarySearch);
    assertTrue(searchResult.isSuccess());
    assertNotNull(searchResult.getRecordList());
    assertTrue(searchResult.getRecordList().size() > 0);
    Subsidiary subsidiary = searchResult.getRecordList().get(0);
    RecordRef subsidiaryRef = new RecordRef();
    subsidiaryRef.setType(RecordType.SUBSIDIARY);
    subsidiaryRef.setInternalId(subsidiary.getInternalId());
    List<Account> recordsToAdd = makeAccountRecords(5, subsidiaryRef);
    final List<RecordRef> refList = new ArrayList<>(recordsToAdd.size());
    // Add records
    List<NsWriteResponse<RecordRef>> writeResponseList = clientService.addList(recordsToAdd);
    for (NsWriteResponse<RecordRef> writeResponse : writeResponseList) {
        assertTrue(writeResponse.getStatus().isSuccess());
        assertNotNull(writeResponse.getRef());
        refList.add(writeResponse.getRef());
    }
    // Read added records
    List<Account> recordList = new ArrayList<>(refList.size());
    List<NsReadResponse<Account>> readResponseList = clientService.execute(new NetSuiteClientService.PortOperation<List<NsReadResponse<Account>>, NetSuitePortType>() {

        @Override
        public List<NsReadResponse<Account>> execute(NetSuitePortType port) throws Exception {
            GetListRequest request = new GetListRequest();
            request.getBaseRef().addAll(refList);
            return NetSuiteClientServiceImpl.toNsReadResponseList(port.getList(request).getReadResponseList());
        }
    });
    for (NsReadResponse<Account> readResponse : readResponseList) {
        assertTrue(readResponse.getStatus().isSuccess());
        recordList.add(readResponse.getRecord());
    }
    List<IndexedRecord> indexedRecordList = new ArrayList<>(refList.size());
    for (Account record : recordList) {
        GenericRecord indexedRecord = new GenericData.Record(schema);
        indexedRecord.put("InternalId", record.getInternalId());
        indexedRecord.put("AcctNumber", record.getAcctNumber());
        indexedRecord.put("AcctType", record.getAcctType().value());
        // Updated fields
        indexedRecord.put("AcctName", record.getAcctName() + " (edited)");
        indexedRecord.put("Description", "qwerty");
        indexedRecordList.add(indexedRecord);
    }
    // Update records
    NetSuiteSink sink = new NetSuiteSinkImpl();
    sink.setClientFactory(clientFactory);
    sink.initialize(container, properties);
    NetSuiteWriteOperation writeOperation = (NetSuiteWriteOperation) sink.createWriteOperation();
    NetSuiteOutputWriter writer = (NetSuiteOutputWriter) writeOperation.createWriter(container);
    writer.open(UUID.randomUUID().toString());
    for (IndexedRecord indexedRecord : indexedRecordList) {
        writer.write(indexedRecord);
    }
    Result writerResult = writer.close();
    assertNotNull(writerResult);
    assertEquals(indexedRecordList.size(), writerResult.totalCount);
    assertEquals(indexedRecordList.size(), writerResult.successCount);
    // Re-read updated records
    readResponseList = clientService.execute(new NetSuiteClientService.PortOperation<List<NsReadResponse<Account>>, NetSuitePortType>() {

        @Override
        public List<NsReadResponse<Account>> execute(NetSuitePortType port) throws Exception {
            GetListRequest request = new GetListRequest();
            request.getBaseRef().addAll(refList);
            return NetSuiteClientServiceImpl.toNsReadResponseList(port.getList(request).getReadResponseList());
        }
    });
    for (NsReadResponse<Account> readResponse : readResponseList) {
        assertTrue(readResponse.getStatus().isSuccess());
        Account record = readResponse.getRecord();
        assertEquals("qwerty", record.getDescription());
        assertTrue(record.getAcctName().endsWith("(edited)"));
    }
    clientService.deleteList(refList);
}
Also used : Account(com.netsuite.webservices.v2016_2.lists.accounting.Account) NetSuiteSinkImpl(org.talend.components.netsuite.v2016_2.NetSuiteSinkImpl) IndexedRecord(org.apache.avro.generic.IndexedRecord) Schema(org.apache.avro.Schema) RecordRef(com.netsuite.webservices.v2016_2.platform.core.RecordRef) CustomRecordRef(com.netsuite.webservices.v2016_2.platform.core.CustomRecordRef) ArrayList(java.util.ArrayList) NetSuiteDatasetRuntime(org.talend.components.netsuite.NetSuiteDatasetRuntime) NetSuiteWriteOperation(org.talend.components.netsuite.output.NetSuiteWriteOperation) NsReadResponse(org.talend.components.netsuite.client.NsReadResponse) NetSuiteRuntimeImpl(org.talend.components.netsuite.v2016_2.NetSuiteRuntimeImpl) Result(org.talend.components.api.component.runtime.Result) NsSearchResult(org.talend.components.netsuite.client.NsSearchResult) SubsidiarySearch(com.netsuite.webservices.v2016_2.lists.accounting.SubsidiarySearch) Subsidiary(com.netsuite.webservices.v2016_2.lists.accounting.Subsidiary) CustomFieldList(com.netsuite.webservices.v2016_2.platform.core.CustomFieldList) List(java.util.List) ArrayList(java.util.ArrayList) RecordRefList(com.netsuite.webservices.v2016_2.platform.core.RecordRefList) CustomRecord(com.netsuite.webservices.v2016_2.setup.customization.CustomRecord) IndexedRecord(org.apache.avro.generic.IndexedRecord) GenericRecord(org.apache.avro.generic.GenericRecord) GenericRecord(org.apache.avro.generic.GenericRecord) NsWriteResponse(org.talend.components.netsuite.client.NsWriteResponse) NetSuiteOutputWriter(org.talend.components.netsuite.output.NetSuiteOutputWriter) NetSuiteClientService(org.talend.components.netsuite.client.NetSuiteClientService) SubsidiarySearchBasic(com.netsuite.webservices.v2016_2.platform.common.SubsidiarySearchBasic) NetSuiteOutputProperties(org.talend.components.netsuite.output.NetSuiteOutputProperties) NetSuiteException(org.talend.components.netsuite.client.NetSuiteException) NetSuitePortType(com.netsuite.webservices.v2016_2.platform.NetSuitePortType) NetSuiteSink(org.talend.components.netsuite.NetSuiteSink) GetListRequest(com.netsuite.webservices.v2016_2.platform.messages.GetListRequest) RuntimeContainer(org.talend.components.api.container.RuntimeContainer) Test(org.junit.Test)

Aggregations

NetSuitePortType (com.netsuite.webservices.v2016_2.platform.NetSuitePortType)7 GetListRequest (com.netsuite.webservices.v2016_2.platform.messages.GetListRequest)6 InvocationOnMock (org.mockito.invocation.InvocationOnMock)6 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 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Schema (org.apache.avro.Schema)4 IndexedRecord (org.apache.avro.generic.IndexedRecord)4 Test (org.junit.Test)4 Result (org.talend.components.api.component.runtime.Result)4 RuntimeContainer (org.talend.components.api.container.RuntimeContainer)4 NetSuiteDatasetRuntime (org.talend.components.netsuite.NetSuiteDatasetRuntime)4 NetSuiteSink (org.talend.components.netsuite.NetSuiteSink)4 NetSuiteClientService (org.talend.components.netsuite.client.NetSuiteClientService)4 NetSuiteException (org.talend.components.netsuite.client.NetSuiteException)4 NsReadResponse (org.talend.components.netsuite.client.NsReadResponse)4 NsSearchResult (org.talend.components.netsuite.client.NsSearchResult)4 NetSuiteOutputProperties (org.talend.components.netsuite.output.NetSuiteOutputProperties)4