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);
}
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;
}
});
}
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;
}
});
}
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;
}
});
}
Aggregations