[jbosstools-commits] JBoss Tools SVN: r30628 - in trunk/cdi: tests/org.jboss.tools.cdi.ui.test/META-INF and 2 other directories.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Fri Apr 15 21:16:26 EDT 2011


Author: dazarov
Date: 2011-04-15 21:16:25 -0400 (Fri, 15 Apr 2011)
New Revision: 30628

Added:
   trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/search/
   trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/search/CDISearchParticipantTest.java
Modified:
   trunk/cdi/plugins/org.jboss.tools.cdi.ui/META-INF/MANIFEST.MF
   trunk/cdi/tests/org.jboss.tools.cdi.ui.test/META-INF/MANIFEST.MF
Log:
https://issues.jboss.org/browse/JBIDE-8705

Modified: trunk/cdi/plugins/org.jboss.tools.cdi.ui/META-INF/MANIFEST.MF
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.ui/META-INF/MANIFEST.MF	2011-04-16 01:12:25 UTC (rev 30627)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.ui/META-INF/MANIFEST.MF	2011-04-16 01:16:25 UTC (rev 30628)
@@ -40,4 +40,5 @@
  org.jboss.tools.cdi.ui.ca,
  org.jboss.tools.cdi.ui.marker,
  org.jboss.tools.cdi.ui.preferences,
+ org.jboss.tools.cdi.ui.search,
  org.jboss.tools.cdi.ui.wizard

Modified: trunk/cdi/tests/org.jboss.tools.cdi.ui.test/META-INF/MANIFEST.MF
===================================================================
--- trunk/cdi/tests/org.jboss.tools.cdi.ui.test/META-INF/MANIFEST.MF	2011-04-16 01:12:25 UTC (rev 30627)
+++ trunk/cdi/tests/org.jboss.tools.cdi.ui.test/META-INF/MANIFEST.MF	2011-04-16 01:16:25 UTC (rev 30628)
@@ -23,5 +23,6 @@
  org.eclipse.jdt.ui,
  org.eclipse.ui.ide,
  org.jboss.tools.jst.jsp.base.test,
- org.eclipse.ltk.core.refactoring
+ org.eclipse.ltk.core.refactoring,
+ org.eclipse.search;bundle-version="3.7.0"
 Export-Package: org.jboss.tools.cdi.ui.test

Added: trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/search/CDISearchParticipantTest.java
===================================================================
--- trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/search/CDISearchParticipantTest.java	                        (rev 0)
+++ trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/search/CDISearchParticipantTest.java	2011-04-16 01:16:25 UTC (rev 30628)
@@ -0,0 +1,126 @@
+package org.jboss.tools.cdi.ui.test.search;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.search.IJavaSearchConstants;
+import org.eclipse.jdt.core.search.IJavaSearchScope;
+import org.eclipse.jdt.internal.ui.search.JavaSearchScopeFactory;
+import org.eclipse.jdt.ui.search.ElementQuerySpecification;
+import org.eclipse.jdt.ui.search.IQueryParticipant;
+import org.eclipse.jdt.ui.search.ISearchRequestor;
+import org.eclipse.jdt.ui.search.QuerySpecification;
+import org.eclipse.search.ui.text.Match;
+import org.jboss.tools.cdi.core.test.tck.TCKTest;
+import org.jboss.tools.cdi.ui.marker.MarkerResolutionUtils;
+import org.jboss.tools.cdi.ui.search.CDIMatch;
+import org.jboss.tools.common.EclipseUtil;
+
+public class CDISearchParticipantTest  extends TCKTest {
+	private static final int FIELD_SEARCH = 1;
+	private static final int METHOD_SEARCH = 2;
+	private static final int TYPE_SEARCH = 3;
+	private static final int PARAMETER_SEARCH = 4;
+	
+	private void testSearchParticipant(IFile file, int searchType, String elementName, String parameterName, IQueryParticipant participant, List<MatchStructure> matches){
+		try{
+			ICompilationUnit compilationUnit = EclipseUtil.getCompilationUnit(file);
+			IJavaElement element = null;
+			
+			IType type = compilationUnit.findPrimaryType();
+			
+			if(searchType == FIELD_SEARCH){
+				element = type.getField(elementName);
+			}else if(searchType == METHOD_SEARCH){
+				element = type.getMethod(elementName, new String[]{});
+			}else if(searchType == TYPE_SEARCH){
+				element = type;
+			}else if(searchType == PARAMETER_SEARCH){
+				IMethod method = type.getMethod(elementName, new String[]{});
+				element = MarkerResolutionUtils.getParameter(method, parameterName);
+			}
+			
+			if(element != null){
+				CDISearchRequestor requestor = new CDISearchRequestor();
+				
+				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");
+		}catch(CoreException ex){
+			fail("Core exception");
+		}
+	}
+	
+	private void checkMatches(List<Match> matchesForCheck, List<MatchStructure> matchList) throws CoreException {
+		assertEquals("There is unexpected number of matches",matchList.size(), matchesForCheck.size());
+
+		for(Match match : matchesForCheck){
+			assertTrue("Match must be CDIMatch", match instanceof CDIMatch);
+			MatchStructure ms = findMatch(matchList, (CDIMatch)match);
+			assertNotNull("Match not found", ms);
+			ms.checked = true;
+		}
+		
+		for(MatchStructure ms : matchList){
+			assertTrue("Not all matches found", ms.checked);
+		}
+	}
+	
+	protected MatchStructure findMatch(List<MatchStructure> matchList, CDIMatch match){
+		for(MatchStructure ms : matchList){
+			if(!ms.checked && ms.type.equals(match.getCDIElement().getClass()) && ms.name.equals(match.getLabel()))
+				return ms;
+		}
+		return null;
+	}
+
+	
+	class CDISearchRequestor implements ISearchRequestor{
+		ArrayList<Match> matches = new ArrayList<Match>();
+		
+		public void reportMatch(Match match){
+			matches.add(match);
+		}
+		
+		public List<Match> getMatches(){
+			return matches;
+		}
+	}
+	
+	class MatchStructure{
+		String type; // CDIElement.getClass()
+		String name; // label
+		boolean checked;
+		
+		public MatchStructure(String type, String name){
+			this.type = type;
+			this.name = name;
+			checked = false;
+		}
+	}
+	
+	public void testInjectionPointQueryParticipant(){
+		
+		//testSearchParticipant();
+	}
+
+	public void testCDIBeanQueryParticipant(){
+		
+	}
+}


Property changes on: trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/search/CDISearchParticipantTest.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain



More information about the jbosstools-commits mailing list