anchor.diff:      end).
   
   -define(CONTENT_TYPE_HEADER, [{<<"content-type">>, <<"application/json">>}]).
  +-define(COMMUNICATION_WAIT, 500).
   
   -define(URLS1, [<<"127.0.0.1">>]).
   -define(URLS2, [<<"127.0.0.2">>]).
  
positive.code:     [Address1, _] = ?config(restAddresses, Config),
      RegisterParams = {Address1, ?CONTENT_TYPE_HEADER, []},
  
      {ProviderID1, SubscribeParams1} = rest_utils:register_provider(?URLS1, ?REDIRECTION_POINT1, ?CLIENT_NAME1, RegisterParams),
      {ProviderID2, SubscribeParams2} = rest_utils:register_provider(?URLS2, ?REDIRECTION_POINT2, ?CLIENT_NAME2, RegisterParams),
      First = ?getFirstSeq(Node1, Config),
  
      subscribe(0, <<"endpoint1">>, SubscribeParams1),
      subscribe(0, <<"endpoint2">>, SubscribeParams2),
  
  
negative.code:     Result = rest_utils:do_request(RestAddress, Headers, post, Data, Options),
      ?assertEqual(204, rest_utils:get_response_status(Result)).
  
  verify_communication(Node, Endpoint, ExpectedMsgs, ForbiddenMsgs) ->
      verify_communication(Node, Endpoint, ExpectedMsgs, ForbiddenMsgs, 1, 10).
  verify_communication(_, _, [], _, _, _) ->
      ok;
  verify_communication(_, _, PresentBodies, _, _, 0) ->
      ?assertMatch([], PresentBodies);
  verify_communication(Node, Endpoint, ExpectedMsgs, ForbiddenMsgs, Request, AllowedFailures) ->
      Body = mock_capture(Node, [Request, http_client, post, [Endpoint, '_', '_'], 3]),
      case Body of
          {badrpc, _} ->
              timer:sleep(?COMMUNICATION_WAIT),
              verify_communication(Node, Endpoint, ExpectedMsgs, ForbiddenMsgs, Request, AllowedFailures - 1);
          _ ->
              Data = json_utils:decode(Body),
              lists:foreach(fun(Absent) -> ?assertNotMatch(Absent, Data) end, ForbiddenMsgs),
              verify_communication(Node, Endpoint, ExpectedMsgs -- [Data], ForbiddenMsgs, Request + 1, 10)
      end.
  
  space_msg(Seq, SpaceDoc) ->
      #document{key = ID, value = #space{name = Name, groups = Groups, users = Users}} = SpaceDoc,
      space_msg(Seq, ID, Name, Groups, Users).
  
  space_msg(Seq, ID, Name, GroupIDs, UserIDs) ->
      [
          {<<"seq">>, Seq},
          {<<"space">>, [{<<"id">>, ID}, {<<"name">>, Name}, {<<"groups">>, GroupIDs}, {<<"users">>, UserIDs}]}
      ].
  
  mock_capture(Node, Args) ->
      rpc:call(Node, meck, capture, Args).