@@ -31,6 +31,10 @@ public abstract class WebPageOperatorAbstractTest {
31
31
32
32
static final KubernetesClient client = new DefaultKubernetesClient ();
33
33
public static final String TEST_PAGE = "test-page" ;
34
+ public static final String TITLE1 = "Hello Operator World" ;
35
+ public static final String TITLE2 = "Hello Operator World Title 2" ;
36
+ public static final int WAIT_SECONDS = 20 ;
37
+ public static final Duration POLL_INTERVAL = Duration .ofSeconds (1 );
34
38
35
39
boolean isLocal () {
36
40
String deployment = System .getProperty ("test.deployment" );
@@ -42,12 +46,12 @@ boolean isLocal() {
42
46
@ Test
43
47
void testAddingWebPage () {
44
48
45
- var webPage = createWebPage ();
49
+ var webPage = createWebPage (TITLE1 );
46
50
operator ().create (WebPage .class , webPage );
47
51
48
52
await ()
49
- .atMost (Duration .ofSeconds (20 ))
50
- .pollInterval (Duration . ofSeconds ( 1 ) )
53
+ .atMost (Duration .ofSeconds (WAIT_SECONDS ))
54
+ .pollInterval (POLL_INTERVAL )
51
55
.untilAsserted (
52
56
() -> {
53
57
var actual = operator ().get (WebPage .class , TEST_PAGE );
@@ -57,9 +61,17 @@ void testAddingWebPage() {
57
61
assertThat (deployment .getSpec ().getReplicas ())
58
62
.isEqualTo (deployment .getStatus ().getReadyReplicas ());
59
63
});
64
+ assertThat (httpGetForWebPage (webPage )).contains (TITLE1 );
60
65
61
- String response = httpGetForWebPage (webPage );
62
- assertThat (response ).contains ("<title>Hello Operator World</title>" );
66
+ // update test: changing title
67
+ operator ().replace (WebPage .class , createWebPage (TITLE2 ));
68
+
69
+ await ().atMost (Duration .ofSeconds (WAIT_SECONDS ))
70
+ .pollInterval (POLL_INTERVAL )
71
+ .untilAsserted (() -> {
72
+ String page = httpGetForWebPage (webPage );
73
+ assertThat (page ).isNotNull ().contains (TITLE2 );
74
+ });
63
75
}
64
76
65
77
String httpGetForWebPage (WebPage webPage ) {
@@ -75,7 +87,7 @@ String httpGetForWebPage(WebPage webPage) {
75
87
.uri (new URI ("http://localhost:" + portForward .getLocalPort ())).build ();
76
88
return httpClient .send (request , HttpResponse .BodyHandlers .ofString ()).body ();
77
89
} catch (URISyntaxException | IOException | InterruptedException e ) {
78
- throw new IllegalStateException ( e ) ;
90
+ return null ;
79
91
} finally {
80
92
if (portForward != null ) {
81
93
try {
@@ -87,7 +99,7 @@ String httpGetForWebPage(WebPage webPage) {
87
99
}
88
100
}
89
101
90
- WebPage createWebPage () {
102
+ WebPage createWebPage (String title ) {
91
103
WebPage webPage = new WebPage ();
92
104
webPage .setMetadata (new ObjectMeta ());
93
105
webPage .getMetadata ().setName (TEST_PAGE );
@@ -98,7 +110,7 @@ WebPage createWebPage() {
98
110
.setHtml (
99
111
"<html>\n "
100
112
+ " <head>\n "
101
- + " <title>Hello Operator World </title>\n "
113
+ + " <title>" + title + " </title>\n "
102
114
+ " </head>\n "
103
115
+ " <body>\n "
104
116
+ " Hello World! \n "
0 commit comments