Search in sources :

Example 1 with ConnectionWizardPageModel

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

the class ConnectionWizardPageModelTest method should_disable_promptCredentials_on_edited_connection_when_disposing_model_and_was_disabled_before_editing_it.

@Test
public void should_disable_promptCredentials_on_edited_connection_when_disposing_model_and_was_disabled_before_editing_it() {
    // given prompt is disabled once connection is being edited
    Connection connection = mockOS3Connection("foo", "https://localhost");
    doReturn(false).when(connection).isEnablePromptCredentials();
    allConnections.add(connection);
    ConnectionWizardPageModel model = new TestableConnectionWizardPageModel(connection, allConnections, connection.getClass(), true, wizardModel);
    verify(connection).enablePromptCredentials(false);
    // when
    model.dispose();
    // then disable 2x, once when editing, 2nd time when disposing
    verify(connection, times(2)).enablePromptCredentials(false);
}
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)

Example 2 with ConnectionWizardPageModel

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

the class ConnectionWizardPageModelTest method should_default_connection_be_OS3.

@Test
public void should_default_connection_be_OS3() {
    ConnectionWizardPageModel model = new TestableConnectionWizardPageModel(null, allConnections, null, true, wizardModel);
    assertThat(model.getConnectionFactory().getId()).isEqualTo(IConnectionsFactory.CONNECTIONFACTORY_OPENSHIFT_ID);
}
Also used : ConnectionWizardPageModel(org.jboss.tools.openshift.internal.common.ui.connection.ConnectionWizardPageModel) Test(org.junit.Test)

Example 3 with ConnectionWizardPageModel

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

the class ConnectionWizardPageModelTest method getAllConnections_should_return_all_connections_and_NewConnectionMarker_if_connection_type_is_null_and_connection_change_is_allowed.

@SuppressWarnings("unchecked")
@Test
public void getAllConnections_should_return_all_connections_and_NewConnectionMarker_if_connection_type_is_null_and_connection_change_is_allowed() {
    // pre-condition
    ConnectionWizardPageModel model = new TestableConnectionWizardPageModel(editedConnection, allConnections, null, true, wizardModel);
    // operation
    // verification
    assertThat(model.getAllConnections()).containsExactlyElementsOf(union(Collections.singletonList(NewConnectionMarker.getInstance()), allConnections));
}
Also used : ConnectionWizardPageModel(org.jboss.tools.openshift.internal.common.ui.connection.ConnectionWizardPageModel) Test(org.junit.Test)

Example 4 with ConnectionWizardPageModel

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

the class ConnectionWizardPageModelTest method getAllHosts_should_only_contain_unique_hosts.

@Test
public void getAllHosts_should_only_contain_unique_hosts() {
    // pre-condition
    assertThat(allConnections).isNotEmpty();
    // add duplicate host
    allConnections.add(allConnections.get(0));
    ConnectionWizardPageModel model = new TestableConnectionWizardPageModel(editedConnection, allConnections, null, false, wizardModel);
    // operation
    Collection<String> allHosts = model.getAllHosts();
    // verification
    assertThat(allHosts).containsOnly(this.allHosts);
}
Also used : ConnectionWizardPageModel(org.jboss.tools.openshift.internal.common.ui.connection.ConnectionWizardPageModel) Test(org.junit.Test)

Example 5 with ConnectionWizardPageModel

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

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