Skip to content

Commit

Permalink
Improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
silviucpp committed Apr 8, 2023
1 parent 0531e9a commit 2f10b14
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
7 changes: 7 additions & 0 deletions src/esmpplib_connection.erl
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
query_sm/2,
query_sm_async/2,
is_connected/1,
stop/1,

init/1,
handle_call/3,
Expand Down Expand Up @@ -99,6 +100,9 @@ query_sm_async(Pid, MessageId) ->
is_connected(Pid) ->
esmpplib_utils:safe_call(Pid, is_connected).

stop(Pid) ->
esmpplib_utils:safe_call(Pid, stop).

% gen_server callbacks

init(Options0) ->
Expand Down Expand Up @@ -211,6 +215,9 @@ handle_call({query_sm, MessageId, Async}, FromPid, #state{
end;
handle_call(is_connected, _From, #state{binding_mode = BindingMode} = State) ->
{reply, {ok, BindingMode =/= undefined}, State};
handle_call(stop, _From, #state{id = Id} = State) ->
?INFO_MSG("connection_id: ~p received stop signal", [Id]),
{stop, normal, ok, State};
handle_call(Request, _From, #state{id = Id} = State) ->
?WARNING_MSG("connection_id: ~p unknown call request: ~p", [Id, Request]),
{reply, ok, State}.
Expand Down
34 changes: 28 additions & 6 deletions test/integrity_test_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ on_submit_sm_response_failed(MessageRef, Error) ->

on_delivery_report(MessageId, From, To, SubmitDate, DlrDate, Status, ErrorCode) ->
?INFO_MSG("### on_delivery_report -> ~p", [[MessageId, From, To, SubmitDate, DlrDate, Status, ErrorCode]]),
ect_event_manager:notify(on_delivery_report, [MessageId, From, To, SubmitDate, DlrDate, Status, ErrorCode]).
ect_config:set({dlr,MessageId}, [From, To, SubmitDate, DlrDate, Status, ErrorCode]).

on_connection_change_notification(Id, Pid, IsConnected) ->
?INFO_MSG("### on_connection_change_notification -> ~p", [[Id, Pid, IsConnected]]),
Expand All @@ -59,9 +59,32 @@ sync_api_test(_Config) ->
?assertEqual(ok , ect_utils:wait_for_config_value({ConnectionId, P, connection_status}, true)),
?assertEqual({ok, true}, esmpplib_connection:is_connected(P)),

{ok, MessageUuid, PartsNumber} = esmpplib_connection:submit_sm(P, <<"INFO">>, <<"1234567890">>, <<"hello world!">>),
?assertEqual(true, is_binary(MessageUuid)),
?assertEqual(1, PartsNumber).
% send failed message

{error, Reason} = esmpplib_connection:submit_sm(P, <<"INFO">>, <<"">>, <<"invalid message">>),
?assertEqual({submit_failed, ?ESME_RINVDSTADR, <<"ESME_RINVDSTADR">>}, Reason),

% send message successful

Src = <<"INFO">>,
Dst = <<"1234567890">>,
{ok, MessageId, PartsNumber} = esmpplib_connection:submit_sm(P, Src, Dst, <<"hello world!">>),
?assertEqual(true, is_binary(MessageId)),
?assertEqual(1, PartsNumber),

% test delivery report

?assertEqual(ok, ect_utils:wait_for_config_is_set({dlr, MessageId})),
[From, To, SubmitDate, DoneDate, Status, ErrorCode] = ect_config:get({dlr, MessageId}),
?assertEqual(From, Src),
?assertEqual(To, Dst),
?assertEqual(true, is_integer(SubmitDate)),
?assertEqual(true, is_integer(DoneDate)),
?assertEqual(<<"DELIVRD">>, Status),
?assertEqual(0, ErrorCode),

ok = esmpplib_connection:stop(P),
ok.

% internals

Expand All @@ -73,7 +96,6 @@ new_connection(Id, Opts) ->
transport => ?TRANSPORT,
interface_version => ?INTERFACE_VERSION,
system_id => ?USERNAME,
password => ?PASSWORD,
registered_delivery => ?REGISTERED_DELIVERY_MC_NEVER
password => ?PASSWORD
},
esmpplib_connection:start_link(maps:merge(Config, Opts)).

0 comments on commit 2f10b14

Please sign in to comment.