Search in sources :

Example 1 with Message

use of com.netsuite.webservices.v2016_2.general.communication.Message 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 2 with Message

use of com.netsuite.webservices.v2016_2.general.communication.Message in project components by Talend.

the class NetSuiteOutputWriterIT method makeMessageRecords.

private static List<Message> makeMessageRecords(int count) {
    List<Message> messageList = new ArrayList<>(count);
    for (int i = 1; i <= count; i++) {
        Message record = new Message();
        record.setSubject("Test subject " + i);
        record.setMessage("Test body text " + i);
        record.setAuthorEmail("doug@acme.com");
        record.setRecipientEmail("bob@acme.com");
        record.setIncoming(false);
        record.setEmailed(false);
        messageList.add(record);
    }
    return messageList;
}
Also used : Message(com.netsuite.webservices.v2016_2.general.communication.Message) ArrayList(java.util.ArrayList)

Aggregations

Message (com.netsuite.webservices.v2016_2.general.communication.Message)2 ArrayList (java.util.ArrayList)2 NetSuitePortType (com.netsuite.webservices.v2016_2.platform.NetSuitePortType)1 CustomFieldList (com.netsuite.webservices.v2016_2.platform.core.CustomFieldList)1 CustomRecordRef (com.netsuite.webservices.v2016_2.platform.core.CustomRecordRef)1 RecordRef (com.netsuite.webservices.v2016_2.platform.core.RecordRef)1 RecordRefList (com.netsuite.webservices.v2016_2.platform.core.RecordRefList)1 GetListRequest (com.netsuite.webservices.v2016_2.platform.messages.GetListRequest)1 List (java.util.List)1 Schema (org.apache.avro.Schema)1 IndexedRecord (org.apache.avro.generic.IndexedRecord)1 Test (org.junit.Test)1 Result (org.talend.components.api.component.runtime.Result)1 RuntimeContainer (org.talend.components.api.container.RuntimeContainer)1 NetSuiteDatasetRuntime (org.talend.components.netsuite.NetSuiteDatasetRuntime)1 NetSuiteSink (org.talend.components.netsuite.NetSuiteSink)1 NetSuiteClientService (org.talend.components.netsuite.client.NetSuiteClientService)1 NetSuiteException (org.talend.components.netsuite.client.NetSuiteException)1 NsReadResponse (org.talend.components.netsuite.client.NsReadResponse)1 NsSearchResult (org.talend.components.netsuite.client.NsSearchResult)1