|
| 1 | +/* |
| 2 | + * -------------------------------------------------------------------------------- |
| 3 | + * <copyright company="Aspose" file="report_test.go"> |
| 4 | + * Copyright (c) 2021 Aspose.Tasks Cloud |
| 5 | + * </copyright> |
| 6 | + * <summary> |
| 7 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 8 | + * of this software and associated documentation files (the "Software"), to deal |
| 9 | + * in the Software without restriction, including without limitation the rights |
| 10 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 11 | + * copies of the Software, and to permit persons to whom the Software is |
| 12 | + * furnished to do so, subject to the following conditions: |
| 13 | + * |
| 14 | + * The above copyright notice and this permission notice shall be included in all |
| 15 | + * copies or substantial portions of the Software. |
| 16 | + * |
| 17 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 20 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 22 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 23 | + * SOFTWARE. |
| 24 | + * </summary> |
| 25 | + * -------------------------------------------------------------------------------- |
| 26 | + */ |
| 27 | + |
| 28 | +// Example of how to work with reports. |
| 29 | +package api_test |
| 30 | + |
| 31 | +import ( |
| 32 | + "github.com/antihax/optional" |
| 33 | + "github.com/aspose-tasks-cloud/aspose-tasks-cloud-go/api/models" |
| 34 | + "github.com/aspose-tasks-cloud/aspose-tasks-cloud-go/api/requests" |
| 35 | + "github.com/stretchr/testify/assert" |
| 36 | + "testing" |
| 37 | +) |
| 38 | + |
| 39 | +// Test for get report pdf. |
| 40 | +func Test_Report_GetReportPdf(t *testing.T) { |
| 41 | + localFileName := "Home_move_plan.mpp" |
| 42 | + remoteFileName := CreateRandomGuid() + localFileName |
| 43 | + client, ctx := UploadTestFileToStorage(t, localFileName, remoteBaseTestDataFolder+"/"+remoteFileName) |
| 44 | + |
| 45 | + opts := &requests.GetReportPdfOpts{ |
| 46 | + Type_: string(models.MILESTONES_ReportType), |
| 47 | + Name: remoteFileName, |
| 48 | + Folder: optional.NewString(remoteBaseTestDataFolder), |
| 49 | + } |
| 50 | + file, response, err := client.TasksApi.GetReportPdf(ctx, opts) |
| 51 | + if err != nil { |
| 52 | + t.Error(err) |
| 53 | + } |
| 54 | + assert.Equal(t, 200, response.StatusCode) |
| 55 | + assert.Less(t, 1, len(file)) |
| 56 | + fileAsStrings := ConvertBytesToStrings(file) |
| 57 | + assert.Equal(t, "%PDF-1.5", fileAsStrings[0]) |
| 58 | + t.Cleanup(func() { DeleteTestFileFromStorage(t, ctx, client) }) |
| 59 | +} |
| 60 | + |
| 61 | +// Test for get critical path. |
| 62 | +func Test_Report_GetCriticalPath(t *testing.T) { |
| 63 | + localFileName := "Home_move_plan.mpp" |
| 64 | + remoteFileName := CreateRandomGuid() + localFileName |
| 65 | + client, ctx := UploadTestFileToStorage(t, localFileName, remoteBaseTestDataFolder+"/"+remoteFileName) |
| 66 | + |
| 67 | + opts := &requests.GetCriticalPathOpts{ |
| 68 | + Name: remoteFileName, |
| 69 | + Folder: optional.NewString(remoteBaseTestDataFolder), |
| 70 | + } |
| 71 | + result, _, err := client.TasksApi.GetCriticalPath(ctx, opts) |
| 72 | + if err != nil { |
| 73 | + t.Error(err) |
| 74 | + } |
| 75 | + assert.Equal(t, int32(200), result.Code) |
| 76 | + assert.Equal(t, 76, len(result.Tasks.TaskItem)) |
| 77 | + t.Cleanup(func() { DeleteTestFileFromStorage(t, ctx, client) }) |
| 78 | +} |
| 79 | + |
| 80 | +// Test for get risk analysis report. |
| 81 | +func Test_Report_GetRiskAnalysisReport(t *testing.T) { |
| 82 | + localFileName := "Home_move_plan.mpp" |
| 83 | + remoteFileName := CreateRandomGuid() + localFileName |
| 84 | + client, ctx := UploadTestFileToStorage(t, localFileName, remoteBaseTestDataFolder+"/"+remoteFileName) |
| 85 | + |
| 86 | + opts := &requests.GetRiskAnalysisReportOpts{ |
| 87 | + Name: remoteFileName, |
| 88 | + TaskUid: 1, |
| 89 | + DistributionType: optional.NewString(string(models.NORMAL_ProbabilityDistributionType)), |
| 90 | + ConfidenceLevel: optional.NewString(string(models.CL85_ConfidenceLevel)), |
| 91 | + Optimistic: optional.NewInt32(80), |
| 92 | + Pessimistic: optional.NewInt32(130), |
| 93 | + Iterations: optional.NewInt32(200), |
| 94 | + Folder: optional.NewString(remoteBaseTestDataFolder), |
| 95 | + } |
| 96 | + file, response, err := client.TasksApi.GetRiskAnalysisReport(ctx, opts) |
| 97 | + if err != nil { |
| 98 | + t.Error(err) |
| 99 | + } |
| 100 | + assert.Equal(t, 200, response.StatusCode) |
| 101 | + assert.Less(t, 1, len(file)) |
| 102 | + fileAsStrings := ConvertBytesToStrings(file) |
| 103 | + assert.Equal(t, "%PDF-1.5", fileAsStrings[0]) |
| 104 | + t.Cleanup(func() { DeleteTestFileFromStorage(t, ctx, client) }) |
| 105 | +} |
0 commit comments