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.corelib.components;
016:
017: import org.apache.tapestry.internal.test.InternalBaseTestCase;
018: import org.testng.annotations.Test;
019:
020: public class FormSupportImplTest extends InternalBaseTestCase {
021: @Test
022: public void execute_deferred_with_no_commands() {
023: FormSupportImpl support = new FormSupportImpl();
024:
025: support.executeDeferred();
026: }
027:
028: @Test
029: public void execute_deferred_execute_in_added_order() {
030: Runnable r1 = mockRunnable();
031: Runnable r2 = mockRunnable();
032:
033: getMocksControl().checkOrder(true);
034:
035: r1.run();
036: r2.run();
037:
038: replay();
039:
040: FormSupportImpl support = new FormSupportImpl();
041:
042: support.defer(r1);
043: support.defer(r2);
044:
045: support.executeDeferred();
046:
047: verify();
048: }
049:
050: @Test
051: public void deferred_commands_execute_once() {
052: Runnable r1 = mockRunnable();
053: Runnable r2 = mockRunnable();
054: Runnable r3 = mockRunnable();
055:
056: getMocksControl().checkOrder(true);
057:
058: r1.run();
059: r2.run();
060:
061: replay();
062:
063: FormSupportImpl support = new FormSupportImpl();
064:
065: support.defer(r1);
066: support.defer(r2);
067:
068: support.executeDeferred();
069:
070: verify();
071:
072: r3.run();
073:
074: replay();
075:
076: support.defer(r3);
077:
078: support.executeDeferred();
079:
080: verify();
081: }
082:
083: @Test
084: public void set_encoding_type() {
085: FormSupportImpl support = new FormSupportImpl();
086:
087: String encodingType = "foo/bar";
088:
089: support.setEncodingType(encodingType);
090:
091: assertSame(support.getEncodingType(), encodingType);
092: }
093:
094: @Test
095: public void set_encoding_type_to_same_value_is_allowed() {
096: FormSupportImpl support = new FormSupportImpl();
097:
098: String encodingType = "foo/bar";
099:
100: support.setEncodingType(encodingType);
101: support.setEncodingType(new String(encodingType));
102:
103: assertEquals(support.getEncodingType(), encodingType);
104: }
105:
106: @Test
107: public void set_encoding_type_conflict() {
108:
109: FormSupportImpl support = new FormSupportImpl();
110:
111: support.setEncodingType("foo");
112: try {
113: support.setEncodingType("bar");
114: unreachable();
115: } catch (IllegalStateException ex) {
116: assertEquals(
117: ex.getMessage(),
118: "Encoding type of form has already been set to \'foo\' and may not be changed to \'bar\'.");
119: }
120:
121: }
122: }
|