diff --git a/binding/review.go b/binding/review.go new file mode 100644 index 000000000..775f87c24 --- /dev/null +++ b/binding/review.go @@ -0,0 +1,61 @@ +package binding + +import ( + "github.com/konveyor/tackle2-hub/api" +) + +// +// Review API. +type Review struct { + client *Client +} + +// +// Create a Review. +func (h *Review) Create(r *api.Review) (err error) { + err = h.client.Post(api.ReviewsRoot, &r) + return +} + +// +// Get a Review by ID. +func (h *Review) Get(id uint) (r *api.Review, err error) { + r = &api.Review{} + path := Path(api.ReviewRoot).Inject(Params{api.ID: id}) + err = h.client.Get(path, r) + return +} + +// +// List Reviews. +func (h *Review) List() (list []api.Review, err error) { + list = []api.Review{} + err = h.client.Get(api.ReviewsRoot, &list) + return +} + +// +// Update a Review. +func (h *Review) Update(r *api.Review) (err error) { + path := Path(api.ReviewRoot).Inject(Params{api.ID: r.ID}) + err = h.client.Put(path, r) + return +} + +// +// Delete a Review. +func (h *Review) Delete(id uint) (err error) { + err = h.client.Delete(Path(api.ReviewRoot).Inject(Params{api.ID: id})) + return +} + +// +// Copy a Review. +func (h *Review) Copy(reviewID uint, appID uint) (err error) { + copyRequest := api.CopyRequest{ + SourceReview: reviewID, + TargetApplications: []uint{appID}, + } + err = h.client.Post(api.CopyRoot, copyRequest) + return +} diff --git a/binding/richclient.go b/binding/richclient.go index a4222d9e7..25c1bd08c 100644 --- a/binding/richclient.go +++ b/binding/richclient.go @@ -28,6 +28,7 @@ type RichClient struct { Identity Identity JobFunction JobFunction Proxy Proxy + Review Review RuleSet RuleSet Setting Setting Stakeholder Stakeholder @@ -74,6 +75,9 @@ func New(baseUrl string) (r *RichClient) { Proxy: Proxy{ client: client, }, + Review: Review{ + client: client, + }, RuleSet: RuleSet{ client: client, }, diff --git a/docs/test-api-matrix.md b/docs/test-api-matrix.md index 78fdaf1ce..052f0d4c2 100644 --- a/docs/test-api-matrix.md +++ b/docs/test-api-matrix.md @@ -8,7 +8,7 @@ bucket||||partially within application dependency|:heavy_check_mark:|:heavy_check_mark:|:heavy_check_mark:| file|:heavy_check_mark:|:heavy_check_mark:|| import||:heavy_check_mark:|| -review|||| +review|:heavy_check_mark|:heavy_check_mark|| **Controls**|||| businessservice|:heavy_check_mark:|:heavy_check_mark:|| group|:heavy_check_mark:|:heavy_check_mark:||aka StakeholderGroup diff --git a/test/api/review/api_test.go b/test/api/review/api_test.go new file mode 100644 index 000000000..2fd67cf99 --- /dev/null +++ b/test/api/review/api_test.go @@ -0,0 +1,164 @@ +package review + +import ( + "fmt" + "testing" + + "github.com/konveyor/tackle2-hub/api" + "github.com/konveyor/tackle2-hub/test/assert" +) + +func TestReviewCRUD(t *testing.T) { + for _, r := range Samples { + t.Run("Review CRUD", func(t *testing.T) { + + // Create Application and Review. + app := api.Application{ + Name: r.Application.Name, + Description: "Application for Review", + } + assert.Must(t, Application.Create(&app)) + + // Update Application ID with the Sample Id. + r.Application.ID = app.ID + + assert.Must(t, Review.Create(&r)) + + // Get. + got, err := Review.Get(r.ID) + if err != nil { + t.Errorf(err.Error()) + } + + // Compare got values with expected values. + AssertEqualReviews(t, got, r) + + // Update Comments and Effort Estimate. + r.Comments = "Updated Comment " + r.Comments + assert.Should(t, Review.Update(&r)) + + // Find Review and check its parameters with the got(On Updation). + got, err = Review.Get(r.ID) + if err != nil { + t.Errorf(err.Error()) + } + + // Check if the unchanged values remain same or not. + AssertEqualReviews(t, got, r) + + // Delete Related Applications. + assert.Must(t, Application.Delete(app.ID)) + // Delete Review. + assert.Must(t, Review.Delete(r.ID)) + + // Check if the review is present even after deletion or not. + _, err = Review.Get(r.ID) + if err == nil { + t.Errorf("Resource exits, but should be deleted: %v", r) + } + }) + + t.Run("Copy Review", func(t *testing.T) { + + // Create Application and Review. + srcApp := api.Application{ + Name: r.Application.Name, + Description: "Application for Review", + } + assert.Must(t, Application.Create(&srcApp)) + + // Update Application ID with the Sample Id. + r.Application.ID = srcApp.ID + + assert.Must(t, Review.Create(&r)) + + // Create another application to copy + destApp := api.Application{ + Name: "New Application", + Description: "Application for Review", + Review: &api.Ref{ + ID: r.ID, + }, + } + assert.Must(t, Application.Create(&destApp)) + + err := Review.Copy(r.ID, destApp.ID) + if err != nil { + t.Errorf(err.Error()) + } + + gotReview, err := Review.Get(destApp.Review.ID) + if err != nil { + fmt.Println(err.Error()) + t.Errorf(err.Error()) + } + + // Check if the expcted review and got review is same. + AssertEqualReviews(t, gotReview, r) + + // Delete Review. + assert.Must(t, Review.Delete(r.ID)) + + // Delete Applications. + assert.Must(t, Application.Delete(srcApp.ID)) + assert.Must(t, Application.Delete(destApp.ID)) + }) + } +} + +func TestReviewList(t *testing.T) { + createdReviews := []api.Review{} + + for _, r := range Samples { + app := api.Application{ + Name: r.Application.Name, + Description: "Application for Review", + } + assert.Must(t, Application.Create(&app)) + + r.Application.ID = app.ID + assert.Should(t, Review.Create(&r)) + createdReviews = append(createdReviews, r) + } + + // List Reviews. + got, err := Review.List() + if err != nil { + t.Errorf(err.Error()) + } + + // check if created Reviews are in the list we got from Review.List() + for _, createdReview := range createdReviews { + found := false + for _, retrievedReview := range got { + if assert.FlatEqual(createdReview.ID, retrievedReview.ID) { + found = true + break + } + } + if !found { + t.Errorf("Expected review not found in the list: %v", createdReview) + } + } + + // Delete related reviews and applications. + for _, review := range createdReviews { + assert.Must(t, Application.Delete(review.ID)) + assert.Must(t, Review.Delete(review.ID)) + } +} + +func AssertEqualReviews(t *testing.T, got *api.Review, expected api.Review) { + if got.BusinessCriticality != expected.BusinessCriticality { + t.Errorf("Different Business Criticality Got %v, expected %v", got.BusinessCriticality, expected.BusinessCriticality) + } + if got.EffortEstimate != expected.EffortEstimate { + t.Errorf("Different Effort Estimate Got %v, expected %v", got.EffortEstimate, expected.EffortEstimate) + } + if got.ProposedAction != expected.ProposedAction { + t.Errorf("Different Proposed Action Got %v, expected %v", got.ProposedAction, expected.ProposedAction) + } + if got.WorkPriority != expected.WorkPriority { + t.Errorf("Different Work Priority Got %v, expected %v", got.WorkPriority, expected.WorkPriority) + } +} diff --git a/test/api/review/pkg.go b/test/api/review/pkg.go new file mode 100644 index 000000000..0575bfb21 --- /dev/null +++ b/test/api/review/pkg.go @@ -0,0 +1,23 @@ +package review + +import ( + "github.com/konveyor/tackle2-hub/binding" + "github.com/konveyor/tackle2-hub/test/api/client" +) + +var ( + RichClient *binding.RichClient + Review binding.Review + Application binding.Application +) + +func init() { + // Prepare RichClient and login to Hub API (configured from env variables). + RichClient = client.PrepareRichClient() + + // Shortcut for Review-related RichClient methods. + Review = RichClient.Review + + // Shortcut for Application-related RichClient methods. + Application = RichClient.Application +} diff --git a/test/api/review/samples.go b/test/api/review/samples.go new file mode 100644 index 000000000..e42441d6a --- /dev/null +++ b/test/api/review/samples.go @@ -0,0 +1,30 @@ +package review + +import ( + "github.com/konveyor/tackle2-hub/api" +) + +var Samples = []api.Review{ + { + BusinessCriticality: 1, + EffortEstimate: "min", + ProposedAction: "run", + WorkPriority: 1, + Comments: "nil", + Application: api.Ref{ + ID: 1, + Name: "Sample Review 1", + }, + }, + { + BusinessCriticality: 2, + EffortEstimate: "max", + ProposedAction: "stop", + WorkPriority: 2, + Comments: "nil", + Application: api.Ref{ + ID: 2, + Name: "Sample Review 2", + }, + }, +}