Skip to content

Commit bd0881c

Browse files
Added unit tests for repository
Signed-off-by: Pascal Wilbrink <pascal.wilbrink@alliander.com>
1 parent f4da177 commit bd0881c

File tree

15 files changed

+263
-8
lines changed

15 files changed

+263
-8
lines changed

app/src/test/java/org/lfenergy/compas/sitipe/rest/v1/model/BayTypicalResponseTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
class BayTypicalResponseTest {
2020

2121
@Test
22-
public void itShouldMapProperties() {
22+
void itShouldMapProperties() {
2323
final BayTypical entity = new BayTypical();
2424

2525
entity.setId(1);

repository/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ SPDX-License-Identifier: Apache-2.0
6767
<groupId>io.quarkus</groupId>
6868
<artifactId>quarkus-hibernate-orm-panache</artifactId>
6969
</dependency>
70+
<dependency>
71+
<groupId>com.openpojo</groupId>
72+
<artifactId>openpojo</artifactId>
73+
<scope>test</scope>
74+
</dependency>
7075
</dependencies>
7176

7277
<build>

repository/src/main/java/org/lfenergy/compas/sitipe/data/repository/BayTypicalRepository.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,4 @@ public List<BayTypical> findByAccessId(final String accessId) {
1717
return this.list("accessId", accessId);
1818
}
1919

20-
21-
22-
2320
}

repository/src/main/java/org/lfenergy/compas/sitipe/data/repository/ImportedComponentRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
public class ImportedComponentRepository implements PanacheRepositoryBase<ImportedComponent, Integer> {
1616

1717
public List<ImportedComponent> getByAccessId(final String accessId) {
18-
return this.list("componentAccessId = ?1 AND type = 'IID'", accessId);
18+
return this.list("componentAccessId = ?1 AND type = ?2", accessId, "IID");
1919
}
2020

2121
public ImportedComponent getById(final Integer id) {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// SPDX-FileCopyrightText: 2023 Alliander N.V.
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
package org.lfenergy.compas.sitipe.data.entity;
6+
7+
class BTComponentTest extends BaseEntityTest {
8+
9+
@Override
10+
protected Class<?> getClassToBeTested() {
11+
return BTComponent.class;
12+
}
13+
14+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// SPDX-FileCopyrightText: 2023 Alliander N.V.
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
package org.lfenergy.compas.sitipe.data.entity;
6+
7+
import com.openpojo.reflection.impl.PojoClassFactory;
8+
import com.openpojo.validation.ValidatorBuilder;
9+
import com.openpojo.validation.rule.impl.GetterMustExistRule;
10+
import com.openpojo.validation.rule.impl.SetterMustExistRule;
11+
import com.openpojo.validation.test.impl.GetterTester;
12+
import com.openpojo.validation.test.impl.SetterTester;
13+
import org.junit.jupiter.api.Test;
14+
15+
abstract class BaseEntityTest {
16+
17+
@Test
18+
void validateSettersAndGetters() {
19+
var personPojo = PojoClassFactory.getPojoClass(getClassToBeTested());
20+
var validator = ValidatorBuilder.create()
21+
// Let's make sure that we have a getter and a setter for every field defined.
22+
.with(new GetterMustExistRule())
23+
.with(new SetterMustExistRule())
24+
// Let's also validate that they are behaving as expected
25+
.with(new SetterTester())
26+
.with(new GetterTester())
27+
.build();
28+
29+
// Start the Test
30+
validator.validate(personPojo);
31+
}
32+
33+
protected abstract Class<?> getClassToBeTested();
34+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// SPDX-FileCopyrightText: 2023 Alliander N.V.
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
package org.lfenergy.compas.sitipe.data.entity;
6+
7+
class BayTypicalTest extends BaseEntityTest {
8+
9+
@Override
10+
protected Class<?> getClassToBeTested() {
11+
return BayTypical.class;
12+
}
13+
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// SPDX-FileCopyrightText: 2023 Alliander N.V.
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
package org.lfenergy.compas.sitipe.data.entity;
6+
7+
class ImportedComponentTest extends BaseEntityTest {
8+
9+
@Override
10+
protected Class<?> getClassToBeTested() {
11+
return ImportedComponent.class;
12+
}
13+
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// SPDX-FileCopyrightText: 2023 Alliander N.V.
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
package org.lfenergy.compas.sitipe.data.entity;
6+
7+
class SystemVersionTest extends BaseEntityTest {
8+
9+
@Override
10+
protected Class<?> getClassToBeTested() {
11+
return SystemVersion.class;
12+
}
13+
14+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// SPDX-FileCopyrightText: 2023 Alliander N.V.
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
package org.lfenergy.compas.sitipe.data.repository;
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.sitipe.data.entity.BTComponent;
11+
import org.lfenergy.compas.sitipe.data.entity.BayTypical;
12+
import org.mockito.ArgumentCaptor;
13+
import org.mockito.junit.jupiter.MockitoExtension;
14+
15+
import java.util.List;
16+
import java.util.UUID;
17+
18+
import static java.util.Collections.emptyList;
19+
import static org.junit.jupiter.api.Assertions.assertEquals;
20+
import static org.mockito.Mockito.doReturn;
21+
import static org.mockito.Mockito.spy;
22+
23+
@ExtendWith(MockitoExtension.class)
24+
class BTComponentRepositoryTest {
25+
26+
private BTComponentRepository sut;
27+
28+
@BeforeEach
29+
public void setUp() {
30+
sut = spy(BTComponentRepository.class);
31+
}
32+
33+
@Test
34+
void itShouldGetBTComponents() {
35+
final ArgumentCaptor<String> causeArgumentCaptor = ArgumentCaptor.forClass(String.class);
36+
final ArgumentCaptor<String> typeArgumentCaptor = ArgumentCaptor.forClass(String.class);
37+
final ArgumentCaptor<String> toolNameArgumentCaptor = ArgumentCaptor.forClass(String.class);
38+
39+
doReturn(emptyList()).when(sut).list(causeArgumentCaptor.capture(), typeArgumentCaptor.capture(), toolNameArgumentCaptor.capture());
40+
41+
final String accessId = UUID.randomUUID().toString();
42+
43+
final List<BTComponent> result = sut.findBayTypicalComponentsByTypicalAccessId(accessId);
44+
45+
assertEquals("DIGSI 5", toolNameArgumentCaptor.getValue());
46+
47+
assertEquals("typicalAccessId = ?1 AND toolName = ?2", causeArgumentCaptor.getValue());
48+
assertEquals(accessId, typeArgumentCaptor.getValue());
49+
assertEquals(0, result.size());
50+
}
51+
}

0 commit comments

Comments
 (0)