Skip to content

Commit 5c41152

Browse files
committed
porting it junit 5
1 parent ce97360 commit 5c41152

File tree

1 file changed

+103
-104
lines changed

1 file changed

+103
-104
lines changed

core/src/test/java/oracle/weblogic/deploy/yaml/YamlTranslatorTest.java

Lines changed: 103 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
import java.util.logging.Logger;
1313

1414
import oracle.weblogic.deploy.util.PyOrderedDict;
15-
import org.junit.Assert;
16-
import org.junit.Test;
15+
16+
import org.junit.jupiter.api.Test;
17+
1718
import org.python.core.PyDictionary;
1819
import org.python.core.PyFloat;
1920
import org.python.core.PyInteger;
@@ -22,6 +23,10 @@
2223
import org.python.core.PyString;
2324

2425
import static java.nio.charset.StandardCharsets.UTF_8;
26+
import static org.junit.jupiter.api.Assertions.assertEquals;
27+
import static org.junit.jupiter.api.Assertions.assertNotNull;
28+
import static org.junit.jupiter.api.Assertions.assertTrue;
29+
import static org.junit.jupiter.api.Assertions.fail;
2530

2631
public class YamlTranslatorTest {
2732

@@ -32,153 +37,146 @@ public void testFlatMapScalarTypes() throws Exception {
3237

3338
PyDictionary actual = yamlTranslator.parse();
3439

35-
Assert.assertNotNull("dict should not be null", actual);
40+
assertNotNull(actual, "dict should not be null");
3641

3742
PyString key = new PyString("field1");
38-
Assert.assertTrue("field1 should be present", actual.has_key(key));
43+
assertTrue(actual.has_key(key), "field1 should be present");
3944
PyObject value = actual.__getitem__(key);
40-
Assert.assertEquals("field1 should be a string", PyString.class, value.getClass());
41-
Assert.assertEquals("field1 value should be string", "string", value.toString());
45+
assertEquals(PyString.class, value.getClass(), "field1 should be a string");
46+
assertEquals("string", value.toString(), "field1 value should be string");
4247

4348
key = new PyString("field2");
44-
Assert.assertTrue("field2 should be present", actual.has_key(key));
49+
assertTrue(actual.has_key(key), "field2 should be present");
4550
value = actual.__getitem__(key);
46-
Assert.assertEquals("field2 should be an integer", PyInteger.class, value.getClass());
47-
Assert.assertEquals("field2 value should be 123", 123,
48-
((PyInteger)value).getValue());
51+
assertEquals(PyInteger.class, value.getClass(), "field2 should be an integer");
52+
assertEquals(123, ((PyInteger)value).getValue(), "field2 value should be 123");
4953

5054
key = new PyString("field3");
51-
Assert.assertTrue("field3 should be present", actual.has_key(key));
55+
assertTrue(actual.has_key(key), "field3 should be present");
5256
value = actual.__getitem__(key);
53-
Assert.assertEquals("field3 should be a long", PyLong.class, value.getClass());
54-
Assert.assertEquals("field3 value should be 123456789012345",
55-
new BigInteger("123456789012345"), ((PyLong)value).getValue());
57+
assertEquals(PyLong.class, value.getClass(), "field3 should be a long");
58+
assertEquals(new BigInteger("123456789012345"), ((PyLong)value).getValue(), "field3 value should be 123456789012345");
5659

5760
key = new PyString("field4");
58-
Assert.assertTrue("field4 should be present", actual.has_key(key));
61+
assertTrue(actual.has_key(key), "field4 should be present");
5962
value = actual.__getitem__(key);
60-
Assert.assertEquals("field4 should be a float", PyFloat.class, value.getClass());
61-
Assert.assertEquals("field4 value should be 123.456",123.456,
62-
((PyFloat)value).getValue(), 0.0000000001);
63+
assertEquals(PyFloat.class, value.getClass(), "field4 should be a float");
64+
assertEquals(123.456, ((PyFloat)value).getValue(), 0.0000000001, "field4 value should be 123.456");
6365

6466
key = new PyString("field5");
65-
Assert.assertTrue("field5 should be present", actual.has_key(key));
67+
assertTrue(actual.has_key(key), "field5 should be present");
6668
value = actual.__getitem__(key);
67-
Assert.assertEquals("field5 should be a float", PyFloat.class, value.getClass());
68-
Assert.assertEquals("field5 value should be 0.12345678901234567890",
69-
0.12345678901234567890, ((PyFloat)value).getValue(), 0.0000000001);
69+
assertEquals(PyFloat.class, value.getClass(), "field5 should be a float");
70+
assertEquals(0.12345678901234567890, ((PyFloat)value).getValue(), 0.0000000001,
71+
"field5 value should be 0.12345678901234567890");
7072

7173
key = new PyString("field6");
72-
Assert.assertTrue("field6 should be present", actual.has_key(key));
74+
assertTrue(actual.has_key(key), "field6 should be present");
7375
value = actual.__getitem__(key);
74-
Assert.assertEquals("field6 should be a string", PyString.class, value.getClass());
75-
Assert.assertEquals("field6 value should be true", "true", value.toString());
76+
assertEquals(PyString.class, value.getClass(), "field6 should be a string");
77+
assertEquals("true", value.toString(), "field6 value should be true");
7678

7779
key = new PyString("field7");
78-
Assert.assertTrue("field7 should be present", actual.has_key(key));
80+
assertTrue(actual.has_key(key), "field7 should be present");
7981
value = actual.__getitem__(key);
80-
Assert.assertEquals("field7 should be a string", PyString.class, value.getClass());
81-
Assert.assertEquals("field7 value should be true", "true", value.toString());
82+
assertEquals(PyString.class, value.getClass(), "field7 should be a string");
83+
assertEquals("true", value.toString(), "field7 value should be true");
8284

8385
key = new PyString("field8");
84-
Assert.assertTrue("field8 should be present", actual.has_key(key));
86+
assertTrue(actual.has_key(key), "field8 should be present");
8587
value = actual.__getitem__(key);
86-
Assert.assertEquals("field8 should be a string", PyString.class, value.getClass());
87-
Assert.assertEquals("field8 value should be false", "false", value.toString());
88+
assertEquals(PyString.class, value.getClass(), "field8 should be a string");
89+
assertEquals("false", value.toString(), "field8 value should be false");
8890

8991
key = new PyString("field9");
90-
Assert.assertTrue("field9 should be present", actual.has_key(key));
92+
assertTrue(actual.has_key(key), "field9 should be present");
9193
value = actual.__getitem__(key);
92-
Assert.assertEquals("field9 should be a string", PyString.class, value.getClass());
93-
Assert.assertEquals("field9 value should be false", "false", value.toString());
94+
assertEquals(PyString.class, value.getClass(), "field9 should be a string");
95+
assertEquals("false", value.toString(), "field9 value should be false");
9496

9597
key = new PyString("field10");
96-
Assert.assertTrue("field10 should be present", actual.has_key(key));
98+
assertTrue(actual.has_key(key), "field10 should be present");
9799
value = actual.__getitem__(key);
98-
Assert.assertEquals("field10 should be a string", PyString.class, value.getClass());
99-
Assert.assertEquals("field10 value should be string", "string", value.toString());
100+
assertEquals(PyString.class, value.getClass(), "field10 should be a string");
101+
assertEquals("string", value.toString(), "field10 value should be string");
100102

101103
key = new PyString("field11");
102-
Assert.assertTrue("field11 should be present", actual.has_key(key));
104+
assertTrue(actual.has_key(key), "field11 should be present");
103105
value = actual.__getitem__(key);
104-
Assert.assertEquals("field11 should be a string", PyString.class, value.getClass());
105-
Assert.assertEquals("field11 value should be string", "string", value.toString());
106+
assertEquals(PyString.class, value.getClass(), "field11 should be a string");
107+
assertEquals("string", value.toString(), "field11 value should be string");
106108

107109
key = new PyString("field12");
108-
Assert.assertTrue("field12 should be present", actual.has_key(key));
110+
assertTrue(actual.has_key(key), "field12 should be present");
109111
value = actual.__getitem__(key);
110-
Assert.assertEquals("field12 should be a string", PyString.class, value.getClass());
111-
Assert.assertEquals("field12 value should be 123", "123", value.toString());
112+
assertEquals(PyString.class, value.getClass(), "field12 should be a string");
113+
assertEquals("123", value.toString(), "field12 value should be 123");
112114

113115
key = new PyString("field13");
114-
Assert.assertTrue("field13 should be present", actual.has_key(key));
116+
assertTrue(actual.has_key(key), "field13 should be present");
115117
value = actual.__getitem__(key);
116-
Assert.assertEquals("field13 should be a string", PyString.class, value.getClass());
117-
Assert.assertEquals("field13 value should be 123", "123", value.toString());
118+
assertEquals(PyString.class, value.getClass(), "field13 should be a string");
119+
assertEquals( "123", value.toString(), "field13 value should be 123");
118120

119121
key = new PyString("field14");
120-
Assert.assertTrue("field14 should be present", actual.has_key(key));
122+
assertTrue(actual.has_key(key), "field14 should be present");
121123
value = actual.__getitem__(key);
122-
Assert.assertEquals("field14 should be a string", PyString.class, value.getClass());
123-
Assert.assertEquals("field14 value should be 123456789012345",
124-
"123456789012345", value.toString());
124+
assertEquals(PyString.class, value.getClass(), "field14 should be a string");
125+
assertEquals("123456789012345", value.toString(), "field14 value should be 123456789012345");
125126

126127
key = new PyString("field15");
127-
Assert.assertTrue("field15 should be present", actual.has_key(key));
128+
assertTrue(actual.has_key(key), "field15 should be present");
128129
value = actual.__getitem__(key);
129-
Assert.assertEquals("field15 should be a string", PyString.class, value.getClass());
130-
Assert.assertEquals("field15 value should be 123456789012345",
131-
"123456789012345", value.toString());
130+
assertEquals(PyString.class, value.getClass(), "field15 should be a string");
131+
assertEquals("123456789012345", value.toString(), "field15 value should be 123456789012345");
132132

133133
key = new PyString("field16");
134-
Assert.assertTrue("field16 should be present", actual.has_key(key));
134+
assertTrue(actual.has_key(key), "field16 should be present");
135135
value = actual.__getitem__(key);
136-
Assert.assertEquals("field16 should be a string", PyString.class, value.getClass());
137-
Assert.assertEquals("field16 value should be 123.456", "123.456", value.toString());
136+
assertEquals(PyString.class, value.getClass(), "field16 should be a string");
137+
assertEquals("123.456", value.toString(), "field16 value should be 123.456");
138138

139139
key = new PyString("field17");
140-
Assert.assertTrue("field17 should be present", actual.has_key(key));
140+
assertTrue(actual.has_key(key), "field17 should be present");
141141
value = actual.__getitem__(key);
142-
Assert.assertEquals("field17 should be a string", PyString.class, value.getClass());
143-
Assert.assertEquals("field17 value should be 123.456", "123.456", value.toString());
142+
assertEquals(PyString.class, value.getClass(), "field17 should be a string");
143+
assertEquals("123.456", value.toString(), "field17 value should be 123.456");
144144

145145
key = new PyString("field18");
146-
Assert.assertTrue("field18 should be present", actual.has_key(key));
146+
assertTrue(actual.has_key(key), "field18 should be present");
147147
value = actual.__getitem__(key);
148-
Assert.assertEquals("field18 should be a string", PyString.class, value.getClass());
149-
Assert.assertEquals("field18 value should be 0.12345678901234567890",
150-
"0.12345678901234567890", value.toString());
148+
assertEquals(PyString.class, value.getClass(), "field18 should be a string");
149+
assertEquals("0.12345678901234567890", value.toString(), "field18 value should be 0.12345678901234567890");
151150

152151
key = new PyString("field19");
153-
Assert.assertTrue("field19 should be present", actual.has_key(key));
152+
assertTrue(actual.has_key(key), "field19 should be present");
154153
value = actual.__getitem__(key);
155-
Assert.assertEquals("field19 should be a string", PyString.class, value.getClass());
156-
Assert.assertEquals("field19 value should be 0.12345678901234567890",
157-
"0.12345678901234567890", value.toString());
154+
assertEquals(PyString.class, value.getClass(), "field19 should be a string");
155+
assertEquals("0.12345678901234567890", value.toString(), "field19 value should be 0.12345678901234567890");
158156

159157
key = new PyString("field20");
160-
Assert.assertTrue("field20 should be present", actual.has_key(key));
158+
assertTrue(actual.has_key(key), "field20 should be present");
161159
value = actual.__getitem__(key);
162-
Assert.assertEquals("field20 should be a string", PyString.class, value.getClass());
163-
Assert.assertEquals("field20 value should be true", "true", value.toString());
160+
assertEquals(PyString.class, value.getClass(), "field20 should be a string");
161+
assertEquals("true", value.toString(), "field20 value should be true");
164162

165163
key = new PyString("field21");
166-
Assert.assertTrue("field21 should be present", actual.has_key(key));
164+
assertTrue(actual.has_key(key), "field21 should be present");
167165
value = actual.__getitem__(key);
168-
Assert.assertEquals("field21 should be a string", PyString.class, value.getClass());
169-
Assert.assertEquals("field21 value should be True", "True", value.toString());
166+
assertEquals(PyString.class, value.getClass(), "field21 should be a string");
167+
assertEquals("True", value.toString(), "field21 value should be True");
170168

171169
key = new PyString("field22");
172-
Assert.assertTrue("field22 should be present", actual.has_key(key));
170+
assertTrue(actual.has_key(key), "field22 should be present");
173171
value = actual.__getitem__(key);
174-
Assert.assertEquals("field22 should be a string", PyString.class, value.getClass());
175-
Assert.assertEquals("field22 value should be false", "false", value.toString());
172+
assertEquals(PyString.class, value.getClass(), "field22 should be a string");
173+
assertEquals("false", value.toString(), "field22 value should be false");
176174

177175
key = new PyString("field23");
178-
Assert.assertTrue("field23 should be present", actual.has_key(key));
176+
assertTrue(actual.has_key(key), "field23 should be present");
179177
value = actual.__getitem__(key);
180-
Assert.assertEquals("field23 should be a string", PyString.class, value.getClass());
181-
Assert.assertEquals("field23 value should be False", "False", value.toString());
178+
assertEquals(PyString.class, value.getClass(), "field23 should be a string");
179+
assertEquals("False", value.toString(), "field23 value should be False");
182180
}
183181

184182
@Test
@@ -187,42 +185,42 @@ public void testNestedDictionaries() throws Exception {
187185
YamlTranslator yamlTranslator = new YamlTranslator(yamlFile.getAbsolutePath(), true);
188186

189187
PyDictionary actual = yamlTranslator.parse();
190-
Assert.assertNotNull("dict should not be null", actual);
188+
assertNotNull(actual, "dict should not be null");
191189

192190
PyString key = new PyString("level1");
193-
Assert.assertTrue("level1 should be present", actual.has_key(key));
191+
assertTrue(actual.has_key(key), "level1 should be present");
194192
PyObject value = actual.__getitem__(key);
195-
Assert.assertNotNull("level1 value should not be null", value);
196-
Assert.assertEquals("level1 should be a dict", PyOrderedDict.class, value.getClass());
193+
assertNotNull(value, "level1 value should not be null");
194+
assertEquals(PyOrderedDict.class, value.getClass(), "level1 should be a dict");
197195
PyDictionary dict = (PyDictionary) value;
198196

199197
key = new PyString("level2");
200-
Assert.assertTrue("level2 should be present", dict.has_key(key));
198+
assertTrue(dict.has_key(key), "level2 should be present");
201199
value = dict.__getitem__(key);
202-
Assert.assertNotNull("level2 value should not be null", value);
203-
Assert.assertEquals("level2 should be a dict", PyOrderedDict.class, value.getClass());
200+
assertNotNull(value, "level2 value should not be null");
201+
assertEquals(PyOrderedDict.class, value.getClass(), "level2 should be a dict");
204202
dict = (PyDictionary) value;
205203

206204
key = new PyString("level3");
207-
Assert.assertTrue("level3 should be present", dict.has_key(key));
205+
assertTrue(dict.has_key(key), "level3 should be present");
208206
value = dict.__getitem__(key);
209-
Assert.assertNotNull("level3 value should not be null", value);
210-
Assert.assertEquals("level3 should be a dict", PyOrderedDict.class, value.getClass());
207+
assertNotNull(value, "level3 value should not be null");
208+
assertEquals(PyOrderedDict.class, value.getClass(), "level3 should be a dict");
211209
dict = (PyDictionary) value;
212210

213211
key = new PyString("field1");
214-
Assert.assertTrue("field1 should be present", dict.has_key(key));
212+
assertTrue(dict.has_key(key), "field1 should be present");
215213
value = dict.__getitem__(key);
216-
Assert.assertNotNull("field1 value should not be null", value);
217-
Assert.assertEquals("field1 should be a string", PyString.class, value.getClass());
218-
Assert.assertEquals("field1 value should be abc", "abc", value.toString());
214+
assertNotNull(value, "field1 value should not be null");
215+
assertEquals(PyString.class, value.getClass(), "field1 should be a string");
216+
assertEquals("abc", value.toString(), "field1 value should be abc");
219217

220218
key = new PyString("field2");
221-
Assert.assertTrue("field2 should be present", dict.has_key(key));
219+
assertTrue(dict.has_key(key), "field2 should be present");
222220
value = dict.__getitem__(key);
223-
Assert.assertNotNull("field2 value should not be null", value);
224-
Assert.assertEquals("field2 should be a string", PyString.class, value.getClass());
225-
Assert.assertEquals("field2 value should be def", "def", value.toString());
221+
assertNotNull(value, "field2 value should not be null");
222+
assertEquals(PyString.class, value.getClass(), "field2 should be a string");
223+
assertEquals("def", value.toString(), "field2 value should be def");
226224
}
227225

228226
@Test
@@ -231,16 +229,16 @@ public void testSecurityConfigModel2() throws Exception {
231229
YamlTranslator yamlTranslator = new YamlTranslator(yamlFile.getAbsolutePath(), true);
232230

233231
PyDictionary actual = yamlTranslator.parse();
234-
235-
Assert.assertNotNull("dict should not be null", actual);
232+
assertNotNull(actual, "dict should not be null");
236233

237234
PyString key = new PyString("topology");
238-
Assert.assertTrue("topology should be present", actual.has_key(key));
235+
assertTrue(actual.has_key(key), "topology should be present");
239236
PyObject value = actual.__getitem__(key);
240-
Assert.assertNotNull("topology value should not be null", value);
241-
Assert.assertEquals("topology should be a dict", PyOrderedDict.class, value.getClass());
237+
assertNotNull(value, "topology value should not be null");
238+
assertEquals(PyOrderedDict.class, value.getClass(), "topology should be a dict");
242239
PyDictionary dict = (PyDictionary) value;
243240

241+
key = new PyString("SecurityConfiguration");
244242
}
245243

246244
/**
@@ -260,8 +258,9 @@ public void testLexicalError() {
260258
String text = "abc:\n xyz: - aa-bb\n";
261259
InputStream stream = new ByteArrayInputStream(text.getBytes(UTF_8));
262260
YamlStreamTranslator translator = new YamlStreamTranslator("String", stream);
261+
System.out.println("translator = " + translator.toString());
263262
translator.parse();
264-
Assert.fail("Test must raise YamlException when model has a lexical error");
263+
fail("Test must raise YamlException when model has a lexical error");
265264

266265
} catch(YamlException e) {
267266
// expected result

0 commit comments

Comments
 (0)