Revisited the persistence layer.

Simplified schema to focus on user and node.
Now possible to have sqlite via ODBC and/or mysql support, and select using configuration file.
Updated demo example.
This commit is contained in:
2015-01-27 19:48:37 +01:00
parent db9e40cec4
commit 7d5869f3b9
71 changed files with 2665 additions and 3313 deletions

View File

@@ -7,6 +7,7 @@
</option>
<setting name="console_application" value="true"/>
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
<library name="cms" location="..\..\..\..\cms-safe.ecf"/>
<library name="crypto" location="$ISE_LIBRARY\unstable\library\text\encryption\crypto\crypto-safe.ecf"/>
<library name="encoder" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\text\encoder\encoder-safe.ecf"/>
<library name="error" location="$ISE_LIBRARY\contrib\library\utility\general\error\error-safe.ecf"/>
@@ -19,7 +20,6 @@
<library name="thread" location="$ISE_LIBRARY\library\thread\thread-safe.ecf"/>
<library name="time" location="$ISE_LIBRARY\library\time\time-safe.ecf"/>
<cluster name="common" location="..\common\" recursive="true"/>
<cluster name="interface" location="..\..\interface\" recursive="true"/>
<cluster name="persistence_sqlite" location=".\src\" recursive="true">
<file_rule>
<exclude>/EIFGENs$</exclude>

View File

@@ -7,19 +7,19 @@
</option>
<setting name="console_application" value="true"/>
<library name="base" location="$ISE_LIBRARY\library\base\base.ecf"/>
<library name="cms" location="..\..\..\..\cms.ecf"/>
<library name="crypto" location="$ISE_LIBRARY\unstable\library\text\encryption\crypto\crypto.ecf"/>
<library name="encoder" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\text\encoder\encoder.ecf"/>
<library name="error" location="$ISE_LIBRARY\contrib\library\utility\general\error\error.ecf"/>
<library name="json" location="$ISE_LIBRARY\contrib\library\text\parser\json\library\json.ecf" readonly="false"/>
<library name="layout" location="..\..\..\layout\layout.ecf"/>
<library name="model" location="..\..\..\model\cms_model.ecf"/>
<library name="logging" location="$ISE_LIBRARY\library\runtime\logging\logging.ecf"/>
<library name="model" location="..\..\..\model\cms_model.ecf"/>
<library name="odbc" location="$ISE_LIBRARY\library\store\dbms\rdbms\odbc\odbc.ecf"/>
<library name="store" location="$ISE_LIBRARY\library\store\store.ecf" readonly="false"/>
<library name="thread" location="$ISE_LIBRARY\library\thread\thread.ecf"/>
<library name="time" location="$ISE_LIBRARY\library\time\time.ecf"/>
<library name="error" location="$ISE_LIBRARY\contrib\library\utility\general\error\error.ecf"/>
<cluster name="common" location="..\common\" recursive="true"/>
<cluster name="interface" location="..\..\interface\" recursive="true"/>
<cluster name="persistence_sqlite" location=".\src\" recursive="true">
<file_rule>
<exclude>/EIFGENs$</exclude>

View File

@@ -1,61 +0,0 @@
-- Creator: MySQL Workbench 6.1.7/ExportSQLite plugin 2009.12.02
-- Author: javier
-- Caption: New Model
-- Project: Name of the project
-- Changed: 2014-09-16 23:12
-- Created: 2014-09-16 23:12
PRAGMA foreign_keys = OFF;
-- Schema: cms_dev
BEGIN;
CREATE TABLE "nodes"(
"id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL CHECK("id">=0),
"publication_date" DATE NOT NULL,
"creation_date" DATE NOT NULL,
"modification_date" DATE NOT NULL,
"title" VARCHAR(255) NOT NULL,
"summary" TEXT NOT NULL,
"content" MEDIUMTEXT NOT NULL
);
CREATE TABLE "roles"(
"id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL CHECK("id">=0),
"role" VARCHAR(100) NOT NULL,
CONSTRAINT "role"
UNIQUE("role")
);
CREATE TABLE "users"(
"id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL CHECK("id">=0),
"username" VARCHAR(100) NOT NULL,
"password" VARCHAR(100) NOT NULL,
"salt" VARCHAR(100) NOT NULL,
"email" VARCHAR(250) NOT NULL,
CONSTRAINT "username"
UNIQUE("username")
);
CREATE TABLE "users_nodes"(
"users_id" INTEGER NOT NULL CHECK("users_id">=0),
"nodes_id" INTEGER NOT NULL CHECK("nodes_id">=0),
PRIMARY KEY("users_id","nodes_id"),
CONSTRAINT "fk_users_has_nodes_nodes1"
FOREIGN KEY("nodes_id")
REFERENCES "nodes"("id"),
CONSTRAINT "fk_users_has_nodes_users"
FOREIGN KEY("users_id")
REFERENCES "users"("id")
);
CREATE INDEX "users_nodes.fk_users_has_nodes_nodes1_idx" ON "users_nodes"("nodes_id");
CREATE INDEX "users_nodes.fk_users_has_nodes_users_idx" ON "users_nodes"("users_id");
CREATE TABLE "users_roles"(
"users_id" INTEGER NOT NULL CHECK("users_id">=0),
"roles_id" INTEGER NOT NULL CHECK("roles_id">=0),
PRIMARY KEY("users_id","roles_id"),
CONSTRAINT "fk_users_has_roles_roles1"
FOREIGN KEY("roles_id")
REFERENCES "roles"("id"),
CONSTRAINT "fk_users_has_roles_users1"
FOREIGN KEY("users_id")
REFERENCES "users"("id")
);
CREATE INDEX "users_roles.fk_users_has_roles_roles1_idx" ON "users_roles"("roles_id");
CREATE INDEX "users_roles.fk_users_has_roles_users1_idx" ON "users_roles"("users_id");
COMMIT;

View File

@@ -0,0 +1,36 @@
PRAGMA foreign_keys = OFF;
BEGIN;
CREATE TABLE "users"(
"uid" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL CHECK("uid">=0),
"name" VARCHAR(100) NOT NULL,
"password" VARCHAR(100) NOT NULL,
"salt" VARCHAR(100) NOT NULL,
"email" VARCHAR(250) NOT NULL,
"status" INTEGER,
"created" DATETIME NOT NULL,
"signed" DATETIME,
CONSTRAINT "name"
UNIQUE("name")
);
CREATE TABLE "users_roles"(
"rid" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL CHECK("rid">=0),
"role" VARCHAR(100) NOT NULL,
CONSTRAINT "role"
UNIQUE("role")
);
CREATE TABLE "nodes"(
"nid" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL CHECK("nid">=0),
"version" INTEGER,
"type" INTEGER,
"title" VARCHAR(255) NOT NULL,
"summary" TEXT NOT NULL,
"content" MEDIUMTEXT NOT NULL,
"author" INTEGER,
"publish" DATETIME,
"created" DATETIME NOT NULL,
"changed" DATETIME NOT NULL
);
COMMIT;

View File

