1 // Copyright (C) 2012 Philip Aston
2 // All rights reserved.
3 //
4 // This file is part of The Grinder software distribution. Refer to
5 // the file LICENSE which is part of The Grinder distribution for
6 // licensing details. The Grinder distribution is available on the
7 // Internet at http://grinder.sourceforge.net/
8 //
9 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
10 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
11 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
12 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
13 // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
14 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
15 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
16 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
17 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
18 // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
19 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
20 // OF THE POSSIBILITY OF SUCH DAMAGE.
21
22 package net.grinder.communication;
23
24 import static net.grinder.testutility.SocketUtilities.findFreePort;
25
26 import net.grinder.util.StandardTimeAuthority;
27
28 import org.junit.After;
29 import org.junit.Before;
30
31 /**
32 * Abstract unit test cases for socket based {@link Sender} and {@link Receiver}
33 * implementations.
34 *
35 * @author Philip Aston
36 */
37 public abstract class AbstractSenderAndReceiverSocketTests
38 extends AbstractSenderAndReceiverTests {
39
40 private ConnectionType m_connectionType;
41 private Acceptor m_acceptor;
42 private Connector m_connector;
43
44 @Before public final void initialiseSockets() throws Exception {
45
46 final int port = findFreePort();
47
48 m_connectionType = ConnectionType.AGENT;
49 m_connector = new Connector("localhost", port, m_connectionType);
50 m_acceptor =
51 new Acceptor("localhost", port, 1, new StandardTimeAuthority());
52 }
53
54 @After public void stopAcceptor() throws Exception {
55 if (m_acceptor != null) {
56 m_acceptor.shutdown();
57 }
58 }
59
60 protected final Acceptor getAcceptor() throws Exception {
61 return m_acceptor;
62 }
63
64 protected final ConnectionType getConnectionType() throws Exception {
65 return m_connectionType;
66 }
67
68 protected final Connector getConnector() throws Exception {
69 return m_connector;
70 }
71 }