Search in sources :

Example 1 with NetSuitePortType

use of com.netsuite.webservices.v2016_2.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();
            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 NetSuitePortType

use of com.netsuite.webservices.v2016_2.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.v2014_2.platform.NetSuitePortType) SearchRequest(com.netsuite.webservices.v2014_2.platform.messages.SearchRequest) SearchMoreWithIdResponse(com.netsuite.webservices.v2014_2.platform.messages.SearchMoreWithIdResponse) InvocationOnMock(org.mockito.invocation.InvocationOnMock) SearchResult(com.netsuite.webservices.v2014_2.platform.core.SearchResult) SearchResponse(com.netsuite.webservices.v2014_2.platform.messages.SearchResponse) SearchMoreWithIdRequest(com.netsuite.webservices.v2014_2.platform.messages.SearchMoreWithIdRequest)

Example 3 with NetSuitePortType

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

the class CustomMetaDataRetrieverImpl method retrieveCustomizationIds.

public List<NsRef> retrieveCustomizationIds(final BasicRecordType type) throws NetSuiteException {
    GetCustomizationIdResult result = clientService.execute(new NetSuiteClientService.PortOperation<GetCustomizationIdResult, NetSuitePortType>() {

        @Override
        public GetCustomizationIdResult execute(NetSuitePortType port) throws Exception {
            logger.debug("Retrieving customization IDs: {}", type.getType());
            StopWatch stopWatch = new StopWatch();
            try {
                stopWatch.start();
                final GetCustomizationIdRequest request = new GetCustomizationIdRequest();
                CustomizationType customizationType = new CustomizationType();
                customizationType.setGetCustomizationType(GetCustomizationType.fromValue(type.getType()));
                request.setCustomizationType(customizationType);
                return port.getCustomizationId(request).getGetCustomizationIdResult();
            } finally {
                stopWatch.stop();
                logger.debug("Retrieved customization IDs: {}, {}", type.getType(), stopWatch);
            }
        }
    });
    if (result.getStatus().getIsSuccess()) {
        List<NsRef> nsRefs;
        if (result.getTotalRecords() > 0) {
            final List<CustomizationRef> refs = result.getCustomizationRefList().getCustomizationRef();
            nsRefs = new ArrayList<>(refs.size());
            for (final CustomizationRef ref : refs) {
                NsRef nsRef = new NsRef();
                nsRef.setRefType(RefType.CUSTOMIZATION_REF);
                nsRef.setScriptId(ref.getScriptId());
                nsRef.setInternalId(ref.getInternalId());
                nsRef.setType(ref.getType().value());
                nsRef.setName(ref.getName());
                nsRefs.add(nsRef);
            }
        } else {
            nsRefs = Collections.emptyList();
        }
        return nsRefs;
    } else {
        throw new NetSuiteException("Retrieving of customizations was not successful: " + type);
    }
}
Also used : NetSuiteClientService(org.talend.components.netsuite.client.NetSuiteClientService) NetSuiteException(org.talend.components.netsuite.client.NetSuiteException) GetCustomizationIdResult(com.netsuite.webservices.v2016_2.platform.core.GetCustomizationIdResult) NetSuiteException(org.talend.components.netsuite.client.NetSuiteException) NsRef(org.talend.components.netsuite.client.NsRef) StopWatch(org.apache.commons.lang3.time.StopWatch) NetSuitePortType(com.netsuite.webservices.v2016_2.platform.NetSuitePortType) GetCustomizationIdRequest(com.netsuite.webservices.v2016_2.platform.messages.GetCustomizationIdRequest) CustomizationType(com.netsuite.webservices.v2016_2.platform.core.CustomizationType) GetCustomizationType(com.netsuite.webservices.v2016_2.platform.core.types.GetCustomizationType) CustomizationRef(com.netsuite.webservices.v2016_2.platform.core.CustomizationRef)

Example 4 with NetSuitePortType

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

the class NetSuiteClientServiceImpl 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.v2016_2.platform.core.Status) NsStatus(org.talend.components.netsuite.client.NsStatus) InvalidCredentialsFault(com.netsuite.webservices.v2016_2.platform.InvalidCredentialsFault) LoginResponse(com.netsuite.webservices.v2016_2.platform.messages.LoginResponse) NetSuiteException(org.talend.components.netsuite.client.NetSuiteException) UnexpectedErrorFault(com.netsuite.webservices.v2016_2.platform.UnexpectedErrorFault) LoginRequest(com.netsuite.webservices.v2016_2.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) WebServiceException(javax.xml.ws.WebServiceException) NetSuitePortType(com.netsuite.webservices.v2016_2.platform.NetSuitePortType) NetSuiteErrorCode(org.talend.components.netsuite.NetSuiteErrorCode) Passport(com.netsuite.webservices.v2016_2.platform.core.Passport) SessionResponse(com.netsuite.webservices.v2016_2.platform.messages.SessionResponse)

