Simon Hunt | e556e94 | 2017-06-19 15:35:44 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 18 | package org.onosproject.ui.lion.stitch; |
| 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 | fb7f95b | 2017-06-20 16:10:55 -0700 | [diff] [blame^] | 28 | import java.util.Locale; |
| 29 | |
Simon Hunt | e556e94 | 2017-06-19 15:35:44 -0700 | [diff] [blame] | 30 | import static org.junit.Assert.assertEquals; |
| 31 | |
| 32 | /** |
| 33 | * Unit tests for {@link BundleStitcher}. |
| 34 | */ |
| 35 | public 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 Hunt | fb7f95b | 2017-06-20 16:10:55 -0700 | [diff] [blame^] | 41 | "of", "flush", "full_house", "pair", "three_oak", |
| 42 | "ace", "king", "queen", "jack", "ten", |
| 43 | "spades", "clubs", |
Simon Hunt | e556e94 | 2017-06-19 15:35:44 -0700 | [diff] [blame] | 44 | }; |
| 45 | |
| 46 | private static final String[] CARD_GAME_1_ENGLISH = { |
Simon Hunt | fb7f95b | 2017-06-20 16:10:55 -0700 | [diff] [blame^] | 47 | "of", "Flush", "Full House", "Pair", "Three of a Kind", |
| 48 | "Ace", "King", "Queen", "Jack", "Ten", |
| 49 | "Spades", "Clubs", |
Simon Hunt | e556e94 | 2017-06-19 15:35:44 -0700 | [diff] [blame] | 50 | }; |
| 51 | |
Simon Hunt | fb7f95b | 2017-06-20 16:10:55 -0700 | [diff] [blame^] | 52 | // 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 Hunt | e556e94 | 2017-06-19 15:35:44 -0700 | [diff] [blame] | 60 | |
| 61 | private LionBundle lion; |
| 62 | |
Simon Hunt | fb7f95b | 2017-06-20 16:10:55 -0700 | [diff] [blame^] | 63 | @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 Hunt | e556e94 | 2017-06-19 15:35:44 -0700 | [diff] [blame] | 80 | 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 Hunt | fb7f95b | 2017-06-20 16:10:55 -0700 | [diff] [blame^] | 97 | // use default locale (en_US) |
| 98 | |
Simon Hunt | e556e94 | 2017-06-19 15:35:44 -0700 | [diff] [blame] | 99 | 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 Hunt | fb7f95b | 2017-06-20 16:10:55 -0700 | [diff] [blame^] | 105 | |
| 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 Hunt | e556e94 | 2017-06-19 15:35:44 -0700 | [diff] [blame] | 127 | } |