Exemple #1
0
func (setupInfo1 *SetupInfo) SaveSetupInfo(setupInfo *SetupInfo) bool {
	err := setup.NewSetupInfoService().SaveSetupInfo(setupInfo, setupFileName, common.XML_ENCODE_GB2312)
	if err != nil {
		return false
	}
	return true
}
func Test_GetAPSServerSetupInfo(t *testing.T) {
	setupInfo := &APSServerSetupInfo{}
	err := setup.NewSetupInfoService().GetSetupInfo(setupInfo, "/mnt/hgfs/Source/c++/iVideo/Source/APS/Bin/config.xml")
	if nil != err { //try a unit test on function
		t.Error(err) // 如果不是如预期的那么就报错
	}
}
Exemple #3
0
func (setupInfo1 *SetupInfo) GetSetupInfo(setupInfo *SetupInfo) bool {
	err := setup.NewSetupInfoService().GetSetupInfo(setupInfo, setupFileName)
	if err != nil {
		return false
	}
	return true
}
func Test_GetSIPServerSetupInfo(t *testing.T) {
	setupInfo := &SIPServerSetupInfo{}
	err := setup.NewSetupInfoService().GetSetupInfo(setupInfo, "/mnt/hgfs/Source/c++/iVideo/Source/SIPServer/config.xml")
	if nil != err { //try a unit test on function
		t.Error(err) // 如果不是如预期的那么就报错
	}
	if utils.IsEmptyStr(setupInfo.ActiveMQInfo.AddressInfo.IP) {
		t.Error("没有ActiveMQ地址")
	}
	if utils.IsEmptyStr(setupInfo.ActiveMQInfo.Topic) {
		t.Error("没有ActiveMQ主题")
	}
}
func Test_CMSServerSetupInfoGetPassword(t *testing.T) {
	setupInfo := &CMSServerSetupInfo{}
	err := setup.NewSetupInfoService().GetSetupInfo(setupInfo, "/home/pc01/source/java/apache-tomcat-7.0.53/webapps/cms/WEB-INF/classes/hibernate.cfg.xml")
	if nil != err { //try a unit test on function
		t.Error(err) // 如果不是如预期的那么就报错
	}
	value, err := setupInfo.GetProperty("connection.password")
	if nil != err { //try a unit test on function
		t.Error(err) // 如果不是如预期的那么就报错
	}

	if "sysware" != value {
		t.Error("错误密码")
	}
}
func (serverConfigSaveHandleAPSImpl *serverConfigSaveHandleAPSImpl) Save(r *http.Request, serverInfo *model.ServerInfo) error {
	if nil == r {
		return errors.New("没有请求")
	}
	setupInfo, err := NewGetServerDetailSetupInfo().GetInfo(serverInfo)
	if nil != err {
		return err
	}
	apsSetupInfo := setupInfo.(*model.APSServerSetupInfo)
	apsSetupInfo.APSInfo.Id = r.FormValue("serverId")
	apsSetupInfo.APSInfo.Password = r.FormValue("password")
	apsSetupInfo.APSInfo.RegisterInterval, err = strconv.Atoi(r.FormValue("registerInterval"))
	if nil != err {
		return err
	}
	apsSetupInfo.APSInfo.DefaultHeartInterval, err = strconv.Atoi(r.FormValue("defaultHeartInterval"))
	if nil != err {
		return err
	}
	apsSetupInfo.APSInfo.AddressInfo.IP = r.FormValue("address")
	apsSetupInfo.APSInfo.AddressInfo.Port, err = strconv.Atoi(r.FormValue("port"))
	if nil != err {
		return err
	}
	apsSetupInfo.APSInfo.LogInfo.Logcfgfile = r.FormValue("logcfgfile")
	if utils.IsEmptyStr(apsSetupInfo.APSInfo.LogInfo.Logcfgfile) {
		return errors.New("没有日志配置文件")
	}
	if !utils.IsFileExist(utils.GetFileDir(serverInfo.Address) + "/" + apsSetupInfo.APSInfo.LogInfo.Logcfgfile) {
		return errors.New("日志配置文件不存在")
	}
	apsSetupInfo.APSInfo.LogInfo.SaveCatalog = r.FormValue("saveCatalog")
	apsSetupInfo.SipServerInfo.Id = r.FormValue("sipServerId")
	apsSetupInfo.SipServerInfo.Domain = r.FormValue("sipServerDomain")
	apsSetupInfo.SipServerInfo.AddressInfo.IP = r.FormValue("sipServerAddress")
	apsSetupInfo.SipServerInfo.AddressInfo.Port, err = strconv.Atoi(r.FormValue("sipServerPort"))
	if nil != err {
		return err
	}
	apsSetupInfo.CMSServerInfo.Address = r.FormValue("cmsServerAddress")
	cfgFileName, err := NewGetServerInfoConfigFileName().GetInfo(serverInfo)
	if nil != err {
		return err
	}
	err = setup.NewSetupInfoService().SaveSetupInfo(apsSetupInfo, cfgFileName, common.XML_ENCODE_GB2312)
	return err

}
func Test_GetMTSServerSetupInfo(t *testing.T) {
	setupInfo := &MTSServerSetupInfo{}
	err := setup.NewSetupInfoService().GetSetupInfo(setupInfo, "/mnt/hgfs/Source/c++/iVideo/Source/mts/config.xml")
	if nil != err { //try a unit test on function
		t.Error(err) // 如果不是如预期的那么就报错
	}
	if utils.IsEmptyStr(setupInfo.MTSInfo.AddressInfo.IP) {
		t.Error("没有服务器地址")
	}
	if utils.IsEmptyStr(setupInfo.SipServerInfo.AddressInfo.IP) {
		t.Error("没有SIP服务器地址")
	}
	if utils.IsEmptyStr(setupInfo.CMSServerInfo.Address) {
		t.Error("没有CMS地址")
	}
}
func (getAPSServerSetupInfoByConfigFile *getAPSServerSetupInfoByConfigFile) GetInfo(cfgFileName string) (interface{}, error) {
	var result interface{} = nil
	if utils.IsEmptyStr(cfgFileName) {
		return nil, errors.New("没有配置文件")
	}
	var aPSServerSetupInfo = model.APSServerSetupInfo{}
	err := setup.NewSetupInfoService().GetSetupInfo(&aPSServerSetupInfo, cfgFileName)
	if nil != err {
		return nil, err
	}
	result = &aPSServerSetupInfo
	if utils.IsEmptyStr(aPSServerSetupInfo.APSInfo.Id) {
		return nil, errors.New("配置文件格式不正确")
	}
	return result, nil
}
func Test_CMSServerSetupInfoAddNewPassword(t *testing.T) {
	setupInfo := &CMSServerSetupInfo{}
	err := setup.NewSetupInfoService().GetSetupInfo(setupInfo, "/home/pc01/source/java/apache-tomcat-7.0.53/webapps/cms/WEB-INF/classes/hibernate.cfg.xml")
	if nil != err { //try a unit test on function
		t.Error(err) // 如果不是如预期的那么就报错
	}
	err = setupInfo.SetProperty("connection.password1", "sysware1")
	if nil != err { //try a unit test on function
		t.Error(err) // 如果不是如预期的那么就报错
	}
	v1, err := setupInfo.GetProperty("connection.password1")
	if nil != err {
		t.Error(err)
	}
	if v1 != "sysware1" {
		t.Error("设置密码失败")
	}
}
func (getCMSServerSetupInfoByConfigFile *getCMSServerSetupInfoByConfigFile) GetInfo(cfgFileName string) (interface{}, error) {
	if utils.IsEmptyStr(cfgFileName) {
		return nil, errors.New("没有配置文件")
	}
	var cMSServerSetupInfo = model.CMSServerSetupInfo{}
	err := setup.NewSetupInfoService().GetSetupInfo(&cMSServerSetupInfo, cfgFileName)
	if nil != err {
		return nil, err
	}
	password, err := cMSServerSetupInfo.GetProperty("connection.password")
	if nil != err {
		return nil, errors.New("配置文件格式不正确")
	}
	result := make(map[string]string)
	result["dbPassword"] = password
	result["dbAddress"], _ = cMSServerSetupInfo.GetProperty("connection.url")
	result["dbUserName"], _ = cMSServerSetupInfo.GetProperty("connection.username")
	result["dbDefaultSchema"], _ = cMSServerSetupInfo.GetProperty("default_schema")
	return result, nil
}
func (serverConfigSaveHandleMTSImpl *serverConfigSaveHandleMTSImpl) Save(r *http.Request, serverInfo *model.ServerInfo) error {
	if nil == r {
		return errors.New("没有请求")
	}
	setupInfo, err := NewGetServerDetailSetupInfo().GetInfo(serverInfo)
	if nil != err {
		return err
	}
	mtsSetupInfo := setupInfo.(*model.MTSServerSetupInfo)
	mtsSetupInfo.MTSInfo.Id = r.FormValue("serverId")
	mtsSetupInfo.MTSInfo.Password = r.FormValue("password")
	mtsSetupInfo.MTSInfo.RegisterInterval, err = strconv.Atoi(r.FormValue("registerInterval"))
	if nil != err {
		return err
	}
	mtsSetupInfo.MTSInfo.DefaultHeartInterval, err = strconv.Atoi(r.FormValue("defaultHeartInterval"))
	if nil != err {
		return err
	}
	mtsSetupInfo.MTSInfo.AddressInfo.IP = r.FormValue("address")
	mtsSetupInfo.MTSInfo.AddressInfo.Port, err = strconv.Atoi(r.FormValue("port"))
	if nil != err {
		return err
	}

	mtsSetupInfo.SipServerInfo.Id = r.FormValue("sipServerId")
	mtsSetupInfo.SipServerInfo.Domain = r.FormValue("sipServerDomain")
	mtsSetupInfo.SipServerInfo.AddressInfo.IP = r.FormValue("sipServerAddress")
	mtsSetupInfo.SipServerInfo.AddressInfo.Port, err = strconv.Atoi(r.FormValue("sipServerPort"))
	if nil != err {
		return err
	}

	mtsSetupInfo.CMSServerInfo.Address = r.FormValue("cmsServerAddress")
	cfgFileName, err := NewGetServerInfoConfigFileName().GetInfo(serverInfo)
	if nil != err {
		return err
	}
	err = setup.NewSetupInfoService().SaveSetupInfo(mtsSetupInfo, cfgFileName, common.XML_ENCODE_GB2312)
	return err
}