public void testRegisterNewFailsOnInvalidLocation() throws PersistenceException { String invalidLocation = "ftp://some$$$&&&###.com"; try { registrar.registerNew(ROBOT_ID, invalidLocation); fail("Location " + invalidLocation + " is invalid, exception is expected."); } catch (RobotRegistrationException e) { // Expected. } }
public void testRegisterNewFailsOnInvalidLocation() throws PersistenceException { String invalidLocation = "ftp://some$$$&&&###.com"; try { registrar.registerNew(ROBOT_ID, invalidLocation); fail("Location " + invalidLocation + " is invalid, exception is expected."); } catch (RobotRegistrationException e) { // Expected. } }
public void testRegisterNewFailsOnExistingAccount() throws PersistenceException { when(accountStore.getAccount(ROBOT_ID)).thenReturn(accountData); try { registrar.registerNew(ROBOT_ID, LOCATION); fail(); } catch (RobotRegistrationException e) { // Expected. } }
public void testRegisterNewFailsOnExistingAccount() throws PersistenceException { when(accountStore.getAccount(ROBOT_ID)).thenReturn(accountData); try { registrar.registerNew(ROBOT_ID, LOCATION); fail(); } catch (RobotRegistrationException e) { // Expected. } }
/** * Handles POST request for the register page. */ private void doRegisterPost(HttpServletRequest req, HttpServletResponse resp) throws IOException { String username = req.getParameter("username"); String location = req.getParameter("location"); if (Strings.isNullOrEmpty(username) || Strings.isNullOrEmpty(location)) { doRegisterGet(req, resp, "Please complete all fields."); return; } ParticipantId id; try { id = ParticipantId.of(username + "@" + domain); } catch (InvalidParticipantAddress e) { doRegisterGet(req, resp, "Invalid username specified, use alphanumeric characters only."); return; } RobotAccountData robotAccount; try{ robotAccount = robotRegistrar.registerNew(id, location); } catch (RobotRegistrationException e) { doRegisterGet(req, resp, e.getMessage()); return; } catch (PersistenceException e) { LOG.severe("Failed to retrieve account data for " + id, e); doRegisterGet(req, resp, "Failed to retrieve account data for " + id.getAddress()); return; } onRegisterSuccess(req, resp, robotAccount); }
public void testRegisterNewSucceeds() throws PersistenceException, RobotRegistrationException { RobotAccountData resultAccountData = registrar.registerNew(ROBOT_ID, LOCATION); verify(accountStore, atLeastOnce()).getAccount(ROBOT_ID); verify(accountStore).putAccount(any(RobotAccountData.class)); verify(tokenGenerator).generateToken(anyInt()); assertTrue(resultAccountData.isRobot()); RobotAccountData robotAccountData = resultAccountData.asRobot(); // Remove the last '/'. assertEquals(LOCATION.substring(0, LOCATION.length() - 1), robotAccountData.getUrl()); assertEquals(ROBOT_ID, robotAccountData.getId()); assertEquals(CONSUMER_TOKEN, robotAccountData.getConsumerSecret()); }
public void testRegisterNewSucceeds() throws PersistenceException, RobotRegistrationException { RobotAccountData resultAccountData = registrar.registerNew(ROBOT_ID, LOCATION); verify(accountStore, atLeastOnce()).getAccount(ROBOT_ID); verify(accountStore).putAccount(any(RobotAccountData.class)); verify(tokenGenerator).generateToken(anyInt()); assertTrue(resultAccountData.isRobot()); RobotAccountData robotAccountData = resultAccountData.asRobot(); // Remove the last '/'. assertEquals(LOCATION.substring(0, LOCATION.length() - 1), robotAccountData.getUrl()); assertEquals(ROBOT_ID, robotAccountData.getId()); assertEquals(CONSUMER_TOKEN, robotAccountData.getConsumerSecret()); }