Skip to content

Commit 239a19b

Browse files
author
Vince Kraemer
committed
added some unit tests, including test that read from a domain yaml file
1 parent 502d5f3 commit 239a19b

File tree

5 files changed

+52
-1
lines changed

5 files changed

+52
-1
lines changed

model/src/test/java/oracle/kubernetes/weblogic/domain/v2/AdminServerTest.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public void whenExportedAccessPointsAreTheSame_objectsAreEqual() {
3333
.addAnnotation("annotation1", "value2")
3434
.addLabel("label1", "value1");
3535

36-
assertThat(server1, equalTo(server1));
36+
assertThat(server1, equalTo(server2));
3737
}
3838

3939
@Test
@@ -59,4 +59,16 @@ public void whenExportedAccessPointsDifferByAnnotation_objectsAreNotEqual() {
5959

6060
assertThat(server1, not(equalTo(server2)));
6161
}
62+
63+
@Test
64+
public void nodePortTests() {
65+
server1.addNodePortAnnotations("key", "value");
66+
assertThat(server1, not(equalTo(server2)));
67+
server2.addNodePortAnnotations("key", "value");
68+
assertThat(server1, equalTo(server2));
69+
server1.addNodePortLabels("key", "value");
70+
assertThat(server1.hashCode(), not(equalTo(server2.hashCode())));
71+
server2.addNodePortLabels("key", "value");
72+
assertThat(server1.hashCode(), equalTo(server2.hashCode()));
73+
}
6274
}

model/src/test/java/oracle/kubernetes/weblogic/domain/v2/BaseConfigurationTestBase.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,16 @@ public void whenServerStartPoliciesDiffer_objectsAreNotEqual() {
8484
private V1EnvVar env(String name, String value) {
8585
return new V1EnvVar().name(name).value(value);
8686
}
87+
88+
@Test
89+
public void serviceLabelAndAnnotation() {
90+
instance1.addServiceLabels("key", "value");
91+
assertThat(instance1, not(equalTo(instance2)));
92+
instance2.addServiceLabels("key", "value");
93+
assertThat(instance1, equalTo(instance2));
94+
instance1.addServiceAnnotations("key", "value");
95+
assertThat(instance1.hashCode(), not(equalTo(instance2.hashCode())));
96+
instance2.addServiceAnnotations("key", "value");
97+
assertThat(instance1.hashCode(), equalTo(instance2.hashCode()));
98+
}
8799
}

model/src/test/java/oracle/kubernetes/weblogic/domain/v2/DomainV2Test.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,6 +1104,13 @@ public void whenDomain2ReadFromYaml_AdminServerInheritPodSecurityContextFromDoma
11041104
assertThat(asPodSecCtx.getRunAsUser(), nullValue());
11051105
}
11061106

1107+
@Test
1108+
public void whenDomain2ReadFromYaml_serviceLabelsAndAnnotations() throws IOException {
1109+
Domain domain = readDomain(DOMAIN_V2_SAMPLE_YAML_2);
1110+
ServerSpec serverSpec = domain.getServer("server2", "cluster1");
1111+
assertThat(serverSpec.getServiceAnnotations(), hasEntry("e", "f"));
1112+
}
1113+
11071114
@Test
11081115
public void whenDomain3ReadFromYaml_PredefinedStorageDefinesClaimName() throws IOException {
11091116
Domain domain = readDomain(DOMAIN_V2_SAMPLE_YAML_3);
@@ -1139,6 +1146,14 @@ public void whenDomain3ReadFromYaml_adminServerHasNodeSelector() throws IOExcept
11391146
assertThat(domain.getAdminServerSpec().getNodeSelectors(), hasEntry("os", "linux"));
11401147
}
11411148

1149+
@Test
1150+
public void whenDomain3ReadFromYaml_adminServerHasAnnotationsAndLabels() throws IOException {
1151+
Domain domain = readDomain(DOMAIN_V2_SAMPLE_YAML_3);
1152+
assertThat(domain.getAdminServerSpec().getServiceAnnotations(), hasEntry("e", "f"));
1153+
assertThat(domain.getAdminServerSpec().getServiceLabels(), hasEntry("a", "b"));
1154+
assertThat(domain.getAdminServerSpec().getServiceLabels(), hasEntry("c", "d"));
1155+
}
1156+
11421157
@Test
11431158
public void whenVolumesConfiguredOnMultipleLevels_useCombination() {
11441159
configureDomain(domain)

model/src/test/resources/oracle/kubernetes/weblogic/domain/v2/domain-sample-2.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ spec:
7777
periodSeconds: 20
7878
nodeSelector:
7979
os: linux
80+
serviceLabels:
81+
a: b
82+
c: d
8083
podSecurityContext:
8184
runAsGroup: 421
8285
runAsNonRoot: true
@@ -107,6 +110,9 @@ spec:
107110
periodSeconds: 18
108111
nodeSelector:
109112
os_type: oel7
113+
serviceAnnotations:
114+
a: b
115+
e: f
110116
podSecurityContext:
111117
runAsGroup: 422
112118
seLinuxOptions:

model/src/test/resources/oracle/kubernetes/weblogic/domain/v2/domain-sample-3.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ spec:
3232
serverPod:
3333
nodeSelector:
3434
os: linux
35+
serviceLabels:
36+
a: b
37+
c: d
38+
serviceAnnotations:
39+
e: f
40+
longer: shorter
3541

3642
domainName: base_domain
3743
# The domainUID must be unique across the entire Kubernetes Cluster. Each WebLogic Domain must

0 commit comments

Comments
 (0)