Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: f94b7c5f0b16fe81b62ea6a3a24ce273fd99b221 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*******************************************************************************
 * Copyright (c) 2007 BEA Systems, Inc.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    wharley@bea.com - initial API and implementation
 *******************************************************************************/

package org.eclipse.jdt.apt.pluggable.tests;

import java.util.Map;

import junit.framework.Test;
import junit.framework.TestSuite;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jdt.apt.core.internal.util.FactoryContainer;
import org.eclipse.jdt.apt.core.internal.util.FactoryPath;
import org.eclipse.jdt.apt.core.util.AptConfig;
import org.eclipse.jdt.apt.pluggable.tests.processors.message6.Message6Proc;
import org.eclipse.jdt.core.IJavaProject;
import org.osgi.framework.Bundle;

/**
 * Ensure that the apt.pluggable code is getting loaded, the test environment is as expected,
 * and the test utilities themselves are working.
 * Keeping these "infrastructure" tests separate from the "real" tests helps avoid confusion when 
 * the real tests fail. 
 */
public class InfrastructureTests extends TestBase
{
	public InfrastructureTests(String name) {
		super(name);
	}

	public static Test suite() {
		return new TestSuite(InfrastructureTests.class);
	}
	
	/**
	 * Test that the apt.pluggable.core plug-in is present.  Obviously since this test plug-in
	 * depends on it, this test will never fail; it will either succeed or not run at all.
	 */
	public void testPluginLoaded() throws Throwable
	{
		Bundle bundle = Platform.getBundle("org.eclipse.jdt.apt.pluggable.core");
		assertNotNull("Couldn't get org.eclipse.jdt.apt.pluggable.core bundle", bundle);
	}
	
	/**
	 * Can we create a Java 1.6 test project populated with resources from this plug-in?
	 * If not, there is not much point in testing the rest of annotation processing.
	 */
	public void testProjectBuild() throws Throwable
	{
		IJavaProject jproj = createJavaProject(_projectName);
		IProject proj = jproj.getProject();
		IdeTestUtils.copyResources(proj, "targets/infrastructure", "src/targets/infrastructure"); // source code
		fullBuild();
		expectingNoProblems();
		String[] expectedClasses = { "targets.infrastructure.NoAnno" };
		expectingCompiledClasses(expectedClasses);
	}

	/**
	 * Does the factory path show Java 6 processors from this plug-in?
	 */
	public void testFactoryPathContents() throws Throwable
	{
		IJavaProject jproj = createJavaProject(_projectName);
		FactoryPath fpath = (FactoryPath) AptConfig.getFactoryPath(jproj);
		Map<FactoryContainer, FactoryPath.Attributes> map = fpath.getAllContainers();
		boolean foundThisPlugin = false;
		for (Map.Entry<FactoryContainer, FactoryPath.Attributes> entry : map.entrySet()) {
			FactoryContainer fc = entry.getKey();
			if (Apt6TestsPlugin.PLUGIN_ID.equals(fc.getId())) {
				foundThisPlugin = true;
				Map<String, String> names = fc.getFactoryNames();
				String service = names.get(Message6Proc.class.getName());
				assertNotNull("Message6Proc was not found in apt.pluggable.tests plug-in", service);
				break;
			}
		}
		assertTrue("apt.pluggable.tests plug-in was not found in project factory path", foundThisPlugin);
	}
}

Back to the top