Skip to content

Commit 8d34291

Browse files
committed
[#464] Added additional unit test for code coverage
Signed-off-by: David Monichi <[email protected]>
1 parent 18f3ba7 commit 8d34291

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// SPDX-FileCopyrightText: 2025 BearingPoint GmbH
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
package org.lfenergy.compas.scl.data.repository.postgresql;
6+
7+
import org.junit.jupiter.api.BeforeEach;
8+
import org.junit.jupiter.api.Test;
9+
import org.junit.jupiter.api.extension.ExtendWith;
10+
import org.lfenergy.compas.scl.data.model.Version;
11+
12+
import org.lfenergy.compas.scl.extensions.model.SclFileType;
13+
import org.mockito.junit.jupiter.MockitoExtension;
14+
15+
import java.util.List;
16+
import java.util.UUID;
17+
18+
import static org.junit.jupiter.api.Assertions.*;
19+
20+
@ExtendWith({MockitoExtension.class, PostgreSQLServerJUnitExtension.class})
21+
class CompasSclDataPostgreSQLRepositoryConfigurationTest {
22+
private SoftDeleteCompasSclDataPostgreSQLRepository repository;
23+
private static final String TYPE = "SCD";
24+
25+
@BeforeEach
26+
void setUp() {
27+
repository = new SoftDeleteCompasSclDataPostgreSQLRepository(PostgreSQLServerJUnitExtension.getDataSource());
28+
}
29+
30+
@Test
31+
void delete_WhenCalledWithExistingUUID_ThenRecordsAreSoftDeleted() {
32+
UUID uuid = UUID.randomUUID();
33+
Version version = new Version(1, 0, 0);
34+
repository.create(SclFileType.SCD, uuid, "TestName", "<SCL></SCL>", version, "tester", List.of("label"));
35+
36+
repository.delete(SclFileType.SCD, uuid);
37+
38+
var items = repository.listVersionsByUUID(SclFileType.SCD, uuid);
39+
assertEquals(0, items.size(), "All versions should be soft deleted");
40+
}
41+
42+
@Test
43+
void deleteVersion_WhenCalledWithExistingUUIDAndVersion_ThenSpecificVersionIsDeleted() {
44+
UUID uuid = UUID.randomUUID();
45+
Version version1 = new Version(1, 0, 0);
46+
Version version2 = new Version(2, 0, 0);
47+
repository.create(SclFileType.SCD, uuid, "TestName", "<SCL></SCL>", version1, "tester", List.of("label"));
48+
repository.create(SclFileType.SCD, uuid, "TestName", "<SCL></SCL>", version2, "tester", List.of("label"));
49+
50+
var items = repository.listVersionsByUUID(SclFileType.SCD, uuid);
51+
assertEquals(2, items.size(), "Exact to versions should be present before deletion");
52+
53+
repository.delete(SclFileType.SCD, uuid, version1);
54+
55+
items = repository.listVersionsByUUID(SclFileType.SCD, uuid);
56+
assertEquals(1, items.size(), "Only one version should remain");
57+
assertEquals(version2.toString(), items.get(0).getVersion(), "Remaining version should be version2");
58+
}
59+
}

0 commit comments

Comments
 (0)