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.compiler.apt.tests;
11:
12: import java.io.File;
13: import java.io.IOException;
14: import java.util.ArrayList;
15: import java.util.List;
16:
17: import javax.tools.JavaCompiler;
18: import javax.tools.ToolProvider;
19:
20: import junit.framework.TestCase;
21:
22: /**
23: *
24: */
25: public class ModelUtilTests extends TestCase {
26: // Processor class names; see corresponding usage in the processor classes.
27: private static final String ELEMENTUTILSPROC = "org.eclipse.jdt.compiler.apt.tests.processors.elementutils.ElementUtilsProc";
28: private static final String TYPEUTILSPROC = "org.eclipse.jdt.compiler.apt.tests.processors.typeutils.TypeUtilsProc";
29:
30: @Override
31: protected void setUp() throws Exception {
32: super .setUp();
33: BatchTestUtils.init();
34: }
35:
36: /**
37: * Validate the testElements test against the javac compiler.
38: * @throws IOException
39: */
40: public void testElementsWithSystemCompiler() throws IOException {
41: JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
42: internalTest(compiler, ELEMENTUTILSPROC);
43: }
44:
45: /**
46: * Test the Elements utility implementation.
47: * @throws IOException
48: */
49: public void testElementsWithEclipseCompiler() throws IOException {
50: JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
51: internalTest(compiler, ELEMENTUTILSPROC);
52: }
53:
54: /**
55: * Validate the testTypes test against the javac compiler.
56: * @throws IOException
57: */
58: public void testTypesWithSystemCompiler() throws IOException {
59: JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
60: internalTest(compiler, TYPEUTILSPROC);
61: }
62:
63: /**
64: * Test the Types utility implementation.
65: * @throws IOException
66: */
67: public void testTypesWithEclipseCompiler() throws IOException {
68: JavaCompiler compiler = BatchTestUtils.getEclipseCompiler();
69: internalTest(compiler, TYPEUTILSPROC);
70: }
71:
72: /**
73: * Test functionality by running a particular processor against the types in
74: * resources/targets. The processor must support "*" (the set of all annotations)
75: * and must report its errors or success via the methods in BaseProcessor.
76: * @throws IOException
77: */
78: private void internalTest(JavaCompiler compiler,
79: String processorClass) throws IOException {
80: System.clearProperty(processorClass);
81: File targetFolder = TestUtils.concatPath(BatchTestUtils
82: .getSrcFolderName(), "targets", "model");
83: BatchTestUtils.copyResources("targets/model", targetFolder);
84:
85: List<String> options = new ArrayList<String>();
86: options.add("-A" + processorClass);
87: BatchTestUtils.compileTree(compiler, options, targetFolder);
88:
89: // If it succeeded, the processor will have set this property to "succeeded";
90: // if not, it will set it to an error value.
91: assertEquals("succeeded", System.getProperty(processorClass));
92: }
93:
94: @Override
95: protected void tearDown() throws Exception {
96: super.tearDown();
97: }
98:
99: }
|