@Test
public void checkMessageReceiveExceptionOnAccessForbidden()
        throws Exception {

    IChainStorage chainStorageMock = mock(IChainStorage.class);
    IChainChoiceStrategy chainChoiceStrategyMock = mock(IChainChoiceStrategy.class);
    Object chainIdMock = mock(Object.class);
    IReceiverChain chainMock = mock(IReceiverChain.class);
    IMessageProcessor messageProcessorMock = mock(IMessageProcessor.class);
    IObject chainDescriptionMock = mock(IObject.class);
    IObject contextMock = mock(IObject.class);
    IMessageReceiver receiver = new ChainCallReceiver(chainStorageMock, chainChoiceStrategyMock);
    when(chainChoiceStrategyMock.chooseChain(same(messageProcessorMock))).thenReturn(chainIdMock);
    when(chainStorageMock.resolve(same(chainIdMock))).thenReturn(chainMock);
    when(messageProcessorMock.getContext()).thenReturn(contextMock);
    when(chainMock.getChainDescription()).thenReturn(chainDescriptionMock);
    when(contextMock.getValue(new FieldName("fromExternal"))).thenReturn(true);
    when(chainDescriptionMock.getValue(new FieldName("externalAccess"))).thenReturn(false);
    try {
        receiver.receive(messageProcessorMock);
        fail();
    } catch (MessageReceiveException e) {
        verify(contextMock, times(1)).setValue(new FieldName("fromExternal"), false);
        verify(contextMock, times(1)).setValue(new FieldName("accessToChainForbiddenError"), true);
    }
}