01: /*******************************************************************************
02: * Copyright (c) 2005, 2006 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.pde.ui.tests.imports;
11:
12: import junit.framework.Test;
13: import junit.framework.TestSuite;
14:
15: import org.eclipse.core.resources.IProject;
16: import org.eclipse.core.runtime.CoreException;
17: import org.eclipse.jdt.core.IClasspathEntry;
18: import org.eclipse.jdt.core.IJavaProject;
19: import org.eclipse.jdt.core.JavaCore;
20: import org.eclipse.jdt.core.JavaModelException;
21: import org.eclipse.pde.internal.core.natures.PDE;
22: import org.eclipse.pde.internal.ui.wizards.imports.PluginImportOperation;
23:
24: public class ImportAsSourceTestCase extends BaseImportTestCase {
25:
26: private static int TYPE = PluginImportOperation.IMPORT_WITH_SOURCE;
27:
28: public static Test suite() {
29: return new TestSuite(ImportAsSourceTestCase.class);
30: }
31:
32: public void testImportSourceJAR() {
33: runOperation(new String[] { "org.eclipse.pde.core" }, TYPE);
34: verifySourceProject("org.eclipse.pde.core", true);
35: }
36:
37: public void testImportSourceFlat() {
38: runOperation(new String[] { "org.eclipse.jdt.debug" }, TYPE);
39: verifySourceProject("org.eclipse.jdt.debug", true);
40: }
41:
42: public void testImportSourceNotJavaJARd() {
43: runOperation(new String[] { "org.eclipse.jdt.doc.user" }, TYPE);
44: verifySourceProject("org.eclipse.jdt.doc.user", false);
45: }
46:
47: public void testImportSourceMultiple() {
48: runOperation(new String[] { "org.eclipse.core.filebuffers",
49: "org.eclipse.jdt.doc.user", "org.eclipse.pde.build" },
50: TYPE);
51: verifySourceProject("org.eclipse.core.filebuffers", true);
52: verifySourceProject("org.eclipse.jdt.doc.user", false);
53: verifySourceProject("org.eclipse.pde.build", true);
54: }
55:
56: private void verifySourceProject(String projectName, boolean isJava) {
57: try {
58: IProject project = verifyProject(projectName);
59: assertTrue(project.hasNature(PDE.PLUGIN_NATURE));
60: assertEquals(isJava, project.hasNature(JavaCore.NATURE_ID));
61: if (isJava) {
62: IJavaProject jProject = JavaCore.create(project);
63: assertTrue(checkSourceAttached(jProject));
64: assertTrue(checkSourceFolder(jProject));
65: }
66: } catch (CoreException e) {
67: fail(e.getMessage());
68: }
69: }
70:
71: private boolean checkSourceFolder(IJavaProject jProject)
72: throws JavaModelException {
73: IClasspathEntry[] entries = jProject.getRawClasspath();
74: for (int i = 0; i < entries.length; i++) {
75: if (entries[i].getEntryKind() == IClasspathEntry.CPE_SOURCE)
76: return true;
77: }
78: return false;
79: }
80: }
|