|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.modules.editor.java; import java.io.File; import java.net.URI; import org.netbeans.editor.ext.DataAccessor; import org.netbeans.editor.ext.java.DAFileProvider; import org.netbeans.editor.ext.java.JCFileProvider; import org.openide.filesystems.FileObject; import org.openide.filesystems.FileSystem; import org.openide.filesystems.LocalFileSystem; import org.openide.filesystems.Repository; /** * Utilities for accessing input data for tests. It mounts * test/unit/src/org/netbeans/modules/editor/java/data folder * as local FS and make its subfolders accessible for you in tests. * Call setupData() in test's setUp() and cleanupData() in test's tearDown(). * Then you can you rest of the utility methods. * * @autor David Konecny */ public final class TestUtils { private static LocalFileSystem lfs; private static FileObject dummySkeleton; /** Returns FO for test/unit/src/org/netbeans/modules/editor/java/data */ public static synchronized FileObject getDataFolder() { if (lfs == null) { return null; } return lfs.getRoot(); } /** Returns FS with root test/unit/src/org/netbeans/modules/editor/java/data */ public static synchronized FileSystem getDataFilesystem() { return lfs; } /** Returns folder where parserDB can be generated. */ public static synchronized FileObject getPdbFolder() { return getDataFolder().getFileObject("parserDBs"); } /** Returns empty PDB file. Used from ParserDBQueryImpl. */ public static synchronized FileObject getDummyPdbFile() { return dummySkeleton; } /** Get JCStorage of parserDB for tests. */ public static synchronized JCStorage getStorage() { return JCStorage.getStorage(); } public static synchronized void setupData() throws Exception { // mount root of the testing data as localFS so that FileUtil.fromFile works File f = new File(URI.create(TestUtils.class.getResource("data").toExternalForm())); lfs = new LocalFileSystem(); lfs.setRootDirectory(f); Repository.getDefault().addFileSystem(lfs); FileObject pdbFolder = getPdbFolder(); if (pdbFolder == null) { pdbFolder = getDataFolder().createFolder("parserDBs"); } dummySkeleton = getDataFolder().getFileObject("dummy", JCFileProvider.SKEL_FILE_EXT); if (dummySkeleton == null) { FileObject skels; FileObject bodies; try { skels = getDataFolder().createData("dummy", JCFileProvider.SKEL_FILE_EXT); //NOI18N bodies = getDataFolder().createData("dummy", JCFileProvider.BODY_FILE_EXT); //NOI18N } catch (Exception e) { throw new RuntimeException(e); } JCFileProvider fp = new DAFileProvider((DataAccessor) new FileObjectAccessor(skels), (DataAccessor) new FileObjectAccessor(bodies)); fp.reset(); dummySkeleton = skels; } } public static synchronized void cleanupData() throws Exception { FileObject pdbFolder = getPdbFolder(); /* JCStorageElement elms[] = getStorage().getElements(); for (int i=0; i |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.