|
7 | 7 | import org.junit.jupiter.api.Test;
|
8 | 8 | import org.junit.jupiter.api.extension.ExtendWith;
|
9 | 9 | import org.lfenergy.compas.core.commons.ElementConverter;
|
| 10 | +import org.lfenergy.compas.scl.data.exception.CompasSclDataServiceException; |
10 | 11 | import org.lfenergy.compas.scl.data.model.ChangeSetType;
|
11 | 12 | import org.lfenergy.compas.scl.data.model.SclType;
|
12 | 13 | import org.lfenergy.compas.scl.data.model.Version;
|
|
21 | 22 | import static java.util.Collections.emptyList;
|
22 | 23 | import static org.junit.jupiter.api.Assertions.*;
|
23 | 24 | import static org.lfenergy.compas.scl.data.Constants.*;
|
| 25 | +import static org.lfenergy.compas.scl.data.exception.CompasSclDataServiceErrorCode.HEADER_NOT_FOUND_ERROR_CODE; |
24 | 26 | import static org.mockito.Mockito.*;
|
25 | 27 |
|
26 | 28 | @ExtendWith(MockitoExtension.class)
|
@@ -141,23 +143,21 @@ void update_WhenCalledWithCompasElements_ThenRepositoryIsCalled() {
|
141 | 143 | }
|
142 | 144 |
|
143 | 145 | @Test
|
144 |
| - void update_WhenCalledWithoutCompasElements_ThenRepositoryIsCalled() { |
| 146 | + void update_WhenCalledPreviousSclDoesNotContainHeader_ThenExceptionIsThrown() { |
145 | 147 | var type = SclType.SCD;
|
146 |
| - var name = "JUSTSOMENAME"; |
147 | 148 | var uuid = UUID.randomUUID();
|
148 | 149 | var changeSet = ChangeSetType.MAJOR;
|
149 | 150 | var scl = readSCL();
|
150 |
| - var previousScl = readSCL(); |
151 |
| - createCompasPrivate(previousScl, name, type); |
152 | 151 |
|
| 152 | + var previousScl = readSCL(); |
| 153 | + // Remove the Header from the previous version. |
| 154 | + processor.getChildNodeByName(previousScl, SCL_HEADER_ELEMENT_NAME) |
| 155 | + .ifPresent(element -> previousScl.removeChild(element)); |
153 | 156 | when(compasSclDataRepository.findByUUID(type, uuid)).thenReturn(previousScl);
|
154 |
| - doNothing().when(compasSclDataRepository).create(type, uuid, scl, currentVersion.getNextVersion(changeSet)); |
155 | 157 |
|
156 |
| - compasSclDataService.update(type, uuid, changeSet, scl); |
157 |
| - |
158 |
| - assertCompasExtenions(scl, name, type); |
159 |
| - verify(compasSclDataRepository, times(1)).create(type, uuid, scl, currentVersion.getNextVersion(changeSet)); |
160 |
| - verify(compasSclDataRepository, times(1)).findByUUID(type, uuid); |
| 158 | + var exception = assertThrows(CompasSclDataServiceException.class, |
| 159 | + () -> compasSclDataService.update(type, uuid, changeSet, scl)); |
| 160 | + assertEquals(HEADER_NOT_FOUND_ERROR_CODE, exception.getErrorCode()); |
161 | 161 | }
|
162 | 162 |
|
163 | 163 | @Test
|
|
0 commit comments