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 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); } }
/** * Executes an {@link OperationRequest}. If the operation throws an * {@link InvalidRequestException} this exception will be used to construct an * error response in the {@link OperationContext}. * * @param operation the operation to be executed. If the operation contains * {@link ParamsProperty.PROXYING_FOR} - then it will be taken in * account. * @param operationRegistry the registry containing the operations that can be * performed. * @param context the context in which the operation is to be executed. * @param author the author of the operation. */ public static void executeOperation(OperationRequest operation, OperationServiceRegistry operationRegistry, OperationContext context, ParticipantId author) { try { OperationService service = operationRegistry.getServiceFor(OperationUtil.getOperationType(operation)); ParticipantId proxyParticipant = OperationUtil.computeParticipant(operation, author); service.execute(operation, context, proxyParticipant); } catch (InvalidRequestException e) { LOG.warning("Operation " + operation + " failed to execute", e); context.constructErrorResponse(operation, e.getMessage()); } }