Commit | Line | Data |
---|---|---|
79e08fd0 BH |
1 | /******************************************************************************* |
2 | * Copyright (c) 2011 Ericsson | |
64636df8 | 3 | * |
79e08fd0 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 | |
64636df8 | 8 | * |
79e08fd0 | 9 | * Contributors: |
09667aa4 | 10 | * Mathieu Denis <mathieu.denis@polymtl.ca> - Initial design and implementation |
79e08fd0 BH |
11 | * Bernd Hufmann - Fixed warnings |
12 | *******************************************************************************/ | |
13 | ||
14 | package org.eclipse.linuxtools.tmf.ui.tests.statistics; | |
15 | ||
16 | import junit.framework.TestCase; | |
17 | ||
18 | import org.eclipse.linuxtools.tmf.ui.views.statistics.model.TmfBaseStatisticsTree; | |
19 | import org.eclipse.linuxtools.tmf.ui.views.statistics.model.AbsTmfStatisticsTree; | |
20 | import org.eclipse.linuxtools.tmf.ui.views.statistics.model.TmfStatisticsTreeNode; | |
21 | import org.eclipse.linuxtools.tmf.ui.views.statistics.model.TmfStatisticsTreeRootFactory; | |
22 | ||
64636df8 BH |
23 | /** |
24 | * TmfStatisticsTreeRootFactory Test Case. | |
25 | */ | |
79e08fd0 BH |
26 | @SuppressWarnings("nls") |
27 | public class TmfStatisticsTreeRootFactoryTest extends TestCase { | |
64636df8 | 28 | |
79e08fd0 BH |
29 | // ------------------------------------------------------------------------ |
30 | // Fields | |
31 | // ------------------------------------------------------------------------ | |
64636df8 | 32 | |
79e08fd0 BH |
33 | AbsTmfStatisticsTree fStatisticsData1; |
34 | AbsTmfStatisticsTree fStatisticsData2; | |
35 | AbsTmfStatisticsTree fStatisticsData3; | |
36 | String fDataKey1 = "key1"; | |
37 | String fDataKey2 = "key2"; | |
38 | String fDataKey3 = "key3"; | |
64636df8 | 39 | |
79e08fd0 BH |
40 | // ------------------------------------------------------------------------ |
41 | // Housekeeping | |
42 | // ------------------------------------------------------------------------ | |
64636df8 | 43 | |
79e08fd0 BH |
44 | @Override |
45 | protected void setUp() throws Exception { | |
46 | super.setUp(); | |
47 | addStatsTreeRoot(); | |
48 | } | |
64636df8 | 49 | |
79e08fd0 BH |
50 | @Override |
51 | protected void tearDown() throws Exception { | |
52 | super.tearDown(); | |
53 | } | |
64636df8 BH |
54 | |
55 | /** | |
56 | * Test adding of statistics tree root. | |
57 | */ | |
79e08fd0 BH |
58 | public void addStatsTreeRoot() { |
59 | fStatisticsData1 = new TmfBaseStatisticsTree(); | |
60 | fStatisticsData2 = new TmfBaseStatisticsTree(); | |
61 | fStatisticsData3 = new TmfBaseStatisticsTree(); | |
62 | TmfStatisticsTreeRootFactory.addStatsTreeRoot(fDataKey1, fStatisticsData1); | |
63 | TmfStatisticsTreeRootFactory.addStatsTreeRoot(fDataKey2, fStatisticsData2); | |
64 | TmfStatisticsTreeRootFactory.addStatsTreeRoot(fDataKey2, fStatisticsData3); | |
65 | } | |
64636df8 | 66 | |
79e08fd0 BH |
67 | // ------------------------------------------------------------------------ |
68 | // get | |
69 | // ------------------------------------------------------------------------ | |
64636df8 BH |
70 | |
71 | /** | |
72 | * Test getting of statistics tree root. | |
73 | */ | |
79e08fd0 BH |
74 | public void testGetStatTreeRoot() { |
75 | TmfStatisticsTreeNode value1 = TmfStatisticsTreeRootFactory.getStatTreeRoot(fDataKey1); | |
76 | TmfStatisticsTreeNode value2 = TmfStatisticsTreeRootFactory.getStatTreeRoot(fDataKey2); | |
77 | TmfStatisticsTreeNode value3 = TmfStatisticsTreeRootFactory.getStatTreeRoot(fDataKey1); | |
78 | assertNotSame("getStatTreeRoot", value1, value2); | |
79 | assertNotSame("getStatTreeRoot", value2, value3); | |
80 | assertSame("getStatTreeRoot", value1, value3); | |
81 | assertNull("getStatTreeRoot", TmfStatisticsTreeRootFactory.getStatTreeRoot(null)); | |
82 | } | |
83 | ||
64636df8 BH |
84 | /** |
85 | * Test getting statistics tree. | |
86 | */ | |
79e08fd0 BH |
87 | public void testGetStatTree() { |
88 | AbsTmfStatisticsTree value1 = TmfStatisticsTreeRootFactory.getStatTree(fDataKey1); | |
89 | AbsTmfStatisticsTree value2 = TmfStatisticsTreeRootFactory.getStatTree(fDataKey2); | |
90 | AbsTmfStatisticsTree value3 = TmfStatisticsTreeRootFactory.getStatTree(fDataKey1); | |
91 | assertNotSame("getStatTree", value1, value2); | |
92 | assertNotSame("getStatTree", value2, value3); | |
93 | assertSame("getStatTree", value1, value3); | |
94 | assertNull("getStatTreeRoot", TmfStatisticsTreeRootFactory.getStatTree(null)); | |
95 | } | |
96 | ||
97 | // ------------------------------------------------------------------------ | |
98 | // contains | |
99 | // ------------------------------------------------------------------------ | |
64636df8 BH |
100 | |
101 | /** | |
102 | * Test checking for tree root existence. | |
103 | */ | |
79e08fd0 BH |
104 | public void testContainsTreeRoot() { |
105 | assertTrue("containsTreeRoot", TmfStatisticsTreeRootFactory.containsTreeRoot(fDataKey1)); | |
106 | assertTrue("containsTreeRoot", TmfStatisticsTreeRootFactory.containsTreeRoot(fDataKey2)); | |
107 | assertFalse("containsTreeRoot", TmfStatisticsTreeRootFactory.containsTreeRoot(null)); | |
108 | } | |
109 | ||
110 | // ------------------------------------------------------------------------ | |
111 | // remove | |
112 | // ------------------------------------------------------------------------ | |
64636df8 BH |
113 | |
114 | /** | |
115 | * Test removal of statistics tree node. | |
116 | */ | |
79e08fd0 BH |
117 | public void testRemoveStatTreeRoot() { |
118 | TmfStatisticsTreeRootFactory.removeStatTreeRoot(fDataKey1); | |
119 | assertNull("removeStatTreeRoot", TmfStatisticsTreeRootFactory.getStatTree(fDataKey1)); | |
64636df8 | 120 | |
79e08fd0 | 121 | try { |
64636df8 | 122 | TmfStatisticsTreeRootFactory.removeStatTreeRoot(null); |
79e08fd0 BH |
123 | // Success |
124 | } catch (Exception e) { | |
125 | fail("removeStatTreeRoot"); | |
126 | } | |
127 | } | |
128 | ||
64636df8 BH |
129 | /** |
130 | * Test removal of all root nodes. | |
131 | */ | |
79e08fd0 BH |
132 | public void testRemoveAll() { |
133 | TmfStatisticsTreeRootFactory.removeAll(); | |
134 | assertNull("removeAll", TmfStatisticsTreeRootFactory.getStatTreeRoot(fDataKey2)); | |
135 | assertNull("removeAll", TmfStatisticsTreeRootFactory.getStatTreeRoot(fDataKey3)); | |
136 | } | |
137 | } |