@@ -50,7 +50,7 @@ void testCategory() {
5050 var ext3 = mockExtension ("openshift" , 4.0 , 100 , 0 , "redhat" , List .of ("Snippets" , "Other" ));
5151 Mockito .when (repositories .findAllActiveExtensions ()).thenReturn (Streamable .of (List .of (ext1 , ext2 , ext3 )));
5252
53- var searchOptions = new ISearchService . Options (null , "Programming Languages" , TargetPlatform . NAME_UNIVERSAL , 50 , 0 , null , null , false , null );
53+ var searchOptions = searchOptions (null , "Programming Languages" ,50 , 0 , null , null );
5454 var result = search .search (searchOptions );
5555 // should find two extensions
5656 assertThat (result .getTotalHits ()).isEqualTo (2 );
@@ -63,7 +63,7 @@ void testRelevance() {
6363 var ext3 = mockExtension ("openshift" , 1.0 , 100 , 10 , "redhat" , List .of ("Snippets" , "Other" ));
6464 Mockito .when (repositories .findAllActiveExtensions ()).thenReturn (Streamable .of (List .of (ext1 , ext2 , ext3 )));
6565
66- var searchOptions = new ISearchService . Options (null , null , TargetPlatform . NAME_UNIVERSAL , 50 , 0 , null , "relevance" , false , null );
66+ var searchOptions = searchOptions (null , null , 50 , 0 , null , "relevance" );
6767 var result = search .search (searchOptions );
6868 // should find all extensions but order should be different
6969 assertThat (result .getTotalHits ()).isEqualTo (3 );
@@ -81,7 +81,7 @@ void testReverse() {
8181 var ext2 = mockExtension ("java" , 4.0 , 100 , 0 , "redhat" , List .of ("Snippets" , "Programming Languages" ));
8282 Mockito .when (repositories .findAllActiveExtensions ()).thenReturn (Streamable .of (List .of (ext1 , ext2 )));
8383
84- var searchOptions = new ISearchService . Options (null , "Programming Languages" , TargetPlatform . NAME_UNIVERSAL , 50 , 0 , "desc" , null , false , null );
84+ var searchOptions = searchOptions (null , "Programming Languages" , 50 , 0 , "desc" , null );
8585 var result = search .search (searchOptions );
8686 // should find two extensions
8787 assertThat (result .getTotalHits ()).isEqualTo (2 );
@@ -103,7 +103,7 @@ void testSimplePageSize() {
103103 Mockito .when (repositories .findAllActiveExtensions ()).thenReturn (Streamable .of (List .of (ext1 , ext2 , ext3 , ext4 , ext5 , ext6 , ext7 )));
104104
105105 var pageSizeItems = 5 ;
106- var searchOptions = new ISearchService . Options (null , null , TargetPlatform . NAME_UNIVERSAL , pageSizeItems , 0 , null , null , false , null );
106+ var searchOptions = searchOptions (null , null , pageSizeItems , 0 , null , null );
107107
108108 var result = search .search (searchOptions );
109109 // 7 total hits
@@ -131,7 +131,7 @@ void testPages() {
131131 Mockito .when (repositories .findAllActiveExtensions ()).thenReturn (Streamable .of (List .of (ext1 , ext2 , ext3 , ext4 , ext5 , ext6 , ext7 )));
132132
133133 var pageSizeItems = 2 ;
134- var searchOptions = new ISearchService . Options (null , null , TargetPlatform . NAME_UNIVERSAL , pageSizeItems , 4 , null , null , false , null );
134+ var searchOptions = searchOptions (null , null , pageSizeItems , 4 , null , null );
135135 var result = search .search (searchOptions );
136136
137137 // 7 total hits
@@ -152,7 +152,7 @@ void testQueryStringPublisherName() {
152152 var ext4 = mockExtension ("foo" , 4.0 , 100 , 0 , "bar" , List .of ("Other" ));
153153 Mockito .when (repositories .findAllActiveExtensions ()).thenReturn (Streamable .of (List .of (ext1 , ext2 , ext3 , ext4 )));
154154
155- var searchOptions = new ISearchService . Options ("redhat" , null , TargetPlatform . NAME_UNIVERSAL , 50 , 0 , null , null , false , null );
155+ var searchOptions = searchOptions ("redhat" , null , 50 , 0 , null , null );
156156 var result = search .search (searchOptions );
157157 // namespace finding
158158 assertThat (result .getTotalHits ()).isEqualTo (3 );
@@ -172,7 +172,7 @@ void testQueryStringExtensionName() {
172172 var ext4 = mockExtension ("foo" , 4.0 , 100 , 0 , "bar" , List .of ("Other" ));
173173 Mockito .when (repositories .findAllActiveExtensions ()).thenReturn (Streamable .of (List .of (ext1 , ext2 , ext3 , ext4 )));
174174
175- var searchOptions = new ISearchService . Options ("openshift" , null , TargetPlatform . NAME_UNIVERSAL , 50 , 0 , null , null , false , null );
175+ var searchOptions = searchOptions ("openshift" , null , 50 , 0 , null , null );
176176 var result = search .search (searchOptions );
177177 // extension name finding
178178 assertThat (result .getTotalHits ()).isEqualTo (1 );
@@ -192,7 +192,7 @@ void testQueryStringDescription() {
192192 var ext4 = mockExtension ("foo" , 4.0 , 100 , 0 , "bar" , List .of ("Other" ));
193193 Mockito .when (repositories .findAllActiveExtensions ()).thenReturn (Streamable .of (List .of (ext1 , ext2 , ext3 , ext4 )));
194194
195- var searchOptions = new ISearchService . Options ("my custom desc" , null , TargetPlatform . NAME_UNIVERSAL , 50 , 0 , null , null , false , null );
195+ var searchOptions = searchOptions ("my custom desc" , null , 50 , 0 , null , null );
196196 var result = search .search (searchOptions );
197197 // custom description
198198 assertThat (result .getTotalHits ()).isEqualTo (1 );
@@ -212,7 +212,7 @@ void testQueryStringDisplayName() {
212212 var ext4 = mockExtension ("foo" , 4.0 , 100 , 0 , "bar" , List .of ("Other" ));
213213 Mockito .when (repositories .findAllActiveExtensions ()).thenReturn (Streamable .of (List .of (ext1 , ext2 , ext3 , ext4 )));
214214
215- var searchOptions = new ISearchService . Options ("Red Hat" , null , TargetPlatform . NAME_UNIVERSAL , 50 , 0 , null , null , false , null );
215+ var searchOptions = searchOptions ("Red Hat" , null , 50 , 0 , null , null );
216216 var result = search .search (searchOptions );
217217
218218 // custom displayname
@@ -235,7 +235,7 @@ void testSortByTimeStamp() {
235235 ext4 .getVersions ().get (0 ).setTimestamp (LocalDateTime .parse ("2021-10-06T00:00" ));
236236 Mockito .when (repositories .findAllActiveExtensions ()).thenReturn (Streamable .of (List .of (ext1 , ext2 , ext3 , ext4 )));
237237
238- var searchOptions = new ISearchService . Options (null , null , TargetPlatform . NAME_UNIVERSAL , 50 , 0 , null , "timestamp" , false , null );
238+ var searchOptions = searchOptions (null , null , 50 , 0 , null , "timestamp" );
239239 var result = search .search (searchOptions );
240240 // all extensions should be there
241241 assertThat (result .getTotalHits ()).isEqualTo (4 );
@@ -256,7 +256,7 @@ void testSortByDownloadCount() {
256256 var ext4 = mockExtension ("foo" , 4.0 , 100 , 500 , "bar" , List .of ("Other" ));
257257 Mockito .when (repositories .findAllActiveExtensions ()).thenReturn (Streamable .of (List .of (ext1 , ext2 , ext3 , ext4 )));
258258
259- var searchOptions = new ISearchService . Options (null , null , TargetPlatform . NAME_UNIVERSAL , 50 , 0 , null , "downloadCount" , false , null );
259+ var searchOptions = searchOptions (null , null , 50 , 0 , null , "downloadCount" );
260260 var result = search .search (searchOptions );
261261 // all extensions should be there
262262 assertThat (result .getTotalHits ()).isEqualTo (4 );
@@ -277,7 +277,7 @@ void testSortByRating() {
277277 var ext4 = mockExtension ("foo" , 1.0 , 1 , 0 , "bar" , List .of ("Other" ));
278278 Mockito .when (repositories .findAllActiveExtensions ()).thenReturn (Streamable .of (List .of (ext1 , ext2 , ext3 , ext4 )));
279279
280- var searchOptions = new ISearchService . Options (null , null , TargetPlatform . NAME_UNIVERSAL , 50 , 0 , null , "rating" , false , null );
280+ var searchOptions = searchOptions (null , null , 50 , 0 , null , "rating" );
281281 var result = search .search (searchOptions );
282282 // all extensions should be there
283283 assertThat (result .getTotalHits ()).isEqualTo (4 );
@@ -292,6 +292,37 @@ void testSortByRating() {
292292
293293 // ---------- UTILITY ----------//
294294
295+ private ISearchService .Options searchOptions (
296+ String queryString ,
297+ String category ,
298+ Integer requestedSize ,
299+ Integer requestedOffset ,
300+ String sortOrder ,
301+ String sortBy
302+ ) {
303+ if (requestedSize == null ) {
304+ requestedSize = 18 ;
305+ }
306+ if (requestedOffset == null ) {
307+ requestedOffset = 0 ;
308+ }
309+ if (sortBy == null ) {
310+ sortBy = "relevance" ;
311+ }
312+
313+ return new ISearchService .Options (
314+ queryString ,
315+ category ,
316+ null ,
317+ requestedSize ,
318+ requestedOffset ,
319+ sortOrder ,
320+ sortBy ,
321+ false ,
322+ null
323+ );
324+ }
325+
295326 long getIdFromExtensionHits (List <SearchHit <ExtensionSearch >> hits , int index ) {
296327 return hits .get (index ).getContent ().getId ();
297328 }
0 commit comments