Skip to content

Commit a04d36b

Browse files
fix: Find roles without pars fixed. (#135)
1 parent f4426f3 commit a04d36b

File tree

2 files changed

+78
-16
lines changed

2 files changed

+78
-16
lines changed

src/main/java/it/pagopa/swclient/mil/auth/dao/RolesRepository.java

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -116,22 +116,39 @@ public Uni<Tuple2<Long, List<SetOfRolesEntity>>> findByParameters(int page, int
116116

117117
Log.debugf("Query: ", query);
118118

119-
return Uni.combine()
120-
.all()
121-
.unis(
122-
count(query, parameters),
123-
find(
124-
query,
125-
Sort.ascending(
126-
SetOfRolesEntity.CLIENT_ID_PRP,
127-
SetOfRolesEntity.ACQUIRER_ID_PRP,
128-
SetOfRolesEntity.CHANNEL_PRP,
129-
SetOfRolesEntity.MERCHANT_ID_PRP,
130-
SetOfRolesEntity.TERMINAL_ID_PRP),
131-
parameters)
132-
.page(page, size)
133-
.list())
134-
.asTuple();
119+
if (query.isEmpty()) {
120+
return Uni.combine()
121+
.all()
122+
.unis(
123+
count(),
124+
findAll(
125+
Sort.ascending(
126+
SetOfRolesEntity.CLIENT_ID_PRP,
127+
SetOfRolesEntity.ACQUIRER_ID_PRP,
128+
SetOfRolesEntity.CHANNEL_PRP,
129+
SetOfRolesEntity.MERCHANT_ID_PRP,
130+
SetOfRolesEntity.TERMINAL_ID_PRP))
131+
.page(page, size)
132+
.list())
133+
.asTuple();
134+
} else {
135+
return Uni.combine()
136+
.all()
137+
.unis(
138+
count(query, parameters),
139+
find(
140+
query,
141+
Sort.ascending(
142+
SetOfRolesEntity.CLIENT_ID_PRP,
143+
SetOfRolesEntity.ACQUIRER_ID_PRP,
144+
SetOfRolesEntity.CHANNEL_PRP,
145+
SetOfRolesEntity.MERCHANT_ID_PRP,
146+
SetOfRolesEntity.TERMINAL_ID_PRP),
147+
parameters)
148+
.page(page, size)
149+
.list())
150+
.asTuple();
151+
}
135152
}
136153

137154
/**

src/test/java/it/pagopa/swclient/mil/auth/dao/RolesRepositoryTest.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,51 @@ void testFindByParameters() {
186186
.assertCompleted()
187187
.assertItem(Tuple2.of(Long.valueOf(2), List.of(entity1, entity2)));
188188
}
189+
190+
/**
191+
*
192+
*/
193+
@Test
194+
void testFindByNoParameters() {
195+
SetOfRolesEntity entity1 = new SetOfRolesEntity()
196+
.setAcquirerId("acquirer_id")
197+
.setChannel("channel")
198+
.setClientId("client_id")
199+
.setMerchantId("merchant_id")
200+
.setTerminalId("terminal_id_1")
201+
.setRoles(List.of("role_1_1", "role_1_2"));
202+
203+
SetOfRolesEntity entity2 = new SetOfRolesEntity()
204+
.setAcquirerId("acquirer_id")
205+
.setChannel("channel")
206+
.setClientId("client_id")
207+
.setMerchantId("merchant_id")
208+
.setTerminalId("terminal_id_2")
209+
.setRoles(List.of("role_2_1", "role_2_2"));
210+
211+
ReactivePanacheQuery<SetOfRolesEntity> query = mock(ReactivePanacheQuery.class);
212+
when(query.list())
213+
.thenReturn(UniGenerator.item(List.of(entity1, entity2)));
214+
when(query.page(0, 2))
215+
.thenReturn(query);
216+
217+
when(repository
218+
.findAll(any(Sort.class)))
219+
.thenReturn(query);
220+
221+
when(repository
222+
.count())
223+
.thenReturn(UniGenerator.item(Long.valueOf(2)));
224+
225+
when(repository.findByParameters(0, 2, null, null, null, null, null))
226+
.thenCallRealMethod();
227+
228+
repository.findByParameters(0, 2, null, null, null, null, null)
229+
.subscribe()
230+
.withSubscriber(UniAssertSubscriber.create())
231+
.assertCompleted()
232+
.assertItem(Tuple2.of(Long.valueOf(2), List.of(entity1, entity2)));
233+
}
189234

190235
/**
191236
*

0 commit comments

Comments
 (0)