@@ -1,14 +0,0 @@
DROP TABLE IF EXISTS nodes;
CREATE TABLE nodes
(
id smallint unsigned NOT NULL auto_increment,
publication_date date NOT NULL, #When the article was published
creation_date date NOT NULL, #When the article was created
modification_date date NOT NULL, #When the article was updated
title varchar(255) NOT NULL, #Full title of the article
summary text NOT NULL, #A short summary of the articule
content mediumtext NOT NULL, #The HTML content of the article
PRIMARY KEY (ID)
);

View File

@@ -0,0 +1,75 @@
note
description: "Summary description for {CMS_NODE_STORAGE_SQLITE}."
author: ""
date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $"
revision: "$Revision: 96542 $"
deferred class
CMS_NODE_STORAGE_SQLITE
inherit
CMS_NODE_STORAGE_SQL
redefine
nodes, recent_nodes
end
feature {NONE} -- Implementation
db_handler: DATABASE_HANDLER
deferred
end
feature -- Access
nodes: LIST [CMS_NODE]
-- List of nodes.
do
create {ARRAYED_LIST [CMS_NODE]} Result.make (0)
across nodes_iterator as ic loop
Result.force (ic.item)
end
end
recent_nodes (a_lower: INTEGER; a_count: INTEGER): LIST [CMS_NODE]
-- List of recent `a_count' nodes with an offset of `lower'.
do
create {ARRAYED_LIST [CMS_NODE]} Result.make (a_count)
across recent_nodes_iterator (a_lower, a_count) as c loop
Result.force (c.item)
end
end
feature -- Access: iterator
nodes_iterator: DATABASE_ITERATION_CURSOR [CMS_NODE]
-- List of nodes.
local
l_parameters: STRING_TABLE [ANY]
do
error_handler.reset
log.write_information (generator + ".nodes_iterator")
create l_parameters.make (0)
sql_query (select_nodes, l_parameters)
sql_post_execution
create Result.make (db_handler, agent fetch_node)
end
recent_nodes_iterator (a_lower, a_rows: INTEGER): DATABASE_ITERATION_CURSOR [CMS_NODE]
-- The most recent `a_rows'.
local
l_parameters: STRING_TABLE [ANY]
l_query: STRING
do
-- FIXME: check implementation...
error_handler.reset
log.write_information (generator + ".recent_nodes_iterator")
create l_parameters.make (2)
l_parameters.put (a_rows, "rows")
l_parameters.put (a_lower, "offset")
create l_query.make_from_string (select_recent_nodes)
sql_query (l_query, l_parameters)
create Result.make (db_handler, agent fetch_node)
sql_post_execution
end
end

View File

@@ -1,249 +1,112 @@
note
description: "Summary description for {CMS_STORAGE_MYSQL}."
date: "$Date: 2014-11-13 12:23:47 -0300 (ju., 13 nov. 2014) $"
revision: "$Revision: 96085 $"
date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $"
revision: "$Revision: 96542 $"
class
CMS_STORAGE_SQLITE
inherit
CMS_STORAGE
CMS_STORAGE_STORE_SQL
CMS_USER_STORAGE_SQLITE
CMS_NODE_STORAGE_SQLITE
REFACTORING_HELPER
create
make
feature {NONE} -- Initialization
--feature {NONE} -- Initialization
make (a_connection: DATABASE_CONNECTION)
--
require
is_connected: a_connection.is_connected
do
log.write_information (generator+".make_with_database is database connected? "+ a_connection.is_connected.out )
create node_provider.make (a_connection)
create user_provider.make (a_connection)
create error_handler.make
end
-- make (a_connection: DATABASE_CONNECTION)
-- --
-- require
-- is_connected: a_connection.is_connected
-- do
-- connection := a_connection
-- log.write_information (generator + ".make_with_database is database connected? "+ a_connection.is_connected.out )
-- create {DATABASE_HANDLER_IMPL} db_handler.make (a_connection)
feature -- Access: user
-- create error_handler.make
---- error_handler.add_synchronization (db_handler.database_error_handler)
-- end
has_user: BOOLEAN
-- Has any user?
do
Result := user_provider.has_user
-- db_handler: DATABASE_HANDLER
end
-- connection: DATABASE_CONNECTION
-- -- Current database connection.
--feature -- Access: user
all_users: LIST [CMS_USER]
do
to_implement("Not implemented!!!")
create {ARRAYED_LIST[CMS_USER]} Result.make (0)
end
-- sql_post_execution
-- -- Post database execution.
-- do
-- error_handler.append (db_handler.database_error_handler)
-- if error_handler.has_error then
-- log.write_critical (generator + ".post_execution " + error_handler.as_string_representation)
-- end
-- end
user_by_id (a_id: like {CMS_USER}.id): detachable CMS_USER
do
Result := user_provider.user (a_id)
-- sql_begin_transaction
-- do
-- connection.begin_transaction
-- end
end
-- sql_commit_transaction
-- do
-- connection.commit
-- end
user_by_name (a_name: like {CMS_USER}.name): detachable CMS_USER
do
Result := user_provider.user_by_name (a_name)
-- sql_query (a_sql_statement: STRING; a_params: detachable STRING_TABLE [detachable ANY])
-- do
-- check_sql_query_validity (a_sql_statement, a_params)
-- db_handler.set_query (create {DATABASE_QUERY}.data_reader (a_sql_statement, a_params))
-- db_handler.execute_query
-- end
end
-- sql_change (a_sql_statement: STRING; a_params: detachable STRING_TABLE [detachable ANY])
-- do
-- check_sql_query_validity (a_sql_statement, a_params)
-- db_handler.set_query (create {DATABASE_QUERY}.data_reader (a_sql_statement, a_params))
-- db_handler.execute_change
-- end
user_by_email (a_email: like {CMS_USER}.email): detachable CMS_USER
do
Result := user_provider.user_by_email (a_email)
-- sql_rows_count: INTEGER
-- -- Number of rows for last sql execution.
-- do
-- Result := db_handler.count
-- end
end
-- sql_start
-- -- Set the cursor on first element.
-- do
-- db_handler.start
-- end
is_valid_credential (l_auth_login, l_auth_password: READABLE_STRING_32): BOOLEAN
local
l_security: SECURITY_PROVIDER
do
if attached user_provider.user_salt (l_auth_login) as l_hash then
if attached user_provider.user_by_name (l_auth_login) as l_user then
create l_security
if
attached l_user.password as l_password and then
l_security.password_hash (l_auth_password, l_hash).is_case_insensitive_equal (l_password)
then
Result := True
else
log.write_information (generator + ".login_valid User: wrong username or password" )
end
else
log.write_information (generator + ".login_valid User:" + l_auth_login + "does not exist" )
end
end
-- sql_after: BOOLEAN
-- -- Are there no more items to iterate over?
-- do
-- Result := db_handler.after
-- end
end
-- sql_forth
-- -- Fetch next row from last sql execution, if any.
-- do
-- db_handler.forth
-- end
feature -- Change: user
save_user (a_user: CMS_USER)
-- Add a new user `a_user'.
do
if
attached a_user.password as l_password and then
attached a_user.email as l_email
then
user_provider.new_user (a_user.name, l_password, l_email)
else
-- set error
end
end
feature -- User Nodes
user_collaborator_nodes (a_id: like {CMS_USER}.id): LIST[CMS_NODE]
-- Possible list of nodes where the user identified by `a_id', is a collaborator.
do
create {ARRAYED_LIST[CMS_NODE]} Result.make (0)
to_implement ("Not implemented")
end
user_author_nodes (a_id: like {CMS_USER}.id): LIST[CMS_NODE]
-- Possible list of nodes where the user identified by `a_id', is the author.
do
create {ARRAYED_LIST[CMS_NODE]} Result.make (0)
to_implement ("Not implemented")
end
feature -- Users roles and permissions
user_role_by_id (a_id: like {CMS_USER_ROLE}.id): detachable CMS_USER_ROLE
-- User role by id `a_id', if any.
do
to_implement ("Not implemented")
end
user_roles: LIST [CMS_USER_ROLE]
-- Possible list of user roles.
do
create {ARRAYED_LIST[CMS_USER_ROLE]} Result.make (0)
to_implement ("Not implemented")
end
feature -- Change: roles and permissions
save_user_role (a_user_role: CMS_USER_ROLE)
-- Save user role `a_user_role'
do
to_implement ("Not implemented")
end
feature -- Access: node
nodes: LIST[CMS_NODE]
-- List of nodes.
do
create {ARRAYED_LIST[CMS_NODE]} Result.make (0)
across node_provider.nodes as c loop
Result.force (c.item)
end
end
recent_nodes (a_lower: INTEGER; a_count: INTEGER): LIST [CMS_NODE]
-- List of the `a_count' most recent nodes, starting from `a_lower'.
do
create {ARRAYED_LIST[CMS_NODE]} Result.make (0)
across node_provider.recent_nodes (a_lower,a_count) as c loop
Result.force (c.item)
end
end
node (a_id: INTEGER_64): detachable CMS_NODE
--
do
Result := node_provider.node (a_id)
end
feature -- Node
save_node (a_node: CMS_NODE)
-- Add a new node
do
node_provider.new_node (a_node)
end
delete_node (a_id: INTEGER_64)
do
node_provider.delete_node (a_id)
end
update_node (a_id: like {CMS_USER}.id; a_node: CMS_NODE)
do
node_provider.update_node (a_node)
end
update_node_title (a_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_title: READABLE_STRING_32)
do
node_provider.update_node_title (a_id, a_title)
end
update_node_summary (a_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_summary: READABLE_STRING_32)
do
node_provider.update_node_summary (a_id, a_summary)
end
update_node_content (a_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_content: READABLE_STRING_32)
do
node_provider.update_node_content (a_id, a_content)
end
node_author (a_id: like {CMS_NODE}.id): detachable CMS_USER
-- Node's author. if any.
do
to_implement ("Not implemented")
end
node_collaborators (a_id: like {CMS_NODE}.id): LIST [CMS_USER]
-- Possible list of node's collaborator.
do
create {ARRAYED_LIST[CMS_USER]} Result.make (0)
to_implement ("Not implemented")
end
feature -- User
new_user (a_user: CMS_USER)
-- Add a new user `a_user'.
do
if
attached a_user.password as l_password and then
attached a_user.email as l_email
then
user_provider.new_user (a_user.name, l_password, l_email)
else
-- set error
end
end
feature {NONE} -- Implementation
node_provider: NODE_DATA_PROVIDER
-- Node Data provider.
user_provider: USER_DATA_PROVIDER
-- User Data provider.
-- sql_item (a_index: INTEGER): detachable ANY
-- do
-- if attached {DB_TUPLE} db_handler.item as l_item and then l_item.count >= a_index then
-- Result := l_item.item (a_index)
-- else
-- check has_item_at_index: False end
-- end
-- end
end

View File

@@ -0,0 +1,43 @@
note
description: "[
Objects that ...
]"
author: "$Author: jfiat $"
date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $"
revision: "$Revision: 96542 $"
class
CMS_STORAGE_SQLITE_BUILDER
inherit
CMS_STORAGE_BUILDER
create
make
feature {NONE} -- Initialization
make
-- Initialize `Current'.
do
end
feature -- Factory
storage (a_setup: CMS_SETUP): detachable CMS_STORAGE_SQLITE
local
s: STRING
do
if attached (create {APPLICATION_JSON_CONFIGURATION_HELPER}).new_database_configuration (a_setup.layout.application_config_path) as l_database_config then
s := "Driver=SQLite3 ODBC Driver;Database="
if attached l_database_config.database_name as db_name then
s.append (db_name)
end
s.append (";LongNames=0;Timeout=1000;NoTXN=0;SyncPragma=NORMAL;StepAPI=0;")
create Result.make (create {DATABASE_CONNECTION_ODBC}.login_with_connection_string (s))
--create Result.make (create {DATABASE_CONNECTION_ODBC}.login_with_connection_string (l_database_config.connection_string))
end
end
end

