Esempio n. 1
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. 2
0
func TestMicroRevisionSvcRetrieveTagRelationship(t *testing.T) {
	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:    "RetrieveTagRelationship",
			Handler: restful.DefaultContainer.ServeHTTP,
			Path:    "%1/%2/tag/%3",
			Sub: map[string]string{
				"%1": mrs.MicroSvc.GetFullPath(),
				"%2": "2",
				"%3": "2",
			},
			Method:          "GET",
			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)
	log.SetPrefix("")
}
Esempio n. 3
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("")
}
Esempio n. 4
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. 5
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("")
}
Esempio n. 6
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("")
}
Esempio n. 7
0
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("")
}
Esempio n. 8
0
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("")
}
Esempio n. 9
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("")
}