Skip to content

Commit a48d6b6

Browse files
author
Flurb
committed
review comments
Signed-off-by: Flurb <[email protected]>
1 parent c650b1e commit a48d6b6

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

repository-postgresql/src/main/java/org/lfenergy/compas/scl/data/repository/postgresql/CompasSclDataPostgreSQLRepository.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,10 @@ public String findByUUID(SclFileType type, UUID id, Version version) {
157157

158158
@Override
159159
public boolean hasDuplicateSclName(SclFileType type, String name) {
160-
var sql = "SELECT DISTINCT ON (id) m.* "
161-
+ FROM_CLAUSE + "m "
162-
+ "WHERE m.type=? "
163-
+ "ORDER BY m.id, m.major_version desc, m.minor_version desc, m.patch_version desc";
160+
var sql = "SELECT DISTINCT ON (id) * "
161+
+ FROM_CLAUSE
162+
+ "WHERE type=? "
163+
+ "ORDER BY id, major_version desc, minor_version desc, patch_version desc";
164164

165165
try (var connection = dataSource.getConnection();
166166
var stmt = connection.prepareStatement(sql)) {

service/src/test/java/org/lfenergy/compas/scl/data/service/impl/CompasSclDataServiceImplTest.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ void create_WhenCalledWithOutCompasExtension_ThenSCLReturnedWithCorrectCompasExt
127127
assertCompasExtenions(scl, name);
128128
assertHistoryItem(scl, INITIAL_VERSION, comment);
129129
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);
130131
}
131132

132133
@Test
@@ -147,6 +148,7 @@ void create_WhenCalledWithCompasExtension_ThenSCLReturnedWithCorrectCompasExtens
147148
assertCompasExtenions(scl, name);
148149
assertHistoryItem(scl, INITIAL_VERSION, comment);
149150
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);
150152
}
151153

152154
@Test
@@ -200,6 +202,7 @@ void update_WhenCalledWithoutCompasElements_ThenSCLReturnedWithCorrectCompasExte
200202
assertHistoryItem(scl, nextVersion, null);
201203
verify(compasSclDataRepository, times(1)).create(eq(SCL_TYPE), eq(uuid), eq(previousName), anyString(), eq(nextVersion), eq(who));
202204
verify(compasSclDataRepository, times(1)).findMetaInfoByUUID(SCL_TYPE, uuid);
205+
verify(compasSclDataRepository, never()).hasDuplicateSclName(SCL_TYPE, previousName);
203206
}
204207

205208
@Test
@@ -217,6 +220,7 @@ void update_WhenCalledWithCompasElementsAndNewName_ThenSCLReturnedWithCorrectCom
217220
var sclMetaInfo = new SclMetaInfo(uuid.toString(), previousName, INITIAL_VERSION.toString());
218221
when(compasSclDataRepository.findMetaInfoByUUID(SCL_TYPE, uuid)).thenReturn(sclMetaInfo);
219222
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);
220224

221225
scl = compasSclDataService.update(SCL_TYPE, uuid, changeSet, who, null, scl);
222226

@@ -225,6 +229,30 @@ void update_WhenCalledWithCompasElementsAndNewName_ThenSCLReturnedWithCorrectCom
225229
assertHistoryItem(scl, nextVersion, null);
226230
verify(compasSclDataRepository, times(1)).create(eq(SCL_TYPE), eq(uuid), eq(newName), anyString(), eq(nextVersion), eq(who));
227231
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);
228256
}
229257

230258
@Test
@@ -249,6 +277,7 @@ void update_WhenCalledWithCompasElementsAndSameName_ThenSCLReturnedWithCorrectCo
249277
assertHistoryItem(scl, nextVersion, null);
250278
verify(compasSclDataRepository, times(1)).create(eq(SCL_TYPE), eq(uuid), eq(previousName), anyString(), eq(nextVersion), eq(who));
251279
verify(compasSclDataRepository, times(1)).findMetaInfoByUUID(SCL_TYPE, uuid);
280+
verify(compasSclDataRepository, never()).hasDuplicateSclName(SCL_TYPE, previousName);
252281
}
253282

254283
@Test

0 commit comments

Comments
 (0)