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 java.io.File;
13:
14: import junit.extensions.TestSetup;
15: import junit.framework.Test;
16:
17: import org.eclipse.core.resources.IProject;
18: import org.eclipse.core.resources.ResourcesPlugin;
19: import org.eclipse.core.runtime.CoreException;
20: import org.eclipse.core.runtime.Path;
21: import org.eclipse.jdt.core.IClasspathEntry;
22: import org.eclipse.jdt.core.IJavaProject;
23: import org.eclipse.jdt.core.JavaCore;
24:
25: import org.eclipse.jdt.internal.ui.JavaPlugin;
26: import org.eclipse.jdt.internal.ui.search.SearchParticipantRecord;
27: import org.eclipse.jdt.internal.ui.search.SearchParticipantsExtensionPoint;
28: import org.eclipse.jdt.testplugin.JavaProjectHelper;
29: import org.eclipse.jdt.testplugin.JavaTestPlugin;
30: import org.eclipse.jdt.testplugin.TestOptions;
31:
32: /**
33: */
34: public class JUnitSourceSetup extends TestSetup {
35: public static final String PROJECT_NAME = "JUnitSource";
36: public static final String SRC_CONTAINER = "src";
37:
38: private IJavaProject fProject;
39: private SearchParticipantsExtensionPoint fExtensionPoint;
40:
41: static class NullExtensionPoint extends
42: SearchParticipantsExtensionPoint {
43: public SearchParticipantRecord[] getSearchParticipants(
44: IProject[] concernedProjects) throws CoreException {
45: return new SearchParticipantRecord[0];
46: }
47: }
48:
49: public static IJavaProject getProject() {
50: IProject project = ResourcesPlugin.getWorkspace().getRoot()
51: .getProject(PROJECT_NAME);
52: return JavaCore.create(project);
53: }
54:
55: public JUnitSourceSetup(Test test,
56: SearchParticipantsExtensionPoint participants) {
57: super (test);
58: fExtensionPoint = participants;
59: }
60:
61: public JUnitSourceSetup(Test test) {
62: this (test, new NullExtensionPoint());
63: }
64:
65: protected void setUp() throws Exception {
66: SearchParticipantsExtensionPoint
67: .debugSetInstance(fExtensionPoint);
68: fProject = JavaProjectHelper.createJavaProject(PROJECT_NAME,
69: "bin"); //$NON-NLS-2$
70: IClasspathEntry jreLib = JavaCore.newContainerEntry(new Path(
71: "org.eclipse.jdt.launching.JRE_CONTAINER")); //$NON-NLS-1$
72: JavaProjectHelper.addToClasspath(fProject, jreLib);
73: File junitSrcArchive = JavaTestPlugin.getDefault()
74: .getFileInPlugin(JavaProjectHelper.JUNIT_SRC_381);
75: JavaProjectHelper.addSourceContainerWithImport(fProject,
76: SRC_CONTAINER, junitSrcArchive,
77: JavaProjectHelper.JUNIT_SRC_ENCODING);
78: JavaCore.setOptions(TestOptions.getDefaultOptions());
79: TestOptions.initializeCodeGenerationOptions();
80: JavaPlugin.getDefault().getCodeTemplateStore().load();
81: }
82:
83: /* (non-Javadoc)
84: * @see junit.extensions.TestSetup#tearDown()
85: */
86: protected void tearDown() throws Exception {
87: JavaProjectHelper.delete(fProject);
88: SearchParticipantsExtensionPoint.debugSetInstance(null);
89: }
90: }
|