lttng: Port unit tests to JUnit4
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.core.tests / src / org / eclipse / linuxtools / lttng2 / core / tests / control / model / impl / SessionInfoTest.java
CommitLineData
eb1bab5b
BH
1/**********************************************************************
2 * Copyright (c) 2012 Ericsson
b0318660 3 *
eb1bab5b
BH
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
b0318660
AM
8 *
9 * Contributors:
eb1bab5b 10 * Bernd Hufmann - Initial API and implementation
2ba3d0a1 11 * Alexandre Montplaisir - Port to JUnit4
eb1bab5b 12 **********************************************************************/
2ba3d0a1 13
9315aeee 14package org.eclipse.linuxtools.lttng2.core.tests.control.model.impl;
eb1bab5b 15
2ba3d0a1
AM
16import static org.junit.Assert.*;
17
eb1bab5b
BH
18import java.util.LinkedList;
19import java.util.List;
20
9315aeee
BH
21import org.eclipse.linuxtools.internal.lttng2.core.control.model.IDomainInfo;
22import org.eclipse.linuxtools.internal.lttng2.core.control.model.ISessionInfo;
23import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceSessionState;
24import org.eclipse.linuxtools.internal.lttng2.core.control.model.impl.SessionInfo;
2ba3d0a1
AM
25import org.junit.Before;
26import org.junit.Test;
eb1bab5b
BH
27
28/**
2ba3d0a1
AM
29 * The class <code>ChannelInfoTest</code> contains tests for the class
30 * <code>{@link SessionInfo}</code>.
eb1bab5b 31 */
2ba3d0a1
AM
32@SuppressWarnings("nls")
33public class SessionInfoTest {
34
eb1bab5b
BH
35 // ------------------------------------------------------------------------
36 // Test data
37 // ------------------------------------------------------------------------
2ba3d0a1 38
eb1bab5b
BH
39 private ISessionInfo fSessionInfo1 = null;
40 private ISessionInfo fSessionInfo2 = null;
b0318660 41
eb1bab5b
BH
42 private IDomainInfo fDomainInfo1 = null;
43 private IDomainInfo fDomainInfo2 = null;
44
45 // ------------------------------------------------------------------------
46 // Housekeeping
47 // ------------------------------------------------------------------------
b0318660 48
eb1bab5b
BH
49 /**
50 * Perform pre-test initialization.
eb1bab5b 51 */
2ba3d0a1 52 @Before
eb1bab5b
BH
53 public void setUp() {
54 ModelImplFactory factory = new ModelImplFactory();
55 fSessionInfo1 = factory.getSessionInfo1();
56 fDomainInfo1 = factory.getDomainInfo1();
57 fSessionInfo2 = factory.getSessionInfo2();
58 fDomainInfo2 = factory.getDomainInfo2();
59 }
60
eb1bab5b
BH
61 // ------------------------------------------------------------------------
62 // Tests
63 // ------------------------------------------------------------------------
b0318660 64
eb1bab5b
BH
65 // ------------------------------------------------------------------------
66 // Constructors
67 // ------------------------------------------------------------------------
68
69 /**
70 * Run the ChannelInfo() constructor test.
eb1bab5b 71 */
2ba3d0a1 72 @Test
eb1bab5b
BH
73 public void testSessionInfo() {
74 ISessionInfo result = new SessionInfo("test");
75 assertNotNull(result);
b0318660 76
eb1bab5b
BH
77 assertEquals("test", result.getName());
78 assertEquals("", result.getSessionPath());
79 TraceSessionState state = result.getSessionState();
80 assertEquals("inactive", state.getInName());
81 assertEquals("INACTIVE", state.name());
82 assertEquals("INACTIVE", state.toString());
83 assertEquals(0, state.ordinal());
84 assertEquals(0, result.getDomains().length);
85 }
86
2ba3d0a1
AM
87 /**
88 * Test copy constructor.
89 */
90 @Test
eb1bab5b
BH
91 public void testSessionInfoCopy() {
92 SessionInfo sessionInfo = new SessionInfo((SessionInfo)fSessionInfo1);
b0318660 93
eb1bab5b
BH
94 assertEquals(sessionInfo.getName(), fSessionInfo1.getName());
95 assertEquals(sessionInfo.getSessionPath(), fSessionInfo1.getSessionPath());
96 assertEquals(sessionInfo.getSessionState(), fSessionInfo1.getSessionState());
97
98 IDomainInfo[] orignalDomains = fSessionInfo1.getDomains();
99 IDomainInfo[] resultDomains = sessionInfo.getDomains();
100 for (int i = 0; i < orignalDomains.length; i++) {
101 assertEquals(orignalDomains[i], resultDomains[i]);
102 }
103 }
104
2ba3d0a1
AM
105 /**
106 * Test copy constructor.
107 */
108 @Test
eb1bab5b
BH
109 public void testSessionCopy2() {
110 try {
111 SessionInfo session = null;
112 new SessionInfo(session);
113 fail("null copy");
114 }
115 catch (IllegalArgumentException e) {
116 // Success
117 }
118 }
119
120 /**
121 * Run the long getNumberOfSubBuffers() method test.
eb1bab5b 122 */
2ba3d0a1 123 @Test
eb1bab5b 124 public void testGetAndSetters() {
b0318660 125
eb1bab5b
BH
126 // Note that addDomain() has been executed in setUp()
127 // check get method here
128 assertEquals(1, fSessionInfo1.getDomains().length);
129 assertNotNull(fSessionInfo1.getDomains()[0]);
130 assertEquals(fDomainInfo1, fSessionInfo1.getDomains()[0]);
b0318660 131
eb1bab5b
BH
132 ISessionInfo session = new SessionInfo("session");
133 List<IDomainInfo> list = new LinkedList<IDomainInfo>();
134 list.add(fDomainInfo1);
135 list.add(fDomainInfo2);
136 session.setDomains(list);
b0318660 137
eb1bab5b
BH
138 IDomainInfo[] result = session.getDomains();
139 assertEquals(2, result.length);
140 assertEquals(fDomainInfo1, result[0]);
141 assertEquals(fDomainInfo2, result[1]);
b0318660 142
eb1bab5b
BH
143 session.setSessionPath("/home/user");
144 assertEquals("/home/user", session.getSessionPath());
b0318660 145
eb1bab5b
BH
146 session.setSessionState("active");
147 TraceSessionState state = session.getSessionState();
148 state = session.getSessionState();
149 assertEquals("active", state.getInName());
150 assertEquals("ACTIVE", state.name());
151 assertEquals("ACTIVE", state.toString());
152 assertEquals(1, state.ordinal());
b0318660 153
eb1bab5b
BH
154 session.setSessionState("inactive");
155 state = session.getSessionState();
156 assertEquals("inactive", state.getInName());
157 assertEquals("INACTIVE", state.name());
158 assertEquals("INACTIVE", state.toString());
159 assertEquals(0, state.ordinal());
160
161 session.setSessionState("test");
162 state = session.getSessionState();
163 assertEquals("inactive", state.getInName());
164 assertEquals("INACTIVE", state.name());
165 assertEquals("INACTIVE", state.toString());
166 assertEquals(0, state.ordinal());
b0318660 167
eb1bab5b
BH
168 session.setSessionState(TraceSessionState.ACTIVE);
169 state = session.getSessionState();
170 assertEquals("active", state.getInName());
171 assertEquals("ACTIVE", state.name());
172 assertEquals("ACTIVE", state.toString());
173 assertEquals(1, state.ordinal());
174
175 session.setSessionState(TraceSessionState.INACTIVE);
176 state = session.getSessionState();
177 assertEquals("inactive", state.getInName());
178 assertEquals("INACTIVE", state.name());
179 assertEquals("INACTIVE", state.toString());
180 assertEquals(0, state.ordinal());
181 }
182
2ba3d0a1
AM
183 /**
184 * Run the String toString() method test.
185 */
186 @Test
eb1bab5b
BH
187 public void testToString_1() {
188 ISessionInfo fixture = new SessionInfo("sessionName");
189
190 String result = fixture.toString();
191
192 // add additional test code here
193 assertEquals("[SessionInfo([TraceInfo(Name=sessionName)],State=INACTIVE,Domains=)]", result);
194 }
195
196 /**
197 * Run the String toString() method test.
eb1bab5b 198 */
2ba3d0a1 199 @Test
eb1bab5b
BH
200 public void testToString_2() {
201 String result = fSessionInfo1.toString();
202
203 // add additional test code here
9d8a90ad 204 assertEquals("[SessionInfo([TraceInfo(Name=session1)],State=ACTIVE,Domains=[DomainInfo([TraceInfo(Name=test1)],Channels=[ChannelInfo([TraceInfo(Name=channel1)],State=DISABLED,OverwriteMode=true,SubBuffersSize=13,NumberOfSubBuffers=12,SwitchTimer=10,ReadTimer=11,output=splice(),Events=[EventInfo([BaseEventInfo([TraceInfo(Name=event1)],type=TRACEPOINT,level=TRACE_DEBUG)],State=ENABLED)])],isKernel=false)])]", result);
eb1bab5b 205 }
b0318660 206
eb1bab5b
BH
207 // ------------------------------------------------------------------------
208 // equals
209 // ------------------------------------------------------------------------
210
2ba3d0a1
AM
211 /**
212 * Run the {@link SessionInfo#equals} method test.
213 */
214 @Test
eb1bab5b
BH
215 public void testEqualsReflexivity() {
216 assertTrue("equals", fSessionInfo1.equals(fSessionInfo1));
217 assertTrue("equals", fSessionInfo2.equals(fSessionInfo2));
218
219 assertTrue("equals", !fSessionInfo1.equals(fSessionInfo2));
220 assertTrue("equals", !fSessionInfo2.equals(fSessionInfo1));
221 }
b0318660 222
2ba3d0a1
AM
223 /**
224 * Run the {@link SessionInfo#equals} method test.
225 */
226 @Test
eb1bab5b
BH
227 public void testEqualsSymmetry() {
228 SessionInfo event1 = new SessionInfo((SessionInfo)fSessionInfo1);
229 SessionInfo event2 = new SessionInfo((SessionInfo)fSessionInfo2);
230
231 assertTrue("equals", event1.equals(fSessionInfo1));
232 assertTrue("equals", fSessionInfo1.equals(event1));
233
234 assertTrue("equals", event2.equals(fSessionInfo2));
235 assertTrue("equals", fSessionInfo2.equals(event2));
236 }
b0318660 237
2ba3d0a1
AM
238 /**
239 * Run the {@link SessionInfo#equals} method test.
240 */
241 @Test
eb1bab5b
BH
242 public void testEqualsTransivity() {
243 SessionInfo channel1 = new SessionInfo((SessionInfo)fSessionInfo1);
244 SessionInfo channel2 = new SessionInfo((SessionInfo)fSessionInfo1);
245 SessionInfo channel3 = new SessionInfo((SessionInfo)fSessionInfo1);
246
247 assertTrue("equals", channel1.equals(channel2));
248 assertTrue("equals", channel2.equals(channel3));
249 assertTrue("equals", channel1.equals(channel3));
250 }
b0318660 251
2ba3d0a1
AM
252 /**
253 * Run the {@link SessionInfo#equals} method test.
254 */
255 @Test
ea21cd65 256 public void testEqualsNull() {
eb1bab5b
BH
257 assertTrue("equals", !fSessionInfo1.equals(null));
258 assertTrue("equals", !fSessionInfo2.equals(null));
259 }
b0318660 260
eb1bab5b
BH
261 // ------------------------------------------------------------------------
262 // hashCode
263 // ------------------------------------------------------------------------
264
2ba3d0a1
AM
265 /**
266 * Run the {@link SessionInfo#hashCode} method test.
267 */
268 @Test
eb1bab5b
BH
269 public void testHashCode() {
270 SessionInfo channel1 = new SessionInfo((SessionInfo)fSessionInfo1);
271 SessionInfo channel2 = new SessionInfo((SessionInfo)fSessionInfo2);
272
273 assertTrue("hashCode", fSessionInfo1.hashCode() == channel1.hashCode());
274 assertTrue("hashCode", fSessionInfo2.hashCode() == channel2.hashCode());
275
276 assertTrue("hashCode", fSessionInfo1.hashCode() != channel2.hashCode());
277 assertTrue("hashCode", fSessionInfo2.hashCode() != channel1.hashCode());
2ba3d0a1
AM
278 }
279}
This page took 0.060234 seconds and 5 git commands to generate.