Refactor persistence library.

Added a persistence speficication cluster and implementation cluser,
Implementation MySQL.
Added test cases for mysql implementation.
This commit is contained in:
jvelilla
2014-09-15 23:27:11 -03:00
parent 46362731f0
commit 3a699b23a0
32 changed files with 196 additions and 8 deletions

View File

@@ -0,0 +1,55 @@
note
description : "tests application root class"
date : "$Date: 2014-08-20 15:21:15 -0300 (mi., 20 ago. 2014) $"
revision : "$Revision: 95678 $"
class
APPLICATION
inherit
ARGUMENTS
create
make
feature {NONE} -- Initialization
make
-- Run application.
local
user: USER_DATA_PROVIDER
node: NODE_DATA_PROVIDER
l_security: SECURITY_PROVIDER
do
create connection.login_with_schema ("cms", "root", "")
-- create user.make (connection)
---- user.new_user ("jv", "test","test@test.com")
-- if attached user.user (3) as l_user then
-- if attached user.user_salt ("jv") as l_salt then
-- create l_security
-- if attached l_user.password as l_password then
-- print (l_password)
-- io.put_new_line
-- print (l_security.password_hash ("test", l_salt))
-- check same_string: l_security.password_hash ("test", l_salt).is_case_insensitive_equal (l_password) end
-- end
-- end
-- end
-- if attached user.user_by_name ("jv") as l_user then
-- check l_user.id = 3 end
-- end
create node.make (connection)
across node.recent_nodes (0, 5) as c loop
print (c.item)
end
end
connection: DATABASE_CONNECTION_MYSQL
end

View File

@@ -0,0 +1,26 @@
note
description: "[
Eiffel tests that can be executed by testing tool.
]"
author: "EiffelStudio test wizard"
date: "$Date$"
revision: "$Revision$"
testing: "type/manual"
class
NODE_TEST_SET
inherit
EQA_TEST_SET
feature -- Test routines
new_test_routine
-- New test routine
do
assert ("not_implemented", False)
end
end

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<system xmlns="http://www.eiffel.com/developers/xml/configuration-1-13-0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.eiffel.com/developers/xml/configuration-1-13-0 http://www.eiffel.com/developers/xml/configuration-1-13-0.xsd" name="tests">
<target name="tests">
<root class="APPLICATION" feature="make"/>
<option warning="true" void_safety="conformance">
<assertions precondition="true" postcondition="true" check="true" invariant="true" loop="true" supplier_precondition="true"/>
</option>
<setting name="concurrency" value="thread"/>
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
<library name="crypto" location="$ISE_LIBRARY\unstable\library\text\encryption\crypto\crypto-safe.ecf"/>
<library name="persitence_mysql" location="..\persistence_mysql.ecf" readonly="false"/>
<library name="testing" location="$ISE_LIBRARY\library\testing\testing-safe.ecf"/>
<library name="process" location="$ISE_LIBRARY\library\process\process-safe.ecf"/>
<cluster name="tests" location=".\" recursive="true">
<file_rule>
<exclude>/EIFGENs$</exclude>
<exclude>/CVS$</exclude>
<exclude>/.svn$</exclude>
</file_rule>
</cluster>
</target>
</system>

View File

