@Test @TransactionalReadWrite public void testCheckEmailAvailability() { User user = testUtils.createAuthenticatedTestUser("SettingsControllerTest@testCheckEmailAvailability"); User takenUser = testUtils.createTestUser("Taken@User"); assertTrue(controller.checkEmailAvailability("CANNOT_FIND")); assertTrue(controller.checkEmailAvailability(user.getEmail())); assertTrue(controller.checkEmailAvailability(user.getEmail().toLowerCase())); assertFalse(controller.checkEmailAvailability(takenUser.getEmail())); assertFalse(controller.checkEmailAvailability(takenUser.getEmail().toLowerCase())); }
/** * Initializes settings. This must be called after addExtraPages(), which created a settings page. * Iterate through all the pages to find the first (and supposedly unique) setting page, and use * it to load and apply these settings. */ private void initializeSettings() { SettingsController c = mUpdaterData.getSettingsController(); c.loadSettings(); c.applySettings(); for (Object page : mPages) { if (page instanceof ISettingsPage) { ISettingsPage settingsPage = (ISettingsPage) page; c.setSettingsPage(settingsPage); break; } } }
/** * Creates an UpdateNoWindow object that will update using the given SDK root and outputs to the * given SDK logger. * * @param osSdkRoot The OS path of the SDK folder to update. * @param sdkManager An existing SDK manager to list current platforms and addons. * @param sdkLog A logger object, that should ideally output to a write-only console. * @param force The reply to any question asked by the update process. Currently this will be * yes/no for ability to replace modified samples or restart ADB. * @param useHttp True to force using HTTP instead of HTTPS for downloads. * @param proxyPort An optional HTTP/HTTPS proxy port. Can be null. * @param proxyHost An optional HTTP/HTTPS proxy host. Can be null. */ public SdkUpdaterNoWindow( String osSdkRoot, SdkManager sdkManager, ISdkLog sdkLog, boolean force, boolean useHttp, String proxyHost, String proxyPort) { mSdkLog = sdkLog; mForce = force; mUpdaterData = new UpdaterData(osSdkRoot, sdkLog); // Read and apply settings from settings file, so that http/https proxy is set // and let the command line args override them as necessary. SettingsController settingsController = mUpdaterData.getSettingsController(); settingsController.loadSettings(); settingsController.applySettings(); setupProxy(proxyHost, proxyPort); // Change the in-memory settings to force the http/https mode settingsController.setSetting(ISettingsPage.KEY_FORCE_HTTP, useHttp); // Use a factory that only outputs to the given ISdkLog. mUpdaterData.setTaskFactory(new ConsoleTaskFactory()); // Check that the AVD Manager has been correctly initialized. This is done separately // from the constructor in the GUI-based UpdaterWindowImpl to give time to the UI to // initialize before displaying a message box. Since we don't have any GUI here // we can call it whenever we want. if (mUpdaterData.checkIfInitFailed()) { return; } // Setup the default sources including the getenv overrides. mUpdaterData.setupDefaultSources(); mUpdaterData.getLocalSdkParser().parseSdk(osSdkRoot, sdkManager, new NullTaskMonitor(sdkLog)); }
/** * Initializes the {@link SettingsController} Extracted so that we can override this in unit * tests. */ @VisibleForTesting(visibility = Visibility.PRIVATE) protected SettingsController initSettingsController() { SettingsController settingsController = new SettingsController(mSdkLog); settingsController.registerOnChangedListener( new OnChangedListener() { @Override public void onSettingsChanged( SettingsController controller, SettingsController.Settings oldSettings) { // Reset the download cache if it doesn't match the right strategy. // The cache instance gets lazily recreated later in getDownloadCache(). if (mDownloadCache != null) { if (controller.getSettings().getUseDownloadCache() && mDownloadCache.getStrategy() != DownloadCache.Strategy.FRESH_CACHE) { mDownloadCache = null; } else if (!controller.getSettings().getUseDownloadCache() && mDownloadCache.getStrategy() != DownloadCache.Strategy.DIRECT) { mDownloadCache = null; } } } }); return settingsController; }
@Test @TransactionalReadWrite public void testInitSettingsPage() { User user = testUtils.createAuthenticatedTestUser("SettingsControllerTest@testInitSettingsPage"); ModelMap model = new ModelMap(); assertEquals("logged/settings", controller.initSettingsPage(model)); assertTrue(model.containsAttribute("settingsform")); SettingsForm settingsForm = (SettingsForm) model.get("settingsform"); assertEquals(user.getEmail(), settingsForm.getEmail()); assertEquals(user.getEmail(), settingsForm.getCurrentEmail()); assertEquals("no", settingsForm.getEditPassword()); assertEquals(user.getLanguage().getCode(), settingsForm.getLang()); }
private ModelAndView getModelAndViewSettingsPage( Map<String, String> parameters, SettingsForm settingsForm, MockHttpServletRequest request) { if (settingsForm == null) { settingsForm = new SettingsForm(); } WebDataBinder binder = new WebDataBinder(settingsForm, "settingsform"); if (parameters != null) { request.setParameters(parameters); binder.bind(new MutablePropertyValues(request.getParameterMap())); } SessionStatus status = new SimpleSessionStatus(); return controller.submitSettingsPage(settingsForm, binder.getBindingResult(), status, request); }
@Test public void testJavascriptLocales() { final String[] keys = { "err.pwd", "err.pwdConf", "err.mailRegist", "err.mail", "ok.mail", "ok.pwd", "ok.pwdConf", "cancel.confirm" }; Map<String, String> map = controller.sendI18nToJavascript(new Locale("en", "US")); assertNotNull(map); for (String key : keys) { assertNotNull(map.get(key)); } }