anchor.diff:           }).
   
   rest_init_test() ->
  -    MeckModules = [cowboy_req],
  -    SetHeader = fun(_Name, _Value, ReqIn) ->
  -                        ReqIn
  -                end,
  -    ok = test_util:meck_new(MeckModules),
  -    ok = meck:expect(cowboy_req, set_resp_header, SetHeader),
  -    ok = meck:expect(cowboy_req, set_resp_body, fun(_, Req) -> Req end),
  +    {ok, Meck} = start_meck(),
       Req = req,
       {ok, Req, #state{}} = tts_rest:rest_init(Req, doesnt_matter),
  -    ok = test_util:meck_done(MeckModules),
  +    ok = stop_meck(Meck),
       ok.
   
   allowed_methods_test() ->
  
positive.code:                               _ -> {error, not_found}
                            end
                end,
      ok = test_util:meck_new(MeckModules),
      ok = meck:expect(tts, get_service_list_for, GetServiceList),
      ok = meck:expect(tts, get_openid_provider_list, GetProvider),
      ok = meck:expect(tts, get_credential_list_for, GetCredList),
      ok = meck:expect(tts, get_temp_cred, GetCred),
      ok = meck:expect(tts, logout, fun(_) -> ok end),
  
      Requests = [
                  {#state{version = latest,
                          type = service,
                          id = undefined,
                          session_pid = pid1,
                          method = get
                         }, <<"{\"service_list\":[{}]}">> },
                  {#state{version = latest,
                          type = service,
                          id = undefined,
                          session_pid = pid2,
                          method = get
                         }, <<"{\"service_list\":[]}">> },
                  {#state{version = latest,
                          type = oidcp,
                          id = undefined,
                          session_pid = undefined,
                          method = get
                         },<<"{\"openid_provider_list\":[{\"id\":\"ID1\",\"issuer\":\"https:\\/\\/test.tts\",\"ready\":true},{\"id\":\"ID2\",\"issuer\":\"https:\\/\\/other.tts\",\"ready\":false}]}">>
                  },
                  %% {#state{version = latest,
                  %%         type = credential,
                  %%         id = undefined,
                  %%         session_pid = pid1,
                  %%         method = get
                  %%        },<<"{\"credential_list\":[{\"id\":\"CredId\"}]}">> },
                  {#state{version = latest,
                          type = cred_data,
                          id = <<"CRED1">>,
                          session_pid = pid1,
                          method = get
                         },<<"{\"password\":\"secret\"}">> },
                  {#state{version = latest,
                          type = cred_data,
                          id = <<"CRED1">>,
                          session_pid = pid2,
                          method = get
                         },<<"{\"result\":\"error\",\"user_msg\":\"Sorry, the requested data was not found\"}">> }
                 ],
  
      Test  = fun({State, ExpResult}, _) ->
                      io:format("Expecting ~p on state ~p~n",[ExpResult, State]),
                      {Result, req, _NewState} = tts_rest:get_json(req, State),
                      ?assertEqual(ExpResult, Result),
                      ok
              end,
      ok = lists:foldl(Test,ok,Requests),
      ok = test_util:meck_done(MeckModules),
  
      ok.
  
  post_json_test() ->
      application:set_env(tts, ep_main, <<"/">>),
      MeckModules = [ tts ],
      CredRequest = fun(_ServiceId, SessionPid, _Params, _IFace) ->
                          case SessionPid of
                              pid1 -> {ok, #{}};
  
negative.code:                                    {error, bad_token}
                             end
                     end,
      CredExists = fun(CredId, _Session) ->
                            case CredId of
                                <<"123">> -> true;
  