|
16 | 16 | import org.lfenergy.compas.scl.data.model.Item;
|
17 | 17 | import org.lfenergy.compas.scl.data.model.Version;
|
18 | 18 | import org.lfenergy.compas.scl.data.rest.v1.model.CreateRequest;
|
| 19 | +import org.lfenergy.compas.scl.data.rest.v1.model.DuplicateNameCheckRequest; |
19 | 20 | import org.lfenergy.compas.scl.data.rest.v1.model.UpdateRequest;
|
20 | 21 | import org.lfenergy.compas.scl.data.service.CompasSclDataService;
|
21 | 22 | import org.lfenergy.compas.scl.extensions.model.SclFileType;
|
|
27 | 28 |
|
28 | 29 | import static io.restassured.RestAssured.given;
|
29 | 30 | import static io.restassured.path.xml.config.XmlPathConfig.xmlPathConfig;
|
30 |
| -import static org.junit.jupiter.api.Assertions.assertEquals; |
| 31 | +import static org.junit.jupiter.api.Assertions.*; |
31 | 32 | import static org.lfenergy.compas.scl.data.SclDataServiceConstants.SCL_NS_URI;
|
32 | 33 | import static org.lfenergy.compas.scl.data.rest.Constants.*;
|
33 | 34 | import static org.mockito.Mockito.*;
|
@@ -267,6 +268,54 @@ void deleteVersion_WhenCalled_ThenServiceCalled() {
|
267 | 268 | verify(compasSclDataService).delete(type, uuid, version);
|
268 | 269 | }
|
269 | 270 |
|
| 271 | + @Test |
| 272 | + void checkNameForDuplication_WhenCalled_WithDuplicateName_ThenServiceCalled() { |
| 273 | + var type = SclFileType.SCD; |
| 274 | + var name = "STATION-0012312"; |
| 275 | + |
| 276 | + when(compasSclDataService.hasDuplicateSclName(type, name)).thenReturn(true); |
| 277 | + |
| 278 | + var request = new DuplicateNameCheckRequest(); |
| 279 | + request.setName(name); |
| 280 | + |
| 281 | + var response = given() |
| 282 | + .pathParam(TYPE_PATH_PARAM, type) |
| 283 | + .contentType(ContentType.XML) |
| 284 | + .body(request) |
| 285 | + .when().post("/checkname") |
| 286 | + .then() |
| 287 | + .statusCode(200) |
| 288 | + .extract() |
| 289 | + .response(); |
| 290 | + |
| 291 | + verify(compasSclDataService).hasDuplicateSclName(type, name); |
| 292 | + assertTrue(response.xmlPath().getBoolean("DuplicateNameCheckResponse.Duplicate")); |
| 293 | + } |
| 294 | + |
| 295 | + @Test |
| 296 | + void checkNameForDuplication_WhenCalled_WithUniqueName_ThenServiceCalled() { |
| 297 | + var type = SclFileType.SCD; |
| 298 | + var name = "STATION-0012312"; |
| 299 | + |
| 300 | + when(compasSclDataService.hasDuplicateSclName(type, name)).thenReturn(false); |
| 301 | + |
| 302 | + var request = new DuplicateNameCheckRequest(); |
| 303 | + request.setName(name); |
| 304 | + |
| 305 | + var response = given() |
| 306 | + .pathParam(TYPE_PATH_PARAM, type) |
| 307 | + .contentType(ContentType.XML) |
| 308 | + .body(request) |
| 309 | + .when().post("/checkname") |
| 310 | + .then() |
| 311 | + .statusCode(200) |
| 312 | + .extract() |
| 313 | + .response(); |
| 314 | + |
| 315 | + verify(compasSclDataService).hasDuplicateSclName(type, name); |
| 316 | + assertFalse(response.xmlPath().getBoolean("DuplicateNameCheckResponse.Duplicate")); |
| 317 | + } |
| 318 | + |
270 | 319 | private String readSCL() throws IOException {
|
271 | 320 | try (var inputStream = getClass().getResourceAsStream("/scl/icd_import_ied_test.scd")) {
|
272 | 321 | assert inputStream != null;
|
|
0 commit comments