001 // Copyright 2004, 2005 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 package org.apache.tapestry.form; 015 016 import org.testng.annotations.Test; 017 018 019 /** 020 * Tests functionaliy of {@link EnumPropertySelectionModel}. 021 * 022 */ 023 @Test 024 public class TestEnumPropertySelectionModel 025 { 026 enum AbstractFormat 027 { 028 FreePaperOnly("Free Paper Only"), 029 ScientificPosterOnly("Scientific Poster Only"), 030 DemonstrationPosterOnly("Demonstration Poster Only"), 031 FreePaperorScientificPoster("Free Paper or Scientific Poster"), 032 FreePaperorDemonstrationPoster("Free Paper or Demonstration Poster"), 033 InstructionalCourse("Instructional Course"); 034 035 private final String category; 036 037 AbstractFormat(String category){ 038 this.category = category; 039 } 040 041 public String toString() 042 { 043 return this.category; 044 } 045 } 046 047 public void test_Simple_Enum() 048 { 049 EnumPropertySelectionModel ep = new EnumPropertySelectionModel(AbstractFormat.values()); 050 051 assert "None".equals(ep.getLabel(0)); 052 053 assert AbstractFormat.FreePaperOnly.toString().equals(ep.getLabel(1)); 054 055 assert AbstractFormat.FreePaperorDemonstrationPoster.equals(ep.getOption(5)); 056 057 assert AbstractFormat.values().length + 1 == ep.getOptionCount(); 058 059 assert "None".equals(ep.getValue(0)); 060 061 assert ep.getOption(0) == null; 062 063 assert AbstractFormat.ScientificPosterOnly.toString().equals(ep.getValue(2)); 064 065 assert AbstractFormat.FreePaperOnly == ep.translateValue(AbstractFormat.FreePaperOnly.toString()); 066 } 067 }