quynguyen@1808
|
1 |
/*
|
quynguyen@1808
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
jglick@2927
|
3 |
*
|
jglick@2927
|
4 |
* Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
|
jglick@2927
|
5 |
*
|
jglick@2927
|
6 |
* Oracle and Java are registered trademarks of Oracle and/or its affiliates.
|
jglick@2927
|
7 |
* Other names may be trademarks of their respective owners.
|
jglick@2927
|
8 |
*
|
quynguyen@1808
|
9 |
* The contents of this file are subject to the terms of either the GNU
|
quynguyen@1808
|
10 |
* General Public License Version 2 only ("GPL") or the Common
|
quynguyen@1808
|
11 |
* Development and Distribution License("CDDL") (collectively, the
|
quynguyen@1808
|
12 |
* "License"). You may not use this file except in compliance with the
|
quynguyen@1808
|
13 |
* License. You can obtain a copy of the License at
|
quynguyen@1808
|
14 |
* http://www.netbeans.org/cddl-gplv2.html
|
quynguyen@1808
|
15 |
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
|
quynguyen@1808
|
16 |
* specific language governing permissions and limitations under the
|
quynguyen@1808
|
17 |
* License. When distributing the software, include this License Header
|
quynguyen@1808
|
18 |
* Notice in each file and include the License file at
|
jglick@2927
|
19 |
* nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
|
quynguyen@1808
|
20 |
* particular file as subject to the "Classpath" exception as provided
|
jglick@2927
|
21 |
* by Oracle in the GPL Version 2 section of the License file that
|
quynguyen@1808
|
22 |
* accompanied this code. If applicable, add the following below the
|
quynguyen@1808
|
23 |
* License Header, with the fields enclosed by brackets [] replaced by
|
quynguyen@1808
|
24 |
* your own identifying information:
|
quynguyen@1808
|
25 |
* "Portions Copyrighted [year] [name of copyright owner]"
|
quynguyen@1808
|
26 |
*
|
quynguyen@1808
|
27 |
* If you wish your version of this file to be governed by only the CDDL
|
quynguyen@1808
|
28 |
* or only the GPL Version 2, indicate your decision by adding
|
quynguyen@1808
|
29 |
* "[Contributor] elects to include this software in this distribution
|
quynguyen@1808
|
30 |
* under the [CDDL or GPL Version 2] license." If you do not indicate a
|
quynguyen@1808
|
31 |
* single choice of license, a recipient has the option to distribute
|
quynguyen@1808
|
32 |
* your version of this file under either the CDDL, the GPL Version 2 or
|
quynguyen@1808
|
33 |
* to extend the choice of license to its licensees as provided above.
|
quynguyen@1808
|
34 |
* However, if you add GPL Version 2 code and therefore, elected the GPL
|
quynguyen@1808
|
35 |
* Version 2 license, then the option applies only if the new code is
|
quynguyen@1808
|
36 |
* made subject to such option by the copyright holder.
|
quynguyen@1808
|
37 |
*
|
quynguyen@1808
|
38 |
* Contributor(s):
|
quynguyen@1808
|
39 |
*
|
quynguyen@1808
|
40 |
* Portions Copyrighted 2007 Sun Microsystems, Inc.
|
quynguyen@1808
|
41 |
*/
|
quynguyen@1808
|
42 |
|
quynguyen@1808
|
43 |
package org.netbeans.modules.visualweb.project.jsfloader;
|
quynguyen@1808
|
44 |
|
quynguyen@1808
|
45 |
import org.netbeans.api.project.Project;
|
quynguyen@1808
|
46 |
import org.netbeans.junit.NbTestCase;
|
quynguyen@1808
|
47 |
import org.netbeans.modules.visualweb.project.jsfloader.test.SetupUtils;
|
quynguyen@1808
|
48 |
import org.openide.cookies.EditCookie;
|
quynguyen@1808
|
49 |
import org.openide.cookies.EditorCookie;
|
quynguyen@1808
|
50 |
import org.openide.cookies.OpenCookie;
|
quynguyen@1808
|
51 |
import org.openide.filesystems.FileObject;
|
quynguyen@1808
|
52 |
import org.openide.filesystems.FileUtil;
|
quynguyen@1808
|
53 |
import org.openide.loaders.DataObject;
|
quynguyen@1808
|
54 |
import org.openide.util.Lookup;
|
quynguyen@1808
|
55 |
|
quynguyen@1808
|
56 |
/**
|
quynguyen@1808
|
57 |
*
|
quynguyen@1808
|
58 |
* @author quynguyen
|
quynguyen@1808
|
59 |
*/
|
quynguyen@1808
|
60 |
public class JsfJavaDataObjectTest extends NbTestCase {
|
quynguyen@1808
|
61 |
private Project project;
|
quynguyen@1808
|
62 |
private FileObject projectRoot;
|
quynguyen@1808
|
63 |
|
quynguyen@1808
|
64 |
public JsfJavaDataObjectTest(String testName) {
|
quynguyen@1808
|
65 |
super(testName);
|
quynguyen@1808
|
66 |
}
|
quynguyen@1808
|
67 |
|
quynguyen@1808
|
68 |
@Override
|
quynguyen@1808
|
69 |
protected void setUp() throws Exception {
|
quynguyen@1808
|
70 |
super.setUp();
|
quynguyen@1808
|
71 |
|
quynguyen@1808
|
72 |
project = SetupUtils.setup(getWorkDir());
|
quynguyen@1808
|
73 |
projectRoot = FileUtil.toFileObject(getWorkDir()).getFileObject("VWJavaEE5");
|
quynguyen@1808
|
74 |
|
quynguyen@1808
|
75 |
assertNotNull("Project should not be null", project);
|
quynguyen@1808
|
76 |
assertNotNull("Project root folder should not be null", projectRoot);
|
quynguyen@1808
|
77 |
}
|
quynguyen@1808
|
78 |
|
quynguyen@1808
|
79 |
@Override
|
quynguyen@1808
|
80 |
protected void tearDown() throws Exception {
|
quynguyen@1808
|
81 |
super.tearDown();
|
quynguyen@1808
|
82 |
project = null;
|
quynguyen@1808
|
83 |
projectRoot = null;
|
quynguyen@1808
|
84 |
}
|
quynguyen@1808
|
85 |
|
quynguyen@1816
|
86 |
public void testFindPrimaryFile() throws Exception {
|
quynguyen@1816
|
87 |
System.out.println("JsfJavaDataLoader.findPrimaryFile");
|
quynguyen@1816
|
88 |
|
quynguyen@1816
|
89 |
FileObject srcFolder = projectRoot.getFileObject("src/java/vwjavaee5");
|
quynguyen@1816
|
90 |
FileObject pageJava = projectRoot.getFileObject("src/java/vwjavaee5/Page1.java");
|
quynguyen@1816
|
91 |
FileObject normalJava = projectRoot.getFileObject("src/java/vwjavaee5/RequestBean1.java");
|
quynguyen@1816
|
92 |
|
quynguyen@1816
|
93 |
assertNotNull("srcFolder FileObject should not be null", srcFolder);
|
quynguyen@1816
|
94 |
assertNotNull("pageJava FileObject should not be null", pageJava);
|
quynguyen@1816
|
95 |
assertNotNull("normalJava FileObject should not be null", normalJava);
|
quynguyen@1816
|
96 |
|
quynguyen@1816
|
97 |
JsfJavaDataLoader loader = SetupUtils.getJavaLoader();
|
quynguyen@1816
|
98 |
|
quynguyen@1816
|
99 |
FileObject result1 = loader.findPrimaryFile(pageJava);
|
quynguyen@1816
|
100 |
FileObject result2 = loader.findPrimaryFile(srcFolder);
|
quynguyen@1816
|
101 |
FileObject result3 = loader.findPrimaryFile(normalJava);
|
quynguyen@1816
|
102 |
|
quynguyen@1816
|
103 |
assertEquals("findPrimaryFile did not recognize Page1.java", result1, pageJava);
|
quynguyen@1816
|
104 |
assertNull("findPrimaryFile should not recognize folders", result2);
|
quynguyen@1816
|
105 |
assertNull("findPrimaryFile should not recognize plain java files", result3);
|
quynguyen@1816
|
106 |
}
|
quynguyen@1816
|
107 |
|
quynguyen@1808
|
108 |
/**
|
quynguyen@1808
|
109 |
* Test of getLookup method, of class JsfJspDataObject.
|
quynguyen@1808
|
110 |
*/
|
quynguyen@1808
|
111 |
public void testGetLookup() throws Exception {
|
quynguyen@1808
|
112 |
System.out.println("getLookup");
|
quynguyen@1808
|
113 |
FileObject javaPage = projectRoot.getFileObject("src/java/vwjavaee5/Page1.java");
|
quynguyen@1808
|
114 |
JsfJavaDataObject instance = (JsfJavaDataObject)DataObject.find(javaPage);
|
quynguyen@1808
|
115 |
|
quynguyen@1808
|
116 |
// test validity of lookup results
|
quynguyen@1808
|
117 |
Lookup result = instance.getLookup();
|
quynguyen@1808
|
118 |
JsfJavaEditorSupport support = result.lookup(JsfJavaEditorSupport.class);
|
quynguyen@1808
|
119 |
OpenCookie openCookie = result.lookup(OpenCookie.class);
|
quynguyen@1808
|
120 |
EditCookie editCookie = result.lookup(EditCookie.class);
|
quynguyen@1808
|
121 |
EditorCookie editorCookie = result.lookup(EditorCookie.class);
|
quynguyen@1808
|
122 |
|
quynguyen@1808
|
123 |
assertNotNull("OpenCookie is null", openCookie);
|
quynguyen@1808
|
124 |
assertNotNull("EditCookie is null", editCookie);
|
quynguyen@1808
|
125 |
assertNotNull("EditorCookie is null", editorCookie);
|
quynguyen@1808
|
126 |
assertNotNull("JsfJavaEditorSupport is null", support);
|
quynguyen@1808
|
127 |
|
quynguyen@1808
|
128 |
assertEquals("getLookup and getCookie should return the same OpenCookie",
|
quynguyen@1808
|
129 |
openCookie, instance.getCookie(OpenCookie.class));
|
quynguyen@1808
|
130 |
assertEquals("getLookup and getCookie should return the same EditCookie",
|
quynguyen@1808
|
131 |
editCookie, instance.getCookie(EditCookie.class));
|
quynguyen@1808
|
132 |
assertEquals("getLookup and getCookie should return the same EditorCookie",
|
quynguyen@1808
|
133 |
editorCookie, instance.getCookie(EditorCookie.class));
|
quynguyen@1808
|
134 |
assertEquals("getLookup and getCookie should return the same JsfJavaEditorSupport",
|
quynguyen@1808
|
135 |
support, instance.getCookie(JsfJavaEditorSupport.class));
|
quynguyen@1808
|
136 |
}
|
quynguyen@1808
|
137 |
|
quynguyen@1808
|
138 |
public void testGetCookie() throws Exception {
|
quynguyen@1808
|
139 |
System.out.println("getCookie");
|
quynguyen@1808
|
140 |
FileObject javaPage = projectRoot.getFileObject("src/java/vwjavaee5/Page1.java");
|
quynguyen@1808
|
141 |
JsfJavaDataObject instance = (JsfJavaDataObject)DataObject.find(javaPage);
|
quynguyen@1808
|
142 |
|
quynguyen@1808
|
143 |
// test getCookie
|
quynguyen@1808
|
144 |
EditorCookie editorCookie = instance.getCookie(EditorCookie.class);
|
quynguyen@1808
|
145 |
OpenCookie openCookie = instance.getCookie(OpenCookie.class);
|
quynguyen@1808
|
146 |
EditCookie editCookie = instance.getCookie(EditCookie.class);
|
quynguyen@1808
|
147 |
|
quynguyen@1808
|
148 |
assertNotNull("OpenCookie is null", openCookie);
|
quynguyen@1808
|
149 |
assertNotNull("EditCookie is null", editCookie);
|
quynguyen@1808
|
150 |
assertNotNull("EditorCookie is null", editorCookie);
|
quynguyen@1808
|
151 |
|
quynguyen@1808
|
152 |
Lookup lookup = instance.getLookup();
|
quynguyen@1808
|
153 |
|
quynguyen@1808
|
154 |
assertEquals("getLookup and getCookie should return the same OpenCookie",
|
quynguyen@1808
|
155 |
openCookie, lookup.lookup(OpenCookie.class));
|
quynguyen@1808
|
156 |
assertEquals("getLookup and getCookie should return the same EditCookie",
|
quynguyen@1808
|
157 |
editCookie, lookup.lookup(EditCookie.class));
|
quynguyen@1808
|
158 |
assertEquals("getLookup and getCookie should return the same EditorCookie",
|
quynguyen@1808
|
159 |
editorCookie, lookup.lookup(EditorCookie.class));
|
quynguyen@1808
|
160 |
}
|
quynguyen@1808
|
161 |
|
quynguyen@1808
|
162 |
|
quynguyen@1808
|
163 |
|
quynguyen@1808
|
164 |
}
|