@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 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)); } }
@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 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 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 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 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 void testUpdateCapabilites() throws Exception { OperationRequest operation = new OperationRequest( "robot.notify", OP_ID, Parameter.of(ParamsProperty.CAPABILITIES_HASH, NEW_HASH)); operationService.execute(operation, context, ROBOT); verify(connector).fetchCapabilities(eq(ROBOT_ACCOUNT), anyString()); verify(accountStore).putAccount(NEW_ROBOT_ACCOUNT); }
public void testUpdateCapabilites() throws Exception { OperationRequest operation = new OperationRequest( "robot.notify", OP_ID, Parameter.of(ParamsProperty.CAPABILITIES_HASH, NEW_HASH)); operationService.execute(operation, context, ROBOT); verify(connector).fetchCapabilities(eq(ROBOT_ACCOUNT), anyString()); verify(accountStore).putAccount(NEW_ROBOT_ACCOUNT); }
public void testExceptionOnUnknownAccount() throws Exception { OperationRequest operation = new OperationRequest("robot.notify", OP_ID, Parameter.of(ParamsProperty.CAPABILITIES_HASH, NEW_HASH)); when(accountStore.getAccount(ROBOT)).thenReturn(null); try { operationService.execute(operation, context, ROBOT); fail("Expected InvalidRequestException"); } catch (InvalidRequestException e) { // expected } verifyZeroInteractions(connector); verify(accountStore, never()).putAccount(any(AccountData.class)); }
public void testExceptionOnUnknownAccount() throws Exception { OperationRequest operation = new OperationRequest("robot.notify", OP_ID, Parameter.of(ParamsProperty.CAPABILITIES_HASH, NEW_HASH)); when(accountStore.getAccount(ROBOT)).thenReturn(null); try { operationService.execute(operation, context, ROBOT); fail("Expected InvalidRequestException"); } catch (InvalidRequestException e) { // expected } verifyZeroInteractions(connector); verify(accountStore, never()).putAccount(any(AccountData.class)); }