@Override protected void setUp() throws Exception { MockitoAnnotations.initMocks(this); store = new MemoryStore(); store.putAccount(account); }
@Override protected void setUp() throws Exception { MockitoAnnotations.initMocks(this); store = new MemoryStore(); store.putAccount(account); }
public void testUpdateRobotAccount() throws Exception { Robot robot = mock(Robot.class); RobotAccountData account = mock(RobotAccountData.class); when(robot.getAccount()).thenReturn(account); // Return newAccount when updated RobotAccountData newAccount = mock(RobotAccountData.class); when(robotConnector.fetchCapabilities(eq(account), any(String.class))).thenReturn(newAccount); gateway.updateRobotAccount(robot); verify(accountStore).putAccount(newAccount); } }
public void testUpdateRobotAccount() throws Exception { Robot robot = mock(Robot.class); RobotAccountData account = mock(RobotAccountData.class); when(robot.getAccount()).thenReturn(account); // Return newAccount when updated RobotAccountData newAccount = mock(RobotAccountData.class); when(robotConnector.fetchCapabilities(eq(account), any(String.class))).thenReturn(newAccount); gateway.updateRobotAccount(robot); verify(accountStore).putAccount(newAccount); } }
public void testDontUpdateIfHashesMatch() throws Exception { OperationRequest operation = new OperationRequest("robot.notify", OP_ID, Parameter.of(ParamsProperty.CAPABILITIES_HASH, OLD_HASH)); operationService.execute(operation, context, ROBOT); verifyZeroInteractions(connector); verify(accountStore, never()).putAccount(any(AccountData.class)); }
public void testExceptionOnMissingHash() throws Exception { OperationRequest operation = new OperationRequest("robot.notify", OP_ID); try { operationService.execute(operation, context, ROBOT); fail("Expected InvalidRequestException"); } catch (InvalidRequestException e) { // expected } verifyZeroInteractions(connector); verify(accountStore, never()).putAccount(any(AccountData.class)); } }
public void testExceptionOnMissingHash() throws Exception { OperationRequest operation = new OperationRequest("robot.notify", OP_ID); try { operationService.execute(operation, context, ROBOT); fail("Expected InvalidRequestException"); } catch (InvalidRequestException e) { // expected } verifyZeroInteractions(connector); verify(accountStore, never()).putAccount(any(AccountData.class)); } }
public void testErrorOnFailingConnection() throws Exception { OperationRequest operation = new OperationRequest("robot.notify", OP_ID, Parameter.of(ParamsProperty.CAPABILITIES_HASH, NEW_HASH)); when(connector.fetchCapabilities(any(RobotAccountData.class), anyString())).thenThrow( new CapabilityFetchException("")); operationService.execute(operation, context, ROBOT); verify(accountStore, never()).putAccount(any(AccountData.class)); verify(context).constructErrorResponse(eq(operation), anyString()); }
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); }
@Override protected void setUp() throws Exception { waveletProvider = new WaveletProviderStub(); AccountStore accountStore = new MemoryStore(); accountStore.putAccount(new HumanAccountDataImpl(ParticipantId.ofUnsafe("fred@example.com"))); org.eclipse.jetty.server.SessionManager jettySessionManager = mock(org.eclipse.jetty.server.SessionManager.class); SessionManager sessionManager = new SessionManagerImpl(accountStore, jettySessionManager); session = mock(HttpSession.class); when(session.getAttribute(SessionManager.USER_FIELD)).thenReturn(ParticipantId.ofUnsafe("fred@example.com")); servlet = new FetchServlet(waveletProvider, protoSerializer, sessionManager); }
@Override protected void setUp() throws Exception { MockitoAnnotations.initMocks(this); AccountStore store = new MemoryStore(); account = new HumanAccountDataImpl(ParticipantId.ofUnsafe("tubes@example.com")); store.putAccount(account); sessionManager = new SessionManagerImpl(store, jettySessionManager); }
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 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()); }
@Override protected void setUp() throws Exception { AccountStore store = new MemoryStore(); store.putAccount(new HumanAccountDataImpl( ParticipantId.ofUnsafe("haspwd@example.com"), new PasswordDigest("pwd".toCharArray()))); store.putAccount(new HumanAccountDataImpl(ParticipantId.ofUnsafe("nopwd@example.com"))); AccountStoreHolder.init(store, "example.com"); }
@Override protected void setUp() throws Exception { AccountStore store = new MemoryStore(); store.putAccount(new HumanAccountDataImpl( ParticipantId.ofUnsafe("haspwd@example.com"), new PasswordDigest("pwd".toCharArray()))); store.putAccount(new HumanAccountDataImpl(ParticipantId.ofUnsafe("nopwd@example.com"))); AccountStoreHolder.init(store, "example.com"); }
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 testRoundtripHumanAccount() throws Exception { AccountStore accountStore = newAccountStore(); HumanAccountDataImpl account = new HumanAccountDataImpl(HUMAN_ID); accountStore.putAccount(account); AccountData retrievedAccount = accountStore.getAccount(HUMAN_ID); assertEquals(account, retrievedAccount); }
@Override protected void setUp() throws Exception { waveletProvider = new WaveletProviderStub(); AccountStore accountStore = new MemoryStore(); accountStore.putAccount(new HumanAccountDataImpl(ParticipantId.ofUnsafe("fred@example.com"))); org.eclipse.jetty.server.SessionManager jettySessionManager = mock(org.eclipse.jetty.server.SessionManager.class); SessionManager sessionManager = new SessionManagerImpl(accountStore, jettySessionManager); servlet = new FetchServlet(waveletProvider, protoSerializer, sessionManager); }