visualweb.project.jsfloader/test/unit/src/org/netbeans/modules/visualweb/project/jsfloader/JsfJspDataObjectTest.java
author Jesse Glick <jglick@netbeans.org>
Wed, 23 Mar 2011 17:17:42 -0400
changeset 3214 cf80c1d5c3ea
parent 2927 18a84774d1c7
permissions -rw-r--r--
Really making tests compilable.
quynguyen@1759
     1
/*
quynguyen@1759
     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@1759
     9
 * The contents of this file are subject to the terms of either the GNU
quynguyen@1759
    10
 * General Public License Version 2 only ("GPL") or the Common
quynguyen@1759
    11
 * Development and Distribution License("CDDL") (collectively, the
quynguyen@1759
    12
 * "License"). You may not use this file except in compliance with the
quynguyen@1759
    13
 * License. You can obtain a copy of the License at
quynguyen@1759
    14
 * http://www.netbeans.org/cddl-gplv2.html
quynguyen@1759
    15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
quynguyen@1759
    16
 * specific language governing permissions and limitations under the
quynguyen@1759
    17
 * License.  When distributing the software, include this License Header
quynguyen@1759
    18
 * Notice in each file and include the License file at
jglick@2927
    19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
quynguyen@1759
    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@1759
    22
 * accompanied this code. If applicable, add the following below the
quynguyen@1759
    23
 * License Header, with the fields enclosed by brackets [] replaced by
quynguyen@1759
    24
 * your own identifying information:
quynguyen@1759
    25
 * "Portions Copyrighted [year] [name of copyright owner]"
quynguyen@1759
    26
 * 
quynguyen@1759
    27
 * If you wish your version of this file to be governed by only the CDDL
quynguyen@1759
    28
 * or only the GPL Version 2, indicate your decision by adding
quynguyen@1759
    29
 * "[Contributor] elects to include this software in this distribution
quynguyen@1759
    30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
quynguyen@1759
    31
 * single choice of license, a recipient has the option to distribute
quynguyen@1759
    32
 * your version of this file under either the CDDL, the GPL Version 2 or
quynguyen@1759
    33
 * to extend the choice of license to its licensees as provided above.
quynguyen@1759
    34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
quynguyen@1759
    35
 * Version 2 license, then the option applies only if the new code is
quynguyen@1759
    36
 * made subject to such option by the copyright holder.
quynguyen@1759
    37
 * 
quynguyen@1759
    38
 * Contributor(s):
quynguyen@1759
    39
 * 
quynguyen@1759
    40
 * Portions Copyrighted 2007 Sun Microsystems, Inc.
quynguyen@1759
    41
 */
quynguyen@1759
    42
quynguyen@1759
    43
package org.netbeans.modules.visualweb.project.jsfloader;
quynguyen@1759
    44
quynguyen@1759
    45
import org.netbeans.api.project.Project;
quynguyen@1759
    46
import org.netbeans.junit.NbTestCase;
quynguyen@1759
    47
import org.netbeans.modules.visualweb.project.jsfloader.test.SetupUtils;
quynguyen@1759
    48
import org.netbeans.modules.web.core.jsploader.api.TagLibParseCookie;
quynguyen@1759
    49
import org.openide.cookies.EditCookie;
quynguyen@1759
    50
import org.openide.cookies.EditorCookie;
quynguyen@1759
    51
import org.openide.cookies.OpenCookie;
quynguyen@1759
    52
import org.openide.filesystems.FileObject;
quynguyen@1759
    53
import org.openide.filesystems.FileUtil;
quynguyen@1759
    54
import org.openide.loaders.DataObject;
quynguyen@1759
    55
import org.openide.util.Lookup;
quynguyen@1759
    56
quynguyen@1759
    57
/**
quynguyen@1759
    58
 *
quynguyen@1759
    59
 * @author quynguyen
quynguyen@1759
    60
 */
quynguyen@1759
    61
