Commit | Line | Data |
---|---|---|
589d0d33 BH |
1 | /********************************************************************** |
2 | * Copyright (c) 2013 Ericsson | |
3 | * | |
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 | |
8 | * | |
9 | * Contributors: | |
10 | * Bernd Hufmann - Initial API and implementation | |
11 | **********************************************************************/ | |
12 | ||
8e8c0226 | 13 | package org.eclipse.linuxtools.lttng2.control.core.tests.model.impl; |
589d0d33 BH |
14 | |
15 | import static org.junit.Assert.assertEquals; | |
16 | import static org.junit.Assert.assertNotNull; | |
17 | import static org.junit.Assert.assertTrue; | |
18 | import static org.junit.Assert.fail; | |
19 | ||
8e8c0226 AM |
20 | import org.eclipse.linuxtools.internal.lttng2.control.core.model.ISnapshotInfo; |
21 | import org.eclipse.linuxtools.internal.lttng2.control.core.model.impl.SnapshotInfo; | |
22 | import org.eclipse.linuxtools.internal.lttng2.control.core.model.impl.TraceInfo; | |
589d0d33 BH |
23 | import org.junit.Before; |
24 | import org.junit.Test; | |
25 | ||
26 | /** | |
27 | * The class <code>SnapshotInfoTest</code> contains test for the class | |
28 | * <code>{@link SnapshotInfo}</code>. | |
29 | */ | |
30 | public class SnapshotInfoTest { | |
31 | ||
32 | // ------------------------------------------------------------------------ | |
33 | // Test data | |
34 | // ------------------------------------------------------------------------ | |
35 | ||
36 | private ISnapshotInfo fSnapshotInfo1 = null; | |
37 | private ISnapshotInfo fSnapshotInfo2 = null; | |
38 | ||
39 | ||
40 | // ------------------------------------------------------------------------ | |
41 | // Housekeeping | |
42 | // ------------------------------------------------------------------------ | |
43 | ||
44 | /** | |
45 | * Perform pre-test initialization. | |
46 | */ | |
47 | @Before | |
48 | public void setUp() { | |
49 | ModelImplFactory factory = new ModelImplFactory(); | |
50 | fSnapshotInfo1 = factory.getSnapshotInfo1(); | |
51 | fSnapshotInfo2 = factory.getSnapshotInfo2(); | |
52 | } | |
53 | ||
54 | // ------------------------------------------------------------------------ | |
55 | // Tests | |
56 | // ------------------------------------------------------------------------ | |
57 | ||
58 | /** | |
59 | * Constructor test. | |
60 | */ | |
61 | @Test | |
62 | public void testSnapshotInfo() { | |
63 | SnapshotInfo fixture = new SnapshotInfo("event"); | |
64 | assertNotNull(fixture); | |
65 | assertEquals("event", fixture.getName()); | |
66 | } | |
67 | ||
68 | /** | |
69 | * Test Copy Constructor | |
70 | */ | |
71 | @Test | |
72 | public void testSnapshotInfo2() { | |
73 | try { | |
74 | String name = null; | |
75 | new SnapshotInfo(name); | |
76 | fail("null name in custructor"); | |
77 | } | |
78 | catch (IllegalArgumentException e) { | |
79 | // Success | |
80 | } | |
81 | } | |
82 | ||
83 | /** | |
84 | * Test Copy Constructor | |
85 | */ | |
86 | @Test | |
87 | public void testSnapshotCopy() { | |
88 | SnapshotInfo info = new SnapshotInfo((SnapshotInfo)fSnapshotInfo1); | |
89 | ||
90 | assertEquals(fSnapshotInfo1.getName(), info.getName()); | |
91 | } | |
92 | ||
93 | /** | |
94 | * Test Copy Constructor | |
95 | */ | |
96 | @Test | |
97 | public void testTraceCopy2() { | |
98 | try { | |
99 | SnapshotInfo info = null; | |
100 | new SnapshotInfo(info); | |
101 | fail("null copy"); | |
102 | } | |
103 | catch (IllegalArgumentException e) { | |
104 | // Success | |
105 | } | |
106 | } | |
107 | ||
108 | /** | |
109 | * Run the void setEventType(String) method test. | |
110 | */ | |
111 | @Test | |
112 | public void testSetName() { | |
113 | SnapshotInfo fixture = new SnapshotInfo("event"); | |
114 | fixture.setName("newName"); | |
115 | assertEquals("newName", fixture.getName()); | |
116 | } | |
117 | ||
118 | /** | |
119 | * Run the String toString() method test. | |
120 | */ | |
121 | @Test | |
122 | public void testToString_1() { | |
123 | String result = fSnapshotInfo1.toString(); | |
124 | ||
125 | // add additional test code here | |
126 | assertEquals("[SnapshotInfo([TraceInfo(Name=snapshot-1)],snapshotPath=/home/user/lttng-trace/mysession/,ID=1,isStreamedSnapshot=false)]", result); | |
127 | } | |
128 | ||
129 | // ------------------------------------------------------------------------ | |
130 | // equals | |
131 | // ------------------------------------------------------------------------ | |
132 | ||
133 | /** | |
134 | * Run the equals() method test. | |
135 | */ | |
136 | @Test | |
137 | public void testEqualsReflexivity() { | |
138 | assertTrue("equals", fSnapshotInfo1.equals(fSnapshotInfo1)); | |
139 | assertTrue("equals", fSnapshotInfo2.equals(fSnapshotInfo2)); | |
140 | ||
141 | assertTrue("equals", !fSnapshotInfo1.equals(fSnapshotInfo2)); | |
142 | assertTrue("equals", !fSnapshotInfo2.equals(fSnapshotInfo1)); | |
143 | } | |
144 | ||
145 | /** | |
146 | * Run the equals() method test. | |
147 | */ | |
148 | @Test | |
149 | public void testEqualsSymmetry() { | |
150 | SnapshotInfo info1 = new SnapshotInfo((SnapshotInfo)fSnapshotInfo1); | |
151 | SnapshotInfo info2 = new SnapshotInfo((SnapshotInfo)fSnapshotInfo2); | |
152 | ||
153 | assertTrue("equals", info1.equals(fSnapshotInfo1)); | |
154 | assertTrue("equals", fSnapshotInfo1.equals(info1)); | |
155 | ||
156 | assertTrue("equals", info2.equals(fSnapshotInfo2)); | |
157 | assertTrue("equals", fSnapshotInfo2.equals(info2)); | |
158 | } | |
159 | /** | |
160 | * Run the equals() method test. | |
161 | */ | |
162 | @Test | |
163 | public void testEqualsTransivity() { | |
164 | SnapshotInfo info1 = new SnapshotInfo((SnapshotInfo)fSnapshotInfo1); | |
165 | SnapshotInfo info2 = new SnapshotInfo((SnapshotInfo)fSnapshotInfo1); | |
166 | SnapshotInfo info3 = new SnapshotInfo((SnapshotInfo)fSnapshotInfo1); | |
167 | ||
168 | assertTrue("equals", info1.equals(info2)); | |
169 | assertTrue("equals", info2.equals(info3)); | |
170 | assertTrue("equals", info1.equals(info3)); | |
171 | } | |
172 | /** | |
173 | * Run the equals() method test. | |
174 | */ | |
175 | @Test | |
176 | public void testEqualsNull() { | |
177 | assertTrue("equals", !fSnapshotInfo1.equals(null)); | |
178 | assertTrue("equals", !fSnapshotInfo2.equals(null)); | |
179 | ||
180 | SnapshotInfo info = new SnapshotInfo("snapshot-1"); | |
181 | assertTrue("equals", !fSnapshotInfo1.equals(info)); | |
182 | ||
183 | info.setSnapshotPath(null); | |
184 | assertTrue("equals", !fSnapshotInfo1.equals(info)); | |
185 | ||
186 | info.setId(fSnapshotInfo1.getId()); | |
187 | assertTrue("equals", !info.equals(fSnapshotInfo1)); | |
188 | ||
189 | info.setSnapshotPath("/home/user/lttng-trace/mysession/"); | |
190 | assertTrue("equals", fSnapshotInfo1.equals(info)); | |
191 | info.setId(2); | |
192 | assertTrue("equals", !fSnapshotInfo1.equals(info)); | |
193 | ||
194 | info.setId(fSnapshotInfo1.getId()); | |
195 | info.setStreamedSnapshot(true); | |
196 | assertTrue("equals", !fSnapshotInfo1.equals(info)); | |
197 | ||
198 | assertTrue("equals", !fSnapshotInfo1.equals(new TraceInfo(fSnapshotInfo1.getName()))); | |
199 | } | |
200 | ||
201 | // ------------------------------------------------------------------------ | |
202 | // hashCode | |
203 | // ------------------------------------------------------------------------ | |
204 | ||
205 | /** | |
206 | * Run the hashCode() method test. | |
207 | */ | |
208 | @Test | |
209 | public void testHashCode() { | |
210 | SnapshotInfo info1 = new SnapshotInfo((SnapshotInfo)fSnapshotInfo1); | |
211 | SnapshotInfo info2 = new SnapshotInfo((SnapshotInfo)fSnapshotInfo2); | |
212 | ||
213 | assertTrue("hashCode", fSnapshotInfo1.hashCode() == info1.hashCode()); | |
214 | assertTrue("hashCode", fSnapshotInfo2.hashCode() == info2.hashCode()); | |
215 | ||
216 | assertTrue("hashCode", fSnapshotInfo1.hashCode() != info2.hashCode()); | |
217 | assertTrue("hashCode", fSnapshotInfo2.hashCode() != info1.hashCode()); | |
218 | ||
219 | // null values | |
220 | SnapshotInfo info3 = new SnapshotInfo("snapshot-1"); | |
221 | assertTrue("hashCode", fSnapshotInfo1.hashCode() != info3.hashCode()); | |
222 | ||
223 | info3.setSnapshotPath(null); | |
224 | assertTrue("hashCode", fSnapshotInfo1.hashCode() != info3.hashCode()); | |
225 | ||
226 | info3.setSnapshotPath("/home/user/lttng-trace/mysession/"); | |
227 | assertTrue("hashCode", fSnapshotInfo1.hashCode() != info3.hashCode()); | |
228 | } | |
229 | } |