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 testExecuteOperationCallsExecute() throws Exception { String operationId = "op1"; OperationRequest operation = new OperationRequest("wavelet.create", operationId); OperationService service = mock(OperationService.class); when(operationRegistry.getServiceFor(any(OperationType.class))).thenReturn(service); OperationUtil.executeOperation(operation, operationRegistry, context, ALEX); verify(service).execute(operation, context, ALEX); }
public void testExecuteOperationCallsExecute() throws Exception { String operationId = "op1"; OperationRequest operation = new OperationRequest("wavelet.create", operationId); OperationService service = mock(OperationService.class); when(operationRegistry.getServiceFor(any(OperationType.class))).thenReturn(service); OperationUtil.executeOperation(operation, operationRegistry, context, ALEX); verify(service).execute(operation, context, ALEX); }
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 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)); }
@Override protected void setUp() throws Exception { waveletProvider = mock(WaveletProvider.class); operationRegistry = mock(OperationServiceRegistry.class); ConversationUtil conversationUtil = mock(ConversationUtil.class); converter = mock(EventDataConverter.class); operation = new OperationRequest("wavelet.fetch", "op1", s(WAVE_ID), s(WAVELET_ID)); context = new OperationContextImpl(waveletProvider, converter, conversationUtil); }
public void testSuccessfulSendMessageBundle() throws Exception { final List<OperationRequest> expectedOperations = Collections.unmodifiableList( Lists.newArrayList(new OperationRequest("wavelet.setTitle", "op1"))); when(serializer.serialize(BUNDLE, PROTOCOL_VERSION)).thenReturn(SERIALIZED_BUNDLE); when(connection.postJson(TEST_RPC_ENDPOINT, SERIALIZED_BUNDLE)).thenReturn(RETURNED_OPERATION); when(serializer.deserializeOperations(RETURNED_OPERATION)).thenReturn(expectedOperations); List<OperationRequest> operations = connector.sendMessageBundle(BUNDLE, robot, PROTOCOL_VERSION); assertEquals(expectedOperations, operations); }
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 testSuccessfulSendMessageBundle() throws Exception { final List<OperationRequest> expectedOperations = Collections.unmodifiableList( Lists.newArrayList(new OperationRequest("wavelet.setTitle", "op1"))); when(serializer.serialize(BUNDLE, PROTOCOL_VERSION)).thenReturn(SERIALIZED_BUNDLE); when(connection.postJson(TEST_RPC_ENDPOINT, SERIALIZED_BUNDLE)).thenReturn(RETURNED_OPERATION); when(serializer.deserializeOperations(RETURNED_OPERATION)).thenReturn(expectedOperations); List<OperationRequest> operations = connector.sendMessageBundle(BUNDLE, robot, PROTOCOL_VERSION); assertEquals(expectedOperations, operations); }
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); }
protected static OperationRequest operationRequest(OperationType opType, String operationId, String rootBlipId, Parameter... params) { return new OperationRequest(opType.method(), operationId, s(WAVE_ID), s(WAVELET_ID), rootBlipId, params); }
/** Creates an operation request. */ protected static OperationRequest operationRequest(OperationType opType, String rootBlipId, Parameter... params) { return new OperationRequest(opType.method(), OPERATION_ID, s(WAVE_ID), s(WAVELET_ID), rootBlipId, params); }
protected static OperationRequest operationRequest(OperationType opType, String operationId, String rootBlipId, Parameter... params) { return new OperationRequest(opType.method(), operationId, s(WAVE_ID), s(WAVELET_ID), rootBlipId, params); }
/** Creates an operation request. */ protected static OperationRequest operationRequest(OperationType opType, String rootBlipId, Parameter... params) { return new OperationRequest(opType.method(), OPERATION_ID, s(WAVE_ID), s(WAVELET_ID), rootBlipId, params); }
public void testExecuteOperationsSetsErrorOnInvalidRequestException() throws Exception { String operationId = "op1"; OperationRequest operation = new OperationRequest("wavelet.create", operationId); OperationService service = mock(OperationService.class, new ThrowsException(new InvalidRequestException(""))); when(operationRegistry.getServiceFor(any(OperationType.class))).thenReturn(service); OperationUtil.executeOperation(operation, operationRegistry, context, ALEX); assertTrue("Expected one response", context.getResponses().size() == 1); assertTrue("Expected an error response", context.getResponse(operationId).isError()); }
public void testExecuteOperationsSetsErrorOnInvalidRequestException() throws Exception { String operationId = "op1"; OperationRequest operation = new OperationRequest("wavelet.create", operationId); OperationService service = mock(OperationService.class, new ThrowsException(new InvalidRequestException(""))); when(operationRegistry.getServiceFor(any(OperationType.class))).thenReturn(service); OperationUtil.executeOperation(operation, operationRegistry, context, ALEX); assertTrue("Expected one response", context.getResponses().size() == 1); assertTrue("Expected an error response", context.getResponse(operationId).isError()); }
public void testFetchWaveWithMissingParamThrowsInvalidRequestException() throws Exception { // No wave id or wavelet id set. OperationRequest operation = new OperationRequest(OperationType.ROBOT_FETCH_WAVE.method(), OPERATION_ID); OperationContextImpl context = helper.getContext(); try { service.execute(operation, context, ALEX); fail("Expected InvalidRequestException because params were not set"); } catch (InvalidRequestException e) { // expected } } }