@Inject public RobotRegistrarImpl(AccountStore accountStore, TokenGenerator tokenGenerator) { this.accountStore = accountStore; this.tokenGenerator = tokenGenerator; addRegistrationListener(REGISTRATION_EVENTS_LOGGER); }
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 testUnregisterNonExistingRobot() throws PersistenceException, RobotRegistrationException { AccountData unregisteredAccountData = registrar.unregister(ROBOT_ID); assertNull(unregisteredAccountData); }
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 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); }
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 testReRegisterSucceedsOnNonExistingAccount() throws PersistenceException, RobotRegistrationException { registrar.registerOrUpdate(ROBOT_ID, OTHER_LOCATION); verify(accountStore).putAccount(any(RobotAccountData.class)); } }
@Override public RobotAccountData unregister(ParticipantId robotId) throws RobotRegistrationException, PersistenceException { Preconditions.checkNotNull(robotId); AccountData accountData = accountStore.getAccount(robotId); if (accountData == null) { return null; } throwExceptionIfNotRobot(accountData); RobotAccountData robotAccount = accountData.asRobot(); removeRobotAccount(robotAccount); return robotAccount; }
/** * Adds the robot to the account store and notifies the listeners. */ private RobotAccountData registerRobot(ParticipantId robotId, String location) throws RobotRegistrationException, PersistenceException { String robotLocation = computeValidateRobotUrl(location); RobotAccountData robotAccount = new RobotAccountDataImpl(robotId, robotLocation, tokenGenerator.generateToken(TOKEN_LENGTH), null, true); accountStore.putAccount(robotAccount); for (Listener listener : listeners) { listener.onRegistrationSuccess(robotAccount); } return robotAccount; }
/** * Removes the robot account and notifies the listeners. * @param existingAccount the account to remove * @throws PersistenceException if the persistence layer reports an error. */ private void removeRobotAccount(RobotAccountData existingAccount) throws PersistenceException { accountStore.removeAccount(existingAccount.getId()); for (Listener listener : listeners) { listener.onUnregistrationSuccess(existingAccount); } }
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 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 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 testUnregisterNonExistingRobot() throws PersistenceException, RobotRegistrationException { AccountData unregisteredAccountData = registrar.unregister(ROBOT_ID); assertNull(unregisteredAccountData); }
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 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 testReRegisterSucceedsOnNonExistingAccount() throws PersistenceException, RobotRegistrationException { registrar.registerOrUpdate(ROBOT_ID, OTHER_LOCATION); verify(accountStore).putAccount(any(RobotAccountData.class)); } }
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. } }