#=============================================================================================
#
# @TITLE			Configure users - Create new user.
#
# @NUMBER			DBM3_DBUser_009_Configure_users_NewUser
#
# @DESCRIPTION		Create new user
#
#=============================================================================================

static TestName = "DBM3_DBUser_009_Configure_users_NewUser";
static expHeaderTitle = "Configure Database Users / User Groups";
static expHeaderSubtitle = "Configure database user for the database administrator 'DBA'.";
static Failure = 0;

#=============================================================================================
# @STEP 1			check if Config Wizard is open --> texit
#=============================================================================================
if (win_exists("Configuration Wizard",0) != E_OK)
{
	tl_step ("Wizard not open",1,"Testname: " & TestName & ", Line:" & getvar("line_no"));
	texit("true");
}	

#=============================================================================================
# @STEP 2		check header title ---> texit
#=============================================================================================	
#get header title
set_window("Configuration Wizard", 1);
ActiveX_get_info("DBMWfr3.Framework","HeaderTitle",HeaderTitle);
ActiveX_get_info("DBMWfr3.Framework","HeaderSubtitle",HeaderSubtitle);

# check if header title is correct
if (HeaderTitle != expHeaderTitle || HeaderSubtitle != expHeaderSubtitle)
{
	tl_step ("Header title not correct",1,"Testname: " & TestName & ", Line:" & getvar("line_no"));
	texit("true");
}

#=============================================================================================
# @STEP 3		Check create NewUser Button and press it
#=============================================================================================

set_window ("Configuration Wizard", 7);
toolbar_get_button_info("msvb_lib_toolbar","New User",ENABLED,btn_NewUser);
if (btn_NewUserGroup == 0)
{
	tl_step ("btn_NewUser not available",1,"Testname: " & TestName & ", Line:" & getvar("line_no")); 
	texit("true");
}

toolbar_button_press ("msvb_lib_toolbar", "New User");

#=============================================================================================
# @STEP 4	 	Check if create NewUser Window appears
#=============================================================================================
if (win_exists("SQL User *",0) != E_OK)
{
	tl_step ("New User Group window not opened",1,"Testname: " & TestName & ", Line:" & getvar("line_no")); 
	texit("true");
}

set_window("SQL User *");

#=============================================================================================
# @STEP 5		 Select <General> Tab & check all Elements
#=============================================================================================
tab_select_item("tabPages","&General");

obj_get_info("txtName","enabled",text_name);
obj_get_info("txtPassword","enabled",text_password);
obj_get_info("txtConfirmPassword","enabled",text_confirm_password);
obj_get_info("comUsermode","enabled",list_user_class);
obj_get_info("comConnectMode","enabled",list_connection_mode);

if (text_name == 0 || text_password == 0 || text_confirm_password == 0 || list_user_class == 0 || list_connection_mode == 0)
{
	tl_step ("Elements not in correct state (SQL User Group Properties - New User Group)",1,"Testname: " & TestName & ", Line:" & getvar("line_no")); 
	Failure = 1;
}

#=============================================================================================
# @STEP 5.1		Check the Name/password/confirm password textField ---> texit
#=============================================================================================
# these fields must be enabled otherwise it is not possible to create a new user
if (text_name == 0 || text_password == 0 || text_confirm_password == 0)
{
	tl_step ("textfield Name/password/confirm password not enabled (SQL User Group Properties - New User Group)",1,"Testname: " & TestName & ", Line:" & getvar("line_no")); 
	texit("true");
}

#get the content of the three textfields
obj_get_text("txtName",text_NameContent);
obj_get_text("txtPassword",text_PasswordContent);
obj_get_text("txtConfirmPassword",text_ConfirmPasswordContent);

#check if they are empty
#set thier content to ""
if (text_NameContent != "" ||text_PasswordContent != "" || text_ConfirmPasswordContent != "")
{
	tl_step ("Textfield Name/password/confirm password is not empty (SQL User Properties - New User)",1,"Testname: " & TestName & ", Line:" & getvar("line_no")); 
	Failure = 1;
	edit_set("txtName","");
	edit_set("txtPassword","");
	edit_set("txtConfirmPassword","");
}

#check if OK Btn. is disabled (must be if all fields are empty)
button_get_info("OK","enabled",OK_enabled);

if (OK_enabled == 1) 
{
	tl_step ("OK button should be disabled (SQL User Properties - New User)",1,"Testname: " & TestName & ", Line:" & getvar("line_no")); 
	texit("true");
}

