blob: e5ae6a60afa5f1b48fa5b82f922bbe0ba2215c3b [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
Simon Hunt00b369a2017-06-20 19:46:40 -070018package org.onosproject.ui.impl.lion;
Simon Hunte556e942017-06-19 15:35:44 -070019
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 Hunt00b369a2017-06-20 19:46:40 -070028import java.util.List;
Simon Huntfb7f95b2017-06-20 16:10:55 -070029import java.util.Locale;
30
Simon Hunte556e942017-06-19 15:35:44 -070031import static org.junit.Assert.assertEquals;
32
33/**
34 * Unit tests for {@link BundleStitcher}.
35 */
36public class BundleStitcherTest extends AbstractUiTest {
37
Simon Hunt00b369a2017-06-20 19:46:40 -070038 private static final String LION_BASE = "/org/onosproject/ui/lion";
39
40 private static final String[] LION_TAGS = {"CardGame1"};
41
Simon Hunte556e942017-06-19 15:35:44 -070042
43 private static final String[] CARD_GAME_1_KEYS = {
Simon Huntfb7f95b2017-06-20 16:10:55 -070044 "of", "flush", "full_house", "pair", "three_oak",
45 "ace", "king", "queen", "jack", "ten",
46 "spades", "clubs",
Simon Hunte556e942017-06-19 15:35:44 -070047 };
48
49 private static final String[] CARD_GAME_1_ENGLISH = {
Simon Huntfb7f95b2017-06-20 16:10:55 -070050 "of", "Flush", "Full House", "Pair", "Three of a Kind",
51 "Ace", "King", "Queen", "Jack", "Ten",
52 "Spades", "Clubs",
Simon Hunte556e942017-06-19 15:35:44 -070053 };
54
Simon Huntfb7f95b2017-06-20 16:10:55 -070055 // TODO: Andrea to Localize to Italian
56 private static final String[] CARD_GAME_1_ITALIAN = {
57 "of", "Flush", "Full House", "Pair", "Three of a Kind",
58 "Ace", "King", "Queen", "Jack", "Ten",
59 "Spades", "Clubs",
60 };
61
62 private static Locale systemLocale;
Simon Hunte556e942017-06-19 15:35:44 -070063
64 private LionBundle lion;
65
Simon Huntfb7f95b2017-06-20 16:10:55 -070066 @BeforeClass
67 public static void classSetup() {
68 systemLocale = Locale.getDefault();
69 }
70
71 @AfterClass
72 public static void classTeardown() {
73 Locale.setDefault(systemLocale);
74 }
75
76 @Before
77 public void testSetup() {
78 // reset to a known default locale before starting each test
79 Locale.setDefault(Locale.US);
80 }
81
82
Simon Hunte556e942017-06-19 15:35:44 -070083 private BundleStitcher testStitcher() {
Simon Hunt00b369a2017-06-20 19:46:40 -070084 return new BundleStitcher(LION_BASE);
Simon Hunte556e942017-06-19 15:35:44 -070085 }
86
87 private void verifyItems(LionBundle lion, String[] values) {
88 final int max = values.length;
89 for (int i = 0; i < max; i++) {
90 String key = CARD_GAME_1_KEYS[i];
91 String expValue = values[i];
92 String actValue = lion.getValue(key);
93 assertEquals("wrong mapping", expValue, actValue);
94 }
95 }
96
Simon Hunt00b369a2017-06-20 19:46:40 -070097 // -- Testing generateLionBundles(...)
98
99 @Test
100 public void generateBundles() {
101 title("generateBundles");
102 List<LionBundle> bundles =
103 BundleStitcher.generateBundles(LION_BASE, LION_TAGS);
104 print(bundles);
105 assertEquals("missing the bundle", 1, bundles.size());
106
107 LionBundle b = bundles.get(0);
108 assertEquals("wrong id", "CardGame1", b.id());
109 assertEquals("unexpected item count", 12, b.size());
110 assertEquals("missing 3oak", "Three of a Kind", b.getValue("three_oak"));
111 assertEquals("missing queen", "Queen", b.getValue("queen"));
112 assertEquals("missing clubs", "Clubs", b.getValue("clubs"));
113 }
114
Simon Hunte556e942017-06-19 15:35:44 -0700115 @Test
116 public void cardGame1English() {
117 title("cardGame1English");
Simon Huntfb7f95b2017-06-20 16:10:55 -0700118 // use default locale (en_US)
119
Simon Hunte556e942017-06-19 15:35:44 -0700120 lion = testStitcher().stitch("CardGame1");
121 print(lion);
122 assertEquals("wrong key", "CardGame1", lion.id());
123 assertEquals("bad key count", 12, lion.size());
124 verifyItems(lion, CARD_GAME_1_ENGLISH);
125 }
Simon Huntfb7f95b2017-06-20 16:10:55 -0700126
127 /*
128 * TODO: Andrea to localize
Simon Hunt00b369a2017-06-20 19:46:40 -0700129 * Under: ${ONOS_ROOT}/web/gui/src/test/resources/
Simon Huntfb7f95b2017-06-20 16:10:55 -0700130 *
131 * Bundles to Localize:
Simon Hunt00b369a2017-06-20 19:46:40 -0700132 * org/onosproject/ui/lion/app/Cards.properties
133 * org/onosproject/ui/lion/core/stuff/Rank.properties
134 * org/onosproject/ui/lion/core/stuff/Suit.properties
Simon Huntfb7f95b2017-06-20 16:10:55 -0700135 */
136 @Ignore("Andrea to localize bundles to Italian")
137 @Test
138 public void cardGame1Italian() {
139 title("cardGame1Italian");
140 Locale.setDefault(Locale.ITALIAN);
141
142 lion = testStitcher().stitch("CardGame1");
143 print(lion);
144 assertEquals("wrong key", "CardGame1", lion.id());
145 assertEquals("bad key count", 12, lion.size());
146 verifyItems(lion, CARD_GAME_1_ITALIAN);
147 }
Simon Hunte556e942017-06-19 15:35:44 -0700148}