View File

@@ -0,0 +1,14 @@
note
description: "Summary description for {CMS_USER_STORAGE_SQLITE}."
author: ""
date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $"
revision: "$Revision: 96542 $"
deferred class
CMS_USER_STORAGE_SQLITE
inherit
CMS_USER_STORAGE_SQL
end

View File

@@ -1,275 +0,0 @@
note
description: "Database access for node uses cases."
date: "$Date: 2014-11-13 12:23:47 -0300 (ju., 13 nov. 2014) $"
revision: "$Revision: 96085 $"
class
NODE_DATA_PROVIDER
inherit
PARAMETER_NAME_HELPER
SHARED_ERROR
REFACTORING_HELPER
create
make
feature -- Initialization
make (a_connection: DATABASE_CONNECTION)
-- Create a data provider.
do
create {DATABASE_HANDLER_IMPL} db_handler.make (a_connection)
end
db_handler: DATABASE_HANDLER
-- Db handler.
feature -- Status Report
is_successful: BOOLEAN
-- Is the last execution sucessful?
do
Result := not db_handler.has_error
end
feature -- Access
nodes: DATABASE_ITERATION_CURSOR [CMS_NODE]
-- List of nodes.
local
l_parameters: STRING_TABLE [ANY]
do
log.write_information (generator + ".nodes")
create l_parameters.make (0)
db_handler.set_query (create {DATABASE_QUERY}.data_reader (Select_nodes, l_parameters))
db_handler.execute_query
create Result.make (db_handler, agent fetch_node)
end
recent_nodes (a_lower, a_rows: INTEGER): DATABASE_ITERATION_CURSOR [CMS_NODE]
-- The most recent `a_rows'.
local
l_parameters: STRING_TABLE [ANY]
l_query: STRING
do
log.write_information (generator + ".recent_nodes")
create l_parameters.make (2)
l_parameters.put (a_rows, "rows")
create l_query.make_from_string (select_recent_nodes)
l_query.replace_substring_all ("$offset", a_lower.out)
db_handler.set_query (create {DATABASE_QUERY}.data_reader (l_query, l_parameters))
db_handler.execute_query
create Result.make (db_handler, agent fetch_node)
end
node (a_id: INTEGER_64): detachable CMS_NODE
-- Node for the given id `a_id', if any.
local
l_parameters: STRING_TABLE [ANY]
do
log.write_information (generator + ".node")
create l_parameters.make (1)
l_parameters.put (a_id,"id")
db_handler.set_query (create {DATABASE_QUERY}.data_reader (select_node_by_id, l_parameters))
db_handler.execute_query
if db_handler.count = 1 then
Result := fetch_node
end
end
count: INTEGER
-- Number of items nodes.
local
l_parameters: STRING_TABLE [ANY]
do
log.write_information (generator + ".count")
create l_parameters.make (0)
db_handler.set_query (create {DATABASE_QUERY}.data_reader (select_count, l_parameters))
db_handler.execute_query
if db_handler.count = 1 then
Result := db_handler.read_integer_32 (1)
end
end
feature -- Basic operations
new_node (a_node: CMS_NODE)
-- Create a new node.
local
l_parameters: STRING_TABLE [ANY]
do
log.write_information (generator + ".new_node")
create l_parameters.make (6)
l_parameters.put (a_node.title, "title")
l_parameters.put (a_node.summary, "summary")
l_parameters.put (a_node.content, "content")
l_parameters.put (a_node.publication_date, "publication_date")
l_parameters.put (a_node.creation_date, "creation_date")
l_parameters.put (a_node.modification_date, "modification_date")
db_handler.set_query (create {DATABASE_QUERY}.data_reader (sql_insert_node, l_parameters))
db_handler.execute_change
end
update_node_title (a_id: INTEGER_64; a_title: READABLE_STRING_32)
-- Update node title for the corresponding the report with id `a_id'.
local
l_parameters: STRING_TABLE [ANY]
do
log.write_information (generator + ".update_node_title")
create l_parameters.make (3)
l_parameters.put (a_title, "title")
l_parameters.put (create {DATE_TIME}.make_now_utc, "modification_date")
l_parameters.put (a_id, "id")
db_handler.set_query (create {DATABASE_QUERY}.data_reader (sql_update_node_title, l_parameters))
db_handler.execute_change
end
update_node_summary (a_id: INTEGER_64; a_summary: READABLE_STRING_32)
-- Update node summary for the corresponding the report with id `a_id'.
local
l_parameters: STRING_TABLE [ANY]
do
log.write_information (generator + ".update_node_summary")
create l_parameters.make (3)
l_parameters.put (a_summary, "summary")
l_parameters.put (create {DATE_TIME}.make_now_utc, "modification_date")
l_parameters.put (a_id, "id")
db_handler.set_query (create {DATABASE_QUERY}.data_reader (sql_update_node_summary, l_parameters))
db_handler.execute_change
end
update_node_content (a_id: INTEGER_64; a_content: READABLE_STRING_32)
-- Update node content for the corresponding the report with id `a_id'.
local
l_parameters: STRING_TABLE [ANY]
do
log.write_information (generator + ".update_node_content")
create l_parameters.make (3)
l_parameters.put (a_content, "content")
l_parameters.put (create {DATE_TIME}.make_now_utc, "modification_date")
l_parameters.put (a_id, "id")
db_handler.set_query (create {DATABASE_QUERY}.data_reader (sql_update_node_content, l_parameters))
db_handler.execute_change
end
update_node (a_node: CMS_NODE)
-- Update node.
local
l_parameters: STRING_TABLE [ANY]
do
log.write_information (generator + ".update_node")
create l_parameters.make (7)
l_parameters.put (a_node.title, "title")
l_parameters.put (a_node.summary, "summary")
l_parameters.put (a_node.content, "content")
l_parameters.put (a_node.publication_date, "publication_date")
l_parameters.put (a_node.creation_date, "creation_date")
l_parameters.put (create {DATE_TIME}.make_now_utc, "modification_date")
l_parameters.put (a_node.id, "id")
db_handler.set_query (create {DATABASE_QUERY}.data_reader (sql_update_node, l_parameters))
db_handler.execute_change
end
delete_node (a_id: INTEGER_64;)
-- Delete node with id `a_id'.
local
l_parameters: STRING_TABLE [ANY]
do
log.write_information (generator + ".delete_node")
create l_parameters.make (1)
l_parameters.put (a_id, "id")
db_handler.set_query (create {DATABASE_QUERY}.data_reader (sql_delete_node, l_parameters))
db_handler.execute_change
end
feature -- Connection
connect
-- Connect to the database.
do
if not db_handler.is_connected then
db_handler.connect
end
end
disconnect
-- Disconnect to the database.
do
if db_handler.is_connected then
db_handler.disconnect
end
end
feature {NONE} -- Queries
Select_count: STRING = "select count(*) from Nodes;"
Select_nodes: STRING = "select * from Nodes;"
-- SQL Query to retrieve all nodes.
Select_node_by_id: STRING = "select * from Nodes where id =:id order by id desc, publication_date desc;"
Select_recent_nodes: STRING = "select * from Nodes order by id desc, publication_date desc Limit $offset , :rows "
SQL_Insert_node: STRING = "insert into nodes (title, summary, content, publication_date, creation_date, modification_date) values (:title, :summary, :content, :publication_date, :creation_date, :modification_date);"
-- SQL Insert to add a new node.
SQL_Update_node_title: STRING ="update nodes SET title=:title, modification_date=:modification_date where id=:id;"
-- SQL update node title.
SQL_Update_node_summary: STRING ="update nodes SET summary=:summary, modification_date=:modification_date where id=:id;"
-- SQL update node summary.
SQL_Update_node_content: STRING ="update nodes SET content=:content, modification_date=:modification_date where id=:id;"
-- SQL node content.
SQL_Update_node : STRING = "update nodes SET title=:title, summary=:summary, content=:content, publication_date=:publication_date, creation_date=:creation_date, modification_date=:modification_date where id=:id;"
-- SQL node.
SQL_Delete_node: STRING = "delete from nodes where id=:id;"
feature -- New Object
fetch_node: CMS_NODE
do
create Result.make ("", "", "")
if attached db_handler.read_integer_32 (1) as l_id then
Result.set_id (l_id)
end
if attached db_handler.read_date_time (2) as l_pd then
Result.set_publication_date (l_pd)
end
if attached db_handler.read_date_time (3) as l_cd then
Result.set_creation_date (l_cd)
end
if attached db_handler.read_date_time (4) as l_md then
Result.set_modification_date (l_md)
end
if attached db_handler.read_string (5) as l_t then
Result.set_title (l_t)
end
if attached db_handler.read_string (6) as l_s then
Result.set_summary (l_s)
end
if attached db_handler.read_string (7) as l_c then
Result.set_content (l_c)
end
end
end

