1 /*******************************************************************************
2 * Copyright (c) 2011 Ericsson
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
10 * Mathieu Denis <mathieu.denis@polymtl.ca> - Initial design and implementation
11 * Bernd Hufmann - Fixed warnings
12 *******************************************************************************/
14 package org
.eclipse
.linuxtools
.tmf
.ui
.tests
.statistics
;
16 import java
.util
.Arrays
;
17 import java
.util
.Collection
;
18 import java
.util
.Vector
;
20 import junit
.framework
.TestCase
;
22 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEventField
;
23 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEvent
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEventField
;
25 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEventType
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimestamp
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.util
.TmfFixedArray
;
28 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.statistics
.model
.AbsTmfStatisticsTree
;
29 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.statistics
.model
.Messages
;
30 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.statistics
.model
.TmfBaseStatisticsTree
;
31 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.statistics
.model
.TmfStatisticsTreeNode
;
32 import org
.eclipse
.linuxtools
.tmf
.ui
.viewers
.statistics
.model
.TmfTreeContentProvider
;
35 * TmfTreeContentProvider Test Cases.
37 @SuppressWarnings("nls")
38 public class TmfTreeContentProviderTest
extends TestCase
{
40 // ------------------------------------------------------------------------
42 // ------------------------------------------------------------------------
44 private String fTestName
= null;
46 private final String fContext
= "UnitTest";
47 private final String fTypeId1
= "Some type1";
48 private final String fTypeId2
= "Some type2";
50 private final String fLabel0
= "label1";
51 private final String fLabel1
= "label2";
52 private final String
[] fLabels
= new String
[] { fLabel0
, fLabel1
};
54 private final TmfTimestamp fTimestamp1
= new TmfTimestamp(12345, (byte) 2, 5);
55 private final TmfTimestamp fTimestamp2
= new TmfTimestamp(12350, (byte) 2, 5);
57 private final String fSource
= "Source";
59 private final TmfEventType fType1
= new TmfEventType(fContext
, fTypeId1
, TmfEventField
.makeRoot(fLabels
));
60 private final TmfEventType fType2
= new TmfEventType(fContext
, fTypeId2
, TmfEventField
.makeRoot(fLabels
));
62 private final String fReference
= "Some reference";
64 private final TmfEvent fEvent1
;
65 private final TmfEvent fEvent2
;
67 private final TmfEventField fContent1
;
68 private final TmfEventField fContent2
;
70 private final TmfBaseStatisticsTree fStatsData
;
72 private final TmfTreeContentProvider treeProvider
;
74 // ------------------------------------------------------------------------
76 // ------------------------------------------------------------------------
82 public TmfTreeContentProviderTest(final String name
) {
87 fContent1
= new TmfEventField(ITmfEventField
.ROOT_FIELD_ID
, "Some content");
88 fEvent1
= new TmfEvent(null, fTimestamp1
, fSource
, fType1
, fContent1
, fReference
);
90 fContent2
= new TmfEventField(ITmfEventField
.ROOT_FIELD_ID
, "Some other content");
91 fEvent2
= new TmfEvent(null, fTimestamp2
, fSource
, fType2
, fContent2
, fReference
);
93 fStatsData
= new TmfBaseStatisticsTree();
95 fStatsData
.setTotal(fTestName
, true, 2);
96 fStatsData
.setTypeCount(fTestName
, fEvent1
.getType().getName(), true, 1);
97 fStatsData
.setTypeCount(fTestName
, fEvent2
.getType().getName(), true, 1);
99 treeProvider
= new TmfTreeContentProvider();
102 // ------------------------------------------------------------------------
104 // ------------------------------------------------------------------------
107 * Test getting of children.
109 public void testGetChildren() {
110 Object
[] objectArray
= treeProvider
.getChildren(fStatsData
.getOrCreate(new TmfFixedArray
<String
>(fTestName
, Messages
.TmfStatisticsData_EventTypes
)));
111 TmfStatisticsTreeNode
[] childrenNode
= Arrays
.asList(objectArray
).toArray(new TmfStatisticsTreeNode
[0]);
113 Collection
<TmfFixedArray
<String
>> childrenExpected
= new Vector
<TmfFixedArray
<String
>>();
114 childrenExpected
.add(new TmfFixedArray
<String
>(fTestName
, Messages
.TmfStatisticsData_EventTypes
, fEvent1
.getType().getName()));
115 childrenExpected
.add(new TmfFixedArray
<String
>(fTestName
, Messages
.TmfStatisticsData_EventTypes
, fEvent2
.getType().getName()));
117 assertEquals("getChildren", childrenExpected
.size(), childrenNode
.length
);
118 // assertTrue("getChildren", childrenPath.equals(childrenExpected));
119 for (TmfStatisticsTreeNode childNode
: childrenNode
) {
120 if (childrenExpected
.contains(childNode
.getPath())) {
121 childrenExpected
.remove(childNode
.getPath());
128 // ------------------------------------------------------------------------
130 // ------------------------------------------------------------------------
133 * Test getting of parent.
135 public void testGetParent() {
136 TmfStatisticsTreeNode parent
= (TmfStatisticsTreeNode
) treeProvider
.getParent(fStatsData
.get(new TmfFixedArray
<String
>(fTestName
)));
138 assertNotNull("getParent", parent
);
139 assertTrue("getParent", parent
.getPath().equals(AbsTmfStatisticsTree
.ROOT
));
142 // ------------------------------------------------------------------------
144 // ------------------------------------------------------------------------
146 * Test checking for children.
148 public void testHasChildren() {
149 Boolean hasChildren
= treeProvider
.hasChildren(fStatsData
.getOrCreate(AbsTmfStatisticsTree
.ROOT
));
150 assertTrue("hasChildren", hasChildren
);
152 hasChildren
= treeProvider
.hasChildren(fStatsData
.getOrCreate(new TmfFixedArray
<String
>(fTestName
)));
153 assertTrue("hasChildren", hasChildren
);
155 hasChildren
= treeProvider
.hasChildren(fStatsData
.getOrCreate(new TmfFixedArray
<String
>(fTestName
, Messages
.TmfStatisticsData_EventTypes
)));
156 assertTrue("hasChildren", hasChildren
);
158 hasChildren
= treeProvider
.hasChildren(fStatsData
.getOrCreate(new TmfFixedArray
<String
>(fTestName
, Messages
.TmfStatisticsData_EventTypes
, fEvent1
.getType().getName())));
159 assertFalse("hasChildren", hasChildren
);
162 // ------------------------------------------------------------------------
164 // ------------------------------------------------------------------------
167 * Test getting of elements.
169 public void testGetElements() {
170 Object
[] objectElements
= treeProvider
.getElements(fStatsData
.get(AbsTmfStatisticsTree
.ROOT
));
171 TmfStatisticsTreeNode
[] nodeElements
= Arrays
.asList(objectElements
).toArray(new TmfStatisticsTreeNode
[0]);
172 assertEquals("getElements", 1, nodeElements
.length
);
173 assertTrue("getElements", nodeElements
[0].getPath().equals(new TmfFixedArray
<String
>(fTestName
)));