Search in sources :

Example 46 with Connection

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

the class ConnectionTest method should_not_equals_if_different_scheme.

@Test
public void should_not_equals_if_different_scheme() throws Exception {
    // given
    Connection two = new Connection("http://localhost:8443", null, null);
    // when
    // then
    assertThat(connection).isNotEqualTo(two);
}
Also used : Connection(org.jboss.tools.openshift.core.connection.Connection) Test(org.junit.Test)

Example 47 with Connection

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

the class ConnectionValidatorsTest method testBasicAuthenticationValidatorInUI.

@Test
public void testBasicAuthenticationValidatorInUI() {
    Connection connection1 = mockConnection(HOST1, USER1, null);
    mockConnection(HOST2, USER2, null);
    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 {
        BasicAuthenticationDetailView view = new BasicAuthenticationDetailView(pageModel, l, null);
        DataBindingContext dbc = new DataBindingContext();
        view.createControls(shell, null, dbc);
        view.onVisible(null, dbc);
        view.getPasswordTextControl().setText("pass");
        view.getUsernameTextControl().setText(USER2);
        MultiValidator v = findValidator(dbc);
        Assert.assertEquals(IStatus.ERROR, getStatusSeverity(v));
        view.getUsernameTextControl().setText(USER3);
        Assert.assertEquals(IStatus.OK, getStatusSeverity(v));
    } finally {
        composite.dispose();
    }
}
Also used : IValueChangeListener(org.eclipse.core.databinding.observable.value.IValueChangeListener) BasicAuthenticationDetailView(org.jboss.tools.openshift.internal.ui.wizard.connection.BasicAuthenticationDetailView) 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 48 with Connection

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

the class ConnectionValidatorsTest method testBasicAuthenticationValidator.

@Test
public void testBasicAuthenticationValidator() {
    Connection connection1 = mockConnection(HOST1, USER1, null);
    mockConnection(HOST2, USER2, null);
    ConnectionWizardPageModel pageModel = mockConnectionWizardPageModel(connection1);
    WritableValue<String> usernameObservable = new WritableValue<String>();
    WritableValue<String> urlObservable = new WritableValue<String>();
    MultiValidator v = ConnectionValidatorFactory.createBasicAuthenticationValidator(pageModel, usernameObservable, urlObservable);
    v.observeValidatedValue(urlObservable);
    // New connection
    urlObservable.setValue(HOST3);
    usernameObservable.setValue(USER3);
    Assert.assertEquals(IStatus.OK, getStatusSeverity(v));
    urlObservable.setValue(HOST2);
    // Host exists, but token is different
    Assert.assertEquals(IStatus.OK, getStatusSeverity(v));
    usernameObservable.setValue(USER2);
    // Existing not selected connection
    Assert.assertEquals(IStatus.ERROR, getStatusSeverity(v));
    // Selected connection
    urlObservable.setValue(HOST1);
    usernameObservable.setValue(USER1);
    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 49 with Connection

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

the class OpenshiftJMXConnectionProvider method createConnection.

@Override
protected IConnectionWrapper createConnection(IServer server) {
    IConnection openshiftCon = OpenShiftServerUtils.getConnection(server);
    String url = computeJolokiaURL(server);
    if (url != null) {
        JolokiaConnectionWrapper cw = new JolokiaConnectionWrapper() {

            @Override
            public IConnectionProvider getProvider() {
                return ExtensionManager.getProvider(PROVIDER_ID);
            }
        };
        cw.setId(server.getName());
        cw.setUrl(url);
        cw.setType("POST");
        cw.setIgnoreSSLErrors(true);
        Map<String, String> headers = new HashMap<>();
        headers.put(AUTHORIZATION_HEADER_KEY, AUTHORIZATION_HEADER_VALUE_PREFIX + ((Connection) openshiftCon).getToken());
        cw.setHeaders(headers);
        return cw;
    } else {
        return null;
    }
}
Also used : HashMap(java.util.HashMap) JolokiaConnectionWrapper(org.jboss.tools.jmx.jolokia.JolokiaConnectionWrapper) Connection(org.jboss.tools.openshift.core.connection.Connection) IConnection(org.jboss.tools.openshift.common.core.connection.IConnection) IConnection(org.jboss.tools.openshift.common.core.connection.IConnection)

Example 50 with Connection

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

the class OpenShiftLaunchController method waitForDeploymentConfigReady.

protected boolean waitForDeploymentConfigReady(IServer server, IProgressMonitor monitor) throws CoreException {
    monitor.subTask("Waiting for deployment configs to become available...");
    Connection connection = OpenShiftServerUtils.getConnectionChecked(server);
    IResource resource = OpenShiftServerUtils.getResourceChecked(server, connection, monitor);
    long timeout = System.currentTimeMillis() + WAIT_FOR_DEPLOYMENTCONFIG_TIMEOUT;
    while ((ResourceUtils.getDeploymentConfigFor(resource, connection)) == null) {
        if (!sleep(RECHECK_DELAY, timeout, monitor)) {
            return false;
        }
    }
    return true;
}
Also used : Connection(org.jboss.tools.openshift.core.connection.Connection) IResource(com.openshift.restclient.model.IResource)

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