001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * If you wish your version of this file to be governed by only the CDDL
025: * or only the GPL Version 2, indicate your decision by adding
026: * "[Contributor] elects to include this software in this distribution
027: * under the [CDDL or GPL Version 2] license." If you do not indicate a
028: * single choice of license, a recipient has the option to distribute
029: * your version of this file under either the CDDL, the GPL Version 2 or
030: * to extend the choice of license to its licensees as provided above.
031: * However, if you add GPL Version 2 code and therefore, elected the GPL
032: * Version 2 license, then the option applies only if the new code is
033: * made subject to such option by the copyright holder.
034: *
035: * Contributor(s):
036: *
037: * Portions Copyrighted 2007 Sun Microsystems, Inc.
038: */
039:
040: package org.netbeans.modules.visualweb.project.jsfloader;
041:
042: import org.netbeans.api.project.Project;
043: import org.netbeans.junit.NbTestCase;
044: import org.netbeans.modules.visualweb.project.jsfloader.test.SetupUtils;
045: import org.openide.cookies.EditCookie;
046: import org.openide.cookies.EditorCookie;
047: import org.openide.cookies.OpenCookie;
048: import org.openide.filesystems.FileObject;
049: import org.openide.filesystems.FileUtil;
050: import org.openide.loaders.DataObject;
051: import org.openide.util.Lookup;
052: import org.openide.util.test.MockLookup;
053:
054: /**
055: *
056: * @author quynguyen
057: */
058: public class JsfJavaDataObjectTest extends NbTestCase {
059: private Project project;
060: private FileObject projectRoot;
061:
062: public JsfJavaDataObjectTest(String testName) {
063: super (testName);
064: }
065:
066: @Override
067: protected void setUp() throws Exception {
068: super .setUp();
069:
070: project = SetupUtils.setup(getWorkDir());
071: projectRoot = FileUtil.toFileObject(getWorkDir())
072: .getFileObject("VWJavaEE5");
073:
074: assertNotNull("Project should not be null", project);
075: assertNotNull("Project root folder should not be null",
076: projectRoot);
077: }
078:
079: @Override
080: protected void tearDown() throws Exception {
081: super .tearDown();
082: project = null;
083: projectRoot = null;
084:
085: MockLookup.setInstances();
086: }
087:
088: public void testFindPrimaryFile() throws Exception {
089: System.out.println("JsfJavaDataLoader.findPrimaryFile");
090:
091: FileObject srcFolder = projectRoot
092: .getFileObject("src/java/vwjavaee5");
093: FileObject pageJava = projectRoot
094: .getFileObject("src/java/vwjavaee5/Page1.java");
095: FileObject normalJava = projectRoot
096: .getFileObject("src/java/vwjavaee5/RequestBean1.java");
097:
098: assertNotNull("srcFolder FileObject should not be null",
099: srcFolder);
100: assertNotNull("pageJava FileObject should not be null",
101: pageJava);
102: assertNotNull("normalJava FileObject should not be null",
103: normalJava);
104:
105: JsfJavaDataLoader loader = SetupUtils.getJavaLoader();
106:
107: FileObject result1 = loader.findPrimaryFile(pageJava);
108: FileObject result2 = loader.findPrimaryFile(srcFolder);
109: FileObject result3 = loader.findPrimaryFile(normalJava);
110:
111: assertEquals("findPrimaryFile did not recognize Page1.java",
112: result1, pageJava);
113: assertNull("findPrimaryFile should not recognize folders",
114: result2);
115: assertNull(
116: "findPrimaryFile should not recognize plain java files",
117: result3);
118: }
119:
120: /**
121: * Test of getLookup method, of class JsfJspDataObject.
122: */
123: public void testGetLookup() throws Exception {
124: System.out.println("getLookup");
125: FileObject javaPage = projectRoot
126: .getFileObject("src/java/vwjavaee5/Page1.java");
127: JsfJavaDataObject instance = (JsfJavaDataObject) DataObject
128: .find(javaPage);
129:
130: // test validity of lookup results
131: Lookup result = instance.getLookup();
132: JsfJavaEditorSupport support = result
133: .lookup(JsfJavaEditorSupport.class);
134: OpenCookie openCookie = result.lookup(OpenCookie.class);
135: EditCookie editCookie = result.lookup(EditCookie.class);
136: EditorCookie editorCookie = result.lookup(EditorCookie.class);
137:
138: assertNotNull("OpenCookie is null", openCookie);
139: assertNotNull("EditCookie is null", editCookie);
140: assertNotNull("EditorCookie is null", editorCookie);
141: assertNotNull("JsfJavaEditorSupport is null", support);
142:
143: assertEquals(
144: "getLookup and getCookie should return the same OpenCookie",
145: openCookie, instance.getCookie(OpenCookie.class));
146: assertEquals(
147: "getLookup and getCookie should return the same EditCookie",
148: editCookie, instance.getCookie(EditCookie.class));
149: assertEquals(
150: "getLookup and getCookie should return the same EditorCookie",
151: editorCookie, instance.getCookie(EditorCookie.class));
152: assertEquals(
153: "getLookup and getCookie should return the same JsfJavaEditorSupport",
154: support, instance.getCookie(JsfJavaEditorSupport.class));
155: }
156:
157: public void testGetCookie() throws Exception {
158: System.out.println("getCookie");
159: FileObject javaPage = projectRoot
160: .getFileObject("src/java/vwjavaee5/Page1.java");
161: JsfJavaDataObject instance = (JsfJavaDataObject) DataObject
162: .find(javaPage);
163:
164: // test getCookie
165: EditorCookie editorCookie = instance
166: .getCookie(EditorCookie.class);
167: OpenCookie openCookie = instance.getCookie(OpenCookie.class);
168: EditCookie editCookie = instance.getCookie(EditCookie.class);
169:
170: assertNotNull("OpenCookie is null", openCookie);
171: assertNotNull("EditCookie is null", editCookie);
172: assertNotNull("EditorCookie is null", editorCookie);
173:
174: Lookup lookup = instance.getLookup();
175:
176: assertEquals(
177: "getLookup and getCookie should return the same OpenCookie",
178: openCookie, lookup.lookup(OpenCookie.class));
179: assertEquals(
180: "getLookup and getCookie should return the same EditCookie",
181: editCookie, lookup.lookup(EditCookie.class));
182: assertEquals(
183: "getLookup and getCookie should return the same EditorCookie",
184: editorCookie, lookup.lookup(EditorCookie.class));
185: }
186:
187: }
|