Line 0
Link Here
|
|
|
1 |
/* |
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
3 |
* |
4 |
* Copyright 2013 Oracle and/or its affiliates. All rights reserved. |
5 |
* |
6 |
* Oracle and Java are registered trademarks of Oracle and/or its affiliates. |
7 |
* Other names may be trademarks of their respective owners. |
8 |
* |
9 |
* The contents of this file are subject to the terms of either the GNU |
10 |
* General Public License Version 2 only ("GPL") or the Common |
11 |
* Development and Distribution License("CDDL") (collectively, the |
12 |
* "License"). You may not use this file except in compliance with the |
13 |
* License. You can obtain a copy of the License at |
14 |
* http://www.netbeans.org/cddl-gplv2.html |
15 |
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the |
16 |
* specific language governing permissions and limitations under the |
17 |
* License. When distributing the software, include this License Header |
18 |
* Notice in each file and include the License file at |
19 |
* nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this |
20 |
* particular file as subject to the "Classpath" exception as provided |
21 |
* by Oracle in the GPL Version 2 section of the License file that |
22 |
* accompanied this code. If applicable, add the following below the |
23 |
* License Header, with the fields enclosed by brackets [] replaced by |
24 |
* your own identifying information: |
25 |
* "Portions Copyrighted [year] [name of copyright owner]" |
26 |
* |
27 |
* If you wish your version of this file to be governed by only the CDDL |
28 |
* or only the GPL Version 2, indicate your decision by adding |
29 |
* "[Contributor] elects to include this software in this distribution |
30 |
* under the [CDDL or GPL Version 2] license." If you do not indicate a |
31 |
* single choice of license, a recipient has the option to distribute |
32 |
* your version of this file under either the CDDL, the GPL Version 2 or |
33 |
* to extend the choice of license to its licensees as provided above. |
34 |
* However, if you add GPL Version 2 code and therefore, elected the GPL |
35 |
* Version 2 license, then the option applies only if the new code is |
36 |
* made subject to such option by the copyright holder. |
37 |
* |
38 |
* Contributor(s): |
39 |
* |
40 |
* Portions Copyrighted 2013 Sun Microsystems, Inc. |
41 |
*/ |
42 |
package org.netbeans.modules.palette; |
43 |
|
44 |
import java.awt.GraphicsEnvironment; |
45 |
import java.io.ByteArrayOutputStream; |
46 |
import java.io.IOException; |
47 |
import static junit.framework.Assert.assertFalse; |
48 |
import static junit.framework.Assert.assertTrue; |
49 |
import org.netbeans.junit.NbTestCase; |
50 |
import org.openide.util.test.AnnotationProcessorTestUtils; |
51 |
|
52 |
/** |
53 |
* |
54 |
* @author Didier |
55 |
*/ |
56 |
public class PaletteItemRegistrationProcessorTest extends NbTestCase { |
57 |
|
58 |
static { |
59 |
System.setProperty("java.awt.headless", "true"); |
60 |
} |
61 |
|
62 |
public PaletteItemRegistrationProcessorTest(String n) { |
63 |
super(n); |
64 |
} |
65 |
|
66 |
@Override |
67 |
protected boolean runInEQ() { |
68 |
return true; |
69 |
} |
70 |
|
71 |
@Override |
72 |
protected void setUp() throws Exception { |
73 |
super.setUp(); |
74 |
} |
75 |
private static final String VALID_CLASS_ANNOTATION = "@PaletteItemRegistration(paletteid = \"JavaPalette\", category = \"dummycat\", itemid = \"myitem\"," |
76 |
+ "icon16 = \"org/netbeans/modules/palette/resources/unknown16.gif\", " |
77 |
+ "icon32 = \"org/netbeans/modules/palette/resources/unknown32.gif\", tooltip = \"tooltip\", name = \"name\")"; |
78 |
private static final String VALID_PACKAGE_ANNOTATION = "@PaletteItemRegistration(paletteid = \"JavaPalette\", category = \"dummycat\", itemid = \"myitem\"," |
79 |
+ "icon16 = \"org/netbeans/modules/palette/resources/unknown16.gif\", " |
80 |
+ "icon32 = \"org/netbeans/modules/palette/resources/unknown32.gif\", tooltip = \"tooltip\", name = \"name\" ,body =\"mydummybody\")"; |
81 |
private static final String INVALID_CLASS_ANNOTATION_1 = "@PaletteItemRegistration(paletteid = \"JavaPalette\", category = \"dummycat\", itemid = \"myitem\"," |
82 |
+ "icon32 = \"org/netbeans/modules/palette/resources/unknown32.gif\", tooltip = \"tooltip\", name = \"name\")"; |
83 |
private static final String INVALID_CLASS_ANNOTATION_2 = "@PaletteItemRegistration(paletteid = \"JavaPalette\", category = \"dummycat\", itemid = \"myitem\"," |
84 |
+ "icon16 = \"org/netbeans/modules/palette/resources/unknown16.gif\", tooltip = \"tooltip\", name = \"name\")"; |
85 |
|
86 |
public void testNoCompliantClassAnnotated() throws IOException { |
87 |
clearWorkDir(); |
88 |
assertTrue("Headless run", GraphicsEnvironment.isHeadless()); |
89 |
AnnotationProcessorTestUtils.makeSource(getWorkDir(), "test.A", |
90 |
"import org.netbeans.spi.palette.PaletteItemRegistration;\n" |
91 |
+ VALID_CLASS_ANNOTATION |
92 |
+ "public class A {\n" |
93 |
+ " A() {}" |
94 |
+ "}\n"); |
95 |
ByteArrayOutputStream os = new ByteArrayOutputStream(); |
96 |
boolean r = AnnotationProcessorTestUtils.runJavac(getWorkDir(), null, getWorkDir(), null, os); |
97 |
assertFalse("Compilation has to fail:\n" + os, r); |
98 |
} |
99 |
|
100 |
public void testActiveEditorDropAnnotated() throws IOException { |
101 |
clearWorkDir(); |
102 |
assertTrue("Headless run", GraphicsEnvironment.isHeadless()); |
103 |
AnnotationProcessorTestUtils.makeSource(getWorkDir(), "test.B", |
104 |
"import org.netbeans.spi.palette.PaletteItemRegistration;\n" |
105 |
+ "import org.openide.text.ActiveEditorDrop;\n;import javax.swing.text.JTextComponent;" |
106 |
+ VALID_CLASS_ANNOTATION |
107 |
+ "public class B implements ActiveEditorDrop {\n" |
108 |
+ " public boolean handleTransfer(JTextComponent targetComponent) {return true; }" |
109 |
+ "}\n"); |
110 |
ByteArrayOutputStream os = new ByteArrayOutputStream(); |
111 |
boolean r = AnnotationProcessorTestUtils.runJavac(getWorkDir(), null, getWorkDir(), null, os); |
112 |
assertTrue("Compilation has to be successfull:\n" + os, r); |
113 |
} |
114 |
|
115 |
public void testActiveEditorDropAnnotatedWithMissingIcon16() throws IOException { |
116 |
clearWorkDir(); |
117 |
assertTrue("Headless run", GraphicsEnvironment.isHeadless()); |
118 |
AnnotationProcessorTestUtils.makeSource(getWorkDir(), "test.B", |
119 |
"import org.netbeans.spi.palette.PaletteItemRegistration;\n" |
120 |
+ "import org.openide.text.ActiveEditorDrop;\n;import javax.swing.text.JTextComponent;" |
121 |
+ INVALID_CLASS_ANNOTATION_1 |
122 |
+ "public class B implements ActiveEditorDrop {\n" |
123 |
+ " public boolean handleTransfer(JTextComponent targetComponent) {return true; }" |
124 |
+ "}\n"); |
125 |
ByteArrayOutputStream os = new ByteArrayOutputStream(); |
126 |
boolean r = AnnotationProcessorTestUtils.runJavac(getWorkDir(), null, getWorkDir(), null, os); |
127 |
assertFalse("Compilation has to fail:\n" + os, r); |
128 |
} |
129 |
|
130 |
public void testActiveEditorDropAnnotatedWithMissingIcon32() throws IOException { |
131 |
clearWorkDir(); |
132 |
assertTrue("Headless run", GraphicsEnvironment.isHeadless()); |
133 |
AnnotationProcessorTestUtils.makeSource(getWorkDir(), "test.B", |
134 |
"import org.netbeans.spi.palette.PaletteItemRegistration;\n" |
135 |
+ "import org.openide.text.ActiveEditorDrop;\n;import javax.swing.text.JTextComponent;" |
136 |
+ INVALID_CLASS_ANNOTATION_2 |
137 |
+ "public class B implements ActiveEditorDrop {\n" |
138 |
+ " public boolean handleTransfer(JTextComponent targetComponent) {return true; }" |
139 |
+ "}\n"); |
140 |
ByteArrayOutputStream os = new ByteArrayOutputStream(); |
141 |
boolean r = AnnotationProcessorTestUtils.runJavac(getWorkDir(), null, getWorkDir(), null, os); |
142 |
assertFalse("Compilation has to fail:\n" + os, r); |
143 |
} |
144 |
|
145 |
public void testInvalidAnnotatedPackage() throws IOException { |
146 |
//missing body |
147 |
clearWorkDir(); |
148 |
assertTrue("Headless run", GraphicsEnvironment.isHeadless()); |
149 |
AnnotationProcessorTestUtils.makeSource(getWorkDir(), "testb.package-info", |
150 |
VALID_CLASS_ANNOTATION |
151 |
+ "\npackage testa\n;" |
152 |
+ "import org.netbeans.spi.palette.PaletteItemRegistration;\n"); |
153 |
ByteArrayOutputStream os = new ByteArrayOutputStream(); |
154 |
boolean r = AnnotationProcessorTestUtils.runJavac(getWorkDir(), null, getWorkDir(), null, os); |
155 |
assertFalse("Compilation has to fail:\n" + os, r); |
156 |
} |
157 |
|
158 |
public void testAnnotatedPackage() throws IOException { |
159 |
//missing body |
160 |
clearWorkDir(); |
161 |
assertTrue("Headless run", GraphicsEnvironment.isHeadless()); |
162 |
AnnotationProcessorTestUtils.makeSource(getWorkDir(), "testa.package-info", |
163 |
VALID_PACKAGE_ANNOTATION |
164 |
+ "\npackage testa\n;" |
165 |
+ "import org.netbeans.spi.palette.PaletteItemRegistration;\n"); |
166 |
ByteArrayOutputStream os = new ByteArrayOutputStream(); |
167 |
boolean r = AnnotationProcessorTestUtils.runJavac(getWorkDir(), null, getWorkDir(), null, os); |
168 |
assertTrue("Compilation has to be successfull:\n" + os, r); |
169 |
} |
170 |
} |