Esempio n. 1
0
func TestRevisionModelUpdate(t *testing.T) {
	funcName := util.GetCallerName()
	log.Printf("---------------- Starting  Test ( %s )---------------------", funcName)
	TestRevisionModelCreate(t)
	log.SetPrefix(funcName + " : ")
	getThisRevision := dto.Revision{
		Id:      revId,
		Content: "Content for my first revision <b>has tags</b>",
		Status:  dto.SetStatus(dto.INITIALIZED),
	}
	smodel := RevisionModel{}
	if gotRevision, retCode, err := smodel.Update("update_revision", revId, &getThisRevision); gotRevision == nil || err != nil {
		//if gotRevision == nil || err != nil {
		log.Fatalf(" %s Failed: %#v", funcName, err)
		count.FailCount++
		return
	} else {

		if got, want := retCode, 0; got != want {
			t.Errorf("%s Broken: got  %d, wanted  %d", funcName, got, want)
			count.FailCount++
			return
		}
		revId = (*gotRevision).Id
		log.Printf("%s Successful for %#v", funcName, gotRevision)
		count.SuccessCount++
	}
	log.SetPrefix("")
}
Esempio n. 2
0
func (trm TagRevisionModel) processVDLCall(vdlOperation string, variadicArgs ...interface{}) (relationship *dto.EntityRelationship, retCode int, err error) {
	funcName := util.GetCallerName()
	if vdlOperation == "" {
		return nil, -1, errors.New(fmt.Sprintf("%s: VDL annotation not set", funcName))
	}
	log.Printf("%s -- Calling operation %s with %v", funcName, vdlOperation, variadicArgs)
	// Get the Postgres Function information
	pgfunc, _ := pgreflect.GetPgFuncInfo(vdlOperation)
	//Call the function and get return values
	retMap, retCode, err := pgfunc.VariadicScan(variadicArgs...)
	if err != nil || retMap == nil {
		log.Printf("%s -- Error Calling Postgres Function - %s ( %#v)", funcName, pgfunc.Name, pgfunc)
		return nil, -1, err
	}
	log.Printf("%s -- Postgres Function Returned- %#v, %d, %#v", funcName, retMap, retCode, err)
	//construct transfer object with return values
	newTRRelationship := &dto.EntityRelationship{
		RelId2:   retMap[0]["ret_tag_uid"].(int64),
		RelId1:   retMap[0]["ret_revision_uid"].(int64),
		RelName1: "dto.Revision",
		RelName2: "dto.Tag",
		RelType2: reflect.TypeOf(dto.Tag{}),
		RelType1: reflect.TypeOf(dto.Revision{}),
		Status:   dto.SetStatus(dto.StatusType(retMap[0]["ret_status"].(int64))),
		Created:  &dto.JsonTime{retMap[0]["ret_created"].(time.Time), time.RFC3339},
		Modified: &dto.JsonTime{retMap[0]["ret_modified"].(time.Time), time.RFC3339},
	}
	log.Printf("%s -- created %v, modified %v", funcName, retMap[0]["ret_created"].(time.Time), retMap[0]["ret_modified"].(time.Time).Format(time.RFC3339))
	log.Printf("%s -- Excution result %#v", funcName, newTRRelationship)
	return newTRRelationship, retCode, nil
}
Esempio n. 3
0
func TestTagModelUpdate(t *testing.T) {
	funcName := util.GetCallerName()
	log.Printf("%s ---------------- Starting  Test ---------------------", funcName)
	TestTagModelCreate(t)
	updateId := int64(tagId)
	tmodel := TagModel{}

	upThisTag := dto.Tag{
		Id:          updateId,
		Name:        "updated tag",
		Description: "Content for my updated tag <b>has tags</b> and updated with more<b> tags </b>",
		Status:      dto.SetStatus(dto.BANNED),
	}
	operation, _ := GetVDLOperation(tmodel, "update")
	tag_id := int64(tagId)
	got, retCode, err := tmodel.Update(operation, tag_id, &upThisTag)
	if err != nil {
		log.Fatalf("%s Failed: %#v", funcName, err)
		count.FailCount++
		return
	}

	if got, want := retCode, 0; got != want {
		t.Errorf("%s got  %d, wanted  %d", funcName, got, want)
		count.FailCount++
		return
	}
	tagId = (*got).Id
	log.Printf("%s Successful for %#v", funcName, got)
	count.SuccessCount++
	log.SetPrefix("")
}
Esempio n. 4
0
func TestTagModelCreate(t *testing.T) {
	funcName := util.GetCallerName()
	log.Printf("%s ---------------- Starting  Test ---------------------", funcName)
	log.SetPrefix(util.GetCallerName() + " : ")
	getThisTag := dto.Tag{
		Name:        "test tag",
		Description: "Content for my first tag <b>has tags</b>",
		Status:      dto.SetStatus(dto.INITIALIZED),
	}
	smodel := TagModel{}
	operation, _ := GetVDLOperation(smodel, "create")
	gotTag, retCode, err := smodel.Create(operation, &getThisTag)
	if err != nil {
		log.Fatalf("%s Failed: %#v", funcName, err)
		count.FailCount++
		return
	}

	if got, want := retCode, 0; got != want {
		t.Errorf("%s got  %d, wanted  %d", funcName, got, want)
		count.FailCount++
		return
	}
	tagId = (*gotTag).Id
	log.Printf("%s Successful for %#v", funcName, gotTag)
	count.SuccessCount++
	log.SetPrefix("")
}
Esempio n. 5
0
func TestUserModelUpdate(t *testing.T) {
	funcName := util.GetCallerName()
	log.Printf("%s ---------------- Starting  Test ---------------------", funcName)
	TestUserModelCreate(t)
	log.SetPrefix(util.GetCallerName() + " : ")
	getThisUser := dto.User{
		Email:  "*****@*****.**",
		Status: dto.SetStatus(dto.ACTIVE),
	}
	umodel := UserModel{}
	operation, _ := GetVDLOperation(umodel, "update")
	user_id := int64(userId)
	gotUser, retCode, err := umodel.Update(operation, user_id, &getThisUser)
	if err != nil {
		log.Fatalf("%s Failed: %#v", funcName, err)
		count.FailCount++
		return
	}

	if got, want := retCode, 0; got != want {
		t.Errorf("%s got  %d, wanted  %d", funcName, got, want)
		count.FailCount++
		return
	}
	userId = (*gotUser).Id
	log.Printf("%s Successful for %#v", funcName, gotUser)
	count.SuccessCount++
	log.SetPrefix("")
}
Esempio n. 6
0
func TestSectionModelUpdate(t *testing.T) {
	funcName := util.GetCallerName()
	log.Printf("%s ---------------- Starting  Test ---------------------", funcName)
	TestSectionModelCreate(t)
	log.SetPrefix(util.GetCallerName() + " : ")
	getThisSection := dto.Section{
		Name:     "Update My First Section",
		PageId:   pageId,
		OrderNum: 1,
		Status:   dto.SetStatus(dto.ACTIVE),
	}
	smodel := SectionModel{}
	operation, _ := GetVDLOperation(smodel, "update")
	section_id := int64(sectionId)
	gotSection, retCode, err := smodel.Update(operation, section_id, &getThisSection)
	if err != nil {
		log.Fatalf("%s Failed: %#v", funcName, err)
		count.FailCount++
		return
	}

	if got, want := retCode, 0; got != want {
		t.Errorf("%s got  %d, wanted  %d", funcName, got, want)
		count.FailCount++
		return
	}
	sectionId = (*gotSection).Id
	log.Printf("%s Successful for %#v", funcName, gotSection)
	count.SuccessCount++
	log.SetPrefix("")
}
Esempio n. 7
0
func (rm SectionModel) processVDLCall(vdlOperation string, variadicArgs ...interface{}) (*dto.Section, int, error) {
	funcName := util.GetCallerName()
	if vdlOperation == "" {
		return nil, -1, errors.New(fmt.Sprintf("%s: VDL annotation not set", funcName))
	}

	log.Printf("%s -- Calling operation %s with %v", funcName, vdlOperation, variadicArgs)
	// Get the Postgres Function information
	pgfunc, err := pgreflect.GetPgFuncInfo(vdlOperation)
	if err != nil {
		log.Printf("%s -- Error Getting Postgres Function Information- %s ", funcName, vdlOperation)
		return nil, -1, err
	}
	//
	// Check the argument list size agrees
	if pgfunc.NumArgs != len(variadicArgs) {
		log.Printf("%s -- Error with number of argument for %s has %d, passing in %d", funcName, vdlOperation, pgfunc.NumArgs, len(variadicArgs))
		return nil, -1, errors.New(fmt.Sprintf("Error with number of argument for %s has %d, passing in %d", vdlOperation, pgfunc.NumArgs, len(variadicArgs)))
	}
	//Call the function and get return values
	retMap, retCode, err := pgfunc.VariadicScan(variadicArgs...)
	if err != nil || retMap == nil {
		log.Printf("%s -- Error Calling Postgres Function - %s ( %#v)", funcName, pgfunc.Name, pgfunc)
		return nil, -1, err
	}
	log.Printf("%s -- Postgres Function Returned- %#v, %d, %#v", funcName, retMap, retCode, err)
	//construct transfer object with return values
	if len(retMap) > 0 {
		dbResults := &dto.Section{
			Id:       retMap[0]["ret_uid"].(int64),
			PageId:   retMap[0]["ret_page_uid"].(int64),
			AuthorId: retMap[0]["ret_user_uid"].(int64),
			Name:     retMap[0]["ret_name"].(string),
			OrderNum: int(retMap[0]["ret_ordernum"].(int64)),
			Status:   dto.SetStatus(dto.StatusType(retMap[0]["ret_status"].(int64))),
			Created:  &dto.JsonTime{retMap[0]["ret_created"].(time.Time), time.RFC3339},
			Modified: &dto.JsonTime{retMap[0]["ret_modified"].(time.Time), time.RFC3339},
		}
		log.Printf("%s -- created %v, modified %v", funcName, retMap[0]["ret_created"].(time.Time), retMap[0]["ret_modified"].(time.Time).Format(time.RFC3339))
		log.Printf("%s -- Excution result %#v", funcName, dbResults)
		return dbResults, retCode, nil
	}

	return nil, 1, errors.New("No data returned")
}
Esempio n. 8
0
func (sm SectionModel) processVDLMultiResults(vdlOperation string, variadicArgs ...interface{}) (*[]dto.Section, int, error) {
	funcName := util.GetCallerName()
	if vdlOperation == "" {
		return nil, -1, errors.New(fmt.Sprintf("%s: VDL annotation not set", funcName))
	}

	log.Printf("%s -- Calling operation %s with %v", funcName, vdlOperation, variadicArgs)
	// Get the Postgres Function information
	pgfunc, _ := pgreflect.GetPgFuncInfo(vdlOperation)
	//
	// Check the argument list size agrees
	if pgfunc.NumArgs != len(variadicArgs) {
		log.Printf("%s -- Error with number of argument for %s has %d, passing in %d", funcName, vdlOperation, pgfunc.NumArgs, len(variadicArgs))
		return nil, -1, errors.New(fmt.Sprintf("Error with number of argument for %s has %d, passing in %d", vdlOperation, pgfunc.NumArgs, len(variadicArgs)))
	}
	//Call the function and get return values
	retMap, retCode, err := pgfunc.VariadicScan(variadicArgs...)
	if err != nil || retMap == nil || len(retMap) == 0 {
		log.Printf("%s -- Error Calling Postgres Function - %s ( %#v)", funcName, pgfunc.Name, pgfunc)
		return nil, -1, err
	}
	log.Printf("%s -- Postgres Function Returned- %#v, %d, %#v", funcName, retMap, retCode, err)

	dbResults := make([]dto.Section, 0)
	for _, row := range retMap {
		//construct transfer object with return values
		dbResult := dto.Section{
			Id:       row["uid"].(int64),
			PageId:   row["page_uid"].(int64),
			AuthorId: row["user_uid"].(int64),
			Name:     row["name"].(string),
			OrderNum: int(row["ordernum"].(int64)),
			Status:   dto.SetStatus(dto.StatusType(row["status"].(int64))),
			Created:  &dto.JsonTime{row["created"].(time.Time), time.RFC3339},
			Modified: &dto.JsonTime{row["modified"].(time.Time), time.RFC3339},
		}
		log.Printf("%s -- created %v, modified %v", funcName, row["created"].(time.Time), row["modified"].(time.Time).Format(time.RFC3339))
		log.Printf("%s -- Excution result %#v", funcName, dbResult)
		dbResults = append(dbResults, dbResult)
	}
	return &dbResults, retCode, nil
}
Esempio n. 9
0
func (tm TagRevisionModel) RetrieveRelationship(revisionId int64, tagId int64) (relationship *dto.EntityRelationship, retCode int, err error) {

	funcName := util.GetCallerName()
	log.Printf("Calling %s (%d, %d)", funcName, tagId, revisionId)

	db, err := db.GetConnection()
	defer db.Close()
	if err != nil {
		log.Printf("%s Connection err %#v", funcName, err)
		return nil, -1, err
	}
	log.Printf("%s Connected to Postgres", funcName)
	defer db.Close()
	stmt, err := db.Prepare(`SELECT * FROM tag_revisiondata WHERE revision_uid =$1 AND tag_uid = $2`)

	if err != nil {
		log.Printf("Prepare err %#v", err)
		//stmt.Close()
		//db.Close()
		return nil, -1, err
	}
	log.Printf("%s Executing ", funcName)
	result, err := stmt.Query(
		revisionId,
		tagId)

	if err != nil {
		log.Printf("%s Execution problem: %#v", funcName, result)
		//result.Close()
		//stmt.Close()
		//db.Close()
		return nil, -1, err
	}
	for result.Next() {
		var status int
		var created, modified time.Time
		if err := result.Scan(&tagId, &revisionId, &status, &created, &modified); err != nil {
			log.Printf("%s Results Error %#v", funcName, err)
			//result.Close()
			//stmt.Close()
			//db.Close()
			return nil, -1, err
		}
		log.Printf("%s Processing return values for entity relationship ids %d, %d", funcName, tagId, revisionId)
		newTRRelationship := &dto.EntityRelationship{
			RelId2:   tagId,
			RelId1:   revisionId,
			RelName1: "dto.Revision",
			RelName2: "dto.Tag",
			RelType2: reflect.TypeOf(dto.Tag{}),
			RelType1: reflect.TypeOf(dto.Revision{}),
			Status:   dto.SetStatus(dto.StatusType(status)),
			Created:  &dto.JsonTime{created, time.RFC3339},
			Modified: &dto.JsonTime{created, time.RFC3339},
		}
		//result.Close()
		//stmt.Close()
		//db.Close()
		log.Printf("%s excution result %v", funcName, newTRRelationship)
		return newTRRelationship, 0, nil
	}

	//result.Close()
	//stmt.Close()
	//db.Close()
	return nil, 1, nil
}