-
Notifications
You must be signed in to change notification settings - Fork 3
/
AllQueries.java
196 lines (181 loc) · 6.46 KB
/
AllQueries.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/*******************************************************************************
* Copyright (c) 2022,2023 IBM Corporation.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.mat.tests.snapshot;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.startsWith;
import static org.hamcrest.core.IsNull.nullValue;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assume.assumeThat;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
import org.eclipse.mat.query.IContextObject;
import org.eclipse.mat.query.IQuery;
import org.eclipse.mat.query.IQueryContext;
import org.eclipse.mat.query.annotations.Argument.Advice;
import org.eclipse.mat.query.registry.ArgumentDescriptor;
import org.eclipse.mat.query.registry.QueryDescriptor;
import org.eclipse.mat.query.registry.QueryRegistry;
import org.eclipse.mat.snapshot.ISnapshot;
import org.eclipse.mat.snapshot.SnapshotInfo;
import org.eclipse.mat.snapshot.UnreachableObjectsHistogram;
import org.eclipse.swt.widgets.Display;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
/**
* Basic test of all the queries.
*/
@RunWith(value = Parameterized.class)
public class AllQueries
{
QueryDescriptor qd;
String command;
@Parameters(name="{index}: Query={0} Command={1}")
public static Collection<Object[]> data()
{
List<Object[]>parms = new ArrayList<Object[]>();
for (QueryDescriptor qd : QueryRegistry.instance().getQueries())
{
parms.add(new Object[] {qd.getName(), qd, qd.getIdentifier()});
}
return parms;
}
public AllQueries(String query, QueryDescriptor qd, String command)
{
this.qd = qd;
this.command = command;
}
@Test
public void testHelp()
{
assertNotNull(qd.getHelp());
}
/**
* Nearly everything should have a category.
*/
@Test
public void testCategory()
{
assumeThat(command, not(equalTo("comparetablesquery")));
assumeThat(command, not(equalTo("export_hprof")));
assumeThat(command, not(equalTo("show_retained_set")));
assumeThat(command, not(equalTo("open_source_file")));
assumeThat(command, not(equalTo("immediate_dominators")));
assertNotNull(qd.getCategory());
}
/**
* Should everything have help?
*/
@Test
public void testHelpAvailable()
{
if (qd.isHelpAvailable())
{
assertNotNull(qd.getHelp());
assertThat(qd.getHelp(), not(equalTo("")));
}
else
assertThat(qd.getHelp(), equalTo(nullValue()));
}
@Test
public void testCommandType()
{
assertNotNull(qd.getCommandType());
assertThat(qd.getCommandType().asSubclass(IQuery.class), not(equalTo(null)));
}
/**
* Not really a URL - just a path into the help.
* @throws MalformedURLException
*/
@Test
public void testHelpUrl() throws MalformedURLException
{
String helpUrl = qd.getHelpUrl();
assumeThat(qd.getCommandType().getName(),not(startsWith("org.eclipse.mat.tests.")));
assumeThat(helpUrl, not(nullValue()));
URL url = new URL(new URL("file:///"), helpUrl);
assertNotNull(url);
}
/**
* All the supplied queries should have help for all the user
* supplied arguments.
*/
@Test
public void testArguments()
{
List<ArgumentDescriptor> args = qd.getArguments();
for (ArgumentDescriptor arg : args)
{
assertNotNull(arg.getField());
assertNotNull(arg.getName());
assertNotNull(arg.getType());
if (qd.isHelpAvailable())
{
if (!qd.getCommandType().getName().startsWith("org.eclipse.mat.tests"))
{
// Some argument types available from the context so don't need help
if ((arg.getType() != ISnapshot.class || Advice.SECONDARY_SNAPSHOT.equals(arg.getAdvice())) &&
!IContextObject.class.isAssignableFrom(arg.getType())
&& !IQueryContext.class.isAssignableFrom(arg.getType())
&& !Display.class.isAssignableFrom(arg.getType())
&& !UnreachableObjectsHistogram.class.isAssignableFrom(arg.getType())
&& !SnapshotInfo.class.isAssignableFrom(arg.getType())
)
{
assertNotNull(arg.getName()+" "+arg.getType(), arg.getHelp());
}
}
}
}
}
/**
* We don't currently supply translations, so everything
* should come from annotations and be marked as English
*/
@Test
public void testHelpLocale()
{
assertNotNull(qd.getHelpLocale());
if (!qd.getCommandType().getName().startsWith("org.eclipse.mat.tests."))
{
// Currently presume all MAT is tested and supplied in English
assertThat(qd.getHelpLocale(), equalTo(Locale.ENGLISH));
}
}
/**
* All the supplied queries should have icons.
*/
@Test
public void testIcon()
{
assumeThat(qd.getCommandType().getName(),not(startsWith("org.eclipse.mat.tests.")));
assertNotNull(qd.getIcon());
}
/**
* All the supplied queries should have an identifier
*/
@Test
public void testIdentifier()
{
assertNotNull(qd.getIdentifier());
assertThat(qd.getIdentifier(), equalTo(command));
}
}