Search in sources :

Example 6 with ConnectionWizardPageModel

use of org.jboss.tools.openshift.internal.common.ui.connection.ConnectionWizardPageModel in project jbosstools-openshift by jbosstools.

the class ConnectionValidatorsTest method mockConnectionWizardPageModel.

private ConnectionWizardPageModel mockConnectionWizardPageModel(Connection selected) {
    ConnectionWizardPageModel pageModel = Mockito.mock(ConnectionWizardPageModel.class);
    Mockito.when(pageModel.getSelectedConnection()).thenReturn(selected);
    return pageModel;
}
Also used : ConnectionWizardPageModel(org.jboss.tools.openshift.internal.common.ui.connection.ConnectionWizardPageModel)

Example 7 with ConnectionWizardPageModel

use of org.jboss.tools.openshift.internal.common.ui.connection.ConnectionWizardPageModel 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 8 with ConnectionWizardPageModel

use of org.jboss.tools.openshift.internal.common.ui.connection.ConnectionWizardPageModel 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 9 with ConnectionWizardPageModel

use of org.jboss.tools.openshift.internal.common.ui.connection.ConnectionWizardPageModel 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 10 with ConnectionWizardPageModel

use of org.jboss.tools.openshift.internal.common.ui.connection.ConnectionWizardPageModel in project jbosstools-openshift by jbosstools.

the class ConnectionWizardPageModelTest method should_enable_promptCredentials_on_edited_connection_when_disposing_model_and_was_enabled_before_editing_it.

@Test
public void should_enable_promptCredentials_on_edited_connection_when_disposing_model_and_was_enabled_before_editing_it() {
    // given prompt is disabled once connection is being edited
    Connection connection = mockOS3Connection("foo", "https://localhost");
    doReturn(true).when(connection).isEnablePromptCredentials();
    allConnections.add(connection);
    ConnectionWizardPageModel model = new TestableConnectionWizardPageModel(connection, allConnections, editedConnection.getClass(), true, wizardModel);
    verify(connection).enablePromptCredentials(false);
    // when
    model.dispose();
    // then
    verify(connection).enablePromptCredentials(true);
}
Also used : ConnectionWizardPageModel(org.jboss.tools.openshift.internal.common.ui.connection.ConnectionWizardPageModel) Connection(org.jboss.tools.openshift.core.connection.Connection) IConnection(org.jboss.tools.openshift.common.core.connection.IConnection) Test(org.junit.Test)

Aggregations

ConnectionWizardPageModel (org.jboss.tools.openshift.internal.common.ui.connection.ConnectionWizardPageModel)12 Test (org.junit.Test)11 Connection (org.jboss.tools.openshift.core.connection.Connection)6 MultiValidator (org.eclipse.core.databinding.validation.MultiValidator)4 DataBindingContext (org.eclipse.core.databinding.DataBindingContext)2 IValueChangeListener (org.eclipse.core.databinding.observable.value.IValueChangeListener)2 ValueChangeEvent (org.eclipse.core.databinding.observable.value.ValueChangeEvent)2 WritableValue (org.eclipse.core.databinding.observable.value.WritableValue)2 Composite (org.eclipse.swt.widgets.Composite)2 Shell (org.eclipse.swt.widgets.Shell)2 IConnection (org.jboss.tools.openshift.common.core.connection.IConnection)2 BasicAuthenticationDetailView (org.jboss.tools.openshift.internal.ui.wizard.connection.BasicAuthenticationDetailView)1 OAuthDetailView (org.jboss.tools.openshift.internal.ui.wizard.connection.OAuthDetailView)1