Beispiel #1
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
}
Beispiel #2
0
func initPages() {
	var uid = int64(99999)
	var title = "Sample Page Demo"
	pageStore[uid] = dto.Page{
		Id:     uid,
		Title:  title,
		Status: dto.StatusDetail{dto.ACTIVE, fmt.Sprint(dto.StatusType(dto.PENDING))},
		//TagList: dto.NewTagList(0),
	}
}
Beispiel #3
0
func initTags() {
	tagStore["Tech"] = dto.Tag{
		Id:          1,
		Name:        "Tech",
		Description: "Technology",
		Status: dto.StatusDetail{
			dto.ACTIVE,
			fmt.Sprint(dto.StatusType(dto.ACTIVE)),
		},
	}
	tagStore["Science"] = dto.Tag{
		Id:          2,
		Name:        "Science",
		Description: "Scientific Discoveries",
		Status: dto.StatusDetail{
			dto.ACTIVE,
			fmt.Sprint(dto.StatusType(dto.ACTIVE)),
		},
	}
	tagStore["Math"] = dto.Tag{
		Id:          3,
		Name:        "Math",
		Description: "Mathematics",
		Status: dto.StatusDetail{
			dto.ACTIVE,
			fmt.Sprint(dto.StatusType(dto.ACTIVE)),
		},
	}
	tagStore["Health"] = dto.Tag{
		Id:          4,
		Name:        "Health",
		Description: "Healthy Living",
		Status: dto.StatusDetail{
			dto.ACTIVE,
			fmt.Sprint(dto.StatusType(dto.ACTIVE)),
		},
	}
}
Beispiel #4
0
func TestMicroPageSvcUpdatePage(t *testing.T) {
	log.SetPrefix(util.GetCallerName() + ":")
	mps.Register(util.GetConfig().RootPath, util.GetConfig().ApiVersion, "/page")
	mps.MicroSvc.AddModel(mockmodel.MockPageModel{})
	timeStr := time.Now().Format(time.RFC850)
	tests := []resttest.RESTTestContainer{
		{
			Desc:    "UpdatePage",
			Handler: restful.DefaultContainer.ServeHTTP,
			Path:    "%1/%2",
			Sub: map[string]string{
				"%1": mps.MicroSvc.GetFullPath(),
				"%2": "4",
			},
			Method:     "PUT",
			JSONParams: `{"Title":"Updating a Test Page ` + timeStr + `", "Status":{"StatusCode":3,"Desc":"Deactivated"}} `,
			Status:     http.StatusOK,
			MatchVal: dto.Page{
				Id:     4,
				Title:  "Updating a Test Page " + timeStr,
				Status: dto.StatusDetail{dto.DEACTIVATED, fmt.Sprint(dto.StatusType(dto.DEACTIVATED))},
			},
			MatchFields:     []string{"Id", "Title", "Status", "StatusCode", "Desc"},
			PreAuthId:       3,
			OwnThreshold:    0,
			GlobalThreshold: 0,
		},
	}

	//mod, _ := mps.MicroSvc.getModel(mps.MicroSvc.GetFullPath())
	//log.Println("----------------------------------------------------------------------------")
	//log.Println("----------------------------------------------------------------------------")
	//log.Printf("----- Testing with Model ( %s )---------------------", reflect.TypeOf(mod))
	//log.Println("----------------------------------------------------------------------------")
	//log.Println("----------------------------------------------------------------------------")
	//resttest.RunTestSet(t, tests)
	// Test w/Actual database
	mps.MicroSvc.AddModel(model.PageModel{})
	mod, _ := mps.MicroSvc.getModel(mps.MicroSvc.GetFullPath())
	log.Println("----------------------------------------------------------------------------")
	log.Println("----------------------------------------------------------------------------")
	log.Printf("----- Testing with Model ( %s )---------------------", reflect.TypeOf(mod))
	log.Println("----------------------------------------------------------------------------")
	log.Println("----------------------------------------------------------------------------")
	resttest.RunTestSet(t, tests)
	log.SetPrefix("")
}
Beispiel #5
0
func TestMicroUserSvcUpdateUser(t *testing.T) {
	log.SetPrefix(util.GetCallerName() + " : ")
	mus.Register(util.GetConfig().RootPath, util.GetConfig().ApiVersion, "/user")
	mus.MicroSvc.AddModel(mockmodel.MockUserModel{})
	tests := []resttest.RESTTestContainer{
		{
			Desc:    "UpdateUser",
			Handler: restful.DefaultContainer.ServeHTTP,
			Path:    "%1/%2",
			Sub: map[string]string{
				"%1": mus.MicroSvc.GetFullPath(),
				"%2": "1",
			},
			Method:     "PUT",
			JSONParams: `{"Id":1,"Email":"*****@*****.**","Status":{"StatusCode":1,"Desc":"Pending"}}`,
			Status:     http.StatusOK,
			MatchVal: dto.User{
				Id:     1,
				Name:   "Testing Create Should Delete",
				Email:  "*****@*****.**",
				Status: dto.StatusDetail{dto.PENDING, fmt.Sprint(dto.StatusType(dto.PENDING))},
			},
			MatchFields:     []string{"Id", "Email", "Status", "StatusCode", "Desc"},
			PreAuthId:       3,
			OwnThreshold:    0,
			GlobalThreshold: 0,
		},
	}
	//mod, _ := mus.MicroSvc.getModel(mus.MicroSvc.GetFullPath())
	//log.Println("----------------------------------------------------------------------------")
	//log.Println("----------------------------------------------------------------------------")
	//log.Printf("----- Testing with Model ( %s )---------------------", reflect.TypeOf(mod))
	//log.Println("----------------------------------------------------------------------------")
	//log.Println("----------------------------------------------------------------------------")
	//resttest.RunTestSet(t, tests)
	// Test w/Actual database
	mus.MicroSvc.AddModel(model.UserModel{})
	mod, _ := mus.MicroSvc.getModel(mus.MicroSvc.GetFullPath())
	log.Println("----------------------------------------------------------------------------")
	log.Println("----------------------------------------------------------------------------")
	log.Printf("----- Testing with Model ( %s )---------------------", reflect.TypeOf(mod))
	log.Println("----------------------------------------------------------------------------")
	log.Println("----------------------------------------------------------------------------")
	resttest.RunTestSet(t, tests)
	log.SetPrefix("")
}
Beispiel #6
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")
}
Beispiel #7
0
func TestMicroPageSvcAddPage(t *testing.T) {
	log.SetPrefix(util.GetCallerName() + ":")
	mps.Register(util.GetConfig().RootPath, util.GetConfig().ApiVersion, "/page")
	mps.MicroSvc.AddModel(mockmodel.MockPageModel{})
	tests := []resttest.RESTTestContainer{
		{
			Desc:    "AddPage",
			Handler: restful.DefaultContainer.ServeHTTP,
			Path:    "%1/",
			Sub: map[string]string{
				"%1": mps.MicroSvc.GetFullPath(),
			},
			Method:     "POST",
			JSONParams: `{"Title":"Rate My First Page"}`,
			Status:     http.StatusCreated,
			MatchVal: dto.Page{
				Title:  "Rate My First Page",
				Status: dto.StatusDetail{dto.INITIALIZED, fmt.Sprint(dto.StatusType(dto.INITIALIZED))},
			},
			MatchFields:     []string{"Title", "Status", "StatusCode", "Desc"},
			PreAuthId:       3,
			OwnThreshold:    -1,
			GlobalThreshold: -1,
		},
	}

	mod, _ := mps.MicroSvc.getModel(mps.MicroSvc.GetFullPath())
	log.Println("----------------------------------------------------------------------------")
	log.Println("----------------------------------------------------------------------------")
	log.Printf("----- Testing with Model ( %s )---------------------", reflect.TypeOf(mod))
	log.Println("----------------------------------------------------------------------------")
	log.Println("----------------------------------------------------------------------------")
	resttest.RunTestSet(t, tests)
	//	 Test w/Actual database
	mps.MicroSvc.AddModel(model.PageModel{})
	mod, _ = mps.MicroSvc.getModel(mps.MicroSvc.GetFullPath())
	log.Println("----------------------------------------------------------------------------")
	log.Println("----------------------------------------------------------------------------")
	log.Printf("----- Testing with Model ( %s )---------------------", reflect.TypeOf(mod))
	log.Println("----------------------------------------------------------------------------")
	log.Println("----------------------------------------------------------------------------")
	resttest.RunTestSet(t, tests)
	log.SetPrefix("")
}
Beispiel #8
0
func TestMicroTagSvcCreateTag(t *testing.T) {
	log.SetPrefix(util.GetCallerName() + " : ")
	funcName := util.GetCallerName()
	mts.Register(util.GetConfig().RootPath, util.GetConfig().ApiVersion, "/tag")
	mts.MicroSvc.AddModel(mockmodel.MockTagModel{})
	timeStr := time.Now().Format(time.RFC850)
	tests := []resttest.RESTTestContainer{
		{
			Desc:       "CreateTag",
			Handler:    restful.DefaultContainer.ServeHTTP,
			Path:       mts.MicroSvc.GetFullPath(),
			Method:     "POST",
			JSONParams: `{"Name":"Creating a RESTTest Tag ` + timeStr + `",  "Description":" Test Tag Desc "} `,
			Status:     http.StatusCreated,
			MatchVal: dto.Tag{
				Name:   "Creating a RESTTest Tag " + timeStr,
				Status: dto.StatusDetail{dto.INITIALIZED, fmt.Sprint(dto.StatusType(dto.INITIALIZED))},
			},
			MatchFields:     []string{"Name", "Status", "StatusCode", "Desc"},
			PreAuthId:       3,
			OwnThreshold:    0,
			GlobalThreshold: 0,
		},
	}

	mod, _ := mts.MicroSvc.getModel(mts.MicroSvc.GetFullPath())
	log.Println("----------------------------------------------------------------------------")
	log.Println("----------------------------------------------------------------------------")
	log.Printf("%s ----- Testing with Model ( %s )---------------------", funcName, reflect.TypeOf(mod))
	log.Println("----------------------------------------------------------------------------")
	log.Println("----------------------------------------------------------------------------")
	resttest.RunTestSet(t, tests)
	// Test w/Actual database
	mts.MicroSvc.AddModel(model.TagModel{})
	mod, _ = mts.MicroSvc.getModel(mts.MicroSvc.GetFullPath())
	log.Println("----------------------------------------------------------------------------")
	log.Println("----------------------------------------------------------------------------")
	log.Printf("%s ----- Testing with Model ( %s )---------------------", funcName, reflect.TypeOf(mod))
	log.Println("----------------------------------------------------------------------------")
	log.Println("----------------------------------------------------------------------------")
	resttest.RunTestSet(t, tests)
	log.SetPrefix("")
}
Beispiel #9
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
}
Beispiel #10
0
func initUsers() {
	for i := 1; i <= 10; i++ {
		var name = "Testing Create Should Delete"
		if i > 1 {
			name = "Testing Create Should Delete" + strconv.Itoa(i)
		}
		var uid = int64(i)
		userStore[uid] = dto.User{
			Id:           uid,
			Name:         name,
			Email:        "*****@*****.**",
			PasswordHash: "13lafjalsdflasfkdjlf",
			Status:       dto.StatusDetail{dto.ACTIVE, fmt.Sprint(dto.StatusType(dto.ACTIVE))},
		}
		if i%2 == 0 {
			userTags[uid] = append(userTags[uid], "Tech")
			userTags[uid] = append(userTags[uid], "Math")
		} else {
			userTags[uid] = append(userTags[uid], "Health")
			userTags[uid] = append(userTags[uid], "Science")
		}
	}
}
func TestMicroRevisionSvcCreateRevision(t *testing.T) {
	log.SetPrefix(util.GetCallerName() + " : ")
	mrs.Register(util.GetConfig().RootPath, util.GetConfig().ApiVersion, "/revision")
	mrs.MicroSvc.AddModel(model.RevisionModel{})
	timeStr := time.Now().Format(time.RFC850)
	tests := []resttest.RESTTestContainer{
		{
			Desc:    "CreateRevision",
			Handler: restful.DefaultContainer.ServeHTTP,
			Path:    "%1/",
			Sub: map[string]string{
				"%1": mrs.MicroSvc.GetFullPath(),
			},
			Method:     "POST",
			JSONParams: `{"SectionId":2, "Content":"Creating a Test Rev ` + timeStr + `"} `,
			Status:     http.StatusCreated,
			MatchVal: dto.Revision{
				SectionId: 2,
				Content:   "Creating a Test Rev  " + timeStr,
				Status:    dto.StatusDetail{dto.INITIALIZED, fmt.Sprint(dto.StatusType(dto.INITIALIZED))},
			},
			MatchFields:     []string{"SectionId", "Status", "StatusCode", "Desc"},
			PreAuthId:       3,
			OwnThreshold:    0,
			GlobalThreshold: 0,
		},
	}
	mod, _ := mrs.MicroSvc.getModel(mrs.MicroSvc.GetFullPath())
	rel := mrs.MicroSvc.getRelationship(reflect.TypeOf(dto.Tag{}))
	log.Println("----------------------------------------------------------------------------")
	log.Printf("----- Testing with Model ( %s )---------------------", reflect.TypeOf(mod))
	log.Printf("----- Testing with Relationship ( %s )---------------------", reflect.TypeOf(rel))
	log.Println("----------------------------------------------------------------------------")
	resttest.RunTestSet(t, tests)
	//// Test w/Actual database
	log.SetPrefix("")
}
func TestMicroRevisionSvcUpdateRevision(t *testing.T) {
	log.SetPrefix(util.GetCallerName() + " : ")
	mrs.Register(util.GetConfig().RootPath, util.GetConfig().ApiVersion, "/revision")
	mrs.MicroSvc.AddModel(model.RevisionModel{})
	timeStr := time.Now().Format(time.RFC850)
	tests := []resttest.RESTTestContainer{
		{
			Desc:    "UpdateRevision",
			Handler: restful.DefaultContainer.ServeHTTP,
			Path:    "%1/%2",
			Sub: map[string]string{
				"%1": mrs.MicroSvc.GetFullPath(),
				"%2": "7",
			},
			Method:     "PUT",
			JSONParams: `{"Content":"Updating a Test Rev ` + timeStr + `", "Status":{"StatusCode":3,"Desc":"Deactivated"}} `,
			Status:     http.StatusOK,
			MatchVal: dto.Revision{
				Id:     7,
				Status: dto.StatusDetail{dto.DEACTIVATED, fmt.Sprint(dto.StatusType(dto.DEACTIVATED))},
			},
			MatchFields:     []string{"Id", "Status", "StatusCode", "Desc"},
			PreAuthId:       3,
			OwnThreshold:    0,
			GlobalThreshold: 0,
		},
		{
			Desc:    "UpdateRevisionFailsGlobalThreshold",
			Handler: restful.DefaultContainer.ServeHTTP,
			Path:    "%1/%2",
			Sub: map[string]string{
				"%1": mrs.MicroSvc.GetFullPath(),
				"%2": "4",
			},
			Method:          "PUT",
			JSONParams:      `{"Content":"Updating a Test Rev ` + timeStr + `", "Status":{"StatusCode":3,"Desc":"Deactivated"}} `,
			Status:          http.StatusUnauthorized,
			PreAuthId:       3,
			OwnThreshold:    0,
			GlobalThreshold: 2500000,
		},
		{
			Desc:    "UpdateRevisionFailsThresholdNotProvided",
			Handler: restful.DefaultContainer.ServeHTTP,
			Path:    "%1/%2",
			Sub: map[string]string{
				"%1": mrs.MicroSvc.GetFullPath(),
				"%2": "4",
			},
			Method:          "PUT",
			JSONParams:      `{"Content":"Updating a Test Rev ` + timeStr + `", "Status":{"StatusCode":3,"Desc":"Deactivated"}} `,
			Status:          http.StatusPreconditionFailed,
			PreAuthId:       3,
			OwnThreshold:    -1,
			GlobalThreshold: -1,
		},
	}
	mod, _ := mrs.MicroSvc.getModel(mrs.MicroSvc.GetFullPath())
	rel := mrs.MicroSvc.getRelationship(reflect.TypeOf(dto.Tag{}))
	log.Println("----------------------------------------------------------------------------")
	log.Printf("----- Testing with Model ( %s )---------------------", reflect.TypeOf(mod))
	log.Printf("----- Testing with Relationship ( %s )---------------------", reflect.TypeOf(rel))
	log.Println("----------------------------------------------------------------------------")
	resttest.RunTestSet(t, tests)
	//// Test w/Actual database
	log.SetPrefix("")
}
Beispiel #13
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
}
Beispiel #14
0
func init() {
	typeMap = make(map[string]reflect.Type)
	typeMap["int64"] = reflect.TypeOf(int64(1))
	typeMap["string"] = reflect.TypeOf(string(""))
	typeMap["dto.StatusType"] = reflect.TypeOf(dto.StatusType(0))
}
Beispiel #15
0
func TestMicroUserSvcAddUser(t *testing.T) {
	log.SetPrefix(util.GetCallerName() + " : ")
	mus.Register(util.GetConfig().RootPath, util.GetConfig().ApiVersion, "/user")
	mus.MicroSvc.AddModel(mockmodel.MockUserModel{})
	tests := []resttest.RESTTestContainer{
		{
			Desc:    "AddUserHappyCase",
			Handler: restful.DefaultContainer.ServeHTTP,
			Path:    "%1/",
			Sub: map[string]string{
				"%1": mus.MicroSvc.GetFullPath(),
			},
			Method:     "POST",
			JSONParams: `{"Name":"UsernameNew9","Email":"*****@*****.**","PasswordHash":"23lafjalsdflasfkdjlf","Status":{"StatusCode":0,"Desc":"Initialized"}}`,
			Status:     http.StatusCreated,
			MatchVal: dto.User{
				Name:   "UsernameNew9",
				Email:  "*****@*****.**",
				Status: dto.StatusDetail{dto.INITIALIZED, fmt.Sprint(dto.StatusType(dto.INITIALIZED))},
			},
			MatchFields:     []string{"Name", "Email", "Status", "StatusCode", "Desc"},
			PreAuthId:       3,
			OwnThreshold:    0,
			GlobalThreshold: 0,
		},
		//{
		//	Desc:       "AddUserDuplicate",
		//	Handler:    restful.DefaultContainer.ServeHTTP,
		//	Path:       mus.MicroSvc.GetFullPath(),
		//	Method:     "PUT",
		//	JSONParams: `{"Name":"UsernameNew9","Email":"*****@*****.**","PasswordHash":"23lafjalsdflasfkdjlf","Status":{"StatusCode":1,"Desc":"Pending"}}`,
		//	Status:     http.StatusCreated, // change after unique name constraint
		//	MatchVal: dto.User{
		//		Name:   "UsernameNew9",
		//		Email:  "*****@*****.**",
		//		Status: dto.StatusDetail{dto.PENDING, fmt.Sprint(dto.StatusType(dto.PENDING))},
		//	},
		//	MatchFields: []string{"Name", "Email", "Status", "StatusCode", "Desc"},
		//},
		//{
		//	Desc:    "GetUserHappyCase",
		//	Handler: restful.DefaultContainer.ServeHTTP,
		//	Path:    "%1/%2",
		//	Sub: map[string]string{
		//		"%1": mus.MicroSvc.GetFullPath(),
		//		"%2": "1",
		//	},
		//	Method: "GET",
		//	Status: http.StatusOK,
		//	MatchVal: dto.User{
		//		Name:  "Testing Create Should Delete",
		//		Email: "*****@*****.**",
		//		//Status: dto.StatusDetail{dto.DELETED, fmt.Sprint(dto.StatusType(dto.DELETED))}, //TODO: update this
		//	},
		//	MatchFields: []string{"Name", "Email"},
		//},
	}
	mod, _ := mus.MicroSvc.getModel(mus.MicroSvc.GetFullPath())
	log.Println("----------------------------------------------------------------------------")
	log.Println("----------------------------------------------------------------------------")
	log.Printf("----- Testing with Model ( %s )---------------------", reflect.TypeOf(mod))
	log.Println("----------------------------------------------------------------------------")
	log.Println("----------------------------------------------------------------------------")
	resttest.RunTestSet(t, tests)
	// Test w/Actual database
	mus.MicroSvc.AddModel(model.UserModel{})
	mod, _ = mus.MicroSvc.getModel(mus.MicroSvc.GetFullPath())
	log.Println("----------------------------------------------------------------------------")
	log.Println("----------------------------------------------------------------------------")
	log.Printf("----- Testing with Model ( %s )---------------------", reflect.TypeOf(mod))
	log.Println("----------------------------------------------------------------------------")
	log.Println("----------------------------------------------------------------------------")
	resttest.RunTestSet(t, tests)
	log.SetPrefix("")
}