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.BinaryRepositoryProvider;
22: import org.eclipse.pde.internal.core.natures.PDE;
23: import org.eclipse.pde.internal.ui.wizards.imports.PluginImportOperation;
24: import org.eclipse.team.core.RepositoryProvider;
25:
26: public class ImportWithLinksTestCase extends BaseImportTestCase {
27:
28: private static int TYPE = PluginImportOperation.IMPORT_BINARY_WITH_LINKS;
29:
30: public static Test suite() {
31: return new TestSuite(ImportWithLinksTestCase.class);
32: }
33:
34: public void testImportLinksJAR() {
35: runOperation(new String[] { "org.eclipse.pde.core" }, TYPE);
36: verifyLinkedProject("org.eclipse.pde.core", true);
37: }
38:
39: public void testImportLinksFlat() {
40: runOperation(new String[] { "org.eclipse.jdt.debug" }, TYPE);
41: verifyLinkedProject("org.eclipse.jdt.debug", true);
42: }
43:
44: public void testImportLinksNotJavaFlat() {
45: runOperation(new String[] { "org.eclipse.pde.source" }, TYPE);
46: verifyLinkedProject("org.eclipse.pde.source", false);
47: }
48:
49: public void testImportLinksNotJavaJARd() {
50: runOperation(new String[] { "org.eclipse.jdt.doc.user" }, TYPE);
51: verifyLinkedProject("org.eclipse.jdt.doc.user", false);
52: }
53:
54: public void testImportLinksMultiple() {
55: runOperation(new String[] { "org.eclipse.core.filebuffers",
56: "org.eclipse.jdt.doc.user", "org.eclipse.pde.build" },
57: TYPE);
58: verifyLinkedProject("org.eclipse.core.filebuffers", true);
59: verifyLinkedProject("org.eclipse.jdt.doc.user", false);
60: verifyLinkedProject("org.eclipse.pde.build", true);
61: }
62:
63: private void verifyLinkedProject(String projectName, boolean isJava) {
64: try {
65: IProject project = verifyProject(projectName);
66: RepositoryProvider provider = RepositoryProvider
67: .getProvider(project);
68: assertTrue(provider instanceof BinaryRepositoryProvider);
69: assertTrue(project.hasNature(PDE.PLUGIN_NATURE));
70: assertEquals(isJava, project.hasNature(JavaCore.NATURE_ID));
71: if (isJava) {
72: IJavaProject jProject = JavaCore.create(project);
73: assertTrue(checkSourceAttached(jProject));
74: assertTrue(checkLibraryEntry(jProject));
75: }
76: } catch (CoreException e) {
77: fail(e.getMessage());
78: }
79: }
80:
81: private boolean checkLibraryEntry(IJavaProject jProject)
82: throws JavaModelException {
83: IClasspathEntry[] entries = jProject.getRawClasspath();
84: for (int i = 0; i < entries.length; i++) {
85: if (entries[i].getEntryKind() == IClasspathEntry.CPE_LIBRARY)
86: return true;
87: }
88: return false;
89: }
90:
91: }
|