1   /****************************************************************
2    * Licensed to the Apache Software Foundation (ASF) under one   *
3    * or more contributor license agreements.  See the NOTICE file *
4    * distributed with this work for additional information        *
5    * regarding copyright ownership.  The ASF licenses this file   *
6    * to you under the Apache License, Version 2.0 (the            *
7    * "License"); you may not use this file except in compliance   *
8    * with the License.  You may obtain a copy of the License at   *
9    *                                                              *
10   *   http://www.apache.org/licenses/LICENSE-2.0                 *
11   *                                                              *
12   * Unless required by applicable law or agreed to in writing,   *
13   * software distributed under the License is distributed on an  *
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
15   * KIND, either express or implied.  See the License for the    *
16   * specific language governing permissions and limitations      *
17   * under the License.                                           *
18   ****************************************************************/
19  
20  
21  package org.apache.james.transport.matchers;
22  
23  import java.io.UnsupportedEncodingException;
24  import java.util.Collection;
25  
26  import javax.mail.MessagingException;
27  
28  public class RemoteAddrInNetworkTest extends AbstractRemoteAddrInNetworkTest {
29  
30      private final String ALLOWED_NETWORK = "192.168.200.0/24";
31  
32      public RemoteAddrInNetworkTest(String arg0)
33              throws UnsupportedEncodingException {
34          super(arg0);
35      }
36  
37      // test if the recipients get returned as matched
38      public void testRemoteAddrInNetworkMatched() throws MessagingException {
39          setRemoteAddr("192.168.200.1");
40  
41          setupAll();
42  
43          Collection matchedRecipients = matcher.match(mockedMail);
44  
45          assertNotNull(matchedRecipients);
46          assertEquals(matchedRecipients.size(), mockedMail.getRecipients()
47                  .size());
48      }
49  
50      // test if no recipient get returned cause it not match
51      public void testRemoteAddrInNetworkNotMatch() throws MessagingException {
52          setRemoteAddr("192.168.1.1");
53  
54          setupAll();
55  
56          Collection matchedRecipients = matcher.match(mockedMail);
57  
58          assertNull(matchedRecipients);
59      }
60  
61      protected AbstractNetworkMatcher createMatcher() {
62          return new RemoteAddrInNetwork();
63      }
64  
65      protected String getConfigOption() {
66          return "AllowedNetworkIs=";
67      }
68  
69      protected String getAllowedNetworks() {
70          return ALLOWED_NETWORK;
71      }
72  }