01: /*******************************************************************************
02: * Copyright (c) 2007 BEA Systems, Inc.
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: * wharley@bea.com - initial API and implementation
10: *******************************************************************************/package org.eclipse.jdt.apt.pluggable.tests;
11:
12: import java.util.Map;
13:
14: import junit.framework.Test;
15: import junit.framework.TestSuite;
16:
17: import org.eclipse.core.resources.IProject;
18: import org.eclipse.core.runtime.Platform;
19: import org.eclipse.jdt.apt.core.internal.util.FactoryContainer;
20: import org.eclipse.jdt.apt.core.internal.util.FactoryPath;
21: import org.eclipse.jdt.apt.core.util.AptConfig;
22: import org.eclipse.jdt.apt.pluggable.tests.processors.message6.Message6Proc;
23: import org.eclipse.jdt.core.IJavaProject;
24: import org.osgi.framework.Bundle;
25:
26: /**
27: * Ensure that the apt.pluggable code is getting loaded, the test environment is as expected,
28: * and the test utilities themselves are working.
29: * Keeping these "infrastructure" tests separate from the "real" tests helps avoid confusion when
30: * the real tests fail.
31: */
32: public class InfrastructureTests extends TestBase {
33: public InfrastructureTests(String name) {
34: super (name);
35: }
36:
37: public static Test suite() {
38: return new TestSuite(InfrastructureTests.class);
39: }
40:
41: /**
42: * Test that the apt.pluggable.core plug-in is present. Obviously since this test plug-in
43: * depends on it, this test will never fail; it will either succeed or not run at all.
44: */
45: public void testPluginLoaded() throws Throwable {
46: Bundle bundle = Platform
47: .getBundle("org.eclipse.jdt.apt.pluggable.core");
48: assertNotNull(
49: "Couldn't get org.eclipse.jdt.apt.pluggable.core bundle",
50: bundle);
51: }
52:
53: /**
54: * Can we create a Java 1.6 test project populated with resources from this plug-in?
55: * If not, there is not much point in testing the rest of annotation processing.
56: */
57: public void testProjectBuild() throws Throwable {
58: IJavaProject jproj = createJavaProject(_projectName);
59: IProject proj = jproj.getProject();
60: IdeTestUtils.copyResources(proj, "targets/infrastructure",
61: "src/targets/infrastructure"); // source code
62: fullBuild();
63: expectingNoProblems();
64: String[] expectedClasses = { "targets.infrastructure.NoAnno" };
65: expectingCompiledClasses(expectedClasses);
66: }
67:
68: /**
69: * Does the factory path show Java 6 processors from this plug-in?
70: */
71: public void testFactoryPathContents() throws Throwable {
72: IJavaProject jproj = createJavaProject(_projectName);
73: FactoryPath fpath = (FactoryPath) AptConfig
74: .getFactoryPath(jproj);
75: Map<FactoryContainer, FactoryPath.Attributes> map = fpath
76: .getAllContainers();
77: boolean foundThisPlugin = false;
78: for (Map.Entry<FactoryContainer, FactoryPath.Attributes> entry : map
79: .entrySet()) {
80: FactoryContainer fc = entry.getKey();
81: if (Apt6TestsPlugin.PLUGIN_ID.equals(fc.getId())) {
82: foundThisPlugin = true;
83: Map<String, String> names = fc.getFactoryNames();
84: String service = names
85: .get(Message6Proc.class.getName());
86: assertNotNull(
87: "Message6Proc was not found in apt.pluggable.tests plug-in",
88: service);
89: break;
90: }
91: }
92: assertTrue(
93: "apt.pluggable.tests plug-in was not found in project factory path",
94: foundThisPlugin);
95: }
96: }
|