blob: 52fd3f632905703373df94a3b2ad0c6f8cea8b35 [file] [log] [blame]
Simon Hunt0c85f112017-06-12 21:02:17 -07001/*
2 * Copyright 2017-present Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17
18package org.onosproject.ui.lion;
19
20import org.junit.AfterClass;
21import org.junit.Before;
22import org.junit.BeforeClass;
23import org.junit.Test;
24import org.onosproject.ui.AbstractUiTest;
25
26import java.util.Locale;
27import java.util.ResourceBundle;
28
29import static org.junit.Assert.assertEquals;
30import static org.junit.Assert.assertNotNull;
31
32/**
33 * Unit tests for {@link LionUtils}.
34 */
35public class LionUtilsTest extends AbstractUiTest {
36
37 private static Locale systemLocale;
38
39 private ResourceBundle res;
40
41 @BeforeClass
42 public static void classSetup() {
43 systemLocale = Locale.getDefault();
44 }
45
46 @AfterClass
47 public static void classTeardown() {
48 Locale.setDefault(systemLocale);
49 }
50
51 @Before
52 public void testSetup() {
53 // reset to a known default locale before starting each test
54 Locale.setDefault(Locale.US);
55 }
56
57 @Test
58 public void getBundleByClassAndName() {
59 title("getBundleByClassAndName");
60 res = LionUtils.getBundledResource(LionUtilsTest.class, "SomeResource");
61 assertNotNull("missing resource bundle", res);
62 String v1 = res.getString("key1");
63 String v2 = res.getString("key2");
64 print("v1 is %s, v2 is %s", v1, v2);
65 assertEquals("v1 value wrong", "value one", v1);
66 assertEquals("v2 value wrong", "value two", v2);
67
68 res = LionUtils.getBundledResource(LionUtils.class, "SomeOtherResource");
69 assertNotNull("missing OTHER resource bundle", res);
70 v1 = res.getString("key1");
71 v2 = res.getString("key2");
72 print("v1 is %s, v2 is %s", v1, v2);
73 assertEquals("v1 value wrong", "Hay", v1);
74 assertEquals("v2 value wrong", "Bee", v2);
75 }
76
77 @Test
78 public void getBundleByClassname() {
79 title("getBundleByClassname");
80 res = LionUtils.getBundledResource(LionUtils.class);
81 assertNotNull("missing resource bundle", res);
82 String v1 = res.getString("foo");
83 String v2 = res.getString("boo");
84 print("v1 is %s, v2 is %s", v1, v2);
85 assertEquals("v1 value wrong", "bar", v1);
86 assertEquals("v2 value wrong", "ghost", v2);
87 }
88
89 @Test
90 public void getBundleByFqcn() {
91 title("getBundleByFqcn");
92 String fqcn = "org.onosproject.ui.lion.LionUtils";
93 res = LionUtils.getBundledResource(fqcn);
94 assertNotNull("missing resource bundle", res);
95 String v1 = res.getString("foo");
96 String v2 = res.getString("boo");
97 print("v1 is %s, v2 is %s", v1, v2);
98 assertEquals("v1 value wrong", "bar", v1);
99 assertEquals("v2 value wrong", "ghost", v2);
100 }
101
102 @Test
103 public void messageInEnglish() {
104 title("messageInEnglish");
105 // use default locale
106 res = LionUtils.getBundledResource(LionUtils.class, "MyBundle");
107 print("res locale is %s", res.getLocale().getLanguage());
108 assertEquals("not disk", "disk", res.getString("disk"));
109 assertEquals("not keyboard", "keyboard", res.getString("keyboard"));
110 }
111
112 @Test
113 public void messageInGerman() {
114 title("messageInGerman");
115 Locale.setDefault(new Locale("de", "DE"));
116 res = LionUtils.getBundledResource(LionUtils.class, "MyBundle");
117 print("res locale is %s", res.getLocale().getLanguage());
118 assertEquals("not DE-disk", "Platte", res.getString("disk"));
119 assertEquals("not DE-keyboard", "Tastatur", res.getString("keyboard"));
120 }
121}