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