Example 5 with NetSuitePortType

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

the class NetSuiteClientServiceTest method testConnectAndLogin.

/**
 */
@Test
public void testConnectAndLogin() throws Exception {
    final NetSuiteCredentials credentials = webServiceMockTestFixture.getCredentials();
    final NetSuitePortType port = webServiceMockTestFixture.getPortMock();
    SessionResponse sessionResponse = new SessionResponse();
    sessionResponse.setStatus(createSuccessStatus());
    LoginResponse response = new LoginResponse();
    response.setSessionResponse(sessionResponse);
    when(port.login(argThat(new AssertMatcher<LoginRequest>() {

        @Override
        protected void doAssert(LoginRequest target) throws Exception {
            assertEquals(credentials.getEmail(), target.getPassport().getEmail());
            assertEquals(credentials.getPassword(), target.getPassport().getPassword());
            assertEquals(credentials.getRoleId(), target.getPassport().getRole().getInternalId());
            assertEquals(credentials.getAccount(), target.getPassport().getAccount());
            MessageContext messageContext = MessageContextHolder.get();
            assertNotNull(messageContext);
            List<Header> headers = (List<Header>) messageContext.get(Header.HEADER_LIST);
            assertNotNull(headers);
            Header appInfoHeader = NetSuiteWebServiceMockTestFixture.getHeader(headers, new QName(NetSuiteClientServiceImpl.NS_URI_PLATFORM_MESSAGES, "applicationInfo"));
            assertNotNull(appInfoHeader);
        }
    }))).thenReturn(response);
    NetSuiteClientService<?> clientService = webServiceMockTestFixture.getClientService();
    clientService.login();
    verify(port, times(1)).login(any(LoginRequest.class));
}
Also used : NetSuitePortType(com.netsuite.webservices.v2016_2.platform.NetSuitePortType) NetSuiteCredentials(org.talend.components.netsuite.client.NetSuiteCredentials) LoginResponse(com.netsuite.webservices.v2016_2.platform.messages.LoginResponse) Header(org.apache.cxf.headers.Header) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) List(java.util.List) LoginRequest(com.netsuite.webservices.v2016_2.platform.messages.LoginRequest) MessageContext(javax.xml.ws.handler.MessageContext) SessionResponse(com.netsuite.webservices.v2016_2.platform.messages.SessionResponse) AssertMatcher(org.talend.components.netsuite.test.AssertMatcher) Test(org.junit.Test)

Aggregations

NetSuitePortType (com.netsuite.webservices.v2016_2.platform.NetSuitePortType)15 ArrayList (java.util.ArrayList)12 InvocationOnMock (org.mockito.invocation.InvocationOnMock)12 Test (org.junit.Test)10 NetSuiteException (org.talend.components.netsuite.client.NetSuiteException)10 NetSuitePortType (com.netsuite.webservices.v2014_2.platform.NetSuitePortType)9 Schema (org.apache.avro.Schema)8 IndexedRecord (org.apache.avro.generic.IndexedRecord)8 Result (org.talend.components.api.component.runtime.Result)8 NetSuiteDatasetRuntime (org.talend.components.netsuite.NetSuiteDatasetRuntime)8 NetSuiteSink (org.talend.components.netsuite.NetSuiteSink)8 NetSuiteOutputWriter (org.talend.components.netsuite.output.NetSuiteOutputWriter)8 NetSuiteWriteOperation (org.talend.components.netsuite.output.NetSuiteWriteOperation)8 GetListRequest (com.netsuite.webservices.v2016_2.platform.messages.GetListRequest)7 List (java.util.List)7 NetSuiteClientService (org.talend.components.netsuite.client.NetSuiteClientService)6 NetSuiteRuntimeImpl (org.talend.components.netsuite.v2016_2.NetSuiteRuntimeImpl)6 NetSuiteSinkImpl (org.talend.components.netsuite.v2016_2.NetSuiteSinkImpl)6 RecordRef (com.netsuite.webservices.v2016_2.platform.core.RecordRef)5 NsReadResponse (org.talend.components.netsuite.client.NsReadResponse)5