NewSSHKeyModal implements NewSSHKeyModalView.Presenter { @Override public void notifyAdd(String name, String key) { view.resetValidation(); boolean nameValid = validateName(name); boolean keyValid = validateKey(key); if (nameValid && keyValid) { serviceCaller.call((RemoteCallback<Void>) response -> { handler.onAddKey(); }, (ErrorCallback<Message>) (message, throwable) -> { view.setKeyValidationError(translationService.getTranslation(AppformerSSHConstants.ValidationKeyFormatError)); return false; }).addKey(name, key); } } @Inject  NewSSHKeyModal(final NewSSHKeyModalView view, final Caller<SSHKeyEditorService> serviceCaller, final TranslationService translationService); void init(NewSSHKeyModalHandler handler); void show(); @Override void notifyCancel(); @Override void notifyAdd(String name, String key); void hide();  }
@Test public void testAddKeyNullValidationFailure() { testBasicFunctions(); modal.notifyAdd(null, null); verify(view).resetValidation(); verify(translationService).getTranslation(eq(AppformerSSHConstants.NewSSHKeyModalViewImplName)); verify(translationService).getTranslation(eq(AppformerSSHConstants.NewSSHKeyModalViewImplKey)); verify(translationService, times(2)).format(eq(AppformerSSHConstants.ValidationCannotBeEmpty), any()); verify(translationService, never()).getTranslation(AppformerSSHConstants.ValidationKeyFormatError); verify(translationService, never()).getTranslation(AppformerSSHConstants.ValidationKeyAlreadyExists); verify(translationService, never()).format(eq(AppformerSSHConstants.ValidationKeyNameAlreadyExists), any()); verify(view).setNameValidationError(any()); verify(view).setKeyValidationError(any()); verify(sshKeyEditorService, never()).addKey(anyString(), anyString()); verify(handler, never()).onAddKey(); }
@Test public void testAddKeyWrongKeyValidationFailure() { testBasicFunctions(); modal.notifyAdd(NAME, WRONG_KEY); verify(view).resetValidation(); verify(translationService, never()).getTranslation(eq(AppformerSSHConstants.NewSSHKeyModalViewImplName)); verify(translationService, never()).getTranslation(eq(AppformerSSHConstants.NewSSHKeyModalViewImplKey)); verify(translationService, never()).format(eq(AppformerSSHConstants.ValidationCannotBeEmpty), any()); verify(translationService).getTranslation(AppformerSSHConstants.ValidationKeyFormatError); verify(translationService, never()).getTranslation(AppformerSSHConstants.ValidationKeyAlreadyExists); verify(translationService, never()).format(eq(AppformerSSHConstants.ValidationKeyNameAlreadyExists), any()); verify(view, never()).setNameValidationError(any()); verify(view).setKeyValidationError(any()); verify(sshKeyEditorService, never()).addKey(anyString(), anyString()); verify(handler, never()).onAddKey(); }
@Test public void testAddKeyWrongKeyFormatValidationFailure() { testBasicFunctions(); modal.notifyAdd(NAME, WRONG_KEY_FORMAT); verify(view).resetValidation(); verify(translationService, never()).getTranslation(eq(AppformerSSHConstants.NewSSHKeyModalViewImplName)); verify(translationService, never()).getTranslation(eq(AppformerSSHConstants.NewSSHKeyModalViewImplKey)); verify(translationService, never()).format(eq(AppformerSSHConstants.ValidationCannotBeEmpty), any()); verify(translationService, never()).getTranslation(AppformerSSHConstants.ValidationKeyAlreadyExists); verify(translationService, never()).format(eq(AppformerSSHConstants.ValidationKeyNameAlreadyExists), any()); verify(view, never()).setNameValidationError(any()); verify(sshKeyEditorService).addKey(anyString(), anyString()); verify(translationService).getTranslation(AppformerSSHConstants.ValidationKeyFormatError); verify(view).setKeyValidationError(any()); verify(handler, never()).onAddKey(); }
@Test public void testAddKeyExistingKeyNameValidationFailure() { testBasicFunctions(); modal.notifyAdd(EXISTING_KEY_NAME, VALID_KEY); verify(view).resetValidation(); verify(translationService, never()).getTranslation(eq(AppformerSSHConstants.NewSSHKeyModalViewImplName)); verify(translationService, never()).getTranslation(eq(AppformerSSHConstants.NewSSHKeyModalViewImplKey)); verify(translationService, never()).format(eq(AppformerSSHConstants.ValidationCannotBeEmpty), any()); verify(translationService, never()).getTranslation(AppformerSSHConstants.ValidationKeyAlreadyExists); verify(translationService).format(eq(AppformerSSHConstants.ValidationKeyNameAlreadyExists), any()); verify(view).setNameValidationError(any()); verify(sshKeyEditorService, never()).addKey(anyString(), anyString()); verify(translationService, never()).getTranslation(AppformerSSHConstants.ValidationKeyFormatError); verify(view, never()).setKeyValidationError(any()); verify(handler, never()).onAddKey(); }
@Test public void testAddKeyExistingKeyValidationFailure() { testBasicFunctions(); modal.notifyAdd(NAME, EXISTING_KEY); verify(view).resetValidation(); verify(translationService, never()).getTranslation(eq(AppformerSSHConstants.NewSSHKeyModalViewImplName)); verify(translationService, never()).getTranslation(eq(AppformerSSHConstants.NewSSHKeyModalViewImplKey)); verify(translationService, never()).format(eq(AppformerSSHConstants.ValidationCannotBeEmpty), any()); verify(translationService).getTranslation(AppformerSSHConstants.ValidationKeyAlreadyExists); verify(translationService, never()).format(eq(AppformerSSHConstants.ValidationKeyNameAlreadyExists), any()); verify(view, never()).setNameValidationError(any()); verify(sshKeyEditorService, never()).addKey(anyString(), anyString()); verify(translationService, never()).getTranslation(AppformerSSHConstants.ValidationKeyFormatError); verify(view).setKeyValidationError(any()); verify(handler, never()).onAddKey(); }
@Test public void testAddKey() { testBasicFunctions(); modal.notifyAdd(NAME, VALID_KEY); verify(view).resetValidation(); verify(translationService, never()).getTranslation(eq(AppformerSSHConstants.NewSSHKeyModalViewImplName)); verify(translationService, never()).getTranslation(eq(AppformerSSHConstants.NewSSHKeyModalViewImplKey)); verify(translationService, never()).format(eq(AppformerSSHConstants.ValidationCannotBeEmpty), any()); verify(translationService, never()).getTranslation(AppformerSSHConstants.ValidationKeyFormatError); verify(translationService, never()).getTranslation(AppformerSSHConstants.ValidationKeyAlreadyExists); verify(translationService, never()).format(eq(AppformerSSHConstants.ValidationKeyNameAlreadyExists), any()); verify(view, never()).setNameValidationError(any()); verify(view, never()).setKeyValidationError(any()); verify(sshKeyEditorService).addKey(anyString(), anyString()); verify(handler).onAddKey(); }