KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > test > notification > engine > AbstractFilterTaskTestCase


1 /*
2  * JacORB - a free Java ORB
3  *
4  * Copyright (C) 1999-2004 Gerald Brose
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the Free
18  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  *
20  */

21
22 package org.jacorb.test.notification.engine;
23
24 import junit.framework.TestCase;
25
26 import org.easymock.MockControl;
27 import org.jacorb.notification.engine.AbstractFilterTask;
28 import org.jacorb.notification.engine.Schedulable;
29 import org.jacorb.notification.engine.TaskExecutor;
30 import org.jacorb.notification.engine.TaskFactory;
31 import org.jacorb.notification.engine.TaskProcessor;
32 import org.jacorb.notification.interfaces.FilterStage;
33 import org.jacorb.notification.interfaces.Message;
34
35 /**
36  * @author Alphonse Bendt
37  * @version $Id: AbstractFilterTaskTestCase.java,v 1.2 2005/04/16 23:22:20 alphonse.bendt Exp $
38  */

39 public abstract class AbstractFilterTaskTestCase extends TestCase
40 {
41     protected MockControl controlMessage_;
42     protected Message mockMessage_;
43     protected FilterStage mockFilterStage_;
44     protected MockControl controlFilterStage_;
45     protected MockControl controlTaskFactory_;
46     protected TaskFactory mockTaskFactory_;
47     protected MockControl controlSchedulable_;
48     protected Schedulable mockSchedulable_;
49     protected FilterStage mockNextFilterStage_;
50     protected MockControl controlTaskExecutor_;
51     protected TaskExecutor mockTaskExecutor_;
52     protected TaskProcessor mockTaskProcessor_;
53     protected MockControl controlTaskProcessor_;
54     
55     private AbstractFilterTask objectUnderTest_;
56     
57     public AbstractFilterTaskTestCase(String JavaDoc name)
58     {
59         super(name);
60     }
61     
62     protected final void setUp() throws Exception JavaDoc
63     {
64         super.setUp();
65     
66         controlTaskExecutor_ = MockControl.createControl(TaskExecutor.class);
67         mockTaskExecutor_ = (TaskExecutor) controlTaskExecutor_.getMock();
68         controlTaskProcessor_ = MockControl.createControl(TaskProcessor.class);
69         mockTaskProcessor_ = (TaskProcessor) controlTaskProcessor_.getMock();
70         controlTaskFactory_ = MockControl.createStrictControl(TaskFactory.class);
71         mockTaskFactory_ = (TaskFactory) controlTaskFactory_.getMock();
72         controlMessage_ = MockControl.createControl(Message.class);
73         mockMessage_ = (Message) controlMessage_.getMock();
74     
75         controlFilterStage_ = MockControl.createControl(FilterStage.class);
76         mockFilterStage_ = (FilterStage) controlFilterStage_.getMock();
77     
78         MockControl controlNextFilterStage = MockControl.createControl(FilterStage.class);
79         mockNextFilterStage_ = (FilterStage) controlNextFilterStage.getMock();
80         controlSchedulable_ = MockControl.createControl(Schedulable.class);
81         mockSchedulable_ = (Schedulable) controlSchedulable_.getMock();
82         
83         objectUnderTest_ = newObjectUnderTest();
84     }
85     
86     public final void testCreate() throws Exception JavaDoc
87     {
88         objectUnderTest_.doWork();
89     }
90     
91     public final void testFilterInvalidMessage() throws Exception JavaDoc
92     {
93         mockMessage_.isInvalid();
94         controlMessage_.setReturnValue(true);
95         mockMessage_.dispose();
96         
97         controlMessage_.replay();
98         
99         controlFilterStage_.replay();
100         
101         objectUnderTest_.setCurrentFilterStage(new FilterStage[] {mockFilterStage_});
102         
103         objectUnderTest_.setMessage(mockMessage_);
104         
105         objectUnderTest_.run();
106         
107         controlMessage_.verify();
108         controlFilterStage_.verify();
109     }
110     
111     protected abstract AbstractFilterTask newObjectUnderTest();
112 }
113
Popular Tags