public class JsfJspDataObjectTest extends NbTestCase {
quynguyen@1759
    62
    private Project project;
quynguyen@1759
    63
    private FileObject projectRoot;
quynguyen@1759
    64
    
quynguyen@1759
    65
    public JsfJspDataObjectTest(String testName) {
quynguyen@1759
    66
        super(testName);
quynguyen@1759
    67
    }            
quynguyen@1759
    68
quynguyen@1759
    69
    @Override
quynguyen@1759
    70
    protected void setUp() throws Exception {
quynguyen@1759
    71
        super.setUp();
quynguyen@1759
    72
quynguyen@1759
    73
        project = SetupUtils.setup(getWorkDir());
quynguyen@1759
    74
        projectRoot = FileUtil.toFileObject(getWorkDir()).getFileObject("VWJavaEE5");
quynguyen@1759
    75
        
quynguyen@1759
    76
        assertNotNull("Project should not be null", project);
quynguyen@1759
    77
        assertNotNull("Project root folder should not be null", projectRoot);
quynguyen@1759
    78
    }
quynguyen@1759
    79
quynguyen@1759
    80
    @Override
quynguyen@1759
    81
    protected void tearDown() throws Exception {
quynguyen@1759
    82
        super.tearDown();
quynguyen@1759
    83
        project = null;
quynguyen@1759
    84
        projectRoot = null;
quynguyen@1759
    85
    }
quynguyen@1759
    86
quynguyen@1816
    87
    public void testFindPrimaryFile() throws Exception {
quynguyen@1816
    88
        System.out.println("JsfJspDataLoader.findPrimaryFile");
quynguyen@1816
    89
        FileObject webFolder = projectRoot.getFileObject("web");
quynguyen@1816
    90
        FileObject pageBean = projectRoot.getFileObject("web/Page1.jsp");
quynguyen@1816
    91
        FileObject plainJsp = projectRoot.getFileObject("web/index.jsp");
quynguyen@1816
    92
        
quynguyen@1816
    93
        assertNotNull("webFolder FileObject should not be null", webFolder);
quynguyen@1816
    94
        assertNotNull("pageBean FileObject should not be null", pageBean);
quynguyen@1816
    95
        assertNotNull("plainJsp FileObject should not be null", plainJsp);
quynguyen@1816
    96
        
quynguyen@1816
    97
        JsfJspDataLoader loader = SetupUtils.getJspLoader();
quynguyen@1816
    98
        
quynguyen@1816
    99
        FileObject result1 = loader.findPrimaryFile(pageBean);
quynguyen@1816
   100
        assertEquals("findPrimaryFile() on web/Page1.jsp did not work", result1, pageBean);
quynguyen@1816
   101
        
quynguyen@1816
   102
        FileObject result2 = loader.findPrimaryFile(webFolder);
quynguyen@1816
   103
        assertNull("findPrimaryFile() should not accept folder objects", result2);
quynguyen@1816
   104
        
quynguyen@1816
   105
        FileObject result3 = loader.findPrimaryFile(plainJsp);
quynguyen@1816
   106
        assertNull("FindPrimaryFile() should not accept non-visual web JSP files", result3);
quynguyen@1816
   107
    }
quynguyen@1816
   108
    
quynguyen@1759
   109
    /**
quynguyen@1759
   110
     * Test of getLookup method, of class JsfJspDataObject.
quynguyen@1759
   111
     */
quynguyen@1759
   112
    public void testGetLookup() throws Exception {
quynguyen@1759
   113
        System.out.println("getLookup");
quynguyen@1759
   114
        FileObject jspPage = projectRoot.getFileObject("web/Page1.jsp");
quynguyen@1759
   115
        JsfJspDataObject instance = (JsfJspDataObject)DataObject.find(jspPage);
quynguyen@1759
   116
        
quynguyen@1759
   117
        // test validity of lookup results
quynguyen@1759
   118
        Lookup result = instance.getLookup();
quynguyen@1759
   119
        JsfJspEditorSupport support = result.lookup(JsfJspEditorSupport.class);
quynguyen@1759
   120
        OpenCookie openCookie = result.lookup(OpenCookie.class);
quynguyen@1759
   121
        EditCookie editCookie = result.lookup(EditCookie.class);
quynguyen@1759
   122
        EditorCookie editorCookie = result.lookup(EditorCookie.class);
quynguyen@1759
   123
        TagLibParseCookie tagLibParseCookie = result.lookup(TagLibParseCookie.class);
quynguyen@1759
   124
        
quynguyen@1759
   125
        assertNotNull("OpenCookie is null", openCookie);
quynguyen@1759
   126
        assertNotNull("EditCookie is null", editCookie);
quynguyen@1759
   127
        assertNotNull("EditorCookie is null", editorCookie);
quynguyen@1759
   128
        assertNotNull("TagLibParseCookie is null", tagLibParseCookie);
quynguyen@1759
   129
        assertNotNull("JsfJspEditorSupport is null", support);
quynguyen@1759
   130
        
quynguyen@1759
   131
        assertEquals("getLookup and getCookie should return the same OpenCookie", 
quynguyen@1759
   132
                openCookie, instance.getCookie(OpenCookie.class));
quynguyen@1759
   133
        assertEquals("getLookup and getCookie should return the same EditCookie", 
quynguyen@1759
   134
                editCookie, instance.getCookie(EditCookie.class));
quynguyen@1759
   135
        assertEquals("getLookup and getCookie should return the same EditorCookie", 
quynguyen@1759
   136
                editorCookie, instance.getCookie(EditorCookie.class));
quynguyen@1759
   137
        assertEquals("getLookup and getCookie should return the same TagLibParseCookie", 
quynguyen@1759
   138
                tagLibParseCookie, instance.getCookie(TagLibParseCookie.class));
quynguyen@1759
   139
        assertEquals("getLookup and getCookie should return the same JsfJspEditorSupport", 
quynguyen@1759
   140
                support, instance.getCookie(JsfJspEditorSupport.class));
quynguyen@1759
   141
    }
quynguyen@1759
   142
    
quynguyen@1808
   143
    public void testGetCookie() throws Exception {
quynguyen@1808
   144
        System.out.println("getCookie");
quynguyen@1808
   145
        FileObject jspPage = projectRoot.getFileObject("web/Page1.jsp");
quynguyen@1808
   146
        JsfJspDataObject instance = (JsfJspDataObject)DataObject.find(jspPage);
quynguyen@1808
   147
        
quynguyen@1808
   148
        // test getCookie
quynguyen@1808
   149
        EditorCookie editorCookie = instance.getCookie(EditorCookie.class);
quynguyen@1808
   150
        OpenCookie openCookie = instance.getCookie(OpenCookie.class);
quynguyen@1808
   151
        EditCookie editCookie = instance.getCookie(EditCookie.class);
quynguyen@1808
   152
        
quynguyen@1808
   153
        assertNotNull("OpenCookie is null", openCookie);
quynguyen@1808
   154
        assertNotNull("EditCookie is null", editCookie);
quynguyen@1808
   155
        assertNotNull("EditorCookie is null", editorCookie);
quynguyen@1808
   156
        
quynguyen@1808
   157
        Lookup lookup = instance.getLookup();
quynguyen@1808
   158
        
quynguyen@1808
   159
        assertEquals("getLookup and getCookie should return the same OpenCookie", 
quynguyen@1808
   160
                openCookie, lookup.lookup(OpenCookie.class));
quynguyen@1808
   161
        assertEquals("getLookup and getCookie should return the same EditCookie", 
quynguyen@1808
   162
                editCookie, lookup.lookup(EditCookie.class));
quynguyen@1808
   163
        assertEquals("getLookup and getCookie should return the same EditorCookie", 
quynguyen@1808
   164
                editorCookie, lookup.lookup(EditorCookie.class));
quynguyen@1808
   165
    }
quynguyen@1808
   166
    
quynguyen@1808
   167
    
quynguyen@1759
   168
    public void testCorrespondingJsfJava() throws Exception {
quynguyen@1759
   169
        System.out.println("correspondingJsfJavaFile");
quynguyen@1759
   170
        FileObject jspPage = projectRoot.getFileObject("web/Page1.jsp");
quynguyen@1759
   171
        JsfJspDataObject instance = (JsfJspDataObject)DataObject.find(jspPage);
quynguyen@1759
   172
        FileObject javaSrc = Utils.findJavaForJsp(instance.getPrimaryFile());
quynguyen@1759
   173
        DataObject dobj = DataObject.find(javaSrc);
quynguyen@1759
   174
        assertTrue("Corresponding java file needs to be JSF", dobj instanceof JsfJavaDataObject);
quynguyen@1759
   175
    }
quynguyen@1759
   176
    
quynguyen@1759
   177
//    /**
quynguyen@1759
   178
//     * Test of createNodeDelegate method, of class JsfJspDataObject.
quynguyen@1759
   179
//     */
quynguyen@1759
   180
//    public void testCreateNodeDelegate() {
quynguyen@1759
   181
//        System.out.println("createNodeDelegate");
quynguyen@1759
   182
//        JsfJspDataObject instance = null;
quynguyen@1759
   183
//        Node expResult = null;
quynguyen@1759
   184
//        Node result = instance.createNodeDelegate();
quynguyen@1759
   185
//        assertEquals(expResult, result);
quynguyen@1759
   186
//        // TODO review the generated test code and remove the default call to fail.
quynguyen@1759
   187
//        fail("The test case is a prototype.");
quynguyen@1759
   188
//    }
quynguyen@1759
   189
//
quynguyen@1759
   190
//    /**
quynguyen@1759
   191
//     * Test of getHelpCtx method, of class JsfJspDataObject.
quynguyen@1759
   192
//     */
quynguyen@1759
   193
//    public void testGetHelpCtx() {
quynguyen@1759
   194
//        System.out.println("getHelpCtx");
quynguyen@1759
   195
//        JsfJspDataObject instance = null;
quynguyen@1759
   196
//        HelpCtx expResult = null;
quynguyen@1759
   197
//        HelpCtx result = instance.getHelpCtx();
quynguyen@1759
   198
//        assertEquals(expResult, result);
quynguyen@1759
   199
//        // TODO review the generated test code and remove the default call to fail.
quynguyen@1759
   200
//        fail("The test case is a prototype.");
quynguyen@1759
   201
//    }
quynguyen@1759
   202
//
quynguyen@1759
   203
//    /**
quynguyen@1759
   204
//     * Test of createCookie method, of class JsfJspDataObject.
quynguyen@1759
   205
//     */
quynguyen@1759
   206
//    public void testCreateCookie() {
quynguyen@1759
   207
//        System.out.println("createCookie");
quynguyen@1759
   208
//        Class klass = null;
quynguyen@1759
   209
//        JsfJspDataObject instance = null;
quynguyen@1759
   210
//        Cookie expResult = null;
quynguyen@1759
   211
//        Cookie result = instance.createCookie(klass);
quynguyen@1759
   212
//        assertEquals(expResult, result);
quynguyen@1759
   213
//        // TODO review the generated test code and remove the default call to fail.
quynguyen@1759
   214
//        fail("The test case is a prototype.");
quynguyen@1759
   215
//    }
quynguyen@1759
   216
//
quynguyen@1759
   217
//    /**
quynguyen@1759
   218
//     * Test of getCookieSet0 method, of class JsfJspDataObject.
quynguyen@1759
   219
//     */
quynguyen@1759
   220
//    public void testGetCookieSet0() {
quynguyen@1759
   221
//        System.out.println("getCookieSet0");
quynguyen@1759
   222
//        JsfJspDataObject instance = null;
quynguyen@1759
   223
//        CookieSet expResult = null;
quynguyen@1759
   224
//        CookieSet result = instance.getCookieSet0();
quynguyen@1759
   225
//        assertEquals(expResult, result);
quynguyen@1759
   226
//        // TODO review the generated test code and remove the default call to fail.
quynguyen@1759
   227
//        fail("The test case is a prototype.");
quynguyen@1759
   228
//    }
quynguyen@1759
   229
//
quynguyen@1759
   230
//
quynguyen@1759
   231
//    /**
quynguyen@1759
   232
//     * Test of getPureCookie method, of class JsfJspDataObject.
quynguyen@1759
   233
//     */
quynguyen@1759
   234
//    public void testGetPureCookie() {
quynguyen@1759
   235
//        System.out.println("getPureCookie");
quynguyen@1759
   236
//        Class clazz = null;
quynguyen@1759
   237
//        JsfJspDataObject instance = null;
quynguyen@1759
   238
//        Cookie expResult = null;
quynguyen@1759
   239
//        Cookie result = instance.getPureCookie(clazz);
quynguyen@1759
   240
//        assertEquals(expResult, result);
quynguyen@1759
   241
//        // TODO review the generated test code and remove the default call to fail.
quynguyen@1759
   242
//        fail("The test case is a prototype.");
quynguyen@1759
   243
//    }
quynguyen@1759
   244
//
quynguyen@1759
   245
//    /**
quynguyen@1759
   246
//     * Test of getCookie method, of class JsfJspDataObject.
quynguyen@1759
   247
//     */
quynguyen@1759
   248
//    public void testGetCookie() {
quynguyen@1759
   249
//        System.out.println("getCookie");
quynguyen@1759
   250
//        Class clazz = null;
quynguyen@1759
   251
//        JsfJspDataObject instance = null;
quynguyen@1759
   252
//        Cookie expResult = null;
quynguyen@1759
   253
//        Cookie result = instance.getCookie(clazz);
quynguyen@1759
   254
//        assertEquals(expResult, result);
quynguyen@1759
   255
//        // TODO review the generated test code and remove the default call to fail.
quynguyen@1759
   256
//        fail("The test case is a prototype.");
quynguyen@1759
   257
//    }
quynguyen@1759
   258
//
quynguyen@1759
   259
//    /**
quynguyen@1759
   260
//     * Test of getFileEncoding method, of class JsfJspDataObject.
quynguyen@1759
   261
//     */
quynguyen@1759
   262
//    public void testGetFileEncoding() {
quynguyen@1759
   263
//        System.out.println("getFileEncoding");
quynguyen@1759
   264
//        JsfJspDataObject instance = null;
quynguyen@1759
   265
//        String expResult = "";
quynguyen@1759
   266
//        String result = instance.getFileEncoding();
quynguyen@1759
   267
//        assertEquals(expResult, result);
quynguyen@1759
   268
//        // TODO review the generated test code and remove the default call to fail.
quynguyen@1759
   269
//        fail("The test case is a prototype.");
quynguyen@1759
   270
//    }
quynguyen@1759
   271
//
quynguyen@1759
   272
//    /**
quynguyen@1759
   273
//     * Test of updateFileEncoding method, of class JsfJspDataObject.
quynguyen@1759
   274
//     */
quynguyen@1759
   275
//    public void testUpdateFileEncoding() {
quynguyen@1759
   276
//        System.out.println("updateFileEncoding");
quynguyen@1759
   277
//        boolean fromEditor = false;
quynguyen@1759
   278
//        JsfJspDataObject instance = null;
quynguyen@1759
   279
//        instance.updateFileEncoding(fromEditor);
quynguyen@1759
   280
//        // TODO review the generated test code and remove the default call to fail.
quynguyen@1759
   281
//        fail("The test case is a prototype.");
quynguyen@1759
   282
//    }
quynguyen@1759
   283
//
quynguyen@1759
   284
//    /**
quynguyen@1759
   285
//     * Test of pureCopy method, of class JsfJspDataObject.
quynguyen@1759
   286
//     */
quynguyen@1759
   287
//    public void testPureCopy() throws Exception {
quynguyen@1759
   288
//        System.out.println("pureCopy");
quynguyen@1759
   289
//        DataFolder folder = null;
quynguyen@1759
   290
//        JsfJspDataObject instance = null;
quynguyen@1759
   291
//        instance.pureCopy(folder);
quynguyen@1759
   292
//        // TODO review the generated test code and remove the default call to fail.
quynguyen@1759
   293
//        fail("The test case is a prototype.");
quynguyen@1759
   294
//    }
quynguyen@1759
   295
//
quynguyen@1759
   296
//
quynguyen@1759
   297
//    /**
quynguyen@1759
   298
//     * Test of handleDelete method, of class JsfJspDataObject.
quynguyen@1759
   299
//     */
quynguyen@1759
   300
//    public void testHandleDelete() throws Exception {
quynguyen@1759
   301
//        System.out.println("handleDelete");
quynguyen@1759
   302
//        JsfJspDataObject instance = null;
quynguyen@1759
   303
//        instance.handleDelete();
quynguyen@1759
   304
//        // TODO review the generated test code and remove the default call to fail.
quynguyen@1759
   305
//        fail("The test case is a prototype.");
quynguyen@1759
   306
//    }
quynguyen@1759
   307
//
quynguyen@1759
   308
//    /**
quynguyen@1759
   309
//     * Test of handleCreateFromTemplate method, of class JsfJspDataObject.
quynguyen@1759
   310
//     */
quynguyen@1759
   311
//    public void testHandleCreateFromTemplate() throws Exception {
quynguyen@1759
   312
//        System.out.println("handleCreateFromTemplate");
quynguyen@1759
   313
//        DataFolder df = null;
quynguyen@1759
   314
//        String name = "";
quynguyen@1759
   315
//        JsfJspDataObject instance = null;
quynguyen@1759
   316
//        DataObject expResult = null;
quynguyen@1759
   317
//        DataObject result = instance.handleCreateFromTemplate(df, name);
quynguyen@1759
   318
//        assertEquals(expResult, result);
quynguyen@1759
   319
//        // TODO review the generated test code and remove the default call to fail.
quynguyen@1759
   320
//        fail("The test case is a prototype.");
quynguyen@1759
   321
//    }
quynguyen@1759
   322
//
quynguyen@1759
   323
//    /**
quynguyen@1759
   324
//     * Test of handleRename method, of class JsfJspDataObject.
quynguyen@1759
   325
//     */
quynguyen@1759
   326
//    public void testHandleRename() throws Exception {
quynguyen@1759
   327
//        System.out.println("handleRename");
quynguyen@1759
   328
//        String name = "";
quynguyen@1759
   329
//        JsfJspDataObject instance = null;
quynguyen@1759
   330
//        FileObject expResult = null;
quynguyen@1759
   331
//        FileObject result = instance.handleRename(name);
quynguyen@1759
   332
//        assertEquals(expResult, result);
quynguyen@1759
   333
//        // TODO review the generated test code and remove the default call to fail.
quynguyen@1759
   334
//        fail("The test case is a prototype.");
quynguyen@1759
   335
//    }
quynguyen@1759
   336
quynguyen@1759
   337
quynguyen@1759
   338
}