use of org.talend.components.netsuite.client.NetSuiteCredentials 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));
}
use of org.talend.components.netsuite.client.NetSuiteCredentials in project components by Talend.
the class NetSuiteEndpoint method createConnectionConfig.
/**
* Create connection configuration for given connection properties.
*
* @param properties connection properties
* @return connection configuration
* @throws NetSuiteException if connection configuration not valid
*/
public static ConnectionConfig createConnectionConfig(NetSuiteProvideConnectionProperties properties) throws NetSuiteException {
NetSuiteConnectionProperties connProps = properties.getConnectionProperties();
if (StringUtils.isEmpty(connProps.endpoint.getStringValue())) {
throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.endpointUrlRequired"));
}
if (StringUtils.isEmpty(connProps.apiVersion.getStringValue())) {
throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.apiVersionRequired"));
}
if (StringUtils.isEmpty(connProps.email.getStringValue())) {
throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.emailRequired"));
}
if (StringUtils.isEmpty(connProps.password.getStringValue())) {
throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.passwordRequired"));
}
if (StringUtils.isEmpty(connProps.account.getStringValue())) {
throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.accountRequired"));
}
if (connProps.role.getValue() == null) {
throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.roleRequired"));
}
String endpointUrl = connProps.endpoint.getStringValue();
NetSuiteVersion endpointApiVersion;
try {
endpointApiVersion = NetSuiteVersion.detectVersion(endpointUrl);
} catch (IllegalArgumentException e) {
throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.couldNotDetectApiVersionFromEndpointUrl", endpointUrl));
}
String apiVersionString = connProps.apiVersion.getStringValue();
NetSuiteVersion apiVersion;
try {
apiVersion = NetSuiteVersion.parseVersion(apiVersionString);
} catch (IllegalArgumentException e) {
throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.invalidApiVersion", apiVersionString));
}
if (!endpointApiVersion.isSameMajor(apiVersion)) {
throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.endpointUrlApiVersionMismatch", endpointUrl, apiVersionString));
}
if (apiVersion.getMajorYear() >= 2015 && StringUtils.isEmpty(connProps.applicationId.getStringValue())) {
throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.applicationIdRequired"));
}
String email = connProps.email.getStringValue();
String password = connProps.password.getStringValue();
Integer roleId = connProps.role.getValue();
String account = connProps.account.getStringValue();
String applicationId = connProps.applicationId.getStringValue();
Boolean customizationEnabled = connProps.customizationEnabled.getValue();
NetSuiteCredentials credentials = new NetSuiteCredentials();
credentials.setEmail(email);
credentials.setPassword(password);
credentials.setRoleId(roleId.toString());
credentials.setAccount(account);
credentials.setApplicationId(applicationId);
try {
ConnectionConfig connectionConfig = new ConnectionConfig(new URL(endpointUrl), apiVersion.getMajor(), credentials);
if (properties instanceof NetSuiteInputProperties) {
connectionConfig.setBodyFieldsOnly(((NetSuiteInputProperties) properties).bodyFieldsOnly.getValue());
}
connectionConfig.setCustomizationEnabled(customizationEnabled);
return connectionConfig;
} catch (MalformedURLException e) {
throw new NetSuiteException(new NetSuiteErrorCode(NetSuiteErrorCode.CLIENT_ERROR), NetSuiteRuntimeI18n.MESSAGES.getMessage("error.invalidEndpointUrl", endpointUrl));
}
}
use of org.talend.components.netsuite.client.NetSuiteCredentials in project components by Talend.
the class NetSuiteWebServiceMockTestFixture method setUp.
@Override
public void setUp() throws Exception {
System.setProperty("com.sun.xml.bind.v2.bytecode.ClassTailor.noOptimize", "true");
if (serviceFactory != null) {
int retryCount = 3;
while (retryCount > 0) {
retryCount--;
try {
publish();
break;
} catch (WebServiceException | IOException e) {
logger.error("Service publishing error: {}", e);
if (retryCount == 0) {
throw e;
}
}
}
URL wsdlLocation = new URL(portMockAdapter.getEndpointAddress().toString().concat("?wsdl"));
// assertNotNull(wsdlLocation.getContent());
service = serviceFactory.createService(wsdlLocation);
} else {
if (portName == null) {
NetSuiteVersion version = clientFactory.getApiVersion();
portName = "NetSuitePort_" + version.getAsString("_");
}
portMockAdapter = portAdapterClass.newInstance();
portMockAdapter.setEndpointAddress(new URL("http://localhost/services/" + portName));
}
credentials = new NetSuiteCredentials("test@test.com", "12345", "test", "3");
credentials.setApplicationId("00000000-0000-0000-0000-000000000000");
reinstall();
}
use of org.talend.components.netsuite.client.NetSuiteCredentials in project components by Talend.
the class NetSuiteClientServiceTest method testConnectAndLogin.
/**
* TODO Verify headers (applicationInfo etc.)
*/
@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