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;
}
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));
}
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();
}
}
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));
}
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);
}
Aggregations