2727import io .gravitee .cockpit .api .command .v1 .designer .DeployModelCommand ;
2828import io .gravitee .cockpit .api .command .v1 .designer .DeployModelCommandPayload ;
2929import io .gravitee .cockpit .api .command .v1 .designer .DeployModelReply ;
30+ import io .gravitee .definition .model .DefinitionVersion ;
3031import io .gravitee .exchange .api .command .CommandStatus ;
3132import io .gravitee .rest .api .model .EnvironmentEntity ;
3233import io .gravitee .rest .api .model .UserEntity ;
@@ -208,6 +209,34 @@ public void creates_an_API_PUBLISHED_mode() throws InterruptedException {
208209 obs .assertValue (reply -> reply .getCommandId ().equals (command .getId ()) && reply .getCommandStatus ().equals (CommandStatus .SUCCEEDED ));
209210 }
210211
212+ @ Test
213+ public void should_return_error_when_updating_migrated_v4_api () throws InterruptedException {
214+ DeployModelCommandPayload payload = createDeployPayload (DeployModelCommandPayload .DeploymentMode .API_DOCUMENTED );
215+
216+ DeployModelCommand command = new DeployModelCommand (payload );
217+
218+ String apiId = "api#id" ;
219+ when (apiSearchService .findIdByEnvironmentIdAndCrossId (ENVIRONMENT_ID , payload .modelId ())).thenReturn (Optional .of (apiId ));
220+ when (apiSearchService .findById (EXECUTION_CONTEXT , apiId )).thenReturn (
221+ io .gravitee .rest .api .model .v4 .api .ApiEntity .builder ().definitionVersion (DefinitionVersion .V4 ).build ()
222+ );
223+
224+ UserEntity user = createUserEntity (payload );
225+ when (userService .findBySource (any (), eq ("cockpit" ), eq (payload .userId ()), eq (true ))).thenReturn (user );
226+
227+ cut
228+ .handle (command )
229+ .test ()
230+ .await ()
231+ .assertNoErrors ()
232+ .assertValue (
233+ reply ->
234+ reply .getCommandId ().equals (command .getId ()) &&
235+ reply .getCommandStatus ().equals (CommandStatus .ERROR ) &&
236+ reply .getErrorDetails ().equals ("API migrated from v2 to v4. Update not yet supported." )
237+ );
238+ }
239+
211240 @ Test
212241 public void updates_an_API_DOCUMENTED () throws InterruptedException {
213242 DeployModelCommandPayload payload = createDeployPayload (DeployModelCommandPayload .DeploymentMode .API_DOCUMENTED );
@@ -216,6 +245,9 @@ public void updates_an_API_DOCUMENTED() throws InterruptedException {
216245
217246 String apiId = "api#id" ;
218247 when (apiSearchService .findIdByEnvironmentIdAndCrossId (ENVIRONMENT_ID , payload .modelId ())).thenReturn (Optional .of (apiId ));
248+ when (apiSearchService .findById (EXECUTION_CONTEXT , apiId )).thenReturn (
249+ io .gravitee .rest .api .model .v4 .api .ApiEntity .builder ().definitionVersion (DefinitionVersion .V2 ).build ()
250+ );
219251
220252 UserEntity user = createUserEntity (payload );
221253 when (userService .findBySource (any (), eq ("cockpit" ), eq (payload .userId ()), eq (true ))).thenReturn (user );
@@ -254,6 +286,9 @@ public void updates_an_API_MOCKED_mode() throws InterruptedException {
254286
255287 String apiId = "api#id" ;
256288 when (apiSearchService .findIdByEnvironmentIdAndCrossId (ENVIRONMENT_ID , payload .modelId ())).thenReturn (Optional .of (apiId ));
289+ when (apiSearchService .findById (EXECUTION_CONTEXT , apiId )).thenReturn (
290+ io .gravitee .rest .api .model .v4 .api .ApiEntity .builder ().definitionVersion (DefinitionVersion .V2 ).build ()
291+ );
257292
258293 UserEntity user = createUserEntity (payload );
259294 when (userService .findBySource (any (), eq ("cockpit" ), eq (payload .userId ()), eq (true ))).thenReturn (user );
@@ -292,6 +327,9 @@ public void updates_an_API_PUBLISHED_mode() throws InterruptedException {
292327
293328 String apiId = "api#id" ;
294329 when (apiSearchService .findIdByEnvironmentIdAndCrossId (ENVIRONMENT_ID , payload .modelId ())).thenReturn (Optional .of (apiId ));
330+ when (apiSearchService .findById (EXECUTION_CONTEXT , apiId )).thenReturn (
331+ io .gravitee .rest .api .model .v4 .api .ApiEntity .builder ().definitionVersion (DefinitionVersion .V2 ).build ()
332+ );
295333
296334 UserEntity user = createUserEntity (payload );
297335 when (userService .findBySource (ORGANIZATION_ID , "cockpit" , payload .userId (), true )).thenReturn (user );
@@ -422,6 +460,9 @@ public void fails_to_update_due_to_permission_issues() throws InterruptedExcepti
422460
423461 String apiId = "api#id" ;
424462 when (apiSearchService .findIdByEnvironmentIdAndCrossId (ENVIRONMENT_ID , payload .modelId ())).thenReturn (Optional .of (apiId ));
463+ when (apiSearchService .findById (EXECUTION_CONTEXT , apiId )).thenReturn (
464+ io .gravitee .rest .api .model .v4 .api .ApiEntity .builder ().definitionVersion (DefinitionVersion .V2 ).build ()
465+ );
425466
426467 UserEntity user = createUserEntity (payload );
427468 when (userService .findBySource (ORGANIZATION_ID , "cockpit" , payload .userId (), true )).thenReturn (user );
0 commit comments