Search in sources :

Example 1 with UsernameAndPassword

use of org.igniterealtime.smack.inttest.IntTestUtil.UsernameAndPassword in project Smack by igniterealtime.

the class SmackIntegrationTestFramework method getConnectedConnection.

static XMPPTCPConnection getConnectedConnection(SmackIntegrationTestEnvironment environment, int connectionId) throws KeyManagementException, NoSuchAlgorithmException, InterruptedException, SmackException, IOException, XMPPException {
    Configuration config = environment.configuration;
    XMPPTCPConnectionConfiguration.Builder builder = XMPPTCPConnectionConfiguration.builder();
    if (config.tlsContext != null) {
        builder.setCustomSSLContext(config.tlsContext);
    }
    builder.setSecurityMode(config.securityMode);
    builder.setXmppDomain(config.service);
    XMPPTCPConnection connection = new XMPPTCPConnection(builder.build());
    connection.connect();
    UsernameAndPassword uap = IntTestUtil.registerAccount(connection, environment, connectionId);
    connection.login(uap.username, uap.password);
    return connection;
}
Also used : SmackConfiguration(org.jivesoftware.smack.SmackConfiguration) XMPPTCPConnectionConfiguration(org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration) XMPPTCPConnection(org.jivesoftware.smack.tcp.XMPPTCPConnection) Builder(org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration.Builder) UsernameAndPassword(org.igniterealtime.smack.inttest.IntTestUtil.UsernameAndPassword) XMPPTCPConnectionConfiguration(org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration)

Example 2 with UsernameAndPassword

use of org.igniterealtime.smack.inttest.IntTestUtil.UsernameAndPassword in project Smack by igniterealtime.

the class SmackIntegrationTestFramework method getConnectedConnectionFor.

private XMPPTCPConnection getConnectedConnectionFor(AccountNum accountNum) throws SmackException, IOException, XMPPException, InterruptedException, KeyManagementException, NoSuchAlgorithmException {
    String middlefix;
    String accountUsername;
    String accountPassword;
    switch(accountNum) {
        case One:
            accountUsername = config.accountOneUsername;
            accountPassword = config.accountOnePassword;
            middlefix = "one";
            break;
        case Two:
            accountUsername = config.accountTwoUsername;
            accountPassword = config.accountTwoPassword;
            middlefix = "two";
            break;
        case Three:
            accountUsername = config.accountThreeUsername;
            accountPassword = config.accountThreePassword;
            middlefix = "three";
            break;
        default:
            throw new IllegalStateException();
    }
    if (StringUtils.isNullOrEmpty(accountUsername)) {
        accountUsername = USERNAME_PREFIX + '-' + middlefix + '-' + testRunResult.testRunId;
    }
    if (StringUtils.isNullOrEmpty(accountPassword)) {
        accountPassword = StringUtils.insecureRandomString(16);
    }
    // @formatter:off
    Builder builder = XMPPTCPConnectionConfiguration.builder().setXmppDomain(config.service).setUsernameAndPassword(accountUsername, accountPassword).setResource(middlefix + '-' + testRunResult.testRunId).setSecurityMode(config.securityMode);
    // @formatter:on
    if (config.tlsContext != null) {
        builder.setCustomSSLContext(config.tlsContext);
    }
    XMPPTCPConnection connection = new XMPPTCPConnection(builder.build());
    connection.connect();
    if (config.isAccountRegistrationPossible()) {
        UsernameAndPassword uap = IntTestUtil.registerAccount(connection, accountUsername, accountPassword, config);
        // TODO is this still required?
        // Some servers, e.g. Openfire, do not support a login right after the account was
        // created, so disconnect and re-connection the connection first.
        connection.disconnect();
        connection.connect();
        connection.login(uap.username, uap.password);
    } else {
        connection.login();
    }
    return connection;
}
Also used : XMPPTCPConnection(org.jivesoftware.smack.tcp.XMPPTCPConnection) Builder(org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration.Builder) UsernameAndPassword(org.igniterealtime.smack.inttest.IntTestUtil.UsernameAndPassword)

Aggregations

UsernameAndPassword (org.igniterealtime.smack.inttest.IntTestUtil.UsernameAndPassword)2 XMPPTCPConnection (org.jivesoftware.smack.tcp.XMPPTCPConnection)2 Builder (org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration.Builder)2 SmackConfiguration (org.jivesoftware.smack.SmackConfiguration)1 XMPPTCPConnectionConfiguration (org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration)1