View File

@@ -1,193 +0,0 @@
note
description: "Summary description for {USER_DATA_PROVIDER}."
date: "$Date: 2014-11-13 12:23:47 -0300 (ju., 13 nov. 2014) $"
revision: "$Revision: 96085 $"
class
USER_DATA_PROVIDER
inherit
PARAMETER_NAME_HELPER
SHARED_ERROR
REFACTORING_HELPER
create
make
feature -- Initialization
make (a_connection: DATABASE_CONNECTION)
-- Create a data provider.
do
create {DATABASE_HANDLER_IMPL} db_handler.make (a_connection)
end
db_handler: DATABASE_HANDLER
-- Db handler.
feature -- Status Report
is_successful: BOOLEAN
-- Is the last execution sucessful?
do
Result := not db_handler.has_error
end
has_user: BOOLEAN
-- Has any user?
do
Result := count > 0
end
feature -- Basic Operations
new_user (a_user_name: READABLE_STRING_32; a_password: READABLE_STRING_32; a_email: READABLE_STRING_32)
-- Create a new node.
local
l_parameters: STRING_TABLE [detachable ANY]
l_password_salt, l_password_hash: STRING
l_security: SECURITY_PROVIDER
do
create l_security
l_password_salt := l_security.salt
l_password_hash := l_security.password_hash (a_password, l_password_salt)
log.write_information (generator + ".new_user")
create l_parameters.make (4)
l_parameters.put (a_user_name,"username")
l_parameters.put (l_password_hash,"password")
l_parameters.put (l_password_salt,"salt")
l_parameters.put (a_email,"email")
db_handler.set_query (create {DATABASE_QUERY}.data_reader (sql_insert_user, l_parameters))
db_handler.execute_change
end
user (a_id: INTEGER_64): detachable CMS_USER
-- User for the given id `a_id', if any.
local
l_parameters: STRING_TABLE [ANY]
do
log.write_information (generator + ".user")
create l_parameters.make (1)
l_parameters.put (a_id,"id")
db_handler.set_query (create {DATABASE_QUERY}.data_reader (select_user_by_id, l_parameters))
db_handler.execute_query
if db_handler.count = 1 then
Result := fetch_user
end
end
user_by_name (a_name: READABLE_STRING_32): detachable CMS_USER
-- User for the given name `a_name', if any.
local
l_parameters: STRING_TABLE [ANY]
do
log.write_information (generator + ".user_by_name")
create l_parameters.make (1)
l_parameters.put (a_name,"name")
db_handler.set_query (create {DATABASE_QUERY}.data_reader (select_user_by_name, l_parameters))
db_handler.execute_query
if db_handler.count = 1 then
Result := fetch_user
end
end
user_by_email (a_email: detachable READABLE_STRING_32): detachable CMS_USER
-- User for the given email `a_email', if any.
local
l_parameters: STRING_TABLE [detachable ANY]
do
log.write_information (generator + ".user_by_email")
create l_parameters.make (1)
l_parameters.put (a_email,"email")
db_handler.set_query (create {DATABASE_QUERY}.data_reader (select_user_by_email, l_parameters))
db_handler.execute_query
if db_handler.count = 1 then
Result := fetch_user
end
end
user_salt (a_username: READABLE_STRING_32): detachable READABLE_STRING_32
-- User salt for the given user `a_username', if any.
local
l_parameters: STRING_TABLE [ANY]
do
log.write_information (generator + ".user_salt")
create l_parameters.make (1)
l_parameters.put (a_username,"name")
db_handler.set_query (create {DATABASE_QUERY}.data_reader (select_salt_by_username, l_parameters))
db_handler.execute_query
if db_handler.count = 1 then
if attached db_handler.read_string (1) as l_salt then
Result := l_salt.as_string_32
end
end
end
count: INTEGER
-- Number of items users.
local
l_parameters: STRING_TABLE [ANY]
do
log.write_information (generator + ".count")
create l_parameters.make (0)
db_handler.set_query (create {DATABASE_QUERY}.data_reader (select_count, l_parameters))
db_handler.execute_query
if db_handler.count = 1 then
Result := db_handler.read_integer_32 (1)
end
end
feature -- New Object
fetch_user: CMS_USER
do
create Result.make ("")
if attached db_handler.read_integer_32 (1) as l_id then
Result.set_id (l_id)
end
if attached db_handler.read_string (2) as l_u then
Result.set_name (l_u)
end
if attached db_handler.read_string (3) as l_p then
Result.set_password (l_p)
end
if attached db_handler.read_string (5) as l_e then
Result.set_email (l_e)
end
end
feature -- Sql Queries
Select_count: STRING = "select count(*) from Users;"
-- Number of users.
Select_user_by_id: STRING = "select * from Users where id =:id;"
-- Retrieve user by id if exists.
Select_user_by_name: STRING = "select * from Users where username =:name;"
-- Retrieve user by name if exists.
Select_user_by_email: STRING = "select * from Users where email =:email;"
-- Retrieve user by email if exists.
Select_salt_by_username: STRING = "select salt from Users where username =:name;"
-- Retrieve salt by username if exists.
SQL_Insert_user: STRING = "insert into users (username, password, salt, email) values (:username, :password, :salt, :email);"
-- SQL Insert to add a new node.
end

