19
19
import static com .github .tomakehurst .wiremock .client .WireMock .stubFor ;
20
20
import static com .github .tomakehurst .wiremock .client .WireMock .urlPathEqualTo ;
21
21
import static com .github .tomakehurst .wiremock .client .WireMock .verify ;
22
- import static org .junit .Assert .*;
22
+ import static com .github .tomakehurst .wiremock .core .WireMockConfiguration .wireMockConfig ;
23
+ import static org .junit .Assert .assertEquals ;
24
+ import static org .junit .Assert .assertFalse ;
25
+ import static org .junit .Assert .fail ;
23
26
24
27
import com .github .tomakehurst .wiremock .junit .WireMockRule ;
25
28
import com .google .common .io .Resources ;
31
34
import java .io .IOException ;
32
35
import java .nio .file .Files ;
33
36
import java .nio .file .Paths ;
37
+ import java .util .Iterator ;
34
38
import java .util .concurrent .CountDownLatch ;
35
39
import java .util .concurrent .ExecutorService ;
36
40
import java .util .concurrent .Executors ;
42
46
public class PagerTest {
43
47
44
48
private ApiClient client ;
49
+ private static final String LIST_PAGE0_FILE_PATH =
50
+ Resources .getResource ("namespace-list-pager0.json" ).getPath ();
45
51
private static final String LIST_PAGE1_FILE_PATH =
46
52
Resources .getResource ("namespace-list-pager1.json" ).getPath ();
47
53
private static final String LIST_PAGE2_FILE_PATH =
@@ -50,12 +56,41 @@ public class PagerTest {
50
56
Resources .getResource ("status-400.json" ).getPath ();
51
57
private static final String STATUS_BAD_TOKEN_FILE_PATH =
52
58
Resources .getResource ("bad-token-status.json" ).getPath ();
53
- private static final int PORT = 8087 ;
54
- @ Rule public WireMockRule wireMockRule = new WireMockRule (PORT );
59
+ @ Rule public WireMockRule wireMockRule = new WireMockRule (wireMockConfig ().dynamicPort ());
55
60
56
61
@ Before
57
62
public void setup () throws IOException {
58
- client = new ClientBuilder ().setBasePath ("http://localhost:" + PORT ).build ();
63
+ client = new ClientBuilder ().setBasePath ("http://localhost:" + wireMockRule .port ()).build ();
64
+ }
65
+
66
+ @ Test
67
+ public void testIteratorForEmptyList () throws IOException {
68
+ String namespaceListPage0Str = new String (Files .readAllBytes (Paths .get (LIST_PAGE0_FILE_PATH )));
69
+ CoreV1Api api = new CoreV1Api (client );
70
+
71
+ stubFor (
72
+ get (urlPathEqualTo ("/api/v1/namespaces" ))
73
+ .willReturn (
74
+ aResponse ()
75
+ .withStatus (200 )
76
+ .withHeader ("Content-Type" , "application/json" )
77
+ .withBody (namespaceListPage0Str )));
78
+
79
+ Pager <V1Namespace , V1NamespaceList > pager =
80
+ new Pager <V1Namespace , V1NamespaceList >(
81
+ (Pager .PagerParams param ) -> {
82
+ try {
83
+ return api .listNamespaceCall (
84
+ null , null , null , null , null , null , null , null , null , null );
85
+ } catch (Exception e ) {
86
+ throw new RuntimeException (e );
87
+ }
88
+ },
89
+ client ,
90
+ 1 ,
91
+ V1NamespaceList .class );
92
+ Iterator <V1Namespace > it = pager .iterator ();
93
+ assertFalse ("Iterator should be empty." , it .hasNext ());
59
94
}
60
95
61
96
@ Test
0 commit comments