text
stringlengths
0
234
Stmt.Add_Param (Value => Object.Get_Key);
Stmt.Add_Param (Value => Object.Version - 1);
declare
Result : Integer;
begin
Stmt.Execute (Result);
if Result /= 1 then
if Result /= 0 then
raise ADO.Objects.UPDATE_ERROR;
else
raise ADO.Objects.LAZY_LOCK;
end if;
end if;
Function Definition: procedure List_Comments (T : in out Test;
Function Body: User : in ADO.Identifier;
Into : out Util.Beans.Objects.Object) is
Comment_Manager : constant Comment_Module_Access := Get_Comment_Module;
Bean : Util.Beans.Basic.Readonly_Bean_Access;
List : AWA.Comments.Beans.Comment_List_Bean_Access;
begin
Bean := Beans.Create_Comment_List_Bean (Comment_Manager);
Into := Util.Beans.Objects.To_Object (Bean.all'Access);
List := AWA.Comments.Beans.Comment_List_Bean'Class (Bean.all)'Access;
List.Set_Value ("entity_type", Util.Beans.Objects.To_Object (String '("awa_user")));
Util.Tests.Assert_Equals (T, 0, Integer (List.Get_Count), "Invalid number of comments");
-- Load the existing comments.
List.Load_Comments (User);
end List_Comments;
-- ------------------------------
-- Create a comment and return the list of comments before and after the creation.
-- ------------------------------
procedure Create_Comment (T : in out Test;
Status : in AWA.Comments.Models.Status_Type;
Before : out Util.Beans.Objects.Object;
After : out Util.Beans.Objects.Object;
Id : out ADO.Identifier) is
Sec_Ctx : Security.Contexts.Security_Context;
Context : AWA.Services.Contexts.Service_Context;
begin
AWA.Tests.Helpers.Users.Login (Context, Sec_Ctx, "test-add-comment@test.com");
declare
Comment_Manager : constant Comment_Module_Access := Get_Comment_Module;
User : constant AWA.Users.Models.User_Ref := Context.Get_User;
Bean : Util.Beans.Basic.Readonly_Bean_Access;
Comment : AWA.Comments.Beans.Comment_Bean_Access;
Cleanup : Util.Beans.Objects.Object;
Outcome : Ada.Strings.Unbounded.Unbounded_String;
begin
T.Assert (Comment_Manager /= null, "There is no comment module");
T.List_Comments (User.Get_Id, Before);
-- Create a new comment associated with the current user.
Bean := Beans.Create_Comment_Bean (Comment_Manager);
Cleanup := Util.Beans.Objects.To_Object (Bean.all'Access);
Comment := AWA.Comments.Beans.Comment_Bean'Class (Bean.all)'Access;
Comment.Set_Value ("entity_type", Util.Beans.Objects.To_Object (String '("awa_user")));
Comment.Set_Value ("permission", Util.Beans.Objects.To_Object (String '("logged-user")));
Comment.Set_Status (Status);
Comment.Set_Entity_Id (User.Get_Id);
-- Create the comment.
Comment.Set_Message ("the comment message for the current user " &
AWA.Comments.Models.Status_Type'Image (Status));
Comment.Create (Outcome);
Id := Comment.Get_Id;
T.Assert (Id /= ADO.NO_IDENTIFIER, "Invalid new comment identifier");
-- Load again the comments.
T.List_Comments (User.Get_Id, After);
T.Assert (not Util.Beans.Objects.Is_Null (Cleanup), "Comment bean is null");
Function Definition: procedure Test_Create_Published_Comment (T : in out Test) is
Function Body: Before : Util.Beans.Objects.Object;
After : Util.Beans.Objects.Object;
Id : ADO.Identifier;
begin
T.Create_Comment (AWA.Comments.Models.COMMENT_PUBLISHED, Before, After, Id);
declare
Before_Count : constant Natural := Get_Count (Before);
After_Count : constant Natural := Get_Count (After);
begin
Util.Tests.Assert_Equals (T, Before_Count + 1, After_Count,
"The new comment does not appear in the list");
Function Definition: procedure Test_Publish_Comment (T : in out Test) is
Function Body: Before : Util.Beans.Objects.Object;
After : Util.Beans.Objects.Object;
Sec_Ctx : Security.Contexts.Security_Context;
Context : AWA.Services.Contexts.Service_Context;
Id : ADO.Identifier;
begin
T.Create_Comment (AWA.Comments.Models.COMMENT_WAITING, Before, After, Id);
Util.Tests.Assert_Equals (T, Get_Count (Before), Get_Count (After),
"The new comment MUST not be in the list");