blob: f1a606a5905637d0af43be6a65fb0dcc9f065fd4 [file] [log] [blame]
Simon Hunte556e942017-06-19 15:35:44 -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.stitch;
19
Simon Huntfb7f95b2017-06-20 16:10:55 -070020import org.junit.AfterClass;
21import org.junit.Before;
22import org.junit.BeforeClass;
23import org.junit.Ignore;
Simon Hunte556e942017-06-19 15:35:44 -070024import org.junit.Test;
25import org.onosproject.ui.AbstractUiTest;
26import org.onosproject.ui.lion.LionBundle;
27
Simon Huntfb7f95b2017-06-20 16:10:55 -070028import java.util.Locale;
29
Simon Hunte556e942017-06-19 15:35:44 -070030import static org.junit.Assert.assertEquals;
31
32/**
33 * Unit tests for {@link BundleStitcher}.
34 */
35public class BundleStitcherTest extends AbstractUiTest {
36
37 private static final String TEST_RESOURCE_BASE =
38 "/org/onosproject/ui/lion/stitchtests";
39
40 private static final String[] CARD_GAME_1_KEYS = {
Simon Huntfb7f95b2017-06-20 16:10:55 -070041 "of", "flush", "full_house", "pair", "three_oak",
42 "ace", "king", "queen", "jack", "ten",
43 "spades", "clubs",
Simon Hunte556e942017-06-19 15:35:44 -070044 };
45
46 private static final String[] CARD_GAME_1_ENGLISH = {
Simon Huntfb7f95b2017-06-20 16:10:55 -070047 "of", "Flush", "Full House", "Pair", "Three of a Kind",
48 "Ace", "King", "Queen", "Jack", "Ten",
49 "Spades", "Clubs",
Simon Hunte556e942017-06-19 15:35:44 -070050 };
51
Simon Huntfb7f95b2017-06-20 16:10:55 -070052 // TODO: Andrea to Localize to Italian
53 private static final String[] CARD_GAME_1_ITALIAN = {
54 "of", "Flush", "Full House", "Pair", "Three of a Kind",
55 "Ace", "King", "Queen", "Jack", "Ten",
56 "Spades", "Clubs",
57 };
58
59 private static Locale systemLocale;
Simon Hunte556e942017-06-19 15:35:44 -070060
61 private LionBundle lion;
62
Simon Huntfb7f95b2017-06-20 16:10:55 -070063 @BeforeClass
64 public static void classSetup() {
65 systemLocale = Locale.getDefault();
66 }
67
68 @AfterClass
69 public static void classTeardown() {
70 Locale.setDefault(systemLocale);
71 }
72
73 @Before
74 public void testSetup() {
75 // reset to a known default locale before starting each test
76 Locale.setDefault(Locale.US);
77 }
78
79
Simon Hunte556e942017-06-19 15:35:44 -070080 private BundleStitcher testStitcher() {
81 return new BundleStitcher(TEST_RESOURCE_BASE);
82 }
83
84 private void verifyItems(LionBundle lion, String[] values) {
85 final int max = values.length;
86 for (int i = 0; i < max; i++) {
87 String key = CARD_GAME_1_KEYS[i];
88 String expValue = values[i];
89 String actValue = lion.getValue(key);
90 assertEquals("wrong mapping", expValue, actValue);
91 }
92 }
93
94 @Test
95 public void cardGame1English() {
96 title("cardGame1English");
Simon Huntfb7f95b2017-06-20 16:10:55 -070097 // use default locale (en_US)
98
Simon Hunte556e942017-06-19 15:35:44 -070099 lion = testStitcher().stitch("CardGame1");
100 print(lion);
101 assertEquals("wrong key", "CardGame1", lion.id());
102 assertEquals("bad key count", 12, lion.size());
103 verifyItems(lion, CARD_GAME_1_ENGLISH);
104 }
Simon Huntfb7f95b2017-06-20 16:10:55 -0700105
106 /*
107 * TODO: Andrea to localize
108 * Under: ${ONOS_ROOT}/core/api/src/test/resources/
109 *
110 * Bundles to Localize:
111 * org/onosproject/ui/lion/stitchtests/app/Cards.properties
112 * org/onosproject/ui/lion/stitchtests/core/stuff/Rank.properties
113 * org/onosproject/ui/lion/stitchtests/core/stuff/Suit.properties
114 */
115 @Ignore("Andrea to localize bundles to Italian")
116 @Test
117 public void cardGame1Italian() {
118 title("cardGame1Italian");
119 Locale.setDefault(Locale.ITALIAN);
120
121 lion = testStitcher().stitch("CardGame1");
122 print(lion);
123 assertEquals("wrong key", "CardGame1", lion.id());
124 assertEquals("bad key count", 12, lion.size());
125 verifyItems(lion, CARD_GAME_1_ITALIAN);
126 }
Simon Hunte556e942017-06-19 15:35:44 -0700127}