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 testReRegisterSucceedsOnNonExistingAccount() throws PersistenceException, RobotRegistrationException { registrar.registerOrUpdate(ROBOT_ID, OTHER_LOCATION); verify(accountStore).putAccount(any(RobotAccountData.class)); } }
public void testUnregisterNonExistingRobot() throws PersistenceException, RobotRegistrationException { AccountData unregisteredAccountData = registrar.unregister(ROBOT_ID); assertNull(unregisteredAccountData); }
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 testReRegisterSucceedsOnNonExistingAccount() throws PersistenceException, RobotRegistrationException { registrar.registerOrUpdate(ROBOT_ID, OTHER_LOCATION); verify(accountStore).putAccount(any(RobotAccountData.class)); } }
public void testUnregisterNonExistingRobot() throws PersistenceException, RobotRegistrationException { AccountData unregisteredAccountData = registrar.unregister(ROBOT_ID); assertNull(unregisteredAccountData); }
public void testRegisterNewFailsOnExistingAccount() throws PersistenceException { when(accountStore.getAccount(ROBOT_ID)).thenReturn(accountData); try { registrar.registerNew(ROBOT_ID, LOCATION); fail(); } catch (RobotRegistrationException e) { // Expected. } }
/** * Ensures that the robot agent is registered in the {@link AccountStore}. */ private void ensureRegistered(String serverFrontendAddress) { ParticipantId robotId; try { robotId = ParticipantId.of(getRobotId() + "@" + waveDomain); } catch (InvalidParticipantAddress e) { LOG.log(Level.SEVERE, "Failed to register the agent:" + getRobotId(), e); return; } try { String location = serverFrontendAddress + getRobotUri(); // In order to re-register the agents if the server frontend address has changed. robotRegistrar.registerOrUpdate(robotId, location); } catch (RobotRegistrationException | PersistenceException e) { LOG.log(Level.SEVERE, "Failed to register the agent:" + getRobotId(), e); } }
public void testUnregisterSucceeds() throws PersistenceException, RobotRegistrationException { when(accountStore.getAccount(ROBOT_ID)).thenReturn(accountData); AccountData unregisteredAccountData = registrar.unregister(ROBOT_ID); assertTrue(unregisteredAccountData.equals(accountData)); verify(accountData).isRobot(); verify(accountStore).removeAccount(ROBOT_ID); }
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 testReRegisterFailsOnExistingHumanAccount() throws PersistenceException { when(accountStore.getAccount(HUMAN_ID)).thenReturn( new HumanAccountDataImpl(ParticipantId.ofUnsafe(HUMAN_ID.getAddress()))); try { registrar.registerOrUpdate(HUMAN_ID, OTHER_LOCATION); fail(); } catch (RobotRegistrationException e) { // Expected. } }
public void testUnregisterSucceeds() throws PersistenceException, RobotRegistrationException { when(accountStore.getAccount(ROBOT_ID)).thenReturn(accountData); AccountData unregisteredAccountData = registrar.unregister(ROBOT_ID); assertTrue(unregisteredAccountData.equals(accountData)); verify(accountData).isRobot(); verify(accountStore).removeAccount(ROBOT_ID); }
/** * 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 testReRegisterFailsOnExistingHumanAccount() throws PersistenceException { when(accountStore.getAccount(HUMAN_ID)).thenReturn( new HumanAccountDataImpl(ParticipantId.ofUnsafe(HUMAN_ID.getAddress()))); try { registrar.registerOrUpdate(HUMAN_ID, OTHER_LOCATION); fail(); } catch (RobotRegistrationException e) { // Expected. } }
public void testUnregisterFailsOnHumanAccount() throws PersistenceException { when(accountStore.getAccount(HUMAN_ID)).thenReturn( new HumanAccountDataImpl(ParticipantId.ofUnsafe(HUMAN_ID.getAddress()))); try { registrar.unregister(HUMAN_ID); fail(); } catch (RobotRegistrationException e) { // Expected. } }
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 testReRegisterSucceedsOnExistingRobotAccount() throws PersistenceException, RobotRegistrationException { when(accountStore.getAccount(ROBOT_ID)).thenReturn(accountData); AccountData unregisteredAccountData = registrar.registerOrUpdate(ROBOT_ID, OTHER_LOCATION); verify(accountStore).removeAccount(ROBOT_ID); verify(accountStore).putAccount(any(RobotAccountData.class)); assertTrue(unregisteredAccountData.isRobot()); RobotAccountData robotAccountData = unregisteredAccountData.asRobot(); // Remove the last '/'. assertEquals(OTHER_LOCATION.substring(0, OTHER_LOCATION.length() - 1), robotAccountData.getUrl()); assertEquals(ROBOT_ID, robotAccountData.getId()); assertEquals(CONSUMER_TOKEN, robotAccountData.getConsumerSecret()); }
public void testUnregisterFailsOnHumanAccount() throws PersistenceException { when(accountStore.getAccount(HUMAN_ID)).thenReturn( new HumanAccountDataImpl(ParticipantId.ofUnsafe(HUMAN_ID.getAddress()))); try { registrar.unregister(HUMAN_ID); fail(); } catch (RobotRegistrationException e) { // Expected. } }
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 testReRegisterSucceedsOnExistingRobotAccount() throws PersistenceException, RobotRegistrationException { when(accountStore.getAccount(ROBOT_ID)).thenReturn(accountData); AccountData unregisteredAccountData = registrar.registerOrUpdate(ROBOT_ID, OTHER_LOCATION); verify(accountStore).removeAccount(ROBOT_ID); verify(accountStore).putAccount(any(RobotAccountData.class)); assertTrue(unregisteredAccountData.isRobot()); RobotAccountData robotAccountData = unregisteredAccountData.asRobot(); // Remove the last '/'. assertEquals(OTHER_LOCATION.substring(0, OTHER_LOCATION.length() - 1), robotAccountData.getUrl()); assertEquals(ROBOT_ID, robotAccountData.getId()); assertEquals(CONSUMER_TOKEN, robotAccountData.getConsumerSecret()); }