View File

@@ -1,7 +1,7 @@
note
description : "tests application root class"
date : "$Date: 2014-08-20 15:21:15 -0300 (mi., 20 ago. 2014) $"
revision : "$Revision: 95678 $"
date : "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $"
revision : "$Revision: 96542 $"
class
APPLICATION
@@ -17,14 +17,11 @@ feature {NONE} -- Initialization
make
-- Run application.
local
user: USER_DATA_PROVIDER
node: NODE_DATA_PROVIDER
l_security: SECURITY_PROVIDER
storage: CMS_STORAGE_SQLITE
do
-- Change the path.
-- Change the path.
create connection.login_with_connection_string ("Driver=SQLite3 ODBC Driver;Database=./cms_lite.db;LongNames=0;Timeout=1000;NoTXN=0;SyncPragma=NORMAL;StepAPI=0;")
create user.make (connection)
user.new_user ("test", "test", "test")
create storage.make (connection)
end
connection: DATABASE_CONNECTION_ODBC

View File

@@ -3,8 +3,8 @@ note
Eiffel tests that can be executed by testing tool.
]"
author: "EiffelStudio test wizard"
date: "$Date$"
revision: "$Revision$"
date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $"
revision: "$Revision: 96542 $"
testing: "type/manual"
class
@@ -30,7 +30,7 @@ feature {NONE} -- Events
-- <Precursor>
do
(create {CLEAN_DB}).clean_db(connection)
assert ("Empty Nodes", node_provider.nodes.after)
assert ("Empty Nodes", storage.nodes.after)
end
on_clean
@@ -42,13 +42,13 @@ feature -- Test routines
test_new_node
do
assert ("Empty Nodes", node_provider.nodes.after)
node_provider.new_node (default_node)
assert ("Not empty Nodes after new_node", not node_provider.nodes.after)
assert ("Empty Nodes", storage.nodes.after)
storage.new_node (default_node)
assert ("Not empty Nodes after new_node", not storage.nodes.after)
-- Exist node with id 1
assert ("Exist node with id 1", attached node_provider.node (1))
assert ("Exist node with id 1", attached storage.node_by_id (1))
-- Not exist node with id 2
assert ("Not exist node with id 2", node_provider.node (2) = Void)
assert ("Not exist node with id 2", storage.node_by_id (2) = Void)
end
@@ -56,31 +56,31 @@ feature -- Test routines
local
l_node: CMS_NODE
do
assert ("Empty Nodes", node_provider.nodes.after)
assert ("Empty Nodes", storage.nodes.after)
l_node := custom_node ("<h1> test node udpate </h1>", "Update node", "Test case update")
node_provider.new_node (l_node)
assert ("Not empty Nodes after new_node", not node_provider.nodes.after)
storage.new_node (l_node)
assert ("Not empty Nodes after new_node", not storage.nodes.after)
-- Exist node with id 1
assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1) as ll_node and then ll_node.content ~ l_node.content and then ll_node.summary ~ l_node.summary and then ll_node.title ~ l_node.title )
assert ("Exist node with id 1", attached {CMS_NODE} storage.node_by_id (1) as ll_node and then ll_node.content ~ l_node.content and then ll_node.summary ~ l_node.summary and then ll_node.title ~ l_node.title )
-- Update node (content and summary)
if attached {CMS_NODE} node_provider.node (1) as l_un then
if attached {CMS_NODE} storage.node_by_id (1) as l_un then
l_un.set_content ("<h1>Updating test node udpate </h1>")
l_un.set_summary ("updating summary")
node_provider.update_node (l_un)
assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1) as ll_node and then not (ll_node.content ~ l_node.content) and then not (ll_node.summary ~ l_node.summary) and then ll_node.title ~ l_node.title )
assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1) as ll_node and then ll_node.content ~ l_un.content and then ll_node.summary ~ l_un.summary and then ll_node.title ~ l_un.title )
storage.update_node (l_un)
assert ("Exist node with id 1", attached {CMS_NODE} storage.node_by_id (1) as ll_node and then not (ll_node.content ~ l_node.content) and then not (ll_node.summary ~ l_node.summary) and then ll_node.title ~ l_node.title )
assert ("Exist node with id 1", attached {CMS_NODE} storage.node_by_id (1) as ll_node and then ll_node.content ~ l_un.content and then ll_node.summary ~ l_un.summary and then ll_node.title ~ l_un.title )
end
-- Update node (content and summary and title)
if attached {CMS_NODE} node_provider.node (1) as l_un then
if attached {CMS_NODE} storage.node_by_id (1) as l_un then
l_un.set_content ("<h1>Updating test node udpate </h1>")
l_un.set_summary ("updating summary")
l_un.set_title ("Updating Test case")
node_provider.update_node (l_un)
assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1) as ll_node and then not (ll_node.content ~ l_node.content) and then not (ll_node.summary ~ l_node.summary) and then not (ll_node.title ~ l_node.title) )
assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1) as ll_node and then ll_node.content ~ l_un.content and then ll_node.summary ~ l_un.summary and then ll_node.title ~ l_un.title )
storage.update_node (l_un)
assert ("Exist node with id 1", attached {CMS_NODE} storage.node_by_id (1) as ll_node and then not (ll_node.content ~ l_node.content) and then not (ll_node.summary ~ l_node.summary) and then not (ll_node.title ~ l_node.title) )
assert ("Exist node with id 1", attached {CMS_NODE} storage.node_by_id (1) as ll_node and then ll_node.content ~ l_un.content and then ll_node.summary ~ l_un.summary and then ll_node.title ~ l_un.title )
end
end
@@ -88,18 +88,18 @@ feature -- Test routines
local
l_node: CMS_NODE
do
assert ("Empty Nodes", node_provider.nodes.after)
assert ("Empty Nodes", storage.nodes.after)
l_node := custom_node ("<h1> test node udpate </h1>", "Update node", "Test case update")
node_provider.new_node (l_node)
assert ("Not empty Nodes after new_node", not node_provider.nodes.after)
storage.new_node (l_node)
assert ("Not empty Nodes after new_node", not storage.nodes.after)
-- Exist node with id 1
assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1) as ll_node and then ll_node.content ~ l_node.content and then ll_node.summary ~ l_node.summary and then ll_node.title ~ l_node.title )
assert ("Exist node with id 1", attached {CMS_NODE} storage.node_by_id (1) as ll_node and then ll_node.content ~ l_node.content and then ll_node.summary ~ l_node.summary and then ll_node.title ~ l_node.title )
-- Update node title
if attached {CMS_NODE} node_provider.node (1) as l_un then
node_provider.update_node_title (l_un.id, "New Title")
assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1) as ll_node and then ll_node.content ~ l_un.content and then ll_node.summary ~ l_un.summary and then not ( ll_node.title ~ l_un.title) and then ll_node.title ~ "New Title" )
if attached {CMS_NODE} storage.node_by_id (1) as l_un then
storage.update_node_title (1, l_un.id, "New Title")
assert ("Exist node with id 1", attached {CMS_NODE} storage.node_by_id (1) as ll_node and then ll_node.content ~ l_un.content and then ll_node.summary ~ l_un.summary and then not ( ll_node.title ~ l_un.title) and then ll_node.title ~ "New Title" )
end
end
@@ -107,18 +107,18 @@ feature -- Test routines
local
l_node: CMS_NODE
do
assert ("Empty Nodes", node_provider.nodes.after)
assert ("Empty Nodes", storage.nodes.after)
l_node := custom_node ("<h1> test node udpate </h1>", "Update node", "Test case update")
node_provider.new_node (l_node)
assert ("Not empty Nodes after new_node", not node_provider.nodes.after)
storage.new_node (l_node)
assert ("Not empty Nodes after new_node", not storage.nodes.after)
-- Exist node with id 1
assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1) as ll_node and then ll_node.content ~ l_node.content and then ll_node.summary ~ l_node.summary and then ll_node.title ~ l_node.title )
assert ("Exist node with id 1", attached {CMS_NODE} storage.node_by_id (1) as ll_node and then ll_node.content ~ l_node.content and then ll_node.summary ~ l_node.summary and then ll_node.title ~ l_node.title )
-- Update node summary
if attached {CMS_NODE} node_provider.node (1) as l_un then
node_provider.update_node_summary (l_un.id,"New Summary")
assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1) as ll_node and then ll_node.content ~ l_un.content and then not (ll_node.summary ~ l_un.summary) and then ll_node.summary ~ "New Summary" and then ll_node.title ~ l_un.title)
if attached {CMS_NODE} storage.node_by_id (1) as l_un then
storage.update_node_summary (1, l_un.id,"New Summary")
assert ("Exist node with id 1", attached {CMS_NODE} storage.node_by_id (1) as ll_node and then ll_node.content ~ l_un.content and then not (ll_node.summary ~ l_un.summary) and then ll_node.summary ~ "New Summary" and then ll_node.title ~ l_un.title)
end
end
@@ -126,18 +126,18 @@ feature -- Test routines
local
l_node: CMS_NODE
do
assert ("Empty Nodes", node_provider.nodes.after)
assert ("Empty Nodes", storage.nodes.after)
l_node := custom_node ("<h1> test node udpate </h1>", "Update node", "Test case update")
node_provider.new_node (l_node)
assert ("Not empty Nodes after new_node", not node_provider.nodes.after)
storage.new_node (l_node)
assert ("Not empty Nodes after new_node", not storage.nodes.after)
-- Exist node with id 1
assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1) as ll_node and then ll_node.content ~ l_node.content and then ll_node.summary ~ l_node.summary and then ll_node.title ~ l_node.title )
assert ("Exist node with id 1", attached {CMS_NODE} storage.node_by_id (1) as ll_node and then ll_node.content ~ l_node.content and then ll_node.summary ~ l_node.summary and then ll_node.title ~ l_node.title )
-- Update node content
if attached {CMS_NODE} node_provider.node (1) as l_un then
node_provider.update_node_content (l_un.id,"New Content")
assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1) as ll_node and then not (ll_node.content ~ l_un.content) and then ll_node.content ~ "New Content" and then ll_node.summary ~ l_un.summary and then ll_node.title ~ l_un.title)
if attached {CMS_NODE} storage.node_by_id (1) as l_un then
storage.update_node_content (1, l_un.id, "New Content")
assert ("Exist node with id 1", attached {CMS_NODE} storage.node_by_id (1) as ll_node and then not (ll_node.content ~ l_un.content) and then ll_node.content ~ "New Content" and then ll_node.summary ~ l_un.summary and then ll_node.title ~ l_un.title)
end
end
@@ -146,17 +146,17 @@ feature -- Test routines
local
l_node: CMS_NODE
do
assert ("Empty Nodes", node_provider.nodes.after)
assert ("Empty Nodes", storage.nodes.after)
l_node := custom_node ("<h1> test node udpate </h1>", "Update node", "Test case update")
node_provider.new_node (l_node)
assert ("Not empty Nodes after new_node", not node_provider.nodes.after)
storage.new_node (l_node)
assert ("Not empty Nodes after new_node", not storage.nodes.after)
-- Exist node with id 1
assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1) as ll_node and then ll_node.content ~ l_node.content and then ll_node.summary ~ l_node.summary and then ll_node.title ~ l_node.title )
assert ("Exist node with id 1", attached {CMS_NODE} storage.node_by_id (1) as ll_node and then ll_node.content ~ l_node.content and then ll_node.summary ~ l_node.summary and then ll_node.title ~ l_node.title )
-- Delte node 1
node_provider.delete_node (1)
assert ("Node does not exist", node_provider.node (1) = Void)
storage.delete_node_by_id (1)
assert ("Node does not exist", storage.node_by_id (1) = Void)
end
test_recent_nodes
@@ -167,57 +167,37 @@ feature -- Test routines
local
i : INTEGER
do
assert ("Empty Nodes", node_provider.nodes.after)
assert ("Empty Nodes", storage.nodes.after)
across 1 |..| 10 as c loop
node_provider.new_node (custom_node ("Content_" + c.item.out, "Summary_" + c.item.out, "Title_" + c.item.out))
storage.new_node (custom_node ("Content_" + c.item.out, "Summary_" + c.item.out, "Title_" + c.item.out))
end
-- Scenario (0,10) rows, recents (10 down to 1)
i := 10
across node_provider.recent_nodes (0, 10) as c loop
across storage.recent_nodes (0, 10) as c loop
assert ("Same id:" + i.out, c.item.id = i)
i := i - 1
end
-- Scenario (5, 10) rows, recent nodes (5 down to 1)
i := 5
across node_provider.recent_nodes (5, 10) as c loop
across storage.recent_nodes (5, 10) as c loop
assert ("Same id:" + i.out, c.item.id = i)
i := i - 1
end
-- Scenario (9,10) rows, recent node 1
i := 1
across node_provider.recent_nodes (9, 10) as c loop
across storage.recent_nodes (9, 10) as c loop
assert ("Same id:" + i.out, c.item.id = i)
i := i - 1
end
-- Scenrario 10..10 empty
assert ("Empty", node_provider.recent_nodes (10, 10).after)
assert ("Empty", storage.recent_nodes (10, 10).after)
end
feature {NONE} -- Implementation
node_provider: NODE_DATA_PROVIDER
-- node provider.
once
create Result.make (connection)
end
feature {NONE} -- Implementation Fixture Factories
default_node: CMS_NODE
do
Result := custom_node ("Default content", "default summary", "Default")
end
custom_node (a_content, a_summary, a_title: READABLE_STRING_32): CMS_NODE
do
create Result.make (a_content, a_summary, a_title)
end
end

