/** * Executes operations in the given context. * * @param context the context to perform the operations in. * @param operations the operations to perform. * @param account the account for which to execute robot operations. */ private void executeOperations( OperationContext context, List<OperationRequest> operations, RobotAccountData account) { for (OperationRequest operation : operations) { // Get the operation of the author taking into account the proxying for // field. OperationUtil.executeOperation(operation, operationRegistry, context, account.getId()); } }
/** * Sets the account for this Robot. The address of the account must match the * address in the {@link RobotName}. * * @param account the account to set. */ void setAccount(RobotAccountData account) { Preconditions.checkArgument(robotName.toEmailAddress().equals(account.getId().getAddress()), String.format("The given RobotAccountData doesn't match the RobotName. %s != %s", account.getId(), robotName.toEmailAddress())); this.account = account; }
@Override public void onUnregistrationSuccess(RobotAccountData account) { log.info("Unregistered robot: " + account.getId().getAddress() + " at " + account.getUrl()); } };
@Override public void onRegistrationSuccess(RobotAccountData account) { log.info("Registered robot: " + account.getId().getAddress() + " at " + account.getUrl()); }
/** * 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); } }
/** * Shows the page that signals that a robot was successfully registered a * robot. It will show the robot's token and token secret to use for the * Active API. * * @param robotAccount the newly registered robot account. */ private void onRegisterSuccess(HttpServletRequest req, HttpServletResponse resp, RobotAccountData robotAccount) throws IOException { RobotRegistrationSuccessPage.write(resp.getWriter(), new GxpContext(req.getLocale()), robotAccount.getId().getAddress(), robotAccount.getConsumerSecret(), analyticsAccount); resp.setContentType("text/html"); resp.setStatus(HttpServletResponse.SC_OK); } }
@Override protected void setUp() throws Exception { accountStore = mock(AccountStore.class); tokenGenerator = mock(TokenGenerator.class); accountData = mock(RobotAccountData.class); when(accountData.isRobot()).thenReturn(true); when(accountData.asRobot()).thenReturn(accountData); when(accountData.getUrl()).thenReturn(LOCATION); when(accountData.getId()).thenReturn(ROBOT_ID); when(tokenGenerator.generateToken(anyInt())).thenReturn(CONSUMER_TOKEN); registrar = new RobotRegistrarImpl(accountStore, tokenGenerator); }
@Override protected void setUp() throws Exception { accountStore = mock(AccountStore.class); tokenGenerator = mock(TokenGenerator.class); accountData = mock(RobotAccountData.class); when(accountData.isRobot()).thenReturn(true); when(accountData.asRobot()).thenReturn(accountData); when(accountData.getUrl()).thenReturn(LOCATION); when(accountData.getId()).thenReturn(ROBOT_ID); when(tokenGenerator.generateToken(anyInt())).thenReturn(CONSUMER_TOKEN); registrar = new RobotRegistrarImpl(accountStore, tokenGenerator); }
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()); }
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 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()); }
/** * Returns a new {@link RobotAccountData} updated with the new capabilities * using the given {@link RobotAccountData}. * * @param account The {@link RobotAccountData} to update the capabilities for. * @param activeApiUrl the url of the Active Robot API. * @throws CapabilityFetchException if the capabilities couldn't be retrieved * or parsed. */ public RobotAccountData fetchCapabilities(RobotAccountData account, String activeApiUrl) throws CapabilityFetchException { RobotCapabilitiesParser parser = new RobotCapabilitiesParser( account.getUrl() + Robot.CAPABILITIES_URL, connection, activeApiUrl); RobotCapabilities capabilities = new RobotCapabilities( parser.getCapabilities(), parser.getCapabilitiesHash(), parser.getProtocolVersion()); return new RobotAccountDataImpl(account.getId(), account.getUrl(), account.getConsumerSecret(), capabilities, account.isVerified()); } }
setupOAuth(account.getId().getAddress(), account.getConsumerSecret(), rpcUrl); Wavelet newWelcomeWavelet = newWave(getWaveDomain(), Sets.newHashSet(id.getAddress())); if (welcomeWaveId != null) {