KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > test > notification > filter > FilterUsageDecoratorTest


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.filter;
23
24 import java.util.Date JavaDoc;
25
26 import junit.framework.Test;
27 import junit.framework.TestCase;
28 import junit.framework.TestSuite;
29
30 import org.easymock.MockControl;
31 import org.jacorb.notification.filter.FilterUsageDecorator;
32 import org.omg.CORBA.Any JavaDoc;
33 import org.omg.CORBA.ORB JavaDoc;
34 import org.omg.CosNotifyFilter.FilterOperations;
35
36 /**
37  * @author Alphonse Bendt
38  * @version $Id: FilterUsageDecoratorTest.java,v 1.1 2005/03/31 20:19:50 alphonse.bendt Exp $
39  */

40 public class FilterUsageDecoratorTest extends TestCase
41 {
42     private FilterUsageDecorator objectUnderTest_;
43
44     private MockControl controlFilterOperations_;
45
46     private FilterOperations mockFilterOperations_;
47
48     private Any JavaDoc any_;
49
50     /*
51      * @see TestCase#setUp()
52      */

53     protected void setUp() throws Exception JavaDoc
54     {
55         super.setUp();
56
57         any_ = ORB.init().create_any();
58
59         controlFilterOperations_ = MockControl.createControl(FilterOperations.class);
60         mockFilterOperations_ = (FilterOperations) controlFilterOperations_.getMock();
61
62         objectUnderTest_ = new FilterUsageDecorator(mockFilterOperations_);
63     }
64
65     /**
66      * Constructor for FilterUsageDecoratorTest.
67      *
68      * @param name
69      */

70     public FilterUsageDecoratorTest(String JavaDoc name)
71     {
72         super(name);
73     }
74
75     public void testFilterOperationsAreDelegated() throws Exception JavaDoc
76     {
77         mockFilterOperations_.match(any_);
78         controlFilterOperations_.setReturnValue(true);
79
80         controlFilterOperations_.replay();
81
82         FilterOperations handle = objectUnderTest_.getFilterOperations();
83
84         assertTrue(handle.match(any_));
85
86         controlFilterOperations_.verify();
87     }
88
89     public void testGetLastUsage() throws Exception JavaDoc
90     {
91         mockFilterOperations_.match(any_);
92         controlFilterOperations_.setReturnValue(true, 2);
93
94         controlFilterOperations_.replay();
95
96         FilterOperations handle = objectUnderTest_.getFilterOperations();
97
98         handle.match(any_);
99
100         Date JavaDoc usage1 = objectUnderTest_.getLastUsage();
101
102         assertTrue(usage1.getTime() <= System.currentTimeMillis());
103
104         Thread.sleep(1000);
105
106         handle.match(any_);
107
108         Date JavaDoc usage2 = objectUnderTest_.getLastUsage();
109
110         assertTrue(usage2.getTime() <= System.currentTimeMillis());
111
112         assertTrue(usage1.getTime() < usage2.getTime());
113
114         controlFilterOperations_.verify();
115     }
116
117     public static Test suite()
118     {
119         return new TestSuite(FilterUsageDecoratorTest.class);
120     }
121 }
122
Popular Tags