Skip to content

Commit

Permalink
TestEcho
Browse files Browse the repository at this point in the history
- Some improvements of code and site.
  • Loading branch information
graninas committed Oct 28, 2011
1 parent bacfcfb commit ec26748
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 24 deletions.
33 changes: 33 additions & 0 deletions ebin/report.log
Original file line number Diff line number Diff line change
Expand Up @@ -2295,3 +2295,36 @@ Stack: [{gen_server,call,2},

=INFO REPORT==== 28-Oct-2011::21:07:09 ===
stop_ready([], <0.53.0>)

=ERROR REPORT==== 28-Oct-2011::22:24:45 ===
Dynamic compiler err /home/gas/Erlang/TestEcho/priv/docroot/data_test.yaws:56:
syntax error before: '}'
generated file at: /home/gas/.yaws/yaws/embedded/m7.erl

=ERROR REPORT==== 28-Oct-2011::22:49:55 ===
Dynamic compiler err /home/gas/Erlang/TestEcho/priv/docroot/data_input.yaws:82:
syntax error before: ']'
generated file at: /home/gas/.yaws/yaws/embedded/m35.erl

=ERROR REPORT==== 28-Oct-2011::22:53:30 ===
Dynamic compiler err /home/gas/Erlang/TestEcho/priv/docroot/data_input.yaws:85:
syntax error before: '}'
generated file at: /home/gas/.yaws/yaws/embedded/m41.erl

=ERROR REPORT==== 28-Oct-2011::23:10:01 ===


ERROR erlang code crashed:
File: /home/gas/Erlang/TestEcho/priv/docroot/data_process.yaws:6
Reason: {{badmatch,undefined},
[{m56,out,1},
{yaws_server,deliver_dyn_part,8},
{yaws_server,aloop,3},
{yaws_server,acceptor0,2},
{proc_lib,init_p_do_apply,3}]}
Req: {http_request,'POST',{abs_path,"/data_process.yaws"},{1,1}}
Stack: [{m56,out,1},
{yaws_server,deliver_dyn_part,8},
{yaws_server,aloop,3},
{yaws_server,acceptor0,2},
{proc_lib,init_p_do_apply,3}]
Binary file modified ebin/security_server.beam
Binary file not shown.
80 changes: 80 additions & 0 deletions ebin/test_echo.access

Large diffs are not rendered by default.

15 changes: 10 additions & 5 deletions priv/docroot/data_input.yaws
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<erl>
out(A) -> {ssi, "HEAD.inc","%%",[{"Pl", " - Input data"}]}.
out(A) -> {ssi, "HEAD.inc","%%",[{"Pl", " - Data input"}]}.
</erl>

<div><h1>Input data:</h1></div>
Expand Down Expand Up @@ -68,6 +68,10 @@ out(A) ->
{input, [{name, transaction_second}, {type, text}, {maxlength, "2"}, {size, "2"}, {value, "10"}]}
]}
]},
{tr, [], [
{td, [], "Merge hardcoded test data"},
{td, [], {input, [{type, checkbox}, {name, merge_test_data}, {value, "merge_test_data"}]}}
]},
{tr, [], [
{td, [], ""},
{td, [], {input, [{type, submit}]}}
Expand All @@ -77,13 +81,14 @@ out(A) ->
{td, [], Result}
]}
]}

}}.


</erl>
<div>
<a href="./index.yaws">Back to home page</a>
</div>


<p><a href="./data_output.yaws">View data</a></p>
<p><a href="./data_test.yaws">Security server tests</a></p>
<p><a href="./index.yaws">Home page</a></p>


16 changes: 11 additions & 5 deletions priv/docroot/data_process.yaws
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
<erl>

out(A) ->

case postvar(A, "merge_test_data") of
{ok, _} -> security_server:merge_test_data();
_ -> do_nothing
end,

{ok, DTMethod} = postvar(A, "datetime_method"),

{ok, SecurityName} = postvar(A, "security"),
Expand Down Expand Up @@ -44,17 +50,17 @@ out(A) ->
SecData = {SN, P, Am},
security_server:add_transaction({DateTime, SecData}),

Result = "Added",
Result = "Added.",

{ehtml, {p, [], Result}}.

</erl>

<div>
<p><a href="./data_input.yaws">Back to input data page</a></p>
<p><a href="./index.yaws">Back to home page</a></p>
</div>

<p><a href="./data_input.yaws">Input data</a></p>
<p><a href="./data_output.yaws">View data</a></p>
<p><a href="./data_test.yaws">Security server tests</a></p>
<p><a href="./index.yaws">Home page</a></p>

</body>
</html>
14 changes: 3 additions & 11 deletions priv/docroot/index.yaws
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,9 @@
</erl>
<h1>Very simple "Deals with security" test site</h1></div>

<p>
<a href="./data_input.yaws">Input data</a>
</p>

<p>
<a href="./data_output.yaws">View data</a>
</p>

<p>
<a href="./data_test.yaws">Testing data and application</a>
</p>
<p><a href="./data_input.yaws">Input data</a></p>
<p><a href="./data_output.yaws">View data</a></p>
<p><a href="./data_test.yaws">Security server tests</a></p>

<erl>
out(A) -> {ssi,"END.inc",[],[]}.
Expand Down
28 changes: 25 additions & 3 deletions src/security_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
terminate/2, code_change/3]).

-export([data/0, add_transaction/1, report/1, load_test_data/0]).
-export([data/0, set_data/1, clear_data/0]).
-export([add_transaction/1, report/1]).
-export([load_test_data/0, merge_test_data/0]).

-import(data_collection, [fetch_data/2, filter_data/2, collect/2, test/0]).
-import(test_data, [test_data_dict/0]).
Expand Down Expand Up @@ -62,6 +64,14 @@ data() ->
load_test_data() ->
gen_server:call(?SERVER, load_test_data).

merge_test_data() ->
gen_server:call(?SERVER, merge_test_data).

set_data(NewDict) ->
gen_server:cast(?SERVER, {set_data, NewDict}).

clear_data() ->
gen_server:cast(?SERVER, clear_data).
%%====================================================================
%% gen_server callbacks
%%====================================================================
Expand Down Expand Up @@ -101,9 +111,15 @@ handle_call({add_transaction, Transaction}, _, State) ->
NewState = dict:store(DateTime, SecData, State),
{reply, NewState, NewState};

handle_call(load_test_data, _, _State) ->
handle_call(load_test_data, _, OldDict) ->
TestDict = test_data:test_data_dict(),
{reply, {OldDict, TestDict}, TestDict};

handle_call(merge_test_data, _, OldDict) ->
TestDict = test_data:test_data_dict(),
{reply, TestDict, TestDict};
MergeF = fun(_, Val1, _) -> Val1 end,
NewDict = dict:merge(MergeF, TestDict, OldDict),
{reply, NewDict, NewDict};

%% Called for unregistered cases.
handle_call(_Request, _From, State) ->
Expand All @@ -116,6 +132,12 @@ handle_call(_Request, _From, State) ->
%% Description: Handling cast messages
%%--------------------------------------------------------------------

handle_cast({set_data, NewDict}, _) ->
{noreply, NewDict};

handle_cast(clear_data, _) ->
{noreply, dict:new()};

%% Casted for unregistered cases.
handle_cast(_Msg, State) ->
{noreply, State}.
Expand Down

0 comments on commit ec26748

Please sign in to comment.