@@ -0,0 +1,78 @@
note
description: "[
Eiffel tests that can be executed by testing tool.
]"
author: "EiffelStudio test wizard"
date: "$Date$"
revision: "$Revision$"
testing: "type/manual"
class
USER_TEST_SET
inherit
EQA_TEST_SET
redefine
on_prepare,
on_clean
select
default_create
end
ABSTRACT_DB_TEST
rename
default_create as default_db_test
end
feature {NONE} -- Events
on_prepare
-- <Precursor>
do
(create {CLEAN_DB}).clean_db(connection)
user_provider.new_user ("admin", "admin","admin@admin.com")
end
on_clean
-- <Precursor>
do
end
feature -- Test routines
test_user_exist
-- User admin exist
do
assert ("Not void", attached user_provider.user_by_email ("admin@admin.com"))
assert ("Not void", attached user_provider.user (1))
assert ("Not void", attached user_provider.user_by_name ("admin"))
end
test_user_not_exist
-- Uset test does not exist.
do
assert ("Void", user_provider.user_by_email ("test@admin.com") = Void)
assert ("Void", user_provider.user(2) = Void )
assert ("Void", user_provider.user_by_name ("test") = Void)
end
test_new_user
do
user_provider.new_user ("test", "test","test@admin.com")
assert ("Not void", attached user_provider.user_by_email ("test@admin.com"))
assert ("Not void", attached user_provider.user (2))
assert ("Not void", attached user_provider.user (2) as l_user and then l_user.id = 2 and then l_user.name ~ "test")
assert ("Not void", attached user_provider.user_by_name ("test"))
end
feature {NONE} -- Implementation
user_provider: USER_DATA_PROVIDER
-- user provider.
once
create Result.make (connection)
end
end

View File

@@ -0,0 +1,17 @@
note
description: "Summary description for {ABSTRACT_DB_TEST}."
date: "$Date$"
revision: "$Revision$"
class
ABSTRACT_DB_TEST
feature -- Database connection
connection: DATABASE_CONNECTION_MYSQL
-- MYSQL database connection
once
create Result.login_with_schema ("cms_dev", "root", "")
end
end

View File

@@ -0,0 +1,66 @@
note
description: "[
Setting up database tests
1. Put the database in a known state before running your test suite.
2. Data reinitialization. For testing in developer sandboxes, something that you should do every time you rebuild the system, you may want to forgo dropping and rebuilding the database in favor of simply reinitializing the source data.
You can do this either by erasing all existing data and then inserting the initial data vales back into the database, or you can simple run updates to reset the data values.
The first approach is less risky and may even be faster for large amounts of data. - See more at: http://www.agiledata.org/essays/databaseTesting.html#sthash.6yVp35g8.dpuf
]"
date: "$Date$"
revision: "$Revision$"
EIS: "name=Database Testing", "src=http://www.agiledata.org/essays/databaseTesting.html", "protocol=uri"
class
CLEAN_DB
feature
clean_db (a_connection: DATABASE_CONNECTION)
-- Clean db test.
local
l_parameters: STRING_TABLE[STRING]
do
create l_parameters.make (0)
db_handler(a_connection).set_query (create {DATABASE_QUERY}.data_reader (Sql_delete_nodes, l_parameters))
db_handler(a_connection).execute_change
-- Clean Users
db_handler(a_connection).set_query (create {DATABASE_QUERY}.data_reader (Sql_delete_users, l_parameters))
db_handler(a_connection).execute_change
-- Reset Autoincremente
db_handler(a_connection).set_query (create {DATABASE_QUERY}.data_reader (Rest_users_autoincrement, l_parameters))
db_handler(a_connection).execute_change
db_handler(a_connection).set_query (create {DATABASE_QUERY}.data_reader (Rest_nodes_autoincrement, l_parameters))
db_handler(a_connection).execute_change
end
feature -- Database Hanlder
db_handler (a_connection: DATABASE_CONNECTION): DATABASE_HANDLER
-- Db handler
once
create {DATABASE_HANDLER_IMPL} Result.make (a_connection)
end
feature -- Sql delete queries
Sql_delete_users: STRING = "delete from Users"
-- Clean Users.
Sql_delete_nodes: STRING = "delete from Nodes"
-- Clean Nodes.
Rest_users_autoincrement: STRING = "ALTER TABLE Users AUTO_INCREMENT = 1"
-- reset autoincrement
Rest_nodes_autoincrement: STRING = "ALTER TABLE Nodes AUTO_INCREMENT = 1"
-- reset autoincrement.
end