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("") }
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("") }
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("") }
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("") }
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("") }
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("") }
func init() { wd, _ := os.Getwd() log.Printf("WORKING DIR %s", wd) config := util.GetConfig() err := os.Setenv("WIKIENV", "test") if err != nil { log.Fatalf("Could not set WIKIENV %#v, %v", err, config) } err = os.Setenv("WIKICONFIGROOT", "../../../deploy/db") if err != nil { log.Fatalf("Could not set WIKICONFIGROOT %#v", err) } }
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("") }
func main() { log.Printf("------------------------------------------------------------------------------------------------------------------------") log.Printf("Starting server API Version = %s at root %s", util.GetConfig().ApiVersion, util.GetConfig().RootPath) log.Printf("------------------------------------------------------------------------------------------------------------------------") /* Process command line arguments*/ util.ReadFlags() sysConfig := util.GetConfig() //TODO: add Container and collection for microservices set root path and version? // Register User Micro Service mus := microrest.NewMicroUserSvc() mus.Register(util.GetConfig().RootPath, util.GetConfig().ApiVersion, "/user") mus.MicroSvc.AddModel(model.UserModel{}) //page mps := microrest.NewMicroPageSvc() mps.Register(util.GetConfig().RootPath, util.GetConfig().ApiVersion, "/page") mps.MicroSvc.AddModel(model.PageModel{}) //section mss := microrest.NewMicroSectionSvc() mss.Register(util.GetConfig().RootPath, util.GetConfig().ApiVersion, "/section") mss.MicroSvc.AddModel(model.SectionModel{}) //revision mrs := microrest.NewMicroRevisionSvc() mrs.Register(util.GetConfig().RootPath, util.GetConfig().ApiVersion, "/revision") mrs.MicroSvc.AddModel(model.RevisionModel{}) mrs.MicroSvc.AddRelationship(reflect.TypeOf(dto.Tag{}), model.TagRevisionModel{}) mrs.MicroSvc.AddRelationship(reflect.TypeOf(dto.Rating{}), model.RatingModel{}) //tag mts := microrest.NewMicroTagSvc() mts.Register(util.GetConfig().RootPath, util.GetConfig().ApiVersion, "/tag") mts.MicroSvc.AddModel(model.TagModel{}) //TODO: need to put url and swagger locations in config config := swagger.Config{ WebServices: restful.RegisteredWebServices(), // you control what services are visible WebServicesUrl: sysConfig.Swagger_WebServicesUrl + ":" + sysConfig.Port, //WebServicesUrl: "http://localhost:8686", ApiPath: "/apidocs.json", // Optionally, specifiy where the UI is located SwaggerPath: "/apidocs/", SwaggerFilePath: sysConfig.SwaggerFilePath} //SwaggerFilePath: "/Users/skircher/CodeProjects/go/src/swagger-ui/dist"} swagger.InstallSwaggerService(config) http.ListenAndServe(":"+sysConfig.Port, nil) }
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("") }