23
23
import oracle .weblogic .kubernetes .annotations .Namespaces ;
24
24
import oracle .weblogic .kubernetes .annotations .tags .Slow ;
25
25
import oracle .weblogic .kubernetes .extensions .LoggedTest ;
26
+ import org .junit .jupiter .api .AfterAll ;
27
+ import org .junit .jupiter .api .BeforeAll ;
26
28
import org .junit .jupiter .api .DisplayName ;
27
29
import org .junit .jupiter .api .Test ;
28
30
45
47
@ IntegrationTest
46
48
class ItSimpleDomainValidation implements LoggedTest {
47
49
48
- @ Test
49
- @ DisplayName ("Create a domain" )
50
- @ Slow
51
- public void testCreatingDomain (@ Namespaces (1 ) List <String > namespaces ) {
50
+ final String domainUid = "domain1" ;
51
+ String namespace ;
52
+ String serviceAccountName ;
53
+ V1ServiceAccount serviceAccount ;
54
+ String pvcName ;
55
+ String pvName ;
52
56
53
- final String domainUid = "domain1" ;
57
+ /**
58
+ * Setup for test suite. Creates service account, namespace, and persistent volumes.
59
+ * @param namespaces injected by Junit extension
60
+ */
61
+ @ BeforeAll
62
+ public void setup (@ Namespaces (1 ) List <String > namespaces ) {
54
63
55
64
// get a new unique namespace
56
65
logger .info ("Creating unique namespace for Operator" );
57
66
assertNotNull (namespaces .get (0 ), "Namespace list is null" );
58
- String namespace = namespaces .get (0 );
67
+ namespace = namespaces .get (0 );
59
68
60
69
// Create a service account for the unique namespace
61
- final String serviceAccountName = namespace + "-sa" ;
62
- final V1ServiceAccount serviceAccount = assertDoesNotThrow (
70
+ serviceAccountName = namespace + "-sa" ;
71
+ serviceAccount = assertDoesNotThrow (
63
72
() -> Kubernetes .createServiceAccount (new V1ServiceAccount ()
64
73
.metadata (new V1ObjectMeta ().namespace (namespace ).name (serviceAccountName ))));
65
74
logger .info ("Created service account: {0}" , serviceAccount .getMetadata ().getName ());
66
75
67
76
// create persistent volume and persistent volume claim
68
- final String pvcName = domainUid + "-pvc" ; // name of the persistent volume claim
69
- final String pvName = domainUid + "-pv" ; // name of the persistent volume
77
+ pvcName = domainUid + "-pvc" ; // name of the persistent volume claim
78
+ pvName = domainUid + "-pv" ; // name of the persistent volume
70
79
71
80
V1PersistentVolumeClaim v1pvc = new V1PersistentVolumeClaim ()
72
81
.spec (new V1PersistentVolumeClaimSpec ()
@@ -85,7 +94,7 @@ public void testCreatingDomain(@Namespaces(1) List<String> namespaces) {
85
94
boolean success = assertDoesNotThrow (
86
95
() -> TestActions .createPersistentVolumeClaim (v1pvc ),
87
96
"Persistent volume claim creation failed, "
88
- + "look at the above console log messages for failure reason in ApiException responsebody"
97
+ + "look at the above console log messages for failure reason in ApiException responsebody"
89
98
);
90
99
assertTrue (success , "PersistentVolumeClaim creation failed" );
91
100
@@ -98,7 +107,7 @@ public void testCreatingDomain(@Namespaces(1) List<String> namespaces) {
98
107
.persistentVolumeReclaimPolicy ("Recycle" )
99
108
.hostPath (new V1HostPathVolumeSource ()
100
109
.path (System .getProperty ("java.io.tmpdir" ) + "/" + domainUid + "-persistentVolume" )))
101
- .metadata (new V1ObjectMetaBuilder ()
110
+ .metadata (new V1ObjectMetaBuilder ()
102
111
.withName (pvName )
103
112
.withNamespace (namespace )
104
113
.build ()
@@ -107,9 +116,18 @@ public void testCreatingDomain(@Namespaces(1) List<String> namespaces) {
107
116
success = assertDoesNotThrow (
108
117
() -> TestActions .createPersistentVolume (v1pv ),
109
118
"Persistent volume creation failed, "
110
- + "look at the above console log messages for failure reason in ApiException responsebody"
119
+ + "look at the above console log messages for failure reason in ApiException responsebody"
111
120
);
112
121
assertTrue (success , "PersistentVolume creation failed" );
122
+ }
123
+
124
+ /**
125
+ * Create a simple domain and checks if pods are coming up.
126
+ */
127
+ @ Test
128
+ @ DisplayName ("Create a domain" )
129
+ @ Slow
130
+ public void testCreatingDomain () {
113
131
114
132
// create the domain CR
115
133
V1ObjectMeta metadata = new V1ObjectMetaBuilder ()
@@ -126,10 +144,10 @@ public void testCreatingDomain(@Namespaces(1) List<String> namespaces) {
126
144
.kind ("Domain" )
127
145
.metadata (metadata )
128
146
.spec (domainSpec );
129
- success = assertDoesNotThrow (
147
+ boolean success = assertDoesNotThrow (
130
148
() -> createDomainCustomResource (domain ),
131
149
"Domain failed to be created, "
132
- + "look at the above console log messages for failure reason in ApiException responsebody"
150
+ + "look at the above console log messages for failure reason in ApiException responsebody"
133
151
);
134
152
assertTrue (success );
135
153
@@ -138,17 +156,20 @@ public void testCreatingDomain(@Namespaces(1) List<String> namespaces) {
138
156
.and ().with ().pollInterval (10 , SECONDS )
139
157
.conditionEvaluationListener (
140
158
condition -> logger .info (
141
- "Waiting for domain to be running (elapsed time {0}ms, remaining time {1}ms)" ,
159
+ "Waiting for domain to be running (elapsed time {0} ms, remaining time {1} ms)" ,
142
160
condition .getElapsedTimeInMS (),
143
161
condition .getRemainingTimeInMS ()))
144
162
// and here we can set the maximum time we are prepared to wait
145
163
.await ().atMost (5 , MINUTES )
146
164
// operatorIsRunning() is one of our custom, reusable assertions
147
165
.until (domainExists (domainUid , "v7" , namespace ));
166
+ }
148
167
149
- // wait for the admin server pod to exist
150
-
151
- // wait for the managed servers to exist
168
+ /**
169
+ * Delete artifacts.
170
+ */
171
+ @ AfterAll
172
+ public void cleanup () {
152
173
153
174
// Delete domain custom resource
154
175
assertTrue (deleteDomainCustomResource (domainUid , namespace ), "Domain failed to be deleted, "
@@ -165,7 +186,7 @@ public void testCreatingDomain(@Namespaces(1) List<String> namespaces) {
165
186
// Delete the persistent volume claim and persistent volume
166
187
assertTrue (deletePersistentVolumeClaim (pvcName , namespace ),
167
188
"Persistent volume claim deletion failed, "
168
- + "look at the above console log messages for failure reason in ApiException responsebody" );
189
+ + "look at the above console log messages for failure reason in ApiException responsebody" );
169
190
170
191
assertTrue (deletePersistentVolume (pvName ), "Persistent volume deletion failed, "
171
192
+ "look at the above console log messages for failure reason in ApiException responsebody" );
@@ -175,5 +196,4 @@ public void testCreatingDomain(@Namespaces(1) List<String> namespaces) {
175
196
+ "look at the above console log messages for failure reason in ApiException responsebody" );
176
197
logger .info ("Deleted namespace: {0}" , namespace );
177
198
}
178
-
179
199
}
0 commit comments