View File

@@ -1,8 +1,8 @@
note
description: "Summary description for {STORAGE_TEST_SET}."
author: ""
date: "$Date$"
revision: "$Revision$"
date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $"
revision: "$Revision: 96542 $"
class
STORAGE_TEST_SET
@@ -177,7 +177,7 @@ feature -- Test routines
l_nodes: LIST[CMS_NODE]
do
across 1 |..| 10 as c loop
storage.save_node (custom_node ("Content_" + c.item.out, "Summary_" + c.item.out, "Title_" + c.item.out))
storage.new_node (custom_node ("Content_" + c.item.out, "Summary_" + c.item.out, "Title_" + c.item.out))
end
l_nodes := storage.recent_nodes (0, 10)
assert ("10 recent nodes", l_nodes.count = 10)
@@ -200,124 +200,74 @@ feature -- Test routines
end
test_node_does_not_exist
local
l_nodes: LIST[CMS_NODE]
do
across 1 |..| 10 as c loop
storage.save_node (custom_node ("Content_" + c.item.out, "Summary_" + c.item.out, "Title_" + c.item.out))
storage.new_node (custom_node ("Content_" + c.item.out, "Summary_" + c.item.out, "Title_" + c.item.out))
end
assert ("Not exist node id: 12", storage.node (12) = Void)
assert ("Not exist node id: 12", storage.node_by_id (12) = Void)
end
test_node
local
l_nodes: LIST[CMS_NODE]
do
across 1 |..| 10 as c loop
storage.save_node (custom_node ("Content_" + c.item.out, "Summary_" + c.item.out, "Title_" + c.item.out))
storage.new_node (custom_node ("Content_" + c.item.out, "Summary_" + c.item.out, "Title_" + c.item.out))
end
assert ("Node id: 10", attached storage.node (10) as l_node and then l_node.title ~ "Title_10" )
assert ("has nodes", storage.nodes.count > 5)
assert ("Node id: 10", attached storage.node_by_id (10) as l_node and then l_node.title ~ "Title_10" )
end
test_update_node
local
l_nodes: LIST[CMS_NODE]
l_node: CMS_NODE
do
storage.save_node (custom_node ("Content", "Summary", "Title"))
if attached {CMS_NODE} storage.node (1) as ll_node then
storage.new_node (custom_node ("Content", "Summary", "Title"))
if attached {CMS_NODE} storage.node_by_id (1) as ll_node then
l_node := ll_node.twin
l_node.set_content ("New Content")
l_node.set_summary ("New Summary")
l_node.set_title("New Title")
-- storage.update_node (l_node)
assert ("Updated", attached {CMS_NODE} storage.node (1) as u_node and then not (u_node.title ~ ll_node.title) and then not (u_node.content ~ ll_node.content) and then not (u_node.summary ~ ll_node.summary))
assert ("Updated", attached {CMS_NODE} storage.node_by_id (1) as u_node and then not (u_node.title ~ ll_node.title) and then not (u_node.content ~ ll_node.content) and then not (u_node.summary ~ ll_node.summary))
end
end
test_update_node_title
local
l_nodes: LIST[CMS_NODE]
l_node: CMS_NODE
do
storage.save_node (custom_node ("Content", "Summary", "Title"))
if attached {CMS_NODE} storage.node (1) as ll_node then
storage.new_node (custom_node ("Content", "Summary", "Title"))
if attached {CMS_NODE} storage.node_by_id (1) as ll_node then
-- storage.update_node_title (ll_node.id, "New Title")
assert ("Updated", attached {CMS_NODE} storage.node (1) as u_node and then not (u_node.title ~ ll_node.title) and then u_node.content ~ ll_node.content and then u_node.summary ~ ll_node.summary)
assert ("Updated", attached {CMS_NODE} storage.node_by_id (1) as u_node and then not (u_node.title ~ ll_node.title) and then u_node.content ~ ll_node.content and then u_node.summary ~ ll_node.summary)
end
end
test_update_node_summary
local
l_nodes: LIST[CMS_NODE]
l_node: CMS_NODE
do
storage.save_node (custom_node ("Content", "Summary", "Title"))
if attached {CMS_NODE} storage.node (1) as ll_node then
storage.new_node (custom_node ("Content", "Summary", "Title"))
if attached {CMS_NODE} storage.node_by_id (1) as ll_node then
-- storage.update_node_summary (ll_node.id, "New Summary")
assert ("Updated", attached {CMS_NODE} storage.node (1) as u_node and then u_node.title ~ ll_node.title and then u_node.content ~ ll_node.content and then not (u_node.summary ~ ll_node.summary))
assert ("Updated", attached {CMS_NODE} storage.node_by_id (1) as u_node and then u_node.title ~ ll_node.title and then u_node.content ~ ll_node.content and then not (u_node.summary ~ ll_node.summary))
end
end
test_update_node_content
local
l_nodes: LIST[CMS_NODE]
l_node: CMS_NODE
do
storage.save_node (custom_node ("Content", "Summary", "Title"))
if attached {CMS_NODE} storage.node (1) as ll_node then
storage.new_node (custom_node ("Content", "Summary", "Title"))
if attached {CMS_NODE} storage.node_by_id (1) as ll_node then
-- storage.update_node_content (ll_node.id, "New Content")
assert ("Updated", attached {CMS_NODE} storage.node (1) as u_node and then u_node.title ~ ll_node.title and then not (u_node.content ~ ll_node.content) and then u_node.summary ~ ll_node.summary)
assert ("Updated", attached {CMS_NODE} storage.node_by_id (1) as u_node and then u_node.title ~ ll_node.title and then not (u_node.content ~ ll_node.content) and then u_node.summary ~ ll_node.summary)
end
end
test_delete_node
local
l_nodes: LIST[CMS_NODE]
do
across 1 |..| 10 as c loop
storage.save_node (custom_node ("Content_" + c.item.out, "Summary_" + c.item.out, "Title_" + c.item.out))
storage.new_node (custom_node ("Content_" + c.item.out, "Summary_" + c.item.out, "Title_" + c.item.out))
end
assert ("Exist node id: 10", attached storage.node (10) as l_node and then l_node.title ~ "Title_10" )
storage.delete_node (10)
assert ("Not exist node id: 10", storage.node (10) = Void)
assert ("Exist node id: 10", attached storage.node_by_id (10) as l_node and then l_node.title ~ "Title_10" )
storage.delete_node_by_id (10)
assert ("Not exist node id: 10", storage.node_by_id (10) = Void)
end
feature {NONE} -- Implementation
storage: CMS_STORAGE
-- Storage
once
create {CMS_STORAGE_SQLITE}Result.make (connection)
end
feature {NONE} -- Fixture Factory: Users
default_user: CMS_USER
do
Result := custom_user ("test", "password", "test@test.com")
end
custom_user (a_name, a_password, a_email: READABLE_STRING_32): CMS_USER
do
create Result.make (a_name)
Result.set_password (a_password)
Result.set_email (a_email)
end
feature {NONE} -- Fixture Factories: Nodes
default_node: CMS_NODE
do
Result := custom_node ("Default content", "default summary", "Default")
end
custom_node (a_content, a_summary, a_title: READABLE_STRING_32): CMS_NODE
do
create Result.make (a_content, a_summary, a_title)
end
end

