Author: akazakov
Date: 2011-08-23 19:08:06 -0400 (Tue, 23 Aug 2011)
New Revision: 34194
Modified:
trunk/jst/tests/org.jboss.tools.jst.web.kb.test/src/org/jboss/tools/jst/web/kb/test/QueryParticipantTestUtils.java
trunk/seam/tests/org.jboss.tools.seam.ui.test/src/org/jboss/tools/seam/ui/test/el/ELReferencesQueryParticipantTest.java
Log:
https://issues.jboss.org/browse/JBIDE-9473
Modified:
trunk/jst/tests/org.jboss.tools.jst.web.kb.test/src/org/jboss/tools/jst/web/kb/test/QueryParticipantTestUtils.java
===================================================================
---
trunk/jst/tests/org.jboss.tools.jst.web.kb.test/src/org/jboss/tools/jst/web/kb/test/QueryParticipantTestUtils.java 2011-08-23
22:55:55 UTC (rev 34193)
+++
trunk/jst/tests/org.jboss.tools.jst.web.kb.test/src/org/jboss/tools/jst/web/kb/test/QueryParticipantTestUtils.java 2011-08-23
23:08:06 UTC (rev 34194)
@@ -26,54 +26,53 @@
import org.jboss.tools.common.EclipseUtil;
import org.jboss.tools.common.util.FileUtil;
-public class QueryParticipantTestUtils extends TestCase{
+public class QueryParticipantTestUtils extends TestCase {
public static final int FIELD_SEARCH = 1;
public static final int METHOD_SEARCH = 2;
public static final int TYPE_SEARCH = 3;
public static final int PARAMETER_SEARCH = 4;
-
+
public static void testSearchParticipant(IProject project, String fileName, int
searchType, String elementName, String parameterName, IQueryParticipant participant,
List<MatchStructure> matches) throws CoreException{
IFile file = project.getFile(fileName);
- assertNotNull("File - "+fileName+" not found", file);
-
+ assertNotNull("File - " + fileName + " not found", file);
+
ICompilationUnit compilationUnit = EclipseUtil.getCompilationUnit(file);
-
+
assertNotNull("CompilationUnit not found", compilationUnit);
-
+
IJavaElement element = null;
-
+
IType type = compilationUnit.findPrimaryType();
-
+
assertNotNull("Primary type not found", type);
-
+
if(searchType == FIELD_SEARCH){
element = type.getField(elementName);
- }else if(searchType == METHOD_SEARCH){
+ } else if(searchType == METHOD_SEARCH){
element = getMethod(type, elementName);
- }else if(searchType == TYPE_SEARCH){
+ } else if(searchType == TYPE_SEARCH){
element = type;
- }else if(searchType == PARAMETER_SEARCH){
+ } else if(searchType == PARAMETER_SEARCH){
IMethod method = getMethod(type, elementName);
element = getParameter(method, parameterName);
}
-
- if(element != null){
- SearchRequestor requestor = new SearchRequestor();
-
- JavaSearchScopeFactory factory= JavaSearchScopeFactory.getInstance();
- IJavaSearchScope scope= factory.createWorkspaceScope(true);
- String description= factory.getWorkspaceScopeDescription(true);
- QuerySpecification specification = new ElementQuerySpecification(element,
IJavaSearchConstants.REFERENCES, scope, description);
-
- participant.search(requestor, specification, new NullProgressMonitor());
-
- List<Match> matchesForCheck = requestor.getMatches();
-
- checkMatches(matchesForCheck, matches);
- }else
- fail("Java Element not found");
+
+ assertNotNull("Java Element not found", element);
+
+ SearchRequestor requestor = new SearchRequestor();
+
+ JavaSearchScopeFactory factory = JavaSearchScopeFactory.getInstance();
+ IJavaSearchScope scope = factory.createWorkspaceScope(true);
+ String description = factory.getWorkspaceScopeDescription(true);
+ QuerySpecification specification = new ElementQuerySpecification(element,
IJavaSearchConstants.REFERENCES, scope, description);
+
+ participant.search(requestor, specification, new NullProgressMonitor());
+
+ List<Match> matchesForCheck = requestor.getMatches();
+
+ checkMatches(matchesForCheck, matches);
}
-
+
private static IMethod getMethod(IType type, String name) throws JavaModelException{
IMethod[] methods = type.getMethods();
for(IMethod method : methods){
@@ -85,35 +84,35 @@
private static ILocalVariable getParameter(IMethod method, String name) throws
JavaModelException{
ILocalVariable[] parameters = method.getParameters();
- for(ILocalVariable parameter : parameters){
- if(parameter.getElementName().equals(name))
+ for(ILocalVariable parameter : parameters) {
+ if(parameter.getElementName().equals(name)) {
return parameter;
+ }
}
return null;
}
-
+
private static void checkMatches(List<Match> matchesForCheck,
List<MatchStructure> matchList) throws CoreException {
for(Match match : matchesForCheck){
assertTrue("Match must return IFile", match.getElement() instanceof IFile);
-
+
IFile file = (IFile)match.getElement();
String filePath = file.getFullPath().toString();
String text = FileUtil.getContentFromEditorOrFile(file);
String name = text.substring(match.getOffset(), match.getOffset()+match.getLength());
-
+
MatchStructure ms = findMatch(matchList, match, filePath, name);
-
- assertNotNull("Unexpected match found (file - "+filePath+" name -
"+name+")", ms);
+
+ assertNotNull("Unexpected match found (file - " + filePath + " name -
" + name + ")", ms);
ms.checked = true;
}
-
+
for(MatchStructure ms : matchList){
assertTrue("Match not found (file - "+ms.path+" name -
"+ms.name+")", ms.checked);
}
}
-
+
protected static MatchStructure findMatch(List<MatchStructure> matchList, Match
match, String filePath, String name){
-
for(MatchStructure ms : matchList){
if(!ms.checked && ms.path.equals(filePath) && ms.name.equals(name)){
//System.out.println("Match found (file - "+ms.path+" name -
"+ms.name+")");
@@ -123,29 +122,27 @@
return null;
}
-
- static class SearchRequestor implements ISearchRequestor{
+ static class SearchRequestor implements ISearchRequestor {
ArrayList<Match> matches = new ArrayList<Match>();
-
+
public void reportMatch(Match match){
matches.add(match);
}
-
+
public List<Match> getMatches(){
return matches;
}
}
-
+
public static class MatchStructure{
String path;
String name; // label
boolean checked;
-
+
public MatchStructure(String path, String name){
this.path = path;
this.name = name;
checked = false;
}
}
-
-}
+}
\ No newline at end of file
Modified:
trunk/seam/tests/org.jboss.tools.seam.ui.test/src/org/jboss/tools/seam/ui/test/el/ELReferencesQueryParticipantTest.java
===================================================================
---
trunk/seam/tests/org.jboss.tools.seam.ui.test/src/org/jboss/tools/seam/ui/test/el/ELReferencesQueryParticipantTest.java 2011-08-23
22:55:55 UTC (rev 34193)
+++
trunk/seam/tests/org.jboss.tools.seam.ui.test/src/org/jboss/tools/seam/ui/test/el/ELReferencesQueryParticipantTest.java 2011-08-23
23:08:06 UTC (rev 34194)
@@ -5,29 +5,25 @@
import junit.framework.TestCase;
import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.jboss.tools.jst.web.kb.refactoring.ELReferencesQueryParticipant;
import org.jboss.tools.jst.web.kb.test.QueryParticipantTestUtils;
import org.jboss.tools.jst.web.kb.test.QueryParticipantTestUtils.MatchStructure;
-import org.jboss.tools.test.util.TestProjectProvider;
public class ELReferencesQueryParticipantTest extends TestCase{
- TestProjectProvider provider = null;
IProject project = null;
-
+
public void setUp() throws Exception {
- IResource project =
ResourcesPlugin.getWorkspace().getRoot().findMember("numberguess");
- this.project = project.getProject();
+ project =
ResourcesPlugin.getWorkspace().getRoot().getProject("numberguess");
}
public void testELReferencesQueryParticipantForType() throws CoreException{
ArrayList<MatchStructure> matches = new ArrayList<MatchStructure>();
-
+
matches.add(new MatchStructure("/numberguess/web/giveup.jspx",
"numberGuess"));
matches.add(new MatchStructure("/numberguess/web/giveup.jspx",
"numberGuess"));
-
+
QueryParticipantTestUtils.testSearchParticipant(project,
"src/org/jboss/seam/example/numberguess/NumberGuess.java",
QueryParticipantTestUtils.TYPE_SEARCH,
@@ -36,12 +32,12 @@
new ELReferencesQueryParticipant(),
matches);
}
-
+
public void testELReferencesQueryParticipantForMethod1() throws CoreException{
ArrayList<MatchStructure> matches = new ArrayList<MatchStructure>();
-
+
matches.add(new MatchStructure("/numberguess/web/giveup.jspx",
"remainingGuesses"));
-
+
QueryParticipantTestUtils.testSearchParticipant(project,
"src/org/jboss/seam/example/numberguess/NumberGuess.java",
QueryParticipantTestUtils.METHOD_SEARCH,
@@ -53,9 +49,9 @@
public void testELReferencesQueryParticipantForMethod2() throws CoreException{
ArrayList<MatchStructure> matches = new ArrayList<MatchStructure>();
-
+
matches.add(new MatchStructure("/numberguess/web/giveup.jspx",
"possibilities"));
-
+
QueryParticipantTestUtils.testSearchParticipant(project,
"src/org/jboss/seam/example/numberguess/NumberGuess.java",
QueryParticipantTestUtils.METHOD_SEARCH,
@@ -64,5 +60,4 @@
new ELReferencesQueryParticipant(),
matches);
}
-
-}
+}
\ No newline at end of file