Search in sources :

Example 6 with ConnectionURL

use of org.jboss.tools.openshift.common.core.connection.ConnectionURL in project jbosstools-openshift by jbosstools.

the class ConnectionUtils method getConnection.

/**
 * Returns a connection for the given connection server and username
 * @param connectionUrlString
 * @return
 *
 * @see ConnectionURL
 */
public static Connection getConnection(String username, String server) {
    try {
        String url = UrlUtils.getUrlFor(username, server);
        ConnectionURL connectionUrl = ConnectionURL.forURL(url);
        return ConnectionsRegistrySingleton.getInstance().getByUrl(connectionUrl, Connection.class);
    } catch (UnsupportedEncodingException | MalformedURLException e) {
        throw new OpenShiftToolsException(NLS.bind("Could not lookup connection to server {0}: {1}", server, e));
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) ConnectionURL(org.jboss.tools.openshift.common.core.connection.ConnectionURL) UnsupportedEncodingException(java.io.UnsupportedEncodingException) OpenShiftToolsException(org.jboss.tools.openshift.reddeer.exception.OpenShiftToolsException)

Example 7 with ConnectionURL

use of org.jboss.tools.openshift.common.core.connection.ConnectionURL in project jbosstools-openshift by jbosstools.

the class ConnectionURLTest method shouldGetForUsernameAndServer.

@Test
public void shouldGetForUsernameAndServer() throws UnsupportedEncodingException, MalformedURLException {
    // pre-conditions
    String username = "adietish@redhat.com";
    String server = "https://openshift.redhat.com";
    // operation
    ConnectionURL connectionUrl = ConnectionURL.forUsernameAndHost(username, server);
    // verifications
    assertEquals("openshift.redhat.com", connectionUrl.getHost());
    assertFalse(connectionUrl.isDefaultHost());
    assertEquals(username, connectionUrl.getUsername());
    assertEquals("https://", connectionUrl.getScheme());
}
Also used : ConnectionURL(org.jboss.tools.openshift.common.core.connection.ConnectionURL) Test(org.junit.Test)

Example 8 with ConnectionURL

use of org.jboss.tools.openshift.common.core.connection.ConnectionURL in project jbosstools-openshift by jbosstools.

the class ConnectionURLTest method shouldCorrectMisplacedSchemeWithDefaultHost.

@Test
public void shouldCorrectMisplacedSchemeWithDefaultHost() throws UnsupportedEncodingException, MalformedURLException {
    // pre-conditions
    String username = "adietish@redhat.com";
    String schemeOnlyUrl = UrlUtils.SCHEME_HTTP;
    // operation
    ConnectionURL connectionURL = ConnectionURL.forURL(URLEncoder.encode(username, "UTF-8") + '@' + schemeOnlyUrl);
    // verifications
    assertEquals(username, connectionURL.getUsername());
    assertEquals(null, connectionURL.getHost());
    assertTrue(connectionURL.isDefaultHost());
    assertEquals(schemeOnlyUrl, connectionURL.getScheme());
    assertEquals(schemeOnlyUrl + URLEncoder.encode(username, "UTF-8") + '@', connectionURL.getUrl());
}
Also used : ConnectionURL(org.jboss.tools.openshift.common.core.connection.ConnectionURL) Test(org.junit.Test)

Example 9 with ConnectionURL

use of org.jboss.tools.openshift.common.core.connection.ConnectionURL in project jbosstools-openshift by jbosstools.

the class ConnectionURLTest method shouldCorrectMisplacedScheme.

@Test
public void shouldCorrectMisplacedScheme() throws UnsupportedEncodingException, MalformedURLException {
    // pre-conditions
    String username = "adietish@redhat.com";
    String scheme = UrlUtils.SCHEME_HTTP;
    String host = "openshift.local";
    // operation
    ConnectionURL connectionUrl = ConnectionURL.forURL(URLEncoder.encode(username, "UTF-8") + '@' + scheme + host);
    // verifications
    assertEquals(host, connectionUrl.getHost());
    assertFalse(connectionUrl.isDefaultHost());
    assertEquals(username, connectionUrl.getUsername());
    assertEquals(scheme, connectionUrl.getScheme());
}
Also used : ConnectionURL(org.jboss.tools.openshift.common.core.connection.ConnectionURL) Test(org.junit.Test)

Example 10 with ConnectionURL

use of org.jboss.tools.openshift.common.core.connection.ConnectionURL in project jbosstools-openshift by jbosstools.

the class ConnectionURLTest method shouldCorrectMisplacedSchemeWithDefaultServer.

@Test
public void shouldCorrectMisplacedSchemeWithDefaultServer() throws UnsupportedEncodingException, MalformedURLException {
    // pre-conditions
    String username = "adietish@redhat.com";
    String scheme = UrlUtils.SCHEME_HTTP;
    // operation
    ConnectionURL connectionUrl = ConnectionURL.forURL(URLEncoder.encode(username, "UTF-8") + '@' + scheme);
    // verifications
    assertEquals(null, connectionUrl.getHost());
    assertTrue(connectionUrl.isDefaultHost());
    assertEquals(username, connectionUrl.getUsername());
    assertEquals(scheme, connectionUrl.getScheme());
}
Also used : ConnectionURL(org.jboss.tools.openshift.common.core.connection.ConnectionURL) Test(org.junit.Test)

Aggregations

ConnectionURL (org.jboss.tools.openshift.common.core.connection.ConnectionURL)11 Test (org.junit.Test)7 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 MalformedURLException (java.net.MalformedURLException)3 IConnection (org.jboss.tools.openshift.common.core.connection.IConnection)3 Connection (org.jboss.tools.openshift.core.connection.Connection)3 OpenShiftToolsException (org.jboss.tools.openshift.reddeer.exception.OpenShiftToolsException)2 ConnectionsRegistryAdapter (org.jboss.tools.openshift.common.core.connection.ConnectionsRegistryAdapter)1 ConnectionPersistency (org.jboss.tools.openshift.core.connection.ConnectionPersistency)1 ResourceChangePublisher (org.jboss.tools.openshift.internal.core.server.resources.ResourceChangePublisher)1 RequiredBasicConnection (org.jboss.tools.openshift.reddeer.requirement.OpenShiftConnectionRequirement.RequiredBasicConnection)1