Esempio n. 1
0
func TestTagModelUpdateStatus(t *testing.T) {
	funcName := util.GetCallerName()
	log.Printf("%s ---------------- Starting  Test ---------------------", funcName)
	TestTagModelCreate(t)
	log.SetPrefix(util.GetCallerName() + " : ")
	smodel := TagModel{}
	operation, _ := GetVDLOperation(smodel, "updatestatus")
	tag_id := int64(tagId)
	gotTag, retCode, err := smodel.UpdateStatus(operation, tag_id, dto.BANNED)
	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. 2
0
func TestUserModelDelete(t *testing.T) {
	funcName := util.GetCallerName()
	log.Printf("%s ---------------- Starting  Test ---------------------", funcName)
	TestUserModelCreate(t)
	log.SetPrefix(util.GetCallerName() + " : ")
	umodel := UserModel{}
	operation, _ := GetVDLOperation(umodel, "delete")
	user_id := int64(userId)
	gotUser, retCode, err := umodel.Delete(operation, user_id)
	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. 3
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. 4
0
func TestUserModelCreate(t *testing.T) {
	funcName := util.GetCallerName()
	log.Printf("%s ---------------- Starting  Test ---------------------", funcName)
	log.SetPrefix(util.GetCallerName() + " : ")
	getThisUser := dto.User{
		Name:  "Rate My First User",
		Email: "*****@*****.**",
		//Status:   dto.SetStatus(dto.INITIALIZED),
	}
	umodel := UserModel{}
	operation, _ := GetVDLOperation(umodel, "create")
	gotUser, retCode, err := umodel.Create(operation, &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. 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 TestTagModelFindById(t *testing.T) {
	funcName := util.GetCallerName()
	log.Printf("%s ---------------- Starting  Test ---------------------", funcName)
	TestTagModelCreate(t)
	log.SetPrefix(util.GetCallerName() + " : ")
	smodel := TagModel{}
	operation, _ := GetVDLOperation(smodel, "findbyid")
	tag_id := int64(tagId)
	gotSection, retCode, err := smodel.FindById(operation, tag_id)
	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 TestRevisionModelCreate(t *testing.T) {
	funcName := util.GetCallerName()
	log.Printf("---------------- Starting  Test ( %s )---------------------", funcName)
	TestUserModelCreate(t)
	TestSectionModelCreate(t)
	log.SetPrefix(util.GetCallerName() + " : ")
	getThisRevision := dto.Revision{
		SectionId: sectionId,
		Content:   "Content for my first revision <b>has tags</b>",
	}
	smodel := RevisionModel{}
	if gotRevision, retCode, err := smodel.Create("create_revision", userId, &getThisRevision); gotRevision == nil || err != nil {
		//if gotRevision == nil || err != nil {
		log.Fatalf(" RevisionModel Create Failed: %#v", err)
		count.FailCount++
		return
	} else {

		if got, want := retCode, 0; got != want {
			t.Errorf("RevisionModelCreate Broken: got  %d, wanted  %d", got, want)
			count.FailCount++
			return
		}
		revId = (*gotRevision).Id
		log.Printf("RevisionModel Create Successful for %#v", gotRevision)
		count.SuccessCount++
	}
	log.SetPrefix("")
}
Esempio n. 8
0
func TestPageModelCreate(t *testing.T) {
	log.Printf("---------------- Starting  Test ( %s )---------------------", util.GetCallerName())
	TestUserModelCreate(t)
	log.SetPrefix(util.GetCallerName() + " : ")
	getThisPage := dto.Page{
		Title: "Rate My First Page",
	}
	pmodel := PageModel{}
	operation, _ := GetVDLOperation(pmodel, "create")
	author_id := int64(userId)
	gotPage, retCode, err := pmodel.Create(operation, author_id, &getThisPage)
	if err != nil {
		log.Fatalf(" PageModel Create Failed: %#v", err)
		count.FailCount++
		return
	}

	if got, want := retCode, 0; got != want {
		t.Errorf("PageModelCreate Broken: got  %d, wanted  %d", got, want)
		count.FailCount++
		return
	}
	pageId = (*gotPage).Id
	log.Printf("PageModel Create Successful for %#v", gotPage)
	count.SuccessCount++
	log.SetPrefix("")
}
Esempio n. 9
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. 10
0
func TestRatingModelCreate(t *testing.T) {
	testName := util.GetCallerName()
	log.Printf("---------------- Starting  Test ( %s )---------------------", testName)
	TestUserModelCreate(t)
	//userId := createId
	TestRevisionModelCreate(t)
	//revId := createId
	trmodel := RatingModel{}
	if gotER, retCode, err := trmodel.CreateRelationship("addrating", userId, revId, 100); gotER == nil || err != nil {
		//if gotER == nil || err != nil {
		log.Fatalf("%s Failed: %#v", testName, err)
		count.FailCount++
		return
	} else {

		if got, want := retCode, 0; got != want {
			t.Errorf("%s Broken: got  %d, wanted  %d", testName, got, want)
			count.FailCount++
			return
		}
		//		createId = (*gotER).Id
		log.Printf("%s Create Successful for relationship (%d)", testName, gotER.AccountId)
		count.SuccessCount++
		return
	}
}
Esempio n. 11
0
func processGenericVDL(vdlOperation string, variadicArgs ...interface{}) ([]map[string]interface{}, 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)

	return retMap, retCode, nil
}
Esempio n. 12
0
func TestCreateUser(t *testing.T) {
	log.Printf("---------------- Starting  Test ( %s )---------------------", util.GetCallerName())
	//now := time.Now();

	wantUserJSON := `{"Id":0,"Name":"sCamelCase","Email":"*****@*****.**","Status":{"StatusCode":0,"Desc":"Initalized"}}`
	u := &User{
		Name:   "sCamelCase",
		Email:  "*****@*****.**",
		Status: StatusDetail{INITIALIZED, fmt.Sprint(StatusType(INITIALIZED))},
	}
	//u.Created = &jsonTime{time.Now(), time.RFC3339}
	//u.Modified = &jsonTime{time.Now(), time.RFC3339}
	gotJSON, err := json.Marshal(u)
	if err != nil {
		t.Error(err)
		return
	}
	//
	if wantUserJSON != string(gotJSON) {
		t.Errorf("Received = %s\n Expected %s", gotJSON, wantUserJSON)
		return
	}
	log.Printf("Successfully created user %s", string(gotJSON))

}
Esempio n. 13
0
func TestEntityRelationShipNoExtraValues(t *testing.T) {
	funcName := util.GetCallerName()
	log.Printf("%s ---------------- Starting  Test ---------------------", funcName)
	er := &EntityRelationship{
		RelId1:   1,
		RelId2:   1,
		RelName1: "dto.Revision",
		RelName2: "dto.Tag",
		RelType1: reflect.TypeOf(Revision{}),
		RelType2: reflect.TypeOf(Tag{}),
		Status:   SetStatus(StatusType(0)),
	}
	//
	if er == nil || er.Values != nil || len(er.Values) != 0 {
		t.Errorf("%s Values  set = %v", funcName, er)
		count.FailCount++
		return
	}

	gotJSON, err := json.Marshal(er)
	if err != nil {
		t.Error("%s Could not construct JSON %v", funcName, err)
		count.FailCount++
		return
	}

	if hasValues := strings.Contains(string(gotJSON), "Values"); hasValues {
		t.Error("%s Values still present in %v", funcName, string(gotJSON))
		count.FailCount++
		return
	}
	log.Printf("%s Successfully created entity relationship %v", funcName, string(gotJSON))

	count.SuccessCount++
}
Esempio n. 14
0
func TestEntityRelationShipExtraValues(t *testing.T) {
	funcName := util.GetCallerName()
	log.Printf("%s ---------------- Starting  Test ---------------------", funcName)
	er := &EntityRelationship{
		RelId1:   1,
		RelId2:   1,
		RelName1: "dto.Revision",
		RelName2: "dto.Tag",
		RelType1: reflect.TypeOf(Revision{}),
		RelType2: reflect.TypeOf(Tag{}),
		Status:   SetStatus(StatusType(0)),
		Values:   map[string]interface{}{"rating": 100, fmt.Sprintf("%s", reflect.TypeOf(Tag{})): Tag{Id: 1}},
	}
	//
	if er == nil || er.Values == nil || len(er.Values) == 0 {
		t.Errorf("%s Values not set = %v", funcName, er)
		count.FailCount++
		return
	}
	for k, v := range er.Values {
		log.Printf("%s Relationship has values ( %s, %s, %v)", funcName, k, reflect.TypeOf(v), reflect.ValueOf(v).Interface())

	}

	gotJSON, err := json.Marshal(er)
	if err != nil {
		t.Error("%s Could not construct JSON %v", funcName, err)
		count.FailCount++
		return
	}
	log.Printf("%s Successfully created entity relationship %v", funcName, string(gotJSON))

	count.SuccessCount++
}
Esempio n. 15
0
func TestMicroPageSvcDeletePage(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:    "DeletePage",
			Handler: restful.DefaultContainer.ServeHTTP,
			Path:    "%1/%2",
			Sub: map[string]string{
				"%1": mps.MicroSvc.GetFullPath(),
				"%2": "3",
			},
			Method:          "DELETE",
			Status:          http.StatusOK,
			PreAuthId:       7,
			OwnThreshold:    0,
			GlobalThreshold: 0,
		},
	}
	//mod, _ := mps.MicroSvc.getModel(mps.MicroSvc.GetFullPath())
	//log.Println("----------------------------------------------------------------------------")
	//log.Printf("----- Testing with Model ( %s )---------------------", reflect.TypeOf(mod))
	//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.Printf("----- Testing with Model ( %s )---------------------", reflect.TypeOf(mod))
	log.Println("----------------------------------------------------------------------------")
	resttest.RunTestSet(t, tests)
	log.SetPrefix("")
}
Esempio n. 16
0
func (revm RevisionModel) Update(vdlOperation string, revisionId int64, refRevision *dto.Revision) (*dto.Revision, int, error) {
	funcName := util.GetCallerName()
	modRevision := *refRevision

	log.Printf("%s Calling %s with %d", funcName, reflect.TypeOf(revm), modRevision)
	return revm.processVDLCall(vdlOperation, revisionId, modRevision.Content, modRevision.Status.StatusCode)
}
Esempio n. 17
0
func TestMicroRevisionSvcCreateTagRelationship(t *testing.T) {
	log.SetPrefix(util.GetCallerName() + " : ")
	mrs.Register(util.GetConfig().RootPath, util.GetConfig().ApiVersion, "/revision")
	mrs.MicroSvc.AddModel(model.RevisionModel{})
	mrs.MicroSvc.AddRelationship(reflect.TypeOf(dto.Tag{}), mockmodel.MockEntityRelationshipModel{})
	tests := []resttest.RESTTestContainer{
		{
			Desc:    "CreateTagRelationship",
			Handler: restful.DefaultContainer.ServeHTTP,
			Path:    "%1/%2/tag/%3",
			Sub: map[string]string{
				"%1": mrs.MicroSvc.GetFullPath(),
				"%2": "1",
				"%3": "1",
			},
			Method:          "PUT",
			Status:          http.StatusOK,
			PreAuthId:       7,
			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("")
}
Esempio n. 18
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. 19
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. 20
0
func (sm SectionModel) Update(vdlOperation string, uid int64, refDTO *dto.Section) (*dto.Section, int, error) {
	funcName := util.GetCallerName()
	modDTO := *refDTO

	log.Printf("%s Calling %s with %d", funcName, reflect.TypeOf(sm), modDTO)
	return sm.processVDLCall(vdlOperation, uid, modDTO.Name, modDTO.OrderNum, modDTO.Status.StatusCode)
}
Esempio n. 21
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. 22
0
func TestTagRevisionModelCreate(t *testing.T) {
	testName := util.GetCallerName()
	log.Printf("---------------- Starting  Test ( %s )---------------------", testName)
	TestTagModelCreate(t)
	TestRevisionModelCreate(t)
	trmodel := TagRevisionModel{}
	vdlOperation := "addtagrevision"
	if gotER, retCode, err := trmodel.CreateRelationship(vdlOperation, tagId, revId); gotER == nil || err != nil {
		//if gotER == nil || err != nil {
		log.Fatalf("%s Failed: %#v", testName, err)
		count.FailCount++
		return
	} else {

		if got, want := retCode, 0; got != want {
			t.Errorf("%s Broken: got  %d, wanted  %d", testName, got, want)
			count.FailCount++
			return
		}
		//		createId = (*gotER).Id
		log.Printf("%s Create Successful for relaionship (%d, %d, %v, %v, %v)", testName, gotER.RelId1, gotER.RelId2, gotER.Status, gotER.RelType1, gotER.RelType2)
		count.SuccessCount++
		return
	}
}
Esempio n. 23
0
//
// Used to indicate that the pre authorized user id needs to be put into the argument list for processing
// down the chain
func usesPreAuthorizedId(req *restful.Request, resp *restful.Response, chain *restful.FilterChain) {
	funcName := util.GetCallerName()
	log.Printf("%s Authorizing Request %s", funcName, req.Request.URL.RequestURI())
	req.Request.Header.Set("X-meritwiki-requires-preauth-id", "true")
	route := req.Request.URL.Path
	log.Printf("%s Authorizing Route Path %#v", funcName, route)
	chain.ProcessFilter(req, resp)
}
Esempio n. 24
0
func TestGetDBConfigProd(t *testing.T) {
	log.Printf("---------------- Starting  Test ( %s )---------------------", util.GetCallerName())
	config, err := getDBConfig("prod", "../../../deploy/db")
	if err != nil {
		log.Fatal(err)
	} else {
		log.Printf("Getting Connection to Database: %s , %s", config.Driver.Name, config.Driver.OpenStr)
	}
}
Esempio n. 25
0
func TestGetDBConfigNotFound(t *testing.T) {
	log.Printf("---------------- Starting  Test ( %s )---------------------", util.GetCallerName())
	_, err := getDBConfig("shouldnteverfindthisconfig", "../../../deploy/db")
	if err != nil {
		log.Printf("Successfully did not find: shouldnteverfindthisconfig , %#v", err)
	} else {
		log.Fatalf("Should have failed to find (shouldnteverfindthisconfig) ")
	}
}
Esempio n. 26
0
func TestRevisionModelFindByIdNotFound(t *testing.T) {
	log.SetPrefix(util.GetCallerName() + " : ")
	log.Printf("---------------- Starting  Test ( %s )---------------------", util.GetCallerName())
	searchId := int64(99991999)
	smodel := RevisionModel{}
	operation, _ := GetVDLOperation(smodel, "findbyid")
	revision, _, err := smodel.FindById(operation, searchId)
	if err != nil {
		count.SuccessCount++
		return

	}
	t.Errorf("RevisionModel RetrieveById  found %v: %s", revision, err)
	count.FailCount++
	return

	count.SuccessCount++
	log.SetPrefix("")
}
Esempio n. 27
0
func TestPageModelRetrieveByIdNotFound(t *testing.T) {
	log.SetPrefix(util.GetCallerName() + " : ")
	log.Printf("---------------- Starting  Test ( %s )---------------------", util.GetCallerName())
	searchId := int64(99991999)
	pmodel := PageModel{}
	operation, _ := GetVDLOperation(pmodel, "findbyid")
	page, retCode, err := pmodel.FindById(operation, searchId)
	if err != nil || retCode != 0 {
		count.SuccessCount++
		return

	}
	t.Errorf("PageModel RetrieveById  found %v: %s", page, err)
	count.FailCount++
	return

	count.SuccessCount++
	log.SetPrefix("")
}
Esempio n. 28
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("")
}
Esempio n. 29
0
func invokeModel(model interface{}, operationName string, args ...interface{}) (result []reflect.Value, failed error) { //interface{} {
	funcName := util.GetCallerName()
	log.Printf("%s model  [%v] [%s] [%#v]", funcName, reflect.TypeOf(model), operationName, args)
	if model == nil {
		log.Printf("%sModel not set", funcName)
		return nil, nil
	}
	inputs := make([]reflect.Value, 0)
	//
	// Use operationName to look up the VDL operation of the model
	// This assumes the model has fields for "operationName" and is annoated with
	// the VDL operations on those fields
	modelType := reflect.TypeOf(model)
	operation := strings.ToLower(operationName) // all postgres operations are lowercase
	vdlField, hasVdl := modelType.FieldByName(operation)
	if hasVdl { // == true
		//
		//If vdl operation provided then prepend it to the argument list
		vdlOperation := vdlField.Tag.Get("vdl")
		log.Printf("%s VDL Opeartion Field [%s]  found [%s]", funcName, operation, vdlOperation)
		inputs = append(inputs, reflect.ValueOf(vdlOperation))
	} else {
		log.Printf("VDL Opeartion Field (%s)) not found", operation)
	}
	//
	// process argument list
	log.Printf("processing %d args ", len(args))
	for i, _ := range args {
		switch reflect.TypeOf(args[i]).Kind() {
		case reflect.Slice:
			s := reflect.ValueOf(args[i])
			log.Printf("processing arg with %d args ", s.Len())
			for j := 0; j < s.Len(); j++ {
				a := s.Index(j).Interface()
				log.Printf("processed arg  %v  ", a)
				inputs = append(inputs, reflect.ValueOf(a))
			}
		default:
			inputs = append(inputs, reflect.ValueOf(args[i]))
		}

	}
	log.Printf(" %s calling [%s] on [%v] with %d args %v", funcName, operationName, modelType, len(inputs), inputs)

	if method := reflect.ValueOf(model).MethodByName(operationName); method.IsValid() {
		retval := method.Call(inputs)
		//retval := reflect.ValueOf(model).MethodByName(operationName).Call(inputs)
		result = retval
		return result, nil
	} else {
		log.Printf("Opearation %s not found on %s", operationName, modelType)
		return nil, errors.New(fmt.Sprintf("Method %s not found on %s", operationName, reflect.TypeOf(model)))
	}

}
Esempio n. 30
0
func (sm UserModel) Create(vdlOperation string, refDTO *dto.User) (*dto.User, int, error) {
	funcName := util.GetCallerName()
	newDTO := *refDTO

	log.Printf("%s Calling %s with %d", funcName, reflect.TypeOf(sm), newDTO)
	return sm.processVDLCall(
		vdlOperation,
		newDTO.Name,
		newDTO.PasswordHash,
		newDTO.Email,
		dto.INITIALIZED)
}