View File

@@ -7,6 +7,7 @@
</option>
<setting name="concurrency" value="thread"/>
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>
<library name="cms" location="..\..\..\..\..\cms-safe.ecf" readonly="false"/>
<library name="crypto" location="$ISE_LIBRARY\unstable\library\text\encryption\crypto\crypto-safe.ecf"/>
<library name="model" location="..\..\..\..\model\cms_model-safe.ecf"/>
<library name="persitence_sqlite" location="..\persistence_sqlite-safe.ecf" readonly="false"/>

View File

@@ -3,8 +3,8 @@ note
Eiffel tests that can be executed by testing tool.
]"
author: "EiffelStudio test wizard"
date: "$Date$"
revision: "$Revision$"
date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $"
revision: "$Revision: 96542 $"
testing: "type/manual"
class
@@ -30,7 +30,7 @@ feature {NONE} -- Events
-- <Precursor>
do
(create {CLEAN_DB}).clean_db(connection)
user_provider.new_user ("admin", "admin","admin@admin.com")
storage.new_user (custom_user ("admin", "admin","admin@admin.com"))
end
on_clean
@@ -43,36 +43,30 @@ 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"))
assert ("Not void", attached storage.user_by_email ("admin@admin.com"))
assert ("Not void", attached storage.user_by_id (1))
assert ("Not void", attached storage.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)
assert ("Void", storage.user_by_email ("test@admin.com") = Void)
assert ("Void", storage.user_by_id (2) = Void )
assert ("Void", storage.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"))
storage.new_user (custom_user ("test", "test","test@admin.com"))
assert ("Not void", attached storage.user_by_email ("test@admin.com"))
assert ("Not void", attached storage.user_by_id (2))
assert ("Not void", attached storage.user_by_id (2) as l_user and then l_user.id = 2 and then l_user.name ~ "test")
assert ("Not void", attached storage.user_by_name ("test"))
end
feature {NONE} -- Implementation
user_provider: USER_DATA_PROVIDER
-- user provider.
once
create Result.make (connection)
end
end

View File

@@ -1,7 +1,7 @@
note
description: "Summary description for {ABSTRACT_DB_TEST}."
date: "$Date$"
revision: "$Revision$"
date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $"
revision: "$Revision: 96542 $"
class
ABSTRACT_DB_TEST
@@ -12,8 +12,43 @@ feature -- Database connection
connection: DATABASE_CONNECTION_ODBC
-- odbc database connection
once
-- create Result.login_with_connection_string ("Driver=SQLite3 ODBC Driver;Database=PATH/SQLITE.FILE;LongNames=0;Timeout=1000;NoTXN=0;SyncPragma=NORMAL;StepAPI=0;")
create Result.make_basic ("cms_dev")
create Result.login_with_connection_string ("Driver=SQLite3 ODBC Driver;Database=cms_lite.db;LongNames=0;Timeout=1000;NoTXN=0;SyncPragma=NORMAL;StepAPI=0;")
-- create Result.make_basic ("cms_lite.db")
end
feature {NONE} -- Implementation
storage: CMS_STORAGE
-- node provider.
once
create {CMS_STORAGE_SQLITE} Result.make (connection)
end
feature {NONE} -- Fixture Factory: Users
default_user: CMS_USER
do
Result := custom_user ("test", "password", "test@test.com")
end
custom_user (a_name, a_password, a_email: READABLE_STRING_32): CMS_USER
do
create Result.make (a_name)
Result.set_password (a_password)
Result.set_email (a_email)
end
feature {NONE} -- Fixture Factories: Nodes
default_node: CMS_NODE
do
Result := custom_node ("Default content", "default summary", "Default")
end
custom_node (a_content, a_summary, a_title: READABLE_STRING_32): CMS_NODE
do
create Result.make (a_content, a_summary, a_title)
end
end