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