Skip to content

Commit ffebcea

Browse files
authored
Break the code in to BeforeAll, Test and AfterAll blocks (#1590)
* Break the code in to BeforeAll, Test and AfterAll blocks * remove comments * add javadoc
1 parent f56b62b commit ffebcea

File tree

1 file changed

+41
-21
lines changed

1 file changed

+41
-21
lines changed

new-integration-tests/src/test/java/oracle/weblogic/kubernetes/ItSimpleDomainValidation.java

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import oracle.weblogic.kubernetes.annotations.Namespaces;
2424
import oracle.weblogic.kubernetes.annotations.tags.Slow;
2525
import oracle.weblogic.kubernetes.extensions.LoggedTest;
26+
import org.junit.jupiter.api.AfterAll;
27+
import org.junit.jupiter.api.BeforeAll;
2628
import org.junit.jupiter.api.DisplayName;
2729
import org.junit.jupiter.api.Test;
2830

@@ -45,28 +47,35 @@
4547
@IntegrationTest
4648
class ItSimpleDomainValidation implements LoggedTest {
4749

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;
5256

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) {
5463

5564
// get a new unique namespace
5665
logger.info("Creating unique namespace for Operator");
5766
assertNotNull(namespaces.get(0), "Namespace list is null");
58-
String namespace = namespaces.get(0);
67+
namespace = namespaces.get(0);
5968

6069
// 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(
6372
() -> Kubernetes.createServiceAccount(new V1ServiceAccount()
6473
.metadata(new V1ObjectMeta().namespace(namespace).name(serviceAccountName))));
6574
logger.info("Created service account: {0}", serviceAccount.getMetadata().getName());
6675

6776
// 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
7079

7180
V1PersistentVolumeClaim v1pvc = new V1PersistentVolumeClaim()
7281
.spec(new V1PersistentVolumeClaimSpec()
@@ -85,7 +94,7 @@ public void testCreatingDomain(@Namespaces(1) List<String> namespaces) {
8594
boolean success = assertDoesNotThrow(
8695
() -> TestActions.createPersistentVolumeClaim(v1pvc),
8796
"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"
8998
);
9099
assertTrue(success, "PersistentVolumeClaim creation failed");
91100

@@ -98,7 +107,7 @@ public void testCreatingDomain(@Namespaces(1) List<String> namespaces) {
98107
.persistentVolumeReclaimPolicy("Recycle")
99108
.hostPath(new V1HostPathVolumeSource()
100109
.path(System.getProperty("java.io.tmpdir") + "/" + domainUid + "-persistentVolume")))
101-
.metadata(new V1ObjectMetaBuilder()
110+
.metadata(new V1ObjectMetaBuilder()
102111
.withName(pvName)
103112
.withNamespace(namespace)
104113
.build()
@@ -107,9 +116,18 @@ public void testCreatingDomain(@Namespaces(1) List<String> namespaces) {
107116
success = assertDoesNotThrow(
108117
() -> TestActions.createPersistentVolume(v1pv),
109118
"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"
111120
);
112121
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() {
113131

114132
// create the domain CR
115133
V1ObjectMeta metadata = new V1ObjectMetaBuilder()
@@ -126,10 +144,10 @@ public void testCreatingDomain(@Namespaces(1) List<String> namespaces) {
126144
.kind("Domain")
127145
.metadata(metadata)
128146
.spec(domainSpec);
129-
success = assertDoesNotThrow(
147+
boolean success = assertDoesNotThrow(
130148
() -> createDomainCustomResource(domain),
131149
"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"
133151
);
134152
assertTrue(success);
135153

@@ -138,17 +156,20 @@ public void testCreatingDomain(@Namespaces(1) List<String> namespaces) {
138156
.and().with().pollInterval(10, SECONDS)
139157
.conditionEvaluationListener(
140158
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)",
142160
condition.getElapsedTimeInMS(),
143161
condition.getRemainingTimeInMS()))
144162
// and here we can set the maximum time we are prepared to wait
145163
.await().atMost(5, MINUTES)
146164
// operatorIsRunning() is one of our custom, reusable assertions
147165
.until(domainExists(domainUid, "v7", namespace));
166+
}
148167

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() {
152173

153174
// Delete domain custom resource
154175
assertTrue(deleteDomainCustomResource(domainUid, namespace), "Domain failed to be deleted, "
@@ -165,7 +186,7 @@ public void testCreatingDomain(@Namespaces(1) List<String> namespaces) {
165186
// Delete the persistent volume claim and persistent volume
166187
assertTrue(deletePersistentVolumeClaim(pvcName, namespace),
167188
"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");
169190

170191
assertTrue(deletePersistentVolume(pvName), "Persistent volume deletion failed, "
171192
+ "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) {
175196
+ "look at the above console log messages for failure reason in ApiException responsebody");
176197
logger.info("Deleted namespace: {0}", namespace);
177198
}
178-
179199
}

0 commit comments

Comments
 (0)