public void testGetOptionalParameter() throws Exception { String waveId = OperationUtil.getOptionalParameter(operation, ParamsProperty.WAVE_ID); assertEquals(s(WAVE_ID), waveId); assertNull("Non existing properties should return null when optional", OperationUtil.getOptionalParameter(operation, ParamsProperty.ANNOTATION)); String defaultValue = "b+1234"; String blipId = OperationUtil.getOptionalParameter(operation, ParamsProperty.BLIP_ID, defaultValue); assertSame("Default value should be returned when object does not exist", defaultValue, blipId); }
public void testGetRequiredParameterThrowsInvalidRequestException() throws Exception { try { OperationUtil.getRequiredParameter(operation, ParamsProperty.ANNOTATION); fail("Expected InvalidRequestException"); } catch (InvalidRequestException e) { // expected } }
public void testGetRequiredParameter() throws Exception { String waveId = OperationUtil.getRequiredParameter(operation, ParamsProperty.WAVE_ID); assertEquals(s(WAVE_ID), waveId); }
public void testToProxyParticipant() throws Exception { ParticipantId participant = ParticipantId.of("foo@example.com"); ParticipantId proxyParticipant = ParticipantId.of("foo+proxyFor@example.com"); assertEquals(proxyParticipant, OperationUtil.toProxyParticipant(participant, "proxyFor")); // If participant is already a proxy - return without a change. assertEquals(proxyParticipant, OperationUtil.toProxyParticipant(proxyParticipant, "proxyFor")); }
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()); }
@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 testGetRequiredParameter() throws Exception { String waveId = OperationUtil.getRequiredParameter(operation, ParamsProperty.WAVE_ID); assertEquals(s(WAVE_ID), waveId); }
public void testToProxyParticipant() throws Exception { ParticipantId participant = ParticipantId.of("foo@example.com"); ParticipantId proxyParticipant = ParticipantId.of("foo+proxyFor@example.com"); assertEquals(proxyParticipant, OperationUtil.toProxyParticipant(participant, "proxyFor")); // If participant is already a proxy - return without a change. assertEquals(proxyParticipant, OperationUtil.toProxyParticipant(proxyParticipant, "proxyFor")); }
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()); }
@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 testGetOptionalParameter() throws Exception { String waveId = OperationUtil.getOptionalParameter(operation, ParamsProperty.WAVE_ID); assertEquals(s(WAVE_ID), waveId); assertNull("Non existing properties should return null when optional", OperationUtil.getOptionalParameter(operation, ParamsProperty.ANNOTATION)); String defaultValue = "b+1234"; String blipId = OperationUtil.getOptionalParameter(operation, ParamsProperty.BLIP_ID, defaultValue); assertSame("Default value should be returned when object does not exist", defaultValue, blipId); }
public void testGetRequiredParameterThrowsInvalidRequestException() throws Exception { try { OperationUtil.getRequiredParameter(operation, ParamsProperty.ANNOTATION); fail("Expected InvalidRequestException"); } catch (InvalidRequestException e) { // expected } }
public void testGetProtocolVersion() throws Exception { ProtocolVersion protocolVersion = OperationUtil.getProtocolVersion(Collections.<OperationRequest> emptyList()); assertEquals( "Empty list should return default version", ProtocolVersion.DEFAULT, protocolVersion); protocolVersion = OperationUtil.getProtocolVersion(Collections.singletonList(operation)); assertEquals("Non notify op as first op should return default", ProtocolVersion.DEFAULT, protocolVersion); OperationRequest notifyOp = new OperationRequest(OperationType.ROBOT_NOTIFY.method(), "op1"); protocolVersion = OperationUtil.getProtocolVersion(Collections.singletonList(notifyOp)); assertEquals("Notify op as first op without version parameter should return default", ProtocolVersion.DEFAULT, protocolVersion); Parameter versionParameter = Parameter.of(ParamsProperty.PROTOCOL_VERSION, ProtocolVersion.V2_1.getVersionString()); notifyOp = new OperationRequest(OperationType.ROBOT_NOTIFY.method(), "op1", versionParameter); protocolVersion = OperationUtil.getProtocolVersion(Collections.singletonList(notifyOp)); assertEquals( "Notify op as first op should return its version", ProtocolVersion.V2_1, protocolVersion); }
public void testComputeParticipantWithInvalidProxyFor() throws Exception { String invalidProxyFor = "~@#+^+"; String participantAddress = "foo@bar.com"; OperationRequest operation = mock(OperationRequest.class); when(operation.getParameter(ParamsProperty.PROXYING_FOR)).thenReturn(invalidProxyFor); try { OperationUtil.computeParticipant(operation, ParticipantId.of(participantAddress)); fail("InvalidRequestException should be thrown."); } catch (InvalidRequestException e) { // Pass. } verify(operation).getParameter(ParamsProperty.PROXYING_FOR); }
public void testGetProtocolVersion() throws Exception { ProtocolVersion protocolVersion = OperationUtil.getProtocolVersion(Collections.<OperationRequest> emptyList()); assertEquals( "Empty list should return default version", ProtocolVersion.DEFAULT, protocolVersion); protocolVersion = OperationUtil.getProtocolVersion(Collections.singletonList(operation)); assertEquals("Non notify op as first op should return default", ProtocolVersion.DEFAULT, protocolVersion); OperationRequest notifyOp = new OperationRequest(OperationType.ROBOT_NOTIFY.method(), "op1"); protocolVersion = OperationUtil.getProtocolVersion(Collections.singletonList(notifyOp)); assertEquals("Notify op as first op without version parameter should return default", ProtocolVersion.DEFAULT, protocolVersion); Parameter versionParameter = Parameter.of(ParamsProperty.PROTOCOL_VERSION, ProtocolVersion.V2_1.getVersionString()); notifyOp = new OperationRequest(OperationType.ROBOT_NOTIFY.method(), "op1", versionParameter); protocolVersion = OperationUtil.getProtocolVersion(Collections.singletonList(notifyOp)); assertEquals( "Notify op as first op should return its version", ProtocolVersion.V2_1, protocolVersion); }
public void testComputeParticipantWithValidProxyFor() throws Exception { String validProxyFor = "foo"; String participantAddress = "foo@bar.com"; OperationRequest operation = mock(OperationRequest.class); when(operation.getParameter(ParamsProperty.PROXYING_FOR)).thenReturn(validProxyFor); try { OperationUtil.computeParticipant(operation, ParticipantId.of(participantAddress)); } catch (InvalidRequestException e) { fail("Exception is thrown for a valid address."); } verify(operation).getParameter(ParamsProperty.PROXYING_FOR); } }
public void testComputeParticipantWithInvalidProxyFor() throws Exception { String invalidProxyFor = "~@#+^+"; String participantAddress = "foo@bar.com"; OperationRequest operation = mock(OperationRequest.class); when(operation.getParameter(ParamsProperty.PROXYING_FOR)).thenReturn(invalidProxyFor); try { OperationUtil.computeParticipant(operation, ParticipantId.of(participantAddress)); fail("InvalidRequestException should be thrown."); } catch (InvalidRequestException e) { // Pass. } verify(operation).getParameter(ParamsProperty.PROXYING_FOR); }
public void testComputeParticipantWithValidProxyFor() throws Exception { String validProxyFor = "foo"; String participantAddress = "foo@bar.com"; OperationRequest operation = mock(OperationRequest.class); when(operation.getParameter(ParamsProperty.PROXYING_FOR)).thenReturn(validProxyFor); try { OperationUtil.computeParticipant(operation, ParticipantId.of(participantAddress)); } catch (InvalidRequestException e) { fail("Exception is thrown for a valid address."); } verify(operation).getParameter(ParamsProperty.PROXYING_FOR); } }