Simon Hunt | e556e94 | 2017-06-19 15:35:44 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Simon Hunt | e556e94 | 2017-06-19 15:35:44 -0700 | [diff] [blame] | 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 Hunt | 00b369a | 2017-06-20 19:46:40 -0700 | [diff] [blame] | 18 | package org.onosproject.ui.impl.lion; |
Simon Hunt | e556e94 | 2017-06-19 15:35:44 -0700 | [diff] [blame] | 19 | |
Simon Hunt | fb7f95b | 2017-06-20 16:10:55 -0700 | [diff] [blame] | 20 | import org.junit.AfterClass; |
| 21 | import org.junit.Before; |
| 22 | import org.junit.BeforeClass; |
| 23 | import org.junit.Ignore; |
Simon Hunt | e556e94 | 2017-06-19 15:35:44 -0700 | [diff] [blame] | 24 | import org.junit.Test; |
| 25 | import org.onosproject.ui.AbstractUiTest; |
| 26 | import org.onosproject.ui.lion.LionBundle; |
| 27 | |
Simon Hunt | 00b369a | 2017-06-20 19:46:40 -0700 | [diff] [blame] | 28 | import java.util.List; |
Simon Hunt | fb7f95b | 2017-06-20 16:10:55 -0700 | [diff] [blame] | 29 | import java.util.Locale; |
| 30 | |
Simon Hunt | e556e94 | 2017-06-19 15:35:44 -0700 | [diff] [blame] | 31 | import static org.junit.Assert.assertEquals; |
| 32 | |
| 33 | /** |
| 34 | * Unit tests for {@link BundleStitcher}. |
| 35 | */ |
| 36 | public class BundleStitcherTest extends AbstractUiTest { |
| 37 | |
Simon Hunt | 00b369a | 2017-06-20 19:46:40 -0700 | [diff] [blame] | 38 | private static final String LION_BASE = "/org/onosproject/ui/lion"; |
| 39 | |
| 40 | private static final String[] LION_TAGS = {"CardGame1"}; |
| 41 | |
Simon Hunt | e556e94 | 2017-06-19 15:35:44 -0700 | [diff] [blame] | 42 | |
| 43 | private static final String[] CARD_GAME_1_KEYS = { |
Simon Hunt | fb7f95b | 2017-06-20 16:10:55 -0700 | [diff] [blame] | 44 | "of", "flush", "full_house", "pair", "three_oak", |
| 45 | "ace", "king", "queen", "jack", "ten", |
| 46 | "spades", "clubs", |
Simon Hunt | e556e94 | 2017-06-19 15:35:44 -0700 | [diff] [blame] | 47 | }; |
| 48 | |
| 49 | private static final String[] CARD_GAME_1_ENGLISH = { |
Simon Hunt | fb7f95b | 2017-06-20 16:10:55 -0700 | [diff] [blame] | 50 | "of", "Flush", "Full House", "Pair", "Three of a Kind", |
| 51 | "Ace", "King", "Queen", "Jack", "Ten", |
| 52 | "Spades", "Clubs", |
Simon Hunt | e556e94 | 2017-06-19 15:35:44 -0700 | [diff] [blame] | 53 | }; |
| 54 | |
Simon Hunt | fb7f95b | 2017-06-20 16:10:55 -0700 | [diff] [blame] | 55 | // 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 Hunt | e556e94 | 2017-06-19 15:35:44 -0700 | [diff] [blame] | 63 | |
| 64 | private LionBundle lion; |
| 65 | |
Simon Hunt | fb7f95b | 2017-06-20 16:10:55 -0700 | [diff] [blame] | 66 | @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 Hunt | e556e94 | 2017-06-19 15:35:44 -0700 | [diff] [blame] | 83 | private BundleStitcher testStitcher() { |
Simon Hunt | 00b369a | 2017-06-20 19:46:40 -0700 | [diff] [blame] | 84 | return new BundleStitcher(LION_BASE); |
Simon Hunt | e556e94 | 2017-06-19 15:35:44 -0700 | [diff] [blame] | 85 | } |
| 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 Hunt | 00b369a | 2017-06-20 19:46:40 -0700 | [diff] [blame] | 97 | // -- 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 Hunt | e556e94 | 2017-06-19 15:35:44 -0700 | [diff] [blame] | 115 | @Test |
| 116 | public void cardGame1English() { |
| 117 | title("cardGame1English"); |
Simon Hunt | fb7f95b | 2017-06-20 16:10:55 -0700 | [diff] [blame] | 118 | // use default locale (en_US) |
| 119 | |
Simon Hunt | e556e94 | 2017-06-19 15:35:44 -0700 | [diff] [blame] | 120 | 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 Hunt | fb7f95b | 2017-06-20 16:10:55 -0700 | [diff] [blame] | 126 | |
| 127 | /* |
| 128 | * TODO: Andrea to localize |
Simon Hunt | 00b369a | 2017-06-20 19:46:40 -0700 | [diff] [blame] | 129 | * Under: ${ONOS_ROOT}/web/gui/src/test/resources/ |
Simon Hunt | fb7f95b | 2017-06-20 16:10:55 -0700 | [diff] [blame] | 130 | * |
| 131 | * Bundles to Localize: |
Simon Hunt | 00b369a | 2017-06-20 19:46:40 -0700 | [diff] [blame] | 132 | * 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 Hunt | fb7f95b | 2017-06-20 16:10:55 -0700 | [diff] [blame] | 135 | */ |
| 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 Hunt | e556e94 | 2017-06-19 15:35:44 -0700 | [diff] [blame] | 148 | } |