ctf: Move plugins to their own sub-directory
[deliverable/tracecompass.git] / org.eclipse.tracecompass.lttng2.control.core.tests / src / org / eclipse / tracecompass / lttng2 / control / core / tests / model / impl / SessionInfoTest.java
CommitLineData
eb1bab5b 1/**********************************************************************
60ae41e1 2 * Copyright (c) 2012, 2014 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
9bc60be7 14package org.eclipse.tracecompass.lttng2.control.core.tests.model.impl;
eb1bab5b 15
2ba3d0a1
AM
16import static org.junit.Assert.*;
17
eb1bab5b
BH
18import java.util.LinkedList;
19import java.util.List;
20
9bc60be7
AM
21import org.eclipse.tracecompass.internal.lttng2.control.core.model.IDomainInfo;
22import org.eclipse.tracecompass.internal.lttng2.control.core.model.ISessionInfo;
23import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceSessionState;
24import org.eclipse.tracecompass.internal.lttng2.control.core.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
32public class SessionInfoTest {
33
eb1bab5b
BH
34 // ------------------------------------------------------------------------
35 // Test data
36 // ------------------------------------------------------------------------
2ba3d0a1 37
eb1bab5b
BH
38 private ISessionInfo fSessionInfo1 = null;
39 private ISessionInfo fSessionInfo2 = null;
b0318660 40
eb1bab5b
BH
41 private IDomainInfo fDomainInfo1 = null;
42 private IDomainInfo fDomainInfo2 = null;
43
44 // ------------------------------------------------------------------------
45 // Housekeeping
46 // ------------------------------------------------------------------------
b0318660 47
eb1bab5b
BH
48 /**
49 * Perform pre-test initialization.
eb1bab5b 50 */
2ba3d0a1 51 @Before
eb1bab5b
BH
52 public void setUp() {
53 ModelImplFactory factory = new ModelImplFactory();
54 fSessionInfo1 = factory.getSessionInfo1();
55 fDomainInfo1 = factory.getDomainInfo1();
56 fSessionInfo2 = factory.getSessionInfo2();
57 fDomainInfo2 = factory.getDomainInfo2();
58 }
59
eb1bab5b
BH
60 // ------------------------------------------------------------------------
61 // Tests
62 // ------------------------------------------------------------------------
b0318660 63
eb1bab5b
BH
64 // ------------------------------------------------------------------------
65 // Constructors
66 // ------------------------------------------------------------------------
67
68 /**
69 * Run the ChannelInfo() constructor test.
eb1bab5b 70 */
2ba3d0a1 71 @Test
eb1bab5b
BH
72 public void testSessionInfo() {
73 ISessionInfo result = new SessionInfo("test");
74 assertNotNull(result);
b0318660 75
eb1bab5b
BH
76 assertEquals("test", result.getName());
77 assertEquals("", result.getSessionPath());
78 TraceSessionState state = result.getSessionState();
79 assertEquals("inactive", state.getInName());
80 assertEquals("INACTIVE", state.name());
81 assertEquals("INACTIVE", state.toString());
82 assertEquals(0, state.ordinal());
83 assertEquals(0, result.getDomains().length);
f7d4d450
MAL
84 assertFalse(result.isSnapshotSession());
85 assertNull(result.getNetworkUrl());
86 assertNull(result.getControlUrl());
87 assertNull(result.getDataUrl());
eb1bab5b
BH
88 }
89
2ba3d0a1
AM
90 /**
91 * Test copy constructor.
92 */
93 @Test
eb1bab5b
BH
94 public void testSessionInfoCopy() {
95 SessionInfo sessionInfo = new SessionInfo((SessionInfo)fSessionInfo1);
b0318660 96
eb1bab5b
BH
97 assertEquals(sessionInfo.getName(), fSessionInfo1.getName());
98 assertEquals(sessionInfo.getSessionPath(), fSessionInfo1.getSessionPath());
99 assertEquals(sessionInfo.getSessionState(), fSessionInfo1.getSessionState());
100
101 IDomainInfo[] orignalDomains = fSessionInfo1.getDomains();
102 IDomainInfo[] resultDomains = sessionInfo.getDomains();
103 for (int i = 0; i < orignalDomains.length; i++) {
104 assertEquals(orignalDomains[i], resultDomains[i]);
105 }
f7d4d450
MAL
106
107 assertEquals(sessionInfo.getNetworkUrl(), fSessionInfo1.getNetworkUrl());
108 assertEquals(sessionInfo.getControlUrl(), fSessionInfo1.getControlUrl());
109 assertEquals(sessionInfo.getDataUrl(), fSessionInfo1.getDataUrl());
eb1bab5b
BH
110 }
111
2ba3d0a1
AM
112 /**
113 * Test copy constructor.
114 */
115 @Test
eb1bab5b
BH
116 public void testSessionCopy2() {
117 try {
118 SessionInfo session = null;
119 new SessionInfo(session);
120 fail("null copy");
121 }
122 catch (IllegalArgumentException e) {
123 // Success
124 }
125 }
126
127 /**
128 * Run the long getNumberOfSubBuffers() method test.
eb1bab5b 129 */
2ba3d0a1 130 @Test
eb1bab5b 131 public void testGetAndSetters() {
b0318660 132
eb1bab5b
BH
133 // Note that addDomain() has been executed in setUp()
134 // check get method here
135 assertEquals(1, fSessionInfo1.getDomains().length);
136 assertNotNull(fSessionInfo1.getDomains()[0]);
137 assertEquals(fDomainInfo1, fSessionInfo1.getDomains()[0]);
b0318660 138
eb1bab5b 139 ISessionInfo session = new SessionInfo("session");
e0838ca1 140 List<IDomainInfo> list = new LinkedList<>();
eb1bab5b
BH
141 list.add(fDomainInfo1);
142 list.add(fDomainInfo2);
143 session.setDomains(list);
b0318660 144
eb1bab5b
BH
145 IDomainInfo[] result = session.getDomains();
146 assertEquals(2, result.length);
147 assertEquals(fDomainInfo1, result[0]);
148 assertEquals(fDomainInfo2, result[1]);
b0318660 149
eb1bab5b
BH
150 session.setSessionPath("/home/user");
151 assertEquals("/home/user", session.getSessionPath());
b0318660 152
eb1bab5b
BH
153 session.setSessionState("active");
154 TraceSessionState state = session.getSessionState();
155 state = session.getSessionState();
156 assertEquals("active", state.getInName());
157 assertEquals("ACTIVE", state.name());
158 assertEquals("ACTIVE", state.toString());
159 assertEquals(1, state.ordinal());
b0318660 160
eb1bab5b
BH
161 session.setSessionState("inactive");
162 state = session.getSessionState();
163 assertEquals("inactive", state.getInName());
164 assertEquals("INACTIVE", state.name());
165 assertEquals("INACTIVE", state.toString());
166 assertEquals(0, state.ordinal());
167
168 session.setSessionState("test");
169 state = session.getSessionState();
170 assertEquals("inactive", state.getInName());
171 assertEquals("INACTIVE", state.name());
172 assertEquals("INACTIVE", state.toString());
173 assertEquals(0, state.ordinal());
b0318660 174
eb1bab5b
BH
175 session.setSessionState(TraceSessionState.ACTIVE);
176 state = session.getSessionState();
177 assertEquals("active", state.getInName());
178 assertEquals("ACTIVE", state.name());
179 assertEquals("ACTIVE", state.toString());
180 assertEquals(1, state.ordinal());
181
182 session.setSessionState(TraceSessionState.INACTIVE);
183 state = session.getSessionState();
184 assertEquals("inactive", state.getInName());
185 assertEquals("INACTIVE", state.name());
186 assertEquals("INACTIVE", state.toString());
187 assertEquals(0, state.ordinal());
188 }
189
2ba3d0a1
AM
190 /**
191 * Run the String toString() method test.
192 */
193 @Test
eb1bab5b
BH
194 public void testToString_1() {
195 ISessionInfo fixture = new SessionInfo("sessionName");
196
197 String result = fixture.toString();
198
199 // add additional test code here
f7d4d450 200 assertEquals("[SessionInfo([TraceInfo(Name=sessionName)],Path=,State=INACTIVE,isStreamedTrace=false,isSnapshot=false,Domains=,NetworkUrl=null,ControlUrl=null,DataUrl=null)]", result);
eb1bab5b
BH
201 }
202
203 /**
204 * Run the String toString() method test.
eb1bab5b 205 */
2ba3d0a1 206 @Test
eb1bab5b
BH
207 public void testToString_2() {
208 String result = fSessionInfo1.toString();
209
210 // add additional test code here
f7d4d450 211 assertEquals("[SessionInfo([TraceInfo(Name=session1)],Path=/home/user/lttng-trace/mysession/,State=ACTIVE,isStreamedTrace=false,isSnapshot=false,snapshotInfo="
589d0d33
BH
212 + "[SnapshotInfo([TraceInfo(Name=snapshot-1)],snapshotPath=/home/user/lttng-trace/mysession/,ID=1,isStreamedSnapshot=false)],"
213 + "Domains=[DomainInfo([TraceInfo(Name=test1)],"
214 + "Channels=[ChannelInfo([TraceInfo(Name=channel1)],State=DISABLED,OverwriteMode=true,SubBuffersSize=13,NumberOfSubBuffers=12,SwitchTimer=10,ReadTimer=11,output=splice(),"
54f2dcc0 215 + "Events=[EventInfo([BaseEventInfo([TraceInfo(Name=event1)],type=TRACEPOINT,level=TRACE_DEBUG)],State=ENABLED,levelType=LOGLEVEL_ONLY)])],"
f7d4d450 216 + "isKernel=false)],NetworkUrl=null,ControlUrl=null,DataUrl=null)]", result);
589d0d33
BH
217 }
218
219 /**
220 * Run the String toString() method test.
221 */
222 @Test
223 public void testToString_3() {
224 SessionInfo info = new SessionInfo((SessionInfo)fSessionInfo1);
f7d4d450 225 info.setSnapshot(false);
589d0d33
BH
226 info.setSnapshotInfo(null);
227 info.setSessionPath("/home/user/lttng-trace/mysession/");
228
229 String result = info.toString();
230
231 // add additional test code here
f7d4d450 232 assertEquals("[SessionInfo([TraceInfo(Name=session1)],Path=/home/user/lttng-trace/mysession/,State=ACTIVE,isStreamedTrace=false,isSnapshot=false,"
589d0d33
BH
233 + "Domains=[DomainInfo([TraceInfo(Name=test1)],"
234 + "Channels=[ChannelInfo([TraceInfo(Name=channel1)],State=DISABLED,OverwriteMode=true,SubBuffersSize=13,NumberOfSubBuffers=12,SwitchTimer=10,ReadTimer=11,output=splice(),"
54f2dcc0 235 + "Events=[EventInfo([BaseEventInfo([TraceInfo(Name=event1)],type=TRACEPOINT,level=TRACE_DEBUG)],State=ENABLED,levelType=LOGLEVEL_ONLY)])],"
f7d4d450 236 + "isKernel=false)],NetworkUrl=null,ControlUrl=null,DataUrl=null)]", result);
eb1bab5b 237 }
b0318660 238
eb1bab5b
BH
239 // ------------------------------------------------------------------------
240 // equals
241 // ------------------------------------------------------------------------
242
2ba3d0a1
AM
243 /**
244 * Run the {@link SessionInfo#equals} method test.
245 */
246 @Test
eb1bab5b
BH
247 public void testEqualsReflexivity() {
248 assertTrue("equals", fSessionInfo1.equals(fSessionInfo1));
249 assertTrue("equals", fSessionInfo2.equals(fSessionInfo2));
250
251 assertTrue("equals", !fSessionInfo1.equals(fSessionInfo2));
252 assertTrue("equals", !fSessionInfo2.equals(fSessionInfo1));
253 }
b0318660 254
2ba3d0a1
AM
255 /**
256 * Run the {@link SessionInfo#equals} method test.
257 */
258 @Test
eb1bab5b
BH
259 public void testEqualsSymmetry() {
260 SessionInfo event1 = new SessionInfo((SessionInfo)fSessionInfo1);
261 SessionInfo event2 = new SessionInfo((SessionInfo)fSessionInfo2);
262
263 assertTrue("equals", event1.equals(fSessionInfo1));
264 assertTrue("equals", fSessionInfo1.equals(event1));
265
266 assertTrue("equals", event2.equals(fSessionInfo2));
267 assertTrue("equals", fSessionInfo2.equals(event2));
268 }
b0318660 269
2ba3d0a1
AM
270 /**
271 * Run the {@link SessionInfo#equals} method test.
272 */
273 @Test
eb1bab5b
BH
274 public void testEqualsTransivity() {
275 SessionInfo channel1 = new SessionInfo((SessionInfo)fSessionInfo1);
276 SessionInfo channel2 = new SessionInfo((SessionInfo)fSessionInfo1);
277 SessionInfo channel3 = new SessionInfo((SessionInfo)fSessionInfo1);
278
279 assertTrue("equals", channel1.equals(channel2));
280 assertTrue("equals", channel2.equals(channel3));
281 assertTrue("equals", channel1.equals(channel3));
282 }
b0318660 283
2ba3d0a1
AM
284 /**
285 * Run the {@link SessionInfo#equals} method test.
286 */
287 @Test
ea21cd65 288 public void testEqualsNull() {
eb1bab5b
BH
289 assertTrue("equals", !fSessionInfo1.equals(null));
290 assertTrue("equals", !fSessionInfo2.equals(null));
291 }
b0318660 292
eb1bab5b
BH
293 // ------------------------------------------------------------------------
294 // hashCode
295 // ------------------------------------------------------------------------
296
2ba3d0a1
AM
297 /**
298 * Run the {@link SessionInfo#hashCode} method test.
299 */
300 @Test
eb1bab5b
BH
301 public void testHashCode() {
302 SessionInfo channel1 = new SessionInfo((SessionInfo)fSessionInfo1);
303 SessionInfo channel2 = new SessionInfo((SessionInfo)fSessionInfo2);
304
305 assertTrue("hashCode", fSessionInfo1.hashCode() == channel1.hashCode());
306 assertTrue("hashCode", fSessionInfo2.hashCode() == channel2.hashCode());
307
308 assertTrue("hashCode", fSessionInfo1.hashCode() != channel2.hashCode());
309 assertTrue("hashCode", fSessionInfo2.hashCode() != channel1.hashCode());
2ba3d0a1
AM
310 }
311}
This page took 0.080162 seconds and 5 git commands to generate.