Search in sources :

Example 61 with Connection

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();
}
Also used : WaitWhile(org.eclipse.reddeer.common.wait.WaitWhile) ProjectExists(org.jboss.tools.openshift.reddeer.condition.core.ProjectExists) CleanConnection(org.jboss.tools.openshift.reddeer.requirement.CleanOpenShiftConnectionRequirement.CleanConnection) Connection(org.jboss.tools.openshift.core.connection.Connection) IResource(com.openshift.restclient.model.IResource)

Example 62 with Connection

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();
    }
}
Also used : IValueChangeListener(org.eclipse.core.databinding.observable.value.IValueChangeListener) OAuthDetailView(org.jboss.tools.openshift.internal.ui.wizard.connection.OAuthDetailView) ValueChangeEvent(org.eclipse.core.databinding.observable.value.ValueChangeEvent) Shell(org.eclipse.swt.widgets.Shell) Composite(org.eclipse.swt.widgets.Composite) ConnectionWizardPageModel(org.jboss.tools.openshift.internal.common.ui.connection.ConnectionWizardPageModel) Connection(org.jboss.tools.openshift.core.connection.Connection) DataBindingContext(org.eclipse.core.databinding.DataBindingContext) MultiValidator(org.eclipse.core.databinding.validation.MultiValidator) Test(org.junit.Test)

Example 63 with Connection

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));
}
Also used : ConnectionWizardPageModel(org.jboss.tools.openshift.internal.common.ui.connection.ConnectionWizardPageModel) Connection(org.jboss.tools.openshift.core.connection.Connection) MultiValidator(org.eclipse.core.databinding.validation.MultiValidator) WritableValue(org.eclipse.core.databinding.observable.value.WritableValue) Test(org.junit.Test)

Example 64 with Connection

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;
}
Also used : Connection(org.jboss.tools.openshift.core.connection.Connection)

Example 65 with 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;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) OpenShiftException(com.openshift.restclient.OpenShiftException) Connection(org.jboss.tools.openshift.core.connection.Connection) IRoute(com.openshift.restclient.model.route.IRoute) IResource(com.openshift.restclient.model.IResource) IProject(com.openshift.restclient.model.IProject) IService(com.openshift.restclient.model.IService)

Aggregations

Connection (org.jboss.tools.openshift.core.connection.Connection)110 Test (org.junit.Test)48 IConnection (org.jboss.tools.openshift.common.core.connection.IConnection)30 IResource (com.openshift.restclient.model.IResource)27 IProject (com.openshift.restclient.model.IProject)18 IService (com.openshift.restclient.model.IService)11 IStatus (org.eclipse.core.runtime.IStatus)11 IDeploymentConfig (com.openshift.restclient.model.IDeploymentConfig)9 Collection (java.util.Collection)8 List (java.util.List)8 ISelection (org.eclipse.jface.viewers.ISelection)8 IPod (com.openshift.restclient.model.IPod)7 ArrayList (java.util.ArrayList)7 CoreException (org.eclipse.core.runtime.CoreException)7 OpenShiftException (com.openshift.restclient.OpenShiftException)6 ResourceKind (com.openshift.restclient.ResourceKind)6 IRoute (com.openshift.restclient.model.route.IRoute)6 MultiValidator (org.eclipse.core.databinding.validation.MultiValidator)6 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 Status (org.eclipse.core.runtime.Status)6