use of org.jboss.tools.openshift.core.connection.Connection in project jbosstools-openshift by jbosstools.
the class CleanOpenShiftConnectionRequirement method fulfill.
@Override
public void fulfill() {
Connection connection = ConnectionUtils.getConnectionOrDefault(cleanConnection.connectionURL());
assertNotNull("There is no connection with URL " + cleanConnection.connectionURL(), connection);
List<IResource> projects = connection.getResources(ResourceKind.PROJECT);
for (IResource project : projects) {
String projectName = project.getName();
connection.deleteResource(project);
new WaitWhile(new ProjectExists(projectName, connection), TimePeriod.LONG);
}
connection.refresh();
}
use of org.jboss.tools.openshift.core.connection.Connection in project jbosstools-openshift by jbosstools.
the class ConnectionValidatorsTest method testOAuthAuthenticationValidatorInUI.
@Test
public void testOAuthAuthenticationValidatorInUI() {
Connection connection1 = mockConnection(HOST1, null, TOKEN1);
mockConnection(HOST2, null, TOKEN2);
ConnectionWizardPageModel pageModel = mockConnectionWizardPageModel(connection1);
Mockito.when(pageModel.getHost()).thenReturn(HOST2);
IValueChangeListener<Object> l = new IValueChangeListener<Object>() {
@Override
public void handleValueChange(ValueChangeEvent<? extends Object> event) {
}
};
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
Composite composite = new Composite(shell, SWT.NONE);
try {
OAuthDetailView view = new OAuthDetailView(null, pageModel, l, null, null);
DataBindingContext dbc = new DataBindingContext();
view.createControls(shell, null, dbc);
view.onVisible(null, dbc);
view.getTokenTextControl().setText(TOKEN2);
MultiValidator v = findValidator(dbc);
Assert.assertEquals(IStatus.ERROR, getStatusSeverity(v));
view.getTokenTextControl().setText(TOKEN3);
Assert.assertEquals(IStatus.OK, getStatusSeverity(v));
} finally {
composite.dispose();
}
}
use of org.jboss.tools.openshift.core.connection.Connection in project jbosstools-openshift by jbosstools.
the class ConnectionValidatorsTest method testOAuthAuthenticationValidator.
@Test
public void testOAuthAuthenticationValidator() {
Connection connection1 = mockConnection(HOST1, null, TOKEN1);
mockConnection(HOST2, null, TOKEN2);
ConnectionWizardPageModel pageModel = mockConnectionWizardPageModel(connection1);
WritableValue<String> tokenObservable = new WritableValue<String>();
WritableValue<String> urlObservable = new WritableValue<String>();
MultiValidator v = ConnectionValidatorFactory.createOAuthAuthenticationValidator(pageModel, tokenObservable, urlObservable);
v.observeValidatedValue(urlObservable);
// New connection
urlObservable.setValue(HOST3);
tokenObservable.setValue(TOKEN3);
Assert.assertEquals(IStatus.OK, getStatusSeverity(v));
urlObservable.setValue(HOST2);
// Host exists, but token is different
Assert.assertEquals(IStatus.OK, getStatusSeverity(v));
tokenObservable.setValue(TOKEN2);
// Existing not selected connection
Assert.assertEquals(IStatus.ERROR, getStatusSeverity(v));
// Selected connection
urlObservable.setValue(HOST1);
tokenObservable.setValue(TOKEN1);
Assert.assertEquals(IStatus.OK, getStatusSeverity(v));
}
use of org.jboss.tools.openshift.core.connection.Connection in project jbosstools-openshift by jbosstools.
the class ConnectionValidatorsTest method mockConnection.
/**
* Creates a connection instance and adds it to the registry.
* @param host
* @param username
* @param token
* @return
*/
private Connection mockConnection(String host, String username, String token) {
boolean isOAuth = token != null;
Connection connection = Mockito.mock(Connection.class);
Mockito.when(connection.getHost()).thenReturn(host);
Mockito.when(connection.getUsername()).thenReturn(username);
Mockito.when(connection.getToken()).thenReturn(token);
Mockito.when(connection.getAuthScheme()).thenReturn(isOAuth ? IAuthorizationContext.AUTHSCHEME_OAUTH : IAuthorizationContext.AUTHSCHEME_BASIC);
registry.add(connection);
connections.add(connection);
return connection;
}
use of org.jboss.tools.openshift.core.connection.Connection in project jbosstools-openshift by jbosstools.
the class OpenShiftServerExtendedProperties method getWelcomePageUrl.
@Override
public String getWelcomePageUrl() throws GetWelcomePageURLException {
String welcomePageUrl = null;
try {
// Get connection explicitly to report failure. Try and connect right now to know if it fails.
// Do not catch OpenShiftException, let it be reported. We are more concerned of NPE.
Connection connection = OpenShiftServerUtils.getConnection(server);
if (connection == null || !connection.connect()) {
throw new GetWelcomePageURLException("Connection is not established.");
}
IResource resource = OpenShiftServerUtils.getResource(server, connection, new NullProgressMonitor());
if (resource == null) {
throw new GetWelcomePageURLException("Resource is missing.");
}
IProject project = resource.getProject();
if ((project != null) && (resource instanceof IService)) {
List<IRoute> routes = ResourceUtils.getRoutesFor((IService) resource, project.getResources(ResourceKind.ROUTE));
IRoute route = getRoute(OpenShiftServerUtils.getRouteURL(server), routes);
if (route == null) {
route = getRoute(routes);
}
// Reporting route == null is implemented in getRoute.
if (route != null) {
welcomePageUrl = route.getURL();
}
}
} catch (OpenShiftException e) {
throw new GetWelcomePageURLException(e.getMessage(), e);
}
return welcomePageUrl;
}
Aggregations