#=============================================================================================
# @TITLE				Configuration - Users
#
# @NUMBER				WDBM_FKT_02054
#
# @DESCRIPTION			The for 'Configuration - Users' will be used and the shown table will
# @						be checked.
#
# @EXP_RESULT			The database1 verfiy will work.
#
# @REQUIREMENTS			Test: WDBM_FKT_01000; WDBM_FKT_00100; WDBM_FKT_01010;
#=============================================================================================

public function trim (in str) {
	if (substr(str, 1, 1) == " ") {

		str = trim(substr(str, 2));
	}
	if (substr(str, length(str)) == " ") {
		str = trim(substr(str, 1, length(str)-1));
	}
	return (str);
}

static table_1_ok = 1;
static table_2_ok = 1;

static table_1 [] =	{
						{"Name","Second Pwd","Disabled","Comment"},
						{"dbm","NO","NO","First Database Manager Operator"},
						{"DOMAIN","NO","NO",""},
						{"dba","NO","NO","Database System Administrator (SYSDBA)"}
					};
static table_2 [] =	{
						{"Name","Second Pwd","Disabled","Comment"},
						{"dbm","NO","NO","First Database Manager Operator"},
						{"DOMAIN","NO","NO",""},
						{"dba","NO","NO","Database System Administrator (SYSDBA)"},
						{"test","YES","NO","test user, can be deleted"}
					};
