01: /*******************************************************************************
02: * Copyright (c) 2000, 2005 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.jdt.ui.tests.search;
11:
12: import junit.framework.Test;
13: import junit.framework.TestCase;
14: import junit.framework.TestSuite;
15:
16: import org.eclipse.core.resources.IProject;
17: import org.eclipse.core.runtime.CoreException;
18: import org.eclipse.core.runtime.IStatus;
19: import org.eclipse.core.runtime.Status;
20: import org.eclipse.jdt.core.JavaCore;
21: import org.eclipse.jdt.internal.ui.search.JavaSearchQuery;
22: import org.eclipse.jdt.internal.ui.search.JavaSearchResult;
23: import org.eclipse.jdt.internal.ui.search.SearchParticipantDescriptor;
24: import org.eclipse.jdt.internal.ui.search.SearchParticipantRecord;
25: import org.eclipse.jdt.internal.ui.search.SearchParticipantsExtensionPoint;
26: import org.eclipse.jdt.ui.search.IQueryParticipant;
27:
28: /**
29: */
30: public class ParticipantTest extends TestCase {
31:
32: static class TestExtensionPoint extends
33: SearchParticipantsExtensionPoint {
34: public SearchParticipantRecord[] getSearchParticipants(
35: IProject[] concernedProjects) throws CoreException {
36: return new SearchParticipantRecord[] { new SearchParticipantRecord(
37: new TestParticipantRecord(), new TestParticipant()) };
38: }
39: }
40:
41: static class TestParticipantRecord extends
42: SearchParticipantDescriptor {
43:
44: TestParticipantRecord() {
45: super (null);
46: }
47:
48: protected IStatus checkSyntax() {
49: return Status.OK_STATUS;
50: }
51:
52: protected IQueryParticipant create() throws CoreException {
53: return new TestParticipant();
54: }
55:
56: public String getID() {
57: return "TestParticipant1 ID";
58: }
59:
60: protected String getNature() {
61: return JavaCore.NATURE_ID;
62: }
63: }
64:
65: public static Test allTests() {
66: return new JUnitSourceSetup(
67: new TestSuite(ParticipantTest.class),
68: new TestExtensionPoint());
69: }
70:
71: public static Test suite() {
72: return allTests();
73: }
74:
75: public ParticipantTest(String name) {
76: super (name);
77: }
78:
79: public void testSimpleParticipant() throws Exception {
80: JavaSearchQuery query = SearchTestHelper.runMethodRefQuery(
81: "frufru", new String[0]);
82: JavaSearchResult result = (JavaSearchResult) query
83: .getSearchResult();
84: assertEquals(20, result.getMatchCount());
85:
86: Object[] elements = result.getElements();
87: for (int i = 0; i < elements.length; i++) {
88: assertTrue(elements[i] instanceof Integer);
89: }
90: }
91:
92: }
|