Search in sources :

Example 1 with NetSuiteCredentials

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

Example 2 with NetSuiteCredentials

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));
    }
}
Also used : NetSuiteInputProperties(org.talend.components.netsuite.input.NetSuiteInputProperties) MalformedURLException(java.net.MalformedURLException) NetSuiteConnectionProperties(org.talend.components.netsuite.connection.NetSuiteConnectionProperties) NetSuiteException(org.talend.components.netsuite.client.NetSuiteException) URL(java.net.URL) NetSuiteCredentials(org.talend.components.netsuite.client.NetSuiteCredentials)

Example 3 with NetSuiteCredentials

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();
}
Also used : NetSuiteCredentials(org.talend.components.netsuite.client.NetSuiteCredentials) WebServiceException(javax.xml.ws.WebServiceException) IOException(java.io.IOException) Endpoint(javax.xml.ws.Endpoint) URL(java.net.URL)

Example 4 with NetSuiteCredentials

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));
}
Also used : NetSuitePortType(com.netsuite.webservices.v2014_2.platform.NetSuitePortType) NetSuiteCredentials(org.talend.components.netsuite.client.NetSuiteCredentials) LoginResponse(com.netsuite.webservices.v2014_2.platform.messages.LoginResponse) Header(org.apache.cxf.headers.Header) QName(javax.xml.namespace.QName) List(java.util.List) LoginRequest(com.netsuite.webservices.v2014_2.platform.messages.LoginRequest) MessageContext(javax.xml.ws.handler.MessageContext) SessionResponse(com.netsuite.webservices.v2014_2.platform.messages.SessionResponse) AssertMatcher(org.talend.components.netsuite.test.AssertMatcher) Test(org.junit.Test)

Aggregations

NetSuiteCredentials (org.talend.components.netsuite.client.NetSuiteCredentials)4 URL (java.net.URL)2 List (java.util.List)2 QName (javax.xml.namespace.QName)2 MessageContext (javax.xml.ws.handler.MessageContext)2 Header (org.apache.cxf.headers.Header)2 Test (org.junit.Test)2 AssertMatcher (org.talend.components.netsuite.test.AssertMatcher)2 NetSuitePortType (com.netsuite.webservices.v2014_2.platform.NetSuitePortType)1 LoginRequest (com.netsuite.webservices.v2014_2.platform.messages.LoginRequest)1 LoginResponse (com.netsuite.webservices.v2014_2.platform.messages.LoginResponse)1 SessionResponse (com.netsuite.webservices.v2014_2.platform.messages.SessionResponse)1 NetSuitePortType (com.netsuite.webservices.v2016_2.platform.NetSuitePortType)1 LoginRequest (com.netsuite.webservices.v2016_2.platform.messages.LoginRequest)1 LoginResponse (com.netsuite.webservices.v2016_2.platform.messages.LoginResponse)1 SessionResponse (com.netsuite.webservices.v2016_2.platform.messages.SessionResponse)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 ArrayList (java.util.ArrayList)1 Endpoint (javax.xml.ws.Endpoint)1