Search in sources :

Example 1 with NetSuitePortType

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

the class TestNetSuiteClientService method doLogin.

@Override
protected void doLogin() throws NetSuiteException {
    port = getNetSuitePort(endpointUrl, credentials.getAccount());
    setHttpClientPolicy(port);
    setLoginHeaders(port);
    PortOperation<SessionResponse, NetSuitePortType> loginOp;
    if (!credentials.isUseSsoLogin()) {
        final Passport passport = createNativePassport(credentials);
        loginOp = new PortOperation<SessionResponse, NetSuitePortType>() {

            @Override
            public SessionResponse execute(NetSuitePortType port) throws Exception {
                LoginRequest request = new LoginRequest();
                request.setPassport(passport);
                LoginResponse response = port.login(request);
                return response.getSessionResponse();
            }
        };
    } else {
        throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.ssoLoginNotSupported"));
    }
    Status status = null;
    SessionResponse sessionResponse;
    String exceptionMessage = null;
    for (int i = 0; i < getRetryCount(); i++) {
        try {
            sessionResponse = loginOp.execute(port);
            status = sessionResponse.getStatus();
        } catch (InvalidCredentialsFault f) {
            throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), f.getFaultInfo().getMessage());
        } catch (UnexpectedErrorFault f) {
            exceptionMessage = f.getFaultInfo().getMessage();
        } catch (Exception e) {
            exceptionMessage = e.getMessage();
        }
        if (status != null) {
            break;
        }
        if (i != getRetryCount() - 1) {
            waitForRetryInterval();
        }
    }
    checkLoginError(toNsStatus(status), exceptionMessage);
    removeLoginHeaders(port);
}
Also used : Status(com.netsuite.webservices.test.platform.core.Status) NsStatus(org.talend.components.netsuite.client.NsStatus) InvalidCredentialsFault(com.netsuite.webservices.test.platform.InvalidCredentialsFault) LoginResponse(com.netsuite.webservices.test.platform.messages.LoginResponse) NetSuiteException(org.talend.components.netsuite.client.NetSuiteException) UnexpectedErrorFault(com.netsuite.webservices.test.platform.UnexpectedErrorFault) LoginRequest(com.netsuite.webservices.test.platform.messages.LoginRequest) NetSuiteException(org.talend.components.netsuite.client.NetSuiteException) InvocationTargetException(java.lang.reflect.InvocationTargetException) RemoteException(java.rmi.RemoteException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) SocketException(java.net.SocketException) MalformedURLException(java.net.MalformedURLException) NetSuitePortType(com.netsuite.webservices.test.platform.NetSuitePortType) NetSuiteErrorCode(org.talend.components.netsuite.NetSuiteErrorCode) Passport(com.netsuite.webservices.test.platform.core.Passport) SessionResponse(com.netsuite.webservices.test.platform.messages.SessionResponse)

Example 2 with NetSuitePortType

use of com.netsuite.webservices.test.platform.NetSuitePortType 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();
            if (record != null) {
                readResponse.setStatus(createSuccessStatus());
            } else {
                readResponse.setStatus(createNotFoundStatus());
            }
            readResponse.setRecord(record);
            response.setReadResponse(readResponse);
            return response;
        }
    });
}
Also used : NetSuitePortType(com.netsuite.webservices.test.platform.NetSuitePortType) ReadResponse(com.netsuite.webservices.test.platform.messages.ReadResponse) InvocationOnMock(org.mockito.invocation.InvocationOnMock) GetRequest(com.netsuite.webservices.test.platform.messages.GetRequest) GetResponse(com.netsuite.webservices.test.platform.messages.GetResponse)

Example 3 with NetSuitePortType

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

the class NetSuiteMockTestBase method mockSearchRequestResults.

protected <T extends Record> void mockSearchRequestResults(List<T> recordList, int pageSize) throws Exception {
    final NetSuitePortType port = webServiceMockTestFixture.getPortMock();
    final List<SearchResult> pageResults = makeRecordPages(recordList, pageSize);
    when(port.search(any(SearchRequest.class))).then(new Answer<SearchResponse>() {

        @Override
        public SearchResponse answer(InvocationOnMock invocationOnMock) throws Throwable {
            SearchResponse response = new SearchResponse();
            response.setSearchResult(pageResults.get(0));
            return response;
        }
    });
    when(port.searchMoreWithId(any(SearchMoreWithIdRequest.class))).then(new Answer<SearchMoreWithIdResponse>() {

        @Override
        public SearchMoreWithIdResponse answer(InvocationOnMock invocationOnMock) throws Throwable {
            SearchMoreWithIdRequest request = (SearchMoreWithIdRequest) invocationOnMock.getArguments()[0];
            SearchMoreWithIdResponse response = new SearchMoreWithIdResponse();
            response.setSearchResult(pageResults.get(request.getPageIndex() - 1));
            return response;
        }
    });
}
Also used : NetSuitePortType(com.netsuite.webservices.test.platform.NetSuitePortType) SearchRequest(com.netsuite.webservices.test.platform.messages.SearchRequest) SearchMoreWithIdResponse(com.netsuite.webservices.test.platform.messages.SearchMoreWithIdResponse) InvocationOnMock(org.mockito.invocation.InvocationOnMock) SearchResult(com.netsuite.webservices.test.platform.core.SearchResult) SearchResponse(com.netsuite.webservices.test.platform.messages.SearchResponse) SearchMoreWithIdRequest(com.netsuite.webservices.test.platform.messages.SearchMoreWithIdRequest)

Example 4 with NetSuitePortType

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

Aggregations

NetSuitePortType (com.netsuite.webservices.test.platform.NetSuitePortType)4 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3 ReadResponse (com.netsuite.webservices.test.platform.messages.ReadResponse)2 InvalidCredentialsFault (com.netsuite.webservices.test.platform.InvalidCredentialsFault)1 UnexpectedErrorFault (com.netsuite.webservices.test.platform.UnexpectedErrorFault)1 Passport (com.netsuite.webservices.test.platform.core.Passport)1 SearchResult (com.netsuite.webservices.test.platform.core.SearchResult)1 Status (com.netsuite.webservices.test.platform.core.Status)1 GetListRequest (com.netsuite.webservices.test.platform.messages.GetListRequest)1 GetListResponse (com.netsuite.webservices.test.platform.messages.GetListResponse)1 GetRequest (com.netsuite.webservices.test.platform.messages.GetRequest)1 GetResponse (com.netsuite.webservices.test.platform.messages.GetResponse)1 LoginRequest (com.netsuite.webservices.test.platform.messages.LoginRequest)1 LoginResponse (com.netsuite.webservices.test.platform.messages.LoginResponse)1 ReadResponseList (com.netsuite.webservices.test.platform.messages.ReadResponseList)1 SearchMoreWithIdRequest (com.netsuite.webservices.test.platform.messages.SearchMoreWithIdRequest)1 SearchMoreWithIdResponse (com.netsuite.webservices.test.platform.messages.SearchMoreWithIdResponse)1 SearchRequest (com.netsuite.webservices.test.platform.messages.SearchRequest)1 SearchResponse (com.netsuite.webservices.test.platform.messages.SearchResponse)1 SessionResponse (com.netsuite.webservices.test.platform.messages.SessionResponse)1