#=============================================================================================
# @STEP 5.2		Enter NewUser Name/password & check if OK Button gets enabled ---> texit
#=============================================================================================
edit_set("txtName","TEST_USER");
edit_set("txtPassword","test");
edit_set("txtConfirmPassword","test");

button_get_info("OK","enabled",OK_enabled);
if (OK_enabled == 0)
{
	tl_step ("OK should be enabled (SQL User Group Properties - New User Group)",1,"Testname: " & TestName & ", Line:" & getvar("line_no")); 
	texit("true");
}

#=============================================================================================
# @STEP 6		Select <Extended> Tab & check all Elements
#=============================================================================================
tab_select_item("tabPages","&Extended");


obj_get_info("txtPermlimit","enabled",text_Permlimit);
obj_get_info("txtTemplimit","enabled",text_TempLimit);
obj_get_info("txtTimeout","enabled",text_Timeout);
obj_get_info("txtCostwarning","enabled",text_CostWarning);
obj_get_info("txtCostlimit","enabled",text_CostLimit);
obj_get_info("comDefaultCode","enabled",text_DefaultCode);

if (text_Permlimit == 1 || text_TempLimit == 1 || text_Timeout == 0 || text_CostWarning == 0 || text_CostLimit == 0 || text_DefaultCode == 0)
{
	tl_step ("Elements not in correct state (SQL User Properties - New User)",1,"Testname: " & TestName & ", Line:" & getvar("line_no")); 
	Failure = 1; 
}

#=============================================================================================
# @STEP 6.1			check correct Timeout Value --> correct OK Button - enabled / else disabled 
#=============================================================================================
# value to LOW
edit_set ("txtTimeout","29");
button_get_info("OK","enabled",OK_enabled);
if (OK_enabled == 1)
{
	tl_step ("OK should be disabled because of illegal Timout value  (SQL User Properties - New User)",1,"Testname: " & TestName & ", Line:" & getvar("line_no")); 
	Failure = 1;
}
# value correct
edit_set ("txtTimeout","30");
button_get_info("OK","enabled",OK_enabled);
if (OK_enabled == 0)
{
	tl_step ("OK should be enabled [correctTimeout value]  (SQL User Properties - New User)",1,"Testname: " & TestName & ", Line:" & getvar("line_no")); 
	Failure = 1;
}
# value to HIGH
edit_set ("txtTimeout","32401");
button_get_info("OK","enabled",OK_enabled);
if (OK_enabled == 1)
{
	tl_step ("OK should be disabled because of illegal Timout value  (SQL User Properties - New User)",1,"Testname: " & TestName & ", Line:" & getvar("line_no")); 
	Failure = 1;
}
# value to correct
edit_set ("txtTimeout","32400");
button_get_info("OK","enabled",OK_enabled);
if (OK_enabled == 0)
{
	tl_step ("OK should be enabled [correctTimeout value]  (SQL User Properties - New User)",1,"Testname: " & TestName & ", Line:" & getvar("line_no")); 
	Failure = 1;
}


#=============================================================================================================
# @STEP 6.2			check correct CostWarning <-> CostLimit ratio --> correct OK Button - enabled / else disabled 
#=============================================================================================================
# false ratio
edit_set("txtCostwarning","10")
edit_set("txtCostlimit","1")
button_get_info("OK","enabled",OK_enabled);
if (OK_enabled == 1)
{
	tl_step ("OK should be disabled because of illegal CostWarning CostLimit ratio (SQL User Properties - New User)",1,"Testname: " & TestName & ", Line:" & getvar("line_no")); 
	Failure = 1;
}
# correct ratio
edit_set("txtCostwarning","1")
edit_set("txtCostlimit","10")
button_get_info("OK","enabled",OK_enabled);
if (OK_enabled == 0)
{
	tl_step ("OK should be enabled [correct CostWarning CostLimit ratio] (SQL User Properties - New User)",1,"Testname: " & TestName & ", Line:" & getvar("line_no")); 
	Failure = 1;
}

#=============================================================================================================
# @STEP 7			Press OK button to confirm the creation of the new group 
#=============================================================================================================
button_press ("OK");


#=============================================================================================
# @STEP 8		check if test passed successfully
#=============================================================================================	
if (Failure == 0)
	tl_step ("Test passed successfully",0,"Testname: " & TestName & ", Line:" & getvar("line_no"));
