@@ -5,6 +5,8 @@ import akka.http.scaladsl.testkit.ScalatestRouteTest
5
5
import cromwell .pipeline .datastorage .dao .utils .{ TestProjectUtils , TestUserUtils }
6
6
import cromwell .pipeline .datastorage .dto ._
7
7
import cromwell .pipeline .datastorage .dto .auth .AccessTokenContent
8
+ import cromwell .pipeline .model .validator .Enable
9
+ import cromwell .pipeline .model .wrapper .ProjectConfigurationId
8
10
import cromwell .pipeline .service .ProjectConfigurationService .Exceptions .{ InternalError , NotFound , ValidationError }
9
11
import cromwell .pipeline .service .{ ProjectConfigurationService , VersioningException }
10
12
import cromwell .pipeline .utils .URLEncoderUtils
@@ -14,6 +16,7 @@ import org.scalatest.{ AsyncWordSpec, Matchers }
14
16
import org .scalatestplus .mockito .MockitoSugar
15
17
16
18
import java .nio .file .Paths
19
+ import java .util .UUID
17
20
import scala .concurrent .Future
18
21
19
22
class ProjectConfigurationControllerTest extends AsyncWordSpec with Matchers with ScalatestRouteTest with MockitoSugar {
@@ -24,7 +27,7 @@ class ProjectConfigurationControllerTest extends AsyncWordSpec with Matchers wit
24
27
val accessToken = AccessTokenContent (TestUserUtils .getDummyUserId)
25
28
val projectId = TestProjectUtils .getDummyProjectId
26
29
val configuration = ProjectConfiguration (
27
- ProjectConfigurationId .randomId ,
30
+ ProjectConfigurationId ( UUID .randomUUID().toString, Enable . Unsafe ) ,
28
31
projectId,
29
32
active = true ,
30
33
WdlParams (Paths .get(" /home/file" ), List (FileParameter (" nodeName" , StringTyped (Some (" hello" ))))),
@@ -46,21 +49,19 @@ class ProjectConfigurationControllerTest extends AsyncWordSpec with Matchers wit
46
49
47
50
" return success for update configuration" in {
48
51
when(configurationService.addConfiguration(configuration, accessToken.userId)).thenReturn(Future .unit)
49
- Put (s " /projects/ ${projectId.value}/configurations " , configurationAdditionRequest) ~> configurationController
50
- .route(
51
- accessToken
52
- ) ~> check {
52
+ Put (s " /projects/ $projectId/configurations " , configurationAdditionRequest) ~> configurationController.route(
53
+ accessToken
54
+ ) ~> check {
53
55
status shouldBe StatusCodes .NoContent
54
56
}
55
57
}
56
58
57
59
" return InternalServerError when failure update configuration" in {
58
60
val error = InternalError (" Something went wrong" )
59
61
when(configurationService.addConfiguration(configuration, accessToken.userId)).thenReturn(Future .failed(error))
60
- Put (s " /projects/ ${projectId.value}/configurations " , configurationAdditionRequest) ~> configurationController
61
- .route(
62
- accessToken
63
- ) ~> check {
62
+ Put (s " /projects/ $projectId/configurations " , configurationAdditionRequest) ~> configurationController.route(
63
+ accessToken
64
+ ) ~> check {
64
65
status shouldBe StatusCodes .InternalServerError
65
66
entityAs[String ] shouldBe " Something went wrong"
66
67
}
@@ -69,10 +70,9 @@ class ProjectConfigurationControllerTest extends AsyncWordSpec with Matchers wit
69
70
" return NotFound when failure find project to update configuration" in {
70
71
when(configurationService.addConfiguration(configuration, accessToken.userId))
71
72
.thenReturn(Future .failed(NotFound ()))
72
- Put (s " /projects/ ${projectId.value}/configurations " , configurationAdditionRequest) ~> configurationController
73
- .route(
74
- accessToken
75
- ) ~> check {
73
+ Put (s " /projects/ $projectId/configurations " , configurationAdditionRequest) ~> configurationController.route(
74
+ accessToken
75
+ ) ~> check {
76
76
status shouldBe StatusCodes .NotFound
77
77
}
78
78
}
@@ -82,18 +82,18 @@ class ProjectConfigurationControllerTest extends AsyncWordSpec with Matchers wit
82
82
" return configuration by existing project id" in {
83
83
when(configurationService.getLastByProjectId(projectId, accessToken.userId))
84
84
.thenReturn(Future .successful(configuration))
85
- Get (s " /projects/ ${ projectId.value} /configurations " ) ~> configurationController.route(accessToken) ~> check {
85
+ Get (s " /projects/ $projectId/configurations " ) ~> configurationController.route(accessToken) ~> check {
86
86
status shouldBe StatusCodes .OK
87
87
entityAs[ProjectConfiguration ] shouldBe configuration
88
88
}
89
89
}
90
90
91
91
" return Configuration not found message" in {
92
92
when(configurationService.getLastByProjectId(projectId, accessToken.userId))
93
- .thenReturn(Future .failed(NotFound (s " There is no configuration with project_id: ${ projectId.value} " )))
94
- Get (s " /projects/ ${ projectId.value} /configurations " ) ~> configurationController.route(accessToken) ~> check {
93
+ .thenReturn(Future .failed(NotFound (s " There is no configuration with project_id: $projectId" )))
94
+ Get (s " /projects/ $projectId/configurations " ) ~> configurationController.route(accessToken) ~> check {
95
95
status shouldBe StatusCodes .NotFound
96
- entityAs[String ] shouldBe s " There is no configuration with project_id: ${ projectId.value} "
96
+ entityAs[String ] shouldBe s " There is no configuration with project_id: $projectId"
97
97
}
98
98
}
99
99
}
@@ -103,15 +103,15 @@ class ProjectConfigurationControllerTest extends AsyncWordSpec with Matchers wit
103
103
104
104
" return success for deactivate configuration" in {
105
105
when(configurationService.deactivateLastByProjectId(projectId, accessToken.userId)).thenReturn(Future .unit)
106
- Delete (s " /projects/ ${ projectId.value} /configurations " ) ~> configurationController.route(accessToken) ~> check {
106
+ Delete (s " /projects/ $projectId/configurations " ) ~> configurationController.route(accessToken) ~> check {
107
107
status shouldBe StatusCodes .NoContent
108
108
}
109
109
}
110
110
111
111
" return InternalServerError when failure deactivate configuration" in {
112
112
when(configurationService.deactivateLastByProjectId(projectId, accessToken.userId))
113
113
.thenReturn(Future .failed(error))
114
- Delete (s " /projects/ ${ projectId.value} /configurations " ) ~> configurationController.route(accessToken) ~> check {
114
+ Delete (s " /projects/ $projectId/configurations " ) ~> configurationController.route(accessToken) ~> check {
115
115
status shouldBe StatusCodes .InternalServerError
116
116
entityAs[String ] shouldBe " Something went wrong"
117
117
}
@@ -120,7 +120,7 @@ class ProjectConfigurationControllerTest extends AsyncWordSpec with Matchers wit
120
120
" return NotFound when failure find project to deactivate configuration" in {
121
121
when(configurationService.deactivateLastByProjectId(projectId, accessToken.userId))
122
122
.thenReturn(Future .failed(NotFound ()))
123
- Delete (s " /projects/ ${ projectId.value} /configurations " ) ~> configurationController.route(accessToken) ~> check {
123
+ Delete (s " /projects/ $projectId/configurations " ) ~> configurationController.route(accessToken) ~> check {
124
124
status shouldBe StatusCodes .NotFound
125
125
}
126
126
}
@@ -131,7 +131,7 @@ class ProjectConfigurationControllerTest extends AsyncWordSpec with Matchers wit
131
131
" return configuration for file" in {
132
132
when(configurationService.buildConfiguration(projectId, path, versionOption, accessToken.userId))
133
133
.thenReturn(Future .successful(configuration))
134
- Get (s " /projects/ ${ projectId.value} /configurations/files/ $pathString?version= $versionString" ) ~>
134
+ Get (s " /projects/ $projectId/configurations/files/ $pathString?version= $versionString" ) ~>
135
135
configurationController.route(accessToken) ~> check {
136
136
status shouldBe StatusCodes .OK
137
137
entityAs[ProjectConfiguration ] shouldBe configuration
@@ -141,7 +141,7 @@ class ProjectConfigurationControllerTest extends AsyncWordSpec with Matchers wit
141
141
" return failed for Bad request" in {
142
142
when(configurationService.buildConfiguration(projectId, path, versionOption, accessToken.userId))
143
143
.thenReturn(Future .failed(VersioningException .HttpException (" Bad request" )))
144
- Get (s " /projects/ ${ projectId.value} /configurations/files/ $pathString?version= $versionString" ) ~>
144
+ Get (s " /projects/ $projectId/configurations/files/ $pathString?version= $versionString" ) ~>
145
145
configurationController.route(accessToken) ~> check {
146
146
status shouldBe StatusCodes .InternalServerError
147
147
entityAs[String ] shouldBe " Bad request"
@@ -151,7 +151,7 @@ class ProjectConfigurationControllerTest extends AsyncWordSpec with Matchers wit
151
151
" return failed for invalid file" in {
152
152
when(configurationService.buildConfiguration(projectId, path, versionOption, accessToken.userId))
153
153
.thenReturn(Future .failed(ValidationError (List (" invalid some field" ).mkString(" ," ))))
154
- Get (s " /projects/ ${ projectId.value} /configurations/files/ $pathString?version= $versionString" ) ~>
154
+ Get (s " /projects/ $projectId/configurations/files/ $pathString?version= $versionString" ) ~>
155
155
configurationController.route(accessToken) ~> check {
156
156
status shouldBe StatusCodes .UnprocessableEntity
157
157
entityAs[String ] shouldBe " invalid some field"
0 commit comments