@@ -127,6 +127,7 @@ void create_WhenCalledWithOutCompasExtension_ThenSCLReturnedWithCorrectCompasExt
127
127
assertCompasExtenions (scl , name );
128
128
assertHistoryItem (scl , INITIAL_VERSION , comment );
129
129
verify (compasSclDataRepository , times (1 )).create (eq (SCL_TYPE ), any (UUID .class ), eq (name ), anyString (), eq (INITIAL_VERSION ), eq (who ));
130
+ verify (compasSclDataRepository , times (1 )).hasDuplicateSclName (SCL_TYPE , name );
130
131
}
131
132
132
133
@ Test
@@ -147,6 +148,7 @@ void create_WhenCalledWithCompasExtension_ThenSCLReturnedWithCorrectCompasExtens
147
148
assertCompasExtenions (scl , name );
148
149
assertHistoryItem (scl , INITIAL_VERSION , comment );
149
150
verify (compasSclDataRepository , times (1 )).create (eq (SCL_TYPE ), any (UUID .class ), eq (name ), anyString (), eq (INITIAL_VERSION ), eq (who ));
151
+ verify (compasSclDataRepository , times (1 )).hasDuplicateSclName (SCL_TYPE , name );
150
152
}
151
153
152
154
@ Test
@@ -200,6 +202,7 @@ void update_WhenCalledWithoutCompasElements_ThenSCLReturnedWithCorrectCompasExte
200
202
assertHistoryItem (scl , nextVersion , null );
201
203
verify (compasSclDataRepository , times (1 )).create (eq (SCL_TYPE ), eq (uuid ), eq (previousName ), anyString (), eq (nextVersion ), eq (who ));
202
204
verify (compasSclDataRepository , times (1 )).findMetaInfoByUUID (SCL_TYPE , uuid );
205
+ verify (compasSclDataRepository , never ()).hasDuplicateSclName (SCL_TYPE , previousName );
203
206
}
204
207
205
208
@ Test
@@ -217,6 +220,7 @@ void update_WhenCalledWithCompasElementsAndNewName_ThenSCLReturnedWithCorrectCom
217
220
var sclMetaInfo = new SclMetaInfo (uuid .toString (), previousName , INITIAL_VERSION .toString ());
218
221
when (compasSclDataRepository .findMetaInfoByUUID (SCL_TYPE , uuid )).thenReturn (sclMetaInfo );
219
222
doNothing ().when (compasSclDataRepository ).create (eq (SCL_TYPE ), eq (uuid ), eq (newName ), anyString (), eq (nextVersion ), eq (who ));
223
+ when (compasSclDataRepository .hasDuplicateSclName (SCL_TYPE , newName )).thenReturn (false );
220
224
221
225
scl = compasSclDataService .update (SCL_TYPE , uuid , changeSet , who , null , scl );
222
226
@@ -225,6 +229,30 @@ void update_WhenCalledWithCompasElementsAndNewName_ThenSCLReturnedWithCorrectCom
225
229
assertHistoryItem (scl , nextVersion , null );
226
230
verify (compasSclDataRepository , times (1 )).create (eq (SCL_TYPE ), eq (uuid ), eq (newName ), anyString (), eq (nextVersion ), eq (who ));
227
231
verify (compasSclDataRepository , times (1 )).findMetaInfoByUUID (SCL_TYPE , uuid );
232
+ verify (compasSclDataRepository , times (1 )).hasDuplicateSclName (SCL_TYPE , newName );
233
+ }
234
+
235
+ @ Test
236
+ void update_WhenCalledWithCompasElementsAndDuplicateNewName_ThenCompasExceptionThrown () throws IOException {
237
+ var previousName = "Previous SCL Filename" ;
238
+ var newName = "New SCL Filename" ;
239
+ var uuid = UUID .randomUUID ();
240
+ var changeSet = ChangeSetType .MAJOR ;
241
+ var who = "User A" ;
242
+ var nextVersion = INITIAL_VERSION .getNextVersion (changeSet );
243
+
244
+ var scl = createCompasPrivate (readSCL (), newName );
245
+
246
+ var sclMetaInfo = new SclMetaInfo (uuid .toString (), previousName , INITIAL_VERSION .toString ());
247
+ when (compasSclDataRepository .findMetaInfoByUUID (SCL_TYPE , uuid )).thenReturn (sclMetaInfo );
248
+ when (compasSclDataRepository .hasDuplicateSclName (SCL_TYPE , newName )).thenReturn (true );
249
+
250
+ var exception = assertThrows (CompasException .class , () -> {
251
+ compasSclDataService .update (SCL_TYPE , uuid , changeSet , who , null , scl );
252
+ });
253
+ assertEquals (DUPLICATE_SCL_NAME_ERROR_CODE , exception .getErrorCode ());
254
+ verify (compasSclDataRepository , times (1 )).findMetaInfoByUUID (SCL_TYPE , uuid );
255
+ verify (compasSclDataRepository , times (1 )).hasDuplicateSclName (SCL_TYPE , newName );
228
256
}
229
257
230
258
@ Test
@@ -249,6 +277,7 @@ void update_WhenCalledWithCompasElementsAndSameName_ThenSCLReturnedWithCorrectCo
249
277
assertHistoryItem (scl , nextVersion , null );
250
278
verify (compasSclDataRepository , times (1 )).create (eq (SCL_TYPE ), eq (uuid ), eq (previousName ), anyString (), eq (nextVersion ), eq (who ));
251
279
verify (compasSclDataRepository , times (1 )).findMetaInfoByUUID (SCL_TYPE , uuid );
280
+ verify (compasSclDataRepository , never ()).hasDuplicateSclName (SCL_TYPE , previousName );
252
281
}
253
282
254
283
@ Test
0 commit comments