#=============================================================================================
# @STEP	1			Clicking the 'Configuration - Users' link.
#=============================================================================================
set_window(menu_window, 0);
web_link_click("Users");
set_window(work_window,3);
web_obj_get_text("Information - CACHES - DB73","#1","#1",text,"","",1);
if (text == "Configuration - Users") {
	
	tl_step ("Configuration - Users","0","Header of work frame is correct");
#=============================================================================================
# @STEP	2			Refresh.
#=============================================================================================
	set_window(work_window,3);
	if (new_interface == "1") {
		web_image_click("1x1.gif", 7, 9);
	} else {
		web_image_click("refresh", 9, 4);
	}
	
	set_window(work_window,3);
	web_obj_get_text("Information - CACHES - DB73","#1","#1",text_1,"","",1);
	
	if (text_1 == "Configuration - Users") {
		tl_step ("Configuration - Users","0","Header of work frame after refresh is correct");
#=============================================================================================
# @STEP	3			Checking table.
#=============================================================================================
		set_window(work_window,3);
		tbl_get_cols_count("Database Users",cols_count);
		tbl_get_rows_count("Database Users",rows_count);

		for (i=0;i<rows_count;i++) {
			
			for (n=0;n<cols_count;n++) {
				
				set_window (work_window,3);
				web_obj_get_text ("Database Users", "#"&(n+1), "#"&(i+1), content, "", "", 1);
		
				if (trim(content) != table_1[n,i]) {
					table_1_ok = 0;
					break;
				}
			}
		}

		if (table_1_ok == 0) {
			tl_step ("Configuration - Users","1","Table content is incorrect.");
		} else {
			tl_step ("Configuration - Users","0","Table content is correct.");
		}
#=============================================================================================
# @STEP	4			Creating new user.
#=============================================================================================	
		set_window(work_window,3);
		web_link_click("Add User");

		set_window(work_window,3);
		web_obj_get_text("Information - CACHES - DB73","#1","#1",text_2,"","",1);
		
		if (text_2 == "Configuration - Users - New User") {
			tl_step ("Configuration - Users - New User","0","Header of work frame is correct");
			
			if (obj_exists("Name",0) == E_OK &&
				obj_exists("Password",0) == E_OK &&
				obj_exists("PwdConfirm",0) == E_OK &&
				obj_exists("Disabled",0) == E_OK &&
				obj_exists("Comment",0) == E_OK &&
				obj_exists("Comment",0) == E_OK &&
				obj_exists("Password2",0) == E_OK &&
				obj_exists("Pwd2Confirm",0) == E_OK) {
				
				tl_step ("Configuration - Users - New User","0","All input fields are displayed.");
				#Checking the server rights
				
				ControlCount = 0;
				
				for (m=0;m<15;m++) {
					
					set_window(work_window,3);
					ControlName = "SrvRight_" & m;
					
					if (obj_exists (ControlName, 0) == E_OK) {
						ControlCount++;
					} else {
						tl_step ("Configuration - Users - New User","1","Checkbox for server rights not displayed - " & ControlName);
					}
				}
				
				if (ControlCount == 14) {
					tl_step ("Configuration - Users - New User","0","All checkboxes for server rights displayed.");
				}
				
				set_window(work_window,3);
				edit_set("Name","test");								# user name
				password_edit_set("Password","3d750d7813a2bece");		# password
				password_edit_set("PwdConfirm","3d750d7813a2bece");		# confirm password
				edit_set("Comment","test user, can be deleted");		# comment
				password_edit_set("Password2","1f175657a5096740");		# password #2
				password_edit_set("Pwd2Confirm","1f175657a5096740");	# confirm password #2
				
				web_link_click("OK");
				
				set_window(work_window,3);
				web_obj_get_text("Information - CACHES - DB73","#1","#1",text_3,"","",1);
				
				if (text_3 == "Configuration - Users") {
					
					#Checking user table with new user 'test' 
					
					set_window(work_window,3);
					tbl_get_cols_count("Database Users",cols_count);
					tbl_get_rows_count("Database Users",rows_count);
			
					for (i=0;i<rows_count;i++) {
						
						for (n=0;n<cols_count;n++) {
							
							set_window (work_window,3);
							web_obj_get_text ("Database Users", "#"&(n+1), "#"&(i+1), content, "", "", 1);
					
							if (trim(content) != table_2[n,i]) {
								table_2_ok = 0;
								break;
							}
						}
					}
					
					if (table_2_ok == 0) {
						tl_step ("Configuration - Users - New User","1","New user not created correctly. User table content correct.");
					} else {
						tl_step ("Configuration - Users - New User","0","New user successfully created. User table content incorrect.");
						
						#Checking properties of the new user
						set_window (work_window,3);
						web_link_click("test");
						
						set_window(work_window,3);
						web_obj_get_text("Information - CACHES - DB73","#1","#1",text_3,"","",1);
						
						if (text_3 == "Configuration - Users - test") {
				
							set_window (work_window,3);
							if (obj_exists("NameRO",0) == E_OK &&
								obj_exists("Change...",0) == E_OK &&
								obj_exists("Disabled",0) == E_OK &&
								obj_exists("Comment",0) == E_OK &&
								obj_exists("Change..._1",0) == E_OK) {
							
								tl_step ("Configuration - Users - New User","0","All input fields are displayed.");
								
								set_window(work_window,3);
								web_obj_get_text("NameRO","#0","#0",text_NameRO,"","",1);
								web_obj_get_text("Comment","#0","#0",text_Comment,"","",1);
								
								if (text_NameRO == "test" &&
									text_Comment == "test user, can be deleted") {
									
									#Changing first password
									set_window(work_window,3);
									web_link_click("Change...");
									
									set_window(work_window,3);
									web_obj_get_text("Information - CACHES - DB73","#1","#1",text_3,"","",1);
									
									if (text_3 == "Configuration - Users - test") {
										
										# Entering no new password just clicking 'OK' - expecting error or same mask
										web_link_click("OK");
										
										set_window(work_window,3);
										web_obj_get_text("Information - CACHES - DB73","#1","#1",text_3,"","",1);
										
										if (text_3 == "Configuration - Users - test") {
											
											#################
											#################
											#################
											##################################
											
											#####   hier gehts weiter
											
											#################
											#################
											#################
											#################										
											
										} else {
											tl_step ("Configuration - Users - test (change password - empty password)","1","No error occurred.");
										}
									} else {
										tl_step ("Configuration - Users - test","1","Work frame header is incorrect.");
									}
								} else {
									tl_step ("Configuration - Users - test","1","Content of NameRO is wrong: '" & text_NameRO & "' expected: 'test'");
									tl_step ("Configuration - Users - test","1","Content of Comment is wrong: '" & text_Comment & "' expected: 'test'");
								}
							} else {
								tl_step ("Configuration - Users - New User","1","Not all input fields are displayed.");
							}
						} else {
							tl_step ("Configuration - Users - test","1","Work frame header is incorrect.");
						}
					}
				} else {
					
					if (match (text_3, "Error") != 0) {
						
						web_obj_get_text("1x1","#1","#1",text_4,"","",1);
						tl_step ("Configuration - Users - New User","1","Error occurred while creating new user (" & text_4 & ").");
						
						set_window (work_window,3);
						web_link_click("OK");
						set_window (work_window,3);
						web_link_click("Cancel");
					} else {
						tl_step ("Configuration - Users - New User","1","Error occurred while creating new user.");
					}
				}
		
				if (table_1_ok == 0) {
					tl_step ("Configuration - Users","1","Table content is incorrect.");
				} else {
					tl_step ("Configuration - Users","0","Table content is correct.");
				}
			} else {
				tl_step ("Configuration - Users - New User","1","Not all input fields are displayed.");
			}
		} else {
			tl_step ("Configuration - Users - New User","1","Header of work frame is incorrect");
		}		
	} else {
		tl_step ("Configuration - Users","1","Header of work frame after refresh is incorrect");
	}	
} else {
	tl_step ("Configuration - Users","1","Header of work frame is incorrect");
}