Skip to content
This repository was archived by the owner on Jan 6, 2023. It is now read-only.

Commit cf582f1

Browse files
committed
add more tests for result and maputils
1 parent 193654d commit cf582f1

File tree

3 files changed

+110
-0
lines changed

3 files changed

+110
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
3+
*
4+
* Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
5+
*/
6+
7+
package weblogic.logging.exporter;
8+
9+
import static org.junit.jupiter.api.Assertions.assertEquals;
10+
11+
import org.junit.jupiter.api.DisplayName;
12+
import org.junit.jupiter.api.Test;
13+
14+
@DisplayName("Test the Result object")
15+
public class ResultTest {
16+
17+
private static final String EXPECTED_STRING =
18+
"Result{response='good', status=1, successful=true}";
19+
20+
@DisplayName("Check constructor and getters")
21+
@Test
22+
public void testConstructorAndGetters() {
23+
Result result = new Result("good", 1, true);
24+
25+
assertEquals("good", result.getResponse());
26+
assertEquals(1, result.getStatus());
27+
assertEquals(true, result.isSuccessful());
28+
}
29+
30+
@DisplayName("Check toString() works")
31+
@Test
32+
public void checkToString() {
33+
Result result = new Result("good", 1, true);
34+
35+
assertEquals(EXPECTED_STRING, result.toString());
36+
}
37+
}

src/test/java/weblogic/logging/exporter/config/FilterConfigTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import java.io.ByteArrayOutputStream;
1212
import java.io.PrintStream;
1313
import java.util.HashMap;
14+
import java.util.List;
1415
import java.util.Map;
1516
import org.junit.jupiter.api.AfterEach;
1617
import org.junit.jupiter.api.BeforeEach;
@@ -93,4 +94,19 @@ public void checkDuplicateValuesAreRejected() {
9394

9495
assertThrows(ConfigurationException.class, () -> FilterConfig.create(map));
9596
}
97+
98+
@DisplayName("Check getServers() returns the right data")
99+
@Test
100+
public void checkGetServersWorks() {
101+
Map<String, Object> map = new HashMap<>();
102+
map.put("FilterServers", new String[] {"managed-server-1", "managed-server-2"});
103+
FilterConfig filterConfig = FilterConfig.create(map);
104+
105+
assertTrue(filterConfig.getServers() instanceof List);
106+
assertEquals(2, filterConfig.getServers().size());
107+
assertTrue(filterConfig.getServers().get(0) instanceof String);
108+
assertEquals("managed-server-1", filterConfig.getServers().get(0));
109+
assertTrue(filterConfig.getServers().get(1) instanceof String);
110+
assertEquals("managed-server-2", filterConfig.getServers().get(1));
111+
}
96112
}

src/test/java/weblogic/logging/exporter/config/MapUtilsTest.java

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@
66

77
import static org.hamcrest.Matchers.arrayContaining;
88
import static org.hamcrest.junit.MatcherAssert.assertThat;
9+
import static org.junit.jupiter.api.Assertions.assertEquals;
10+
import static org.junit.jupiter.api.Assertions.assertThrows;
911

1012
import java.util.Arrays;
1113
import java.util.HashMap;
1214
import java.util.Map;
1315
import org.junit.jupiter.api.BeforeAll;
16+
import org.junit.jupiter.api.DisplayName;
1417
import org.junit.jupiter.api.Test;
1518

1619
@SuppressWarnings("EmptyMethod")
@@ -41,6 +44,60 @@ public void whenStringArrayValueIsList_returnAsArray() {
4144
assertThat(MapUtils.getStringArray(map, "values"), arrayContaining("7", "8", "true"));
4245
}
4346

47+
@DisplayName("Check getBooleanValue for true values")
48+
@Test
49+
public void checkGetBooleanForTrueValues() {
50+
Map<String, Object> map = new HashMap<>();
51+
map.put("1", "true");
52+
map.put("2", "t");
53+
map.put("3", "yes");
54+
map.put("4", "on");
55+
map.put("5", "y");
56+
map.put("6", "truenot");
57+
map.put("7", "nottrue");
58+
map.put("8", "yesss");
59+
map.put("9", "y ");
60+
map.put("10", " y ");
61+
62+
assertEquals(true, MapUtils.getBooleanValue(map, "1"));
63+
assertEquals(true, MapUtils.getBooleanValue(map, "2"));
64+
assertEquals(true, MapUtils.getBooleanValue(map, "3"));
65+
assertEquals(true, MapUtils.getBooleanValue(map, "4"));
66+
assertEquals(true, MapUtils.getBooleanValue(map, "5"));
67+
assertThrows(ConfigurationException.class, () -> MapUtils.getBooleanValue(map, "6"));
68+
assertThrows(ConfigurationException.class, () -> MapUtils.getBooleanValue(map, "7"));
69+
assertThrows(ConfigurationException.class, () -> MapUtils.getBooleanValue(map, "8"));
70+
assertThrows(ConfigurationException.class, () -> MapUtils.getBooleanValue(map, "9"));
71+
assertThrows(ConfigurationException.class, () -> MapUtils.getBooleanValue(map, "10"));
72+
}
73+
74+
@DisplayName("Check getBooleanValue for false values")
75+
@Test
76+
public void checkGetBooleanForFalseValues() {
77+
Map<String, Object> map = new HashMap<>();
78+
map.put("1", "false");
79+
map.put("2", "f");
80+
map.put("3", "no");
81+
map.put("4", "off");
82+
map.put("5", "n");
83+
map.put("6", "falsedata");
84+
map.put("7", "sofalse");
85+
map.put("8", "ono");
86+
map.put("9", "n ");
87+
map.put("10", " n ");
88+
89+
assertEquals(false, MapUtils.getBooleanValue(map, "1"));
90+
assertEquals(false, MapUtils.getBooleanValue(map, "2"));
91+
assertEquals(false, MapUtils.getBooleanValue(map, "3"));
92+
assertEquals(false, MapUtils.getBooleanValue(map, "4"));
93+
assertEquals(false, MapUtils.getBooleanValue(map, "5"));
94+
assertThrows(ConfigurationException.class, () -> MapUtils.getBooleanValue(map, "6"));
95+
assertThrows(ConfigurationException.class, () -> MapUtils.getBooleanValue(map, "7"));
96+
assertThrows(ConfigurationException.class, () -> MapUtils.getBooleanValue(map, "8"));
97+
assertThrows(ConfigurationException.class, () -> MapUtils.getBooleanValue(map, "9"));
98+
assertThrows(ConfigurationException.class, () -> MapUtils.getBooleanValue(map, "10"));
99+
}
100+
44101
private Map<String, Object> createMapWithValue(Object value) {
45102
Map<String, Object> map = new HashMap<>();
46103
map.put("values", value);

0 commit comments

Comments
 (0)