/** * Attempts to get a parameter, returns the {@code null} if not found. * * @param <T> type of class to cast to. * @param operation operation to extract property from. * @param key the key of the parameter. * @return specialized object after being serialized, or {@code null} if the * parameter could not be found. */ public static <T> T getOptionalParameter(OperationRequest operation, ParamsProperty key) { return OperationUtil.<T> getOptionalParameter(operation, key, null); }
/** * Executes operations in the given context. * * @param context the context to perform the operations in. * @param operations the operations to perform. * @param author the author for which to perform the robot operations. */ private void executeOperations( OperationContext context, List<OperationRequest> operations, ParticipantId author) { for (OperationRequest operation : operations) { OperationUtil.executeOperation(operation, operationRegistry, context, author); } }
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 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 testGetRequiredParameter() throws Exception { String waveId = OperationUtil.getRequiredParameter(operation, ParamsProperty.WAVE_ID); assertEquals(s(WAVE_ID), waveId); }
public void testGetRequiredParameterThrowsInvalidRequestException() throws Exception { try { OperationUtil.getRequiredParameter(operation, ParamsProperty.ANNOTATION); fail("Expected InvalidRequestException"); } catch (InvalidRequestException e) { // expected } }
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")); }
@Override protected void setUp() { MockitoAnnotations.initMocks(this); conversationUtil = new ConversationUtil(idGenerator); digester = new WaveDigester(conversationUtil); }
@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); }
/** * Ensures that the account belongs to a robot. * * @param existingAccount the account to check. * @throws RobotRegistrationException if the account is not robot. */ private void throwExceptionIfNotRobot(AccountData existingAccount) throws RobotRegistrationException { if (!existingAccount.isRobot()) { throw new RobotRegistrationException(existingAccount.getId().getAddress() + " is not a robot account!"); } }
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 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 testGetRequiredParameter() throws Exception { String waveId = OperationUtil.getRequiredParameter(operation, ParamsProperty.WAVE_ID); assertEquals(s(WAVE_ID), waveId); }
public void testGetRequiredParameterThrowsInvalidRequestException() throws Exception { try { OperationUtil.getRequiredParameter(operation, ParamsProperty.ANNOTATION); fail("Expected InvalidRequestException"); } catch (InvalidRequestException e) { // expected } }
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")); }
/** * 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()); } }
@Override protected void setUp() { MockitoAnnotations.initMocks(this); conversationUtil = new ConversationUtil(idGenerator); digester = new WaveDigester(conversationUtil); }
@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 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); } }