|
26 | 26 |
|
27 | 27 | import static org.hamcrest.MatcherAssert.assertThat; |
28 | 28 | import static org.hamcrest.Matchers.startsWith; |
| 29 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
29 | 30 |
|
30 | 31 | import java.io.IOException; |
31 | 32 | import net.sf.json.JSONObject; |
32 | | -import org.junit.Assert; |
33 | | -import org.junit.Rule; |
34 | | -import org.junit.Test; |
| 33 | +import org.junit.jupiter.api.BeforeEach; |
| 34 | +import org.junit.jupiter.api.Test; |
35 | 35 | import org.jvnet.hudson.test.Issue; |
36 | 36 | import org.jvnet.hudson.test.JenkinsRule; |
37 | | -import org.xml.sax.SAXException; |
| 37 | +import org.jvnet.hudson.test.junit.jupiter.WithJenkins; |
38 | 38 |
|
39 | 39 | /** |
40 | 40 | * @author <a href="mailto:tom.fennelly@gmail.com">tom.fennelly@gmail.com</a> |
41 | 41 | */ |
42 | | -public class I18nTest { |
| 42 | +@WithJenkins |
| 43 | +class I18nTest { |
43 | 44 |
|
44 | | - @Rule |
45 | | - public JenkinsRule jenkinsRule = new JenkinsRule(); |
| 45 | + private JenkinsRule jenkinsRule; |
| 46 | + |
| 47 | + @BeforeEach |
| 48 | + void setUp(JenkinsRule rule) { |
| 49 | + jenkinsRule = rule; |
| 50 | + } |
46 | 51 |
|
47 | 52 | @Test |
48 | | - public void test_baseName_unspecified() throws IOException, SAXException { |
| 53 | + void test_baseName_unspecified() throws IOException { |
49 | 54 | JSONObject response = jenkinsRule.getJSON("i18n/resourceBundle").getJSONObject(); |
50 | | - Assert.assertEquals("error", response.getString("status")); |
51 | | - Assert.assertEquals("Mandatory parameter 'baseName' not specified.", response.getString("message")); |
| 55 | + assertEquals("error", response.getString("status")); |
| 56 | + assertEquals("Mandatory parameter 'baseName' not specified.", response.getString("message")); |
52 | 57 | } |
53 | 58 |
|
54 | 59 | @Test |
55 | | - public void test_baseName_unknown() throws IOException, SAXException { |
| 60 | + void test_baseName_unknown() throws IOException { |
56 | 61 | JSONObject response = jenkinsRule.getJSON("i18n/resourceBundle?baseName=com.acme.XyzWhatever").getJSONObject(); |
57 | | - Assert.assertEquals("error", response.getString("status")); |
| 62 | + assertEquals("error", response.getString("status")); |
58 | 63 | assertThat(response.getString("message"), startsWith("Can't find bundle for base name com.acme.XyzWhatever")); |
59 | 64 | } |
60 | 65 |
|
61 | 66 | @Issue("JENKINS-35270") |
62 | 67 | @Test |
63 | | - public void test_baseName_plugin() throws Exception { |
| 68 | + void test_baseName_plugin() throws Exception { |
64 | 69 | JSONObject response = jenkinsRule.getJSON("i18n/resourceBundle?baseName=org.jenkinsci.plugins.matrixauth.Messages").getJSONObject(); |
65 | | - Assert.assertEquals(response.toString(), "ok", response.getString("status")); |
| 70 | + assertEquals("ok", response.getString("status"), response.toString()); |
66 | 71 | JSONObject data = response.getJSONObject("data"); |
67 | | - Assert.assertEquals("Matrix-based security", data.getString("GlobalMatrixAuthorizationStrategy.DisplayName")); |
| 72 | + assertEquals("Matrix-based security", data.getString("GlobalMatrixAuthorizationStrategy.DisplayName")); |
68 | 73 | } |
69 | 74 |
|
70 | 75 | @Test |
71 | | - public void test_valid() throws IOException, SAXException { |
| 76 | + void test_valid() throws IOException { |
72 | 77 | JSONObject response = jenkinsRule.getJSON("i18n/resourceBundle?baseName=hudson.logging.Messages&language=de").getJSONObject(); |
73 | | - Assert.assertEquals("ok", response.getString("status")); |
| 78 | + assertEquals("ok", response.getString("status")); |
74 | 79 | JSONObject data = response.getJSONObject("data"); |
75 | | - Assert.assertEquals("Initialisiere Log-Rekorder", data.getString("LogRecorderManager.init")); |
| 80 | + assertEquals("Initialisiere Log-Rekorder", data.getString("LogRecorderManager.init")); |
76 | 81 | } |
77 | 82 |
|
| 83 | + // variant testing |
78 | 84 | @Issue("JENKINS-39034") |
79 | | - @Test // variant testing |
80 | | - public void test_valid_region_variant() throws IOException, SAXException { |
| 85 | + @Test |
| 86 | + void test_valid_region_variant() throws IOException { |
81 | 87 | JSONObject response = jenkinsRule.getJSON("i18n/resourceBundle?baseName=jenkins.i18n.Messages&language=en_AU_variant").getJSONObject(); |
82 | | - Assert.assertEquals("ok", response.getString("status")); |
| 88 | + assertEquals("ok", response.getString("status")); |
83 | 89 | JSONObject data = response.getJSONObject("data"); |
84 | | - Assert.assertEquals("value_au_variant", data.getString("Key")); |
| 90 | + assertEquals("value_au_variant", data.getString("Key")); |
85 | 91 | } |
86 | 92 |
|
| 93 | + //country testing with delimiter '-' instead of '_' |
87 | 94 | @Issue("JENKINS-39034") |
88 | | - @Test //country testing with delimiter '-' instead of '_' |
89 | | - public void test_valid_region() throws IOException, SAXException { |
| 95 | + @Test |
| 96 | + void test_valid_region() throws IOException { |
90 | 97 | JSONObject response = jenkinsRule.getJSON("i18n/resourceBundle?baseName=jenkins.i18n.Messages&language=en-AU").getJSONObject(); |
91 | | - Assert.assertEquals("ok", response.getString("status")); |
| 98 | + assertEquals("ok", response.getString("status")); |
92 | 99 | JSONObject data = response.getJSONObject("data"); |
93 | | - Assert.assertEquals("value_au", data.getString("Key")); |
| 100 | + assertEquals("value_au", data.getString("Key")); |
94 | 101 | } |
95 | 102 |
|
| 103 | + //fallthrough to default language if variant does not exit |
96 | 104 | @Issue("JENKINS-39034") |
97 | | - @Test //fallthrough to default language if variant does not exit |
98 | | - public void test_valid_fallback() throws IOException, SAXException { |
| 105 | + @Test |
| 106 | + void test_valid_fallback() throws IOException { |
99 | 107 | JSONObject response = jenkinsRule.getJSON("i18n/resourceBundle?baseName=jenkins.i18n.Messages&language=en_NZ_variant").getJSONObject(); |
100 | | - Assert.assertEquals("ok", response.getString("status")); |
| 108 | + assertEquals("ok", response.getString("status")); |
101 | 109 | JSONObject data = response.getJSONObject("data"); |
102 | | - Assert.assertEquals("value", data.getString("Key")); |
| 110 | + assertEquals("value", data.getString("Key")); |
103 | 111 | } |
104 | 112 |
|
105 | | - @Test // testing with unknown language falls through to default language |
106 | | - public void test_unsupported_language() throws IOException, SAXException { |
| 113 | + // testing with unknown language falls through to default language |
| 114 | + @Test |
| 115 | + void test_unsupported_language() throws IOException { |
107 | 116 | JSONObject response = jenkinsRule.getJSON("i18n/resourceBundle?baseName=jenkins.i18n.Messages&language=xyz").getJSONObject(); |
108 | | - Assert.assertEquals("ok", response.getString("status")); |
| 117 | + assertEquals("ok", response.getString("status")); |
109 | 118 | JSONObject data = response.getJSONObject("data"); |
110 | | - Assert.assertEquals("value", data.getString("Key")); |
| 119 | + assertEquals("value", data.getString("Key")); |
111 | 120 | } |
112 | 121 |
|
113 | 122 | } |
0 commit comments