Bug 7449: Add message slicing/re-assembly classes
[controller.git] / opendaylight / md-sal / sal-clustering-commons / src / test / java / org / opendaylight / controller / cluster / messaging / AbstractMessagingTest.java
1 /*
2  * Copyright (c) 2017 Inocybe Technologies and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.cluster.messaging;
9
10 import static org.mockito.Matchers.any;
11 import static org.mockito.Matchers.anyInt;
12 import static org.mockito.Mockito.doNothing;
13 import static org.mockito.Mockito.doReturn;
14
15 import akka.actor.ActorSystem;
16 import akka.testkit.JavaTestKit;
17 import akka.testkit.TestProbe;
18 import com.google.common.io.ByteSource;
19 import java.io.IOException;
20 import java.io.InputStream;
21 import org.junit.AfterClass;
22 import org.junit.Before;
23 import org.junit.BeforeClass;
24 import org.mockito.Mock;
25 import org.mockito.MockitoAnnotations;
26 import org.opendaylight.controller.cluster.io.FileBackedOutputStream;
27 import org.opendaylight.controller.cluster.io.FileBackedOutputStreamFactory;
28
29 /**
30  * Abstract base class for messaging tests.
31  *
32  * @author Thomas Pantelis
33  */
34 public class AbstractMessagingTest {
35     protected static final StringIdentifier IDENTIFIER = new StringIdentifier("test");
36     protected static ActorSystem ACTOR_SYSTEM;
37
38     protected final TestProbe testProbe = TestProbe.apply(ACTOR_SYSTEM);
39
40     @Mock
41     protected FileBackedOutputStreamFactory mockFiledBackedStreamFactory;
42
43     @Mock
44     protected FileBackedOutputStream mockFiledBackedStream;
45
46     @Mock
47     protected ByteSource mockByteSource;
48
49     @Mock
50     protected InputStream mockInputStream;
51
52     @BeforeClass
53     public static void setupClass() throws IOException {
54         ACTOR_SYSTEM = ActorSystem.create("test");
55     }
56
57     @Before
58     public void setup() throws IOException {
59         MockitoAnnotations.initMocks(this);
60
61         doReturn(mockFiledBackedStream).when(mockFiledBackedStreamFactory).newInstance();
62         doNothing().when(mockFiledBackedStream).write(any(byte[].class), anyInt(), anyInt());
63         doNothing().when(mockFiledBackedStream).write(any(byte[].class));
64         doNothing().when(mockFiledBackedStream).write(anyInt());
65         doNothing().when(mockFiledBackedStream).close();
66         doNothing().when(mockFiledBackedStream).cleanup();
67         doNothing().when(mockFiledBackedStream).flush();
68         doReturn(mockByteSource).when(mockFiledBackedStream).asByteSource();
69
70         doReturn(mockInputStream).when(mockByteSource).openStream();
71         doReturn(mockInputStream).when(mockByteSource).openBufferedStream();
72         doReturn(10L).when(mockByteSource).size();
73
74         doReturn(0).when(mockInputStream).read(any(byte[].class));
75     }
76
77     @AfterClass
78     public static void tearDownClass() {
79         JavaTestKit.shutdownActorSystem(ACTOR_SYSTEM, Boolean.TRUE);
80     }
81 }