001: // Copyright 2007 The Apache Software Foundation
002: //
003: // Licensed under the Apache License, Version 2.0 (the "License");
004: // you may not use this file except in compliance with the License.
005: // You may obtain a copy of the License at
006: //
007: // http://www.apache.org/licenses/LICENSE-2.0
008: //
009: // Unless required by applicable law or agreed to in writing, software
010: // distributed under the License is distributed on an "AS IS" BASIS,
011: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012: // See the License for the specific language governing permissions and
013: // limitations under the License.
014:
015: package org.apache.tapestry.util;
016:
017: import java.util.List;
018:
019: import org.apache.tapestry.OptionModel;
020: import org.apache.tapestry.SelectModel;
021: import org.apache.tapestry.Stooge;
022: import org.apache.tapestry.ioc.Messages;
023: import org.apache.tapestry.test.TapestryTestCase;
024: import org.testng.annotations.Test;
025:
026: public class EnumSelectModelTest extends TapestryTestCase {
027: @Test
028: public void generated_labels() {
029: Messages messages = mockMessages();
030: stub_contains(messages, false);
031:
032: replay();
033:
034: SelectModel model = new EnumSelectModel(Stooge.class, messages);
035:
036: List<OptionModel> options = model.getOptions();
037:
038: assertEquals(options.size(), 3);
039:
040: checkOption(options, 0, "Moe", Stooge.MOE);
041: checkOption(options, 1, "Larry", Stooge.LARRY);
042: checkOption(options, 2, "Curly Joe", Stooge.CURLY_JOE);
043:
044: verify();
045: }
046:
047: @Test
048: public void prefixed_name_in_message_catalog() {
049: Messages messages = mockMessages();
050: stub_contains(messages, false);
051:
052: train_contains(messages, "Stooge.LARRY", true);
053: train_get(messages, "Stooge.LARRY", "Mr. Larry Fine");
054:
055: replay();
056:
057: SelectModel model = new EnumSelectModel(Stooge.class, messages);
058:
059: List<OptionModel> options = model.getOptions();
060:
061: assertEquals(options.size(), 3);
062:
063: checkOption(options, 0, "Moe", Stooge.MOE);
064: checkOption(options, 1, "Mr. Larry Fine", Stooge.LARRY);
065: checkOption(options, 2, "Curly Joe", Stooge.CURLY_JOE);
066:
067: verify();
068: }
069:
070: @Test
071: public void unprefixed_name_in_message_catalog() {
072: Messages messages = mockMessages();
073: stub_contains(messages, false);
074:
075: train_contains(messages, "MOE", true);
076: train_get(messages, "MOE", "Sir Moe Howard");
077:
078: replay();
079:
080: SelectModel model = new EnumSelectModel(Stooge.class, messages);
081:
082: List<OptionModel> options = model.getOptions();
083:
084: assertEquals(options.size(), 3);
085:
086: checkOption(options, 0, "Sir Moe Howard", Stooge.MOE);
087: checkOption(options, 1, "Larry", Stooge.LARRY);
088: checkOption(options, 2, "Curly Joe", Stooge.CURLY_JOE);
089:
090: verify();
091: }
092:
093: private void checkOption(List<OptionModel> options, int i,
094: String label, Stooge value) {
095: OptionModel model = options.get(i);
096:
097: assertEquals(model.getLabel(), label);
098: assertFalse(model.isDisabled());
099: assertSame(model.getValue(), value);
100: assertNull(model.getAttributes());
101: }
102: }
|