@Override public RobotAccountData registerNew(ParticipantId robotId, String location) throws RobotRegistrationException, PersistenceException { Preconditions.checkNotNull(robotId); Preconditions.checkNotNull(location); Preconditions.checkArgument(!location.isEmpty()); if (accountStore.getAccount(robotId) != null) { throw new RobotRegistrationException(robotId.getAddress() + " is already in use, please choose another one."); } return registerRobot(robotId, location); }
@Override protected void setUp() throws Exception { accountStore = mock(AccountStore.class); connector = mock(RobotConnector.class); context = mock(OperationContext.class); operationService = new NotifyOperationService(accountStore, connector); when(accountStore.getAccount(ROBOT)).thenReturn(ROBOT_ACCOUNT); when(connector.fetchCapabilities(eq(ROBOT_ACCOUNT), anyString())).thenReturn(NEW_ROBOT_ACCOUNT); }
@Override protected void setUp() throws Exception { accountStore = mock(AccountStore.class); connector = mock(RobotConnector.class); context = mock(OperationContext.class); operationService = new NotifyOperationService(accountStore, connector); when(accountStore.getAccount(ROBOT)).thenReturn(ROBOT_ACCOUNT); when(connector.fetchCapabilities(eq(ROBOT_ACCOUNT), anyString())).thenReturn(NEW_ROBOT_ACCOUNT); }
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 testRegisterUserAtForeignDomainThrowsError() throws Exception { attemptToRegister(req, resp, "bilbo@example2.com", "fdsa", false); verify(resp).setStatus(HttpServletResponse.SC_FORBIDDEN); assertNull(store.getAccount(ParticipantId.ofUnsafe("bilbo@example2.com"))); }
public void testUsernameTrimmed() throws Exception { attemptToRegister(req, resp, " ben@example.com ", "beetleguice", false); verify(resp).setStatus(HttpServletResponse.SC_OK); assertNotNull(store.getAccount(ParticipantId.ofUnsafe("ben@example.com"))); }
public void testUsernameTrimmed() throws Exception { attemptToRegister(req, resp, " ben@example.com ", "beetleguice", false); verify(resp).setStatus(HttpServletResponse.SC_OK); assertNotNull(store.getAccount(ParticipantId.ofUnsafe("ben@example.com"))); }
public void testRegisterNewUserDisabled() throws Exception { attemptToRegister(req, resp, "foo@example.com", "internet", true); verify(resp).setStatus(HttpServletResponse.SC_FORBIDDEN); ParticipantId participantId = ParticipantId.ofUnsafe("foo@example.com"); AccountData account = store.getAccount(participantId); assertNull(account); }
public void testRegisterUserAtForeignDomainThrowsError() throws Exception { attemptToRegister(req, resp, "bilbo@example2.com", "fdsa", false); verify(resp).setStatus(HttpServletResponse.SC_FORBIDDEN); assertNull(store.getAccount(ParticipantId.ofUnsafe("bilbo@example2.com"))); }
public final void testPutAccountOverrides() throws Exception { AccountStore accountStore = newAccountStore(); accountStore.putAccount(robotAccount); AccountData account = accountStore.getAccount(ROBOT_ID); assertEquals(robotAccount, account); accountStore.putAccount(updatedRobotAccount); AccountData updatedAccount = accountStore.getAccount(ROBOT_ID); assertEquals(updatedRobotAccount, updatedAccount); }
public final void testPutAccountCanChangeType() throws Exception { AccountStore accountStore = newAccountStore(); accountStore.putAccount(robotAccount); AccountData account = accountStore.getAccount(ROBOT_ID); assertEquals(robotAccount, account); accountStore.putAccount(convertedRobot); AccountData updatedAccount = accountStore.getAccount(ROBOT_ID); assertEquals(convertedRobot, updatedAccount); }
public final void testPutAccountOverrides() throws Exception { AccountStore accountStore = newAccountStore(); accountStore.putAccount(robotAccount); AccountData account = accountStore.getAccount(ROBOT_ID); assertEquals(robotAccount, account); accountStore.putAccount(updatedRobotAccount); AccountData updatedAccount = accountStore.getAccount(ROBOT_ID); assertEquals(updatedRobotAccount, updatedAccount); }
public final void testRemoveAccount() throws Exception { AccountStore accountStore = newAccountStore(); accountStore.putAccount(robotAccount); AccountData account = accountStore.getAccount(ROBOT_ID); assertEquals(robotAccount, account); accountStore.removeAccount(ROBOT_ID); assertNull("Removed account was not null", accountStore.getAccount(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 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 testRegisterNewUserEnabled() throws Exception { attemptToRegister(req, resp, "foo@example.com", "internet", false); verify(resp).setStatus(HttpServletResponse.SC_OK); ParticipantId participantId = ParticipantId.ofUnsafe("foo@example.com"); AccountData account = store.getAccount(participantId); assertNotNull(account); assertTrue(account.asHuman().getPasswordDigest().verify("internet".toCharArray())); verify(welcomeBot).greet(eq(participantId)); }
public final void testRoundtripRobotAccount() throws Exception { AccountStore accountStore = newAccountStore(); accountStore.putAccount(robotAccount); AccountData retrievedAccount = accountStore.getAccount(ROBOT_ID); assertEquals(robotAccount, retrievedAccount); }
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 final void testRoundtripHumanAccount() throws Exception { AccountStore accountStore = newAccountStore(); HumanAccountDataImpl account = new HumanAccountDataImpl(HUMAN_ID); accountStore.putAccount(account); AccountData retrievedAccount = accountStore.getAccount(HUMAN_ID); assertEquals(account, retrievedAccount); }
public final void testRoundtripHumanAccountWithPassword() throws Exception { AccountStore accountStore = newAccountStore(); accountStore.putAccount( new HumanAccountDataImpl(HUMAN_ID, new PasswordDigest("internet".toCharArray()))); AccountData retrievedAccount = accountStore.getAccount(HUMAN_ID); assertTrue(retrievedAccount.asHuman().getPasswordDigest().verify("internet".toCharArray())); }