Search in sources :

Example 1 with ReadResponseList

use of com.netsuite.webservices.v2014_2.platform.messages.ReadResponseList 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 2 with ReadResponseList

use of com.netsuite.webservices.v2014_2.platform.messages.ReadResponseList 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 3 with ReadResponseList

use of com.netsuite.webservices.v2014_2.platform.messages.ReadResponseList in project components by Talend.

the class NetSuitePortTypeMockAdapterImpl method getList.

public GetListResponse getList(GetListRequest parameters) throws InvalidSessionFault, ExceededUsageLimitFault, UnexpectedErrorFault, ExceededRequestLimitFault, ExceededRequestSizeFault, ExceededConcurrentRequestLimitFault, InvalidCredentialsFault, InsufficientPermissionFault, ExceededRecordCountFault {
    GetListResponse response = null;
    if (port != null) {
        response = port.getList(parameters);
    }
    if (response == null) {
        response = new GetListResponse();
        ReadResponseList readResponseList = new ReadResponseList();
        readResponseList.setStatus(createSuccessStatus());
        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)

Example 4 with ReadResponseList

use of com.netsuite.webservices.v2014_2.platform.messages.ReadResponseList 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.v2014_2.platform.NetSuitePortType) GetListResponse(com.netsuite.webservices.v2014_2.platform.messages.GetListResponse) ReadResponse(com.netsuite.webservices.v2014_2.platform.messages.ReadResponse) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ReadResponseList(com.netsuite.webservices.v2014_2.platform.messages.ReadResponseList) GetListRequest(com.netsuite.webservices.v2014_2.platform.messages.GetListRequest)

Example 5 with ReadResponseList

use of com.netsuite.webservices.v2014_2.platform.messages.ReadResponseList 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.v2014_2.platform.messages.GetListResponse) ReadResponseList(com.netsuite.webservices.v2014_2.platform.messages.ReadResponseList) BaseRef(com.netsuite.webservices.v2014_2.platform.core.BaseRef) CustomFieldType(com.netsuite.webservices.v2014_2.setup.customization.CustomFieldType) GetCustomizationIdResult(com.netsuite.webservices.v2014_2.platform.core.GetCustomizationIdResult) NetSuitePortType(com.netsuite.webservices.v2014_2.platform.NetSuitePortType) GetCustomizationIdRequest(com.netsuite.webservices.v2014_2.platform.messages.GetCustomizationIdRequest) RecordType(com.netsuite.webservices.v2014_2.platform.core.types.RecordType) ReadResponse(com.netsuite.webservices.v2014_2.platform.messages.ReadResponse) InvocationOnMock(org.mockito.invocation.InvocationOnMock) CustomizationRefList(com.netsuite.webservices.v2014_2.platform.core.CustomizationRefList) CustomizationType(com.netsuite.webservices.v2014_2.platform.core.CustomizationType) CustomizationRef(com.netsuite.webservices.v2014_2.platform.core.CustomizationRef) GetCustomizationIdResponse(com.netsuite.webservices.v2014_2.platform.messages.GetCustomizationIdResponse) Map(java.util.Map) HashMap(java.util.HashMap) GetListRequest(com.netsuite.webservices.v2014_2.platform.messages.GetListRequest)

Aggregations

InvocationOnMock (org.mockito.invocation.InvocationOnMock)4 GetListResponse (com.netsuite.webservices.v2014_2.platform.messages.GetListResponse)3 ReadResponseList (com.netsuite.webservices.v2014_2.platform.messages.ReadResponseList)3 GetListResponse (com.netsuite.webservices.v2016_2.platform.messages.GetListResponse)3 ReadResponseList (com.netsuite.webservices.v2016_2.platform.messages.ReadResponseList)3 NetSuitePortType (com.netsuite.webservices.v2014_2.platform.NetSuitePortType)2 GetListRequest (com.netsuite.webservices.v2014_2.platform.messages.GetListRequest)2 ReadResponse (com.netsuite.webservices.v2014_2.platform.messages.ReadResponse)2 NetSuitePortType (com.netsuite.webservices.v2016_2.platform.NetSuitePortType)2 GetListRequest (com.netsuite.webservices.v2016_2.platform.messages.GetListRequest)2 ReadResponse (com.netsuite.webservices.v2016_2.platform.messages.ReadResponse)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 BaseRef (com.netsuite.webservices.v2014_2.platform.core.BaseRef)1 CustomizationRef (com.netsuite.webservices.v2014_2.platform.core.CustomizationRef)1 CustomizationRefList (com.netsuite.webservices.v2014_2.platform.core.CustomizationRefList)1 CustomizationType (com.netsuite.webservices.v2014_2.platform.core.CustomizationType)1 GetCustomizationIdResult (com.netsuite.webservices.v2014_2.platform.core.GetCustomizationIdResult)1 RecordType (com.netsuite.webservices.v2014_2.platform.core.types.RecordType)1 GetCustomizationIdRequest (com.netsuite.webservices.v2014_2.platform.messages.GetCustomizationIdRequest)1