View Javadoc

1   // Copyright (C) 2005 - 2011 Philip Aston
2   // Copyright (C) 2007 Venelin Mitov
3   // All rights reserved.
4   //
5   // This file is part of The Grinder software distribution. Refer to
6   // the file LICENSE which is part of The Grinder distribution for
7   // licensing details. The Grinder distribution is available on the
8   // Internet at http://grinder.sourceforge.net/
9   //
10  // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
11  // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
12  // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
13  // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
14  // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
15  // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
16  // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
17  // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
18  // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
19  // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
20  // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
21  // OF THE POSSIBILITY OF SUCH DAMAGE.
22  
23  package net.grinder.plugin.http.tcpproxyfilter;
24  
25  import static org.junit.Assert.assertNotSame;
26  import static org.mockito.Mockito.verifyNoMoreInteractions;
27  import net.grinder.tools.tcpproxy.CommentSource;
28  import net.grinder.tools.tcpproxy.CommentSourceImplementation;
29  import net.grinder.tools.tcpproxy.ConnectionDetails;
30  import net.grinder.tools.tcpproxy.EndPoint;
31  import net.grinder.util.AttributeStringParser;
32  import net.grinder.util.http.URIParser;
33  
34  import org.junit.Before;
35  import org.junit.Test;
36  import org.mockito.Mock;
37  import org.mockito.MockitoAnnotations;
38  import org.slf4j.Logger;
39  
40  
41  /**
42   * Unit tests for {@link ConnectionHandlerFactoryImplementation}.
43   *
44   * @author Philip Aston
45   */
46  public class TestConnectionHandlerFactoryImplementation {
47  
48    @Mock private HTTPRecording m_httpRecording;
49    @Mock private Logger m_logger;
50    @Mock private RegularExpressions m_regularExpressions;
51    @Mock private URIParser m_uriParser;
52    @Mock private AttributeStringParser m_attributeStringParser;
53  
54    final CommentSource m_commentSource = new CommentSourceImplementation();
55  
56    private final ConnectionDetails m_connectionDetails =
57      new ConnectionDetails(
58        new EndPoint("hostA", 80),
59        new EndPoint("hostB", 80),
60        false);
61  
62    @Before public void setUp() {
63      MockitoAnnotations.initMocks(this);
64    }
65  
66    @Test public void testFactory() {
67      final ConnectionHandlerFactory factory =
68        new ConnectionHandlerFactoryImplementation(m_httpRecording,
69          m_logger, m_regularExpressions, m_uriParser,
70          m_attributeStringParser, null, m_commentSource);
71  
72      final ConnectionHandler handler1 = factory.create(m_connectionDetails);
73      final ConnectionHandler handler2 = factory.create(m_connectionDetails);
74      assertNotSame(handler1, handler2);
75  
76      verifyNoMoreInteractions(m_httpRecording,
77                               m_logger,
78                               m_regularExpressions,
79                               m_uriParser,
80                               m_attributeStringParser);
81    }
82  }