View Javadoc
1   package org.apache.commons.jcs.auxiliary.remote.util;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import junit.framework.TestCase;
23  import org.apache.commons.jcs.auxiliary.remote.value.RemoteCacheRequest;
24  import org.apache.commons.jcs.auxiliary.remote.value.RemoteRequestType;
25  import org.apache.commons.jcs.engine.CacheElement;
26  
27  import java.io.Serializable;
28  import java.util.Collections;
29  import java.util.Set;
30  
31  /** Unit tests for the request creator. */
32  public class RemoteCacheRequestFactoryUnitTest
33      extends TestCase
34  {
35      /** Simple test */
36      public void testCreateGetRequest_Normal()
37      {
38          // SETUP
39          String cacheName = "test";
40          Serializable key = "key";
41          long requesterId = 2;
42  
43          // DO WORK
44          RemoteCacheRequest<Serializable, Serializable> result =
45              RemoteCacheRequestFactory.createGetRequest( cacheName, key, requesterId );
46  
47          // VERIFY
48          assertNotNull( "Should have a result", result );
49          assertEquals( "Wrong cacheName", cacheName, result.getCacheName() );
50          assertEquals( "Wrong type", RemoteRequestType.GET, result.getRequestType() );
51      }
52  
53      /** Simple test */
54      public void testCreateGetMatchingRequest_Normal()
55      {
56          // SETUP
57          String cacheName = "test";
58          String pattern = "pattern";
59          long requesterId = 2;
60  
61          // DO WORK
62          RemoteCacheRequest<Serializable, Serializable> result =
63              RemoteCacheRequestFactory.createGetMatchingRequest( cacheName, pattern, requesterId );
64  
65          // VERIFY
66          assertNotNull( "Should have a result", result );
67          assertEquals( "Wrong cacheName", cacheName, result.getCacheName() );
68          assertEquals( "Wrong type", RemoteRequestType.GET_MATCHING, result.getRequestType() );
69      }
70  
71      /** Simple test */
72      public void testCreateGetMultipleRequest_Normal()
73      {
74          // SETUP
75          String cacheName = "test";
76          Set<Serializable> keys = Collections.emptySet();
77          long requesterId = 2;
78  
79          // DO WORK
80          RemoteCacheRequest<Serializable, Serializable> result =
81              RemoteCacheRequestFactory.createGetMultipleRequest( cacheName, keys, requesterId );
82  
83          // VERIFY
84          assertNotNull( "Should have a result", result );
85          assertEquals( "Wrong cacheName", cacheName, result.getCacheName() );
86          assertEquals( "Wrong type", RemoteRequestType.GET_MULTIPLE, result.getRequestType() );
87      }
88  
89      /** Simple test */
90      public void testCreateRemoveRequest_Normal()
91      {
92          // SETUP
93          String cacheName = "test";
94          Serializable key = "key";
95          long requesterId = 2;
96  
97          // DO WORK
98          RemoteCacheRequest<Serializable, Serializable> result = RemoteCacheRequestFactory
99              .createRemoveRequest( cacheName, key, requesterId );
100 
101         // VERIFY
102         assertNotNull( "Should have a result", result );
103         assertEquals( "Wrong cacheName", cacheName, result.getCacheName() );
104         assertEquals( "Wrong type", RemoteRequestType.REMOVE, result.getRequestType() );
105     }
106 
107     /** Simple test */
108     public void testCreateRemoveAllRequest_Normal()
109     {
110         // SETUP
111         String cacheName = "test";
112         long requesterId = 2;
113 
114         // DO WORK
115         RemoteCacheRequest<Serializable, Serializable> result =
116             RemoteCacheRequestFactory.createRemoveAllRequest( cacheName, requesterId );
117 
118         // VERIFY
119         assertNotNull( "Should have a result", result );
120         assertEquals( "Wrong cacheName", cacheName, result.getCacheName() );
121         assertEquals( "Wrong type", RemoteRequestType.REMOVE_ALL, result.getRequestType() );
122     }
123 
124     /** Simple test */
125     public void testCreateUpdateRequest_Normal()
126     {
127         // SETUP
128         String cacheName = "test";
129         Serializable key = "key";
130         long requesterId = 2;
131 
132         CacheElement<Serializable, Serializable> element =
133             new CacheElement<Serializable, Serializable>( cacheName, key, null );
134 
135         // DO WORK
136         RemoteCacheRequest<Serializable, Serializable> result =
137             RemoteCacheRequestFactory.createUpdateRequest( element, requesterId );
138 
139         // VERIFY
140         assertNotNull( "Should have a result", result );
141         assertEquals( "Wrong cacheName", cacheName, result.getCacheName() );
142         assertEquals( "Wrong type", RemoteRequestType.UPDATE, result.getRequestType() );
143     }
144 }