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.ComponentResources;
018: import org.apache.tapestry.internal.services.HeartbeatImpl;
019: import org.apache.tapestry.internal.test.InternalBaseTestCase;
020: import org.apache.tapestry.services.FormSupport;
021: import org.apache.tapestry.services.Heartbeat;
022: import org.apache.tapestry.services.Request;
023: import org.testng.annotations.Test;
024:
025: public class SubmitTest extends InternalBaseTestCase {
026: @Test
027: public void not_trigger_of_submission() {
028: FormSupport support = mockFormSupport();
029: Request request = mockRequest();
030:
031: String elementName = "myname";
032:
033: train_getParameter(request, elementName, null);
034:
035: replay();
036:
037: Submit submit = new Submit(request);
038:
039: submit.processSubmission(support, elementName);
040:
041: verify();
042: }
043:
044: @Test
045: public void trigger_deferred() {
046: Request request = mockRequest();
047: ComponentResources resources = mockComponentResources();
048: FormSupportImpl support = new FormSupportImpl();
049:
050: String elementName = "myname";
051:
052: train_getParameter(request, elementName, "login");
053:
054: replay();
055:
056: Submit submit = new Submit(request);
057:
058: submit.setup(resources, support, null);
059:
060: submit.processSubmission(support, elementName);
061:
062: verify();
063:
064: expect(
065: resources.triggerEvent(Submit.SELECTED_EVENT, null,
066: null)).andReturn(false);
067:
068: replay();
069:
070: support.executeDeferred();
071:
072: verify();
073: }
074:
075: @Test
076: public void trigger_immediate() {
077: FormSupport support = mockFormSupport();
078: ComponentResources resources = mockComponentResources();
079: Heartbeat heartbeat = new HeartbeatImpl();
080: Request request = mockRequest();
081:
082: String elementName = "myname";
083:
084: train_getParameter(request, elementName, "login");
085:
086: replay();
087:
088: heartbeat.begin();
089:
090: Submit submit = new Submit(request);
091:
092: submit.setup(resources, support, heartbeat);
093: submit.setDefer(false);
094:
095: submit.processSubmission(support, elementName);
096:
097: verify();
098:
099: expect(
100: resources.triggerEvent(Submit.SELECTED_EVENT, null,
101: null)).andReturn(false);
102:
103: replay();
104:
105: heartbeat.end();
106:
107: verify();
108:
109: }
110:
111: protected final FormSupport mockFormSupport() {
112: return newMock(FormSupport.class);
113: }
114:
115: }
|