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.PDECore;
22: import org.eclipse.pde.internal.core.natures.PDE;
23: import org.eclipse.pde.internal.ui.wizards.imports.PluginImportOperation;
24:
25: public class ImportAsBinaryTestCase extends BaseImportTestCase {
26:
27: private static int TYPE = PluginImportOperation.IMPORT_BINARY;
28:
29: public static Test suite() {
30: return new TestSuite(ImportAsBinaryTestCase.class);
31: }
32:
33: public void testImportBinaryJAR() {
34: runOperation(new String[] { "org.eclipse.pde.core" }, TYPE);
35: verifyBinaryProject("org.eclipse.pde.core", true);
36: }
37:
38: public void testImportBinaryFlat() {
39: runOperation(new String[] { "org.eclipse.jdt.debug" }, TYPE);
40: verifyBinaryProject("org.eclipse.jdt.debug", true);
41: }
42:
43: public void testImportBinaryNotJavaFlat() {
44: runOperation(new String[] { "org.eclipse.pde.source" }, TYPE);
45: verifyBinaryProject("org.eclipse.pde.source", false);
46: }
47:
48: public void testImportBinaryNotJavaJARd() {
49: runOperation(new String[] { "org.eclipse.jdt.doc.user" }, TYPE);
50: verifyBinaryProject("org.eclipse.jdt.doc.user", false);
51: }
52:
53: public void testImportBinaryMultiple() {
54: runOperation(new String[] { "org.eclipse.core.filebuffers",
55: "org.eclipse.jdt.doc.user", "org.eclipse.pde.build" },
56: TYPE);
57: verifyBinaryProject("org.eclipse.core.filebuffers", true);
58: verifyBinaryProject("org.eclipse.jdt.doc.user", false);
59: verifyBinaryProject("org.eclipse.pde.build", true);
60: }
61:
62: private void verifyBinaryProject(String projectName, boolean isJava) {
63: try {
64: IProject project = verifyProject(projectName);
65: assertEquals(
66: PDECore.BINARY_PROJECT_VALUE,
67: project
68: .getPersistentProperty(PDECore.EXTERNAL_PROJECT_PROPERTY));
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: }
|