|
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-2000 Sun * Microsystems, Inc. All Rights Reserved. */ package org.openide.loaders; import org.openide.filesystems.*; import org.openide.loaders.*; import java.beans.*; import junit.textui.TestRunner; import org.netbeans.junit.*; /* * This class tests the basic functionality of standard DataObjects - Instance, * Settings, Default, Folder and Shadow. * @author js104452 */ public class BasicDataObjectTest extends NbTestCase { /** Creates new BasicDataObjectTest */ public BasicDataObjectTest(String name) { super(name); } // For each test setup a FileSystem and DataObjects protected void setUp() throws Exception { TestUtilHid.destroyLocalFileSystem (getName()); lfs = TestUtilHid.createLocalFileSystem (getName(), fsstruct); Repository.getDefault ().addFileSystem (lfs); subDir = lfs.findResource("/Dir/SubDir"); dir = lfs.findResource("/Dir"); do1 = DataObject.find(subDir); do2 = DataObject.find(dir); df1 = DataFolder.findFolder(subDir); df2 = DataFolder.findFolder(dir); } //Clear all stuff when the test finish protected void tearDown() throws Exception { TestUtilHid.destroyLocalFileSystem (getName()); } public void testDirectCallToDataObjectContructorIsNotAllowed () throws Exception { try { LocalFileSystem lfs = new LocalFileSystem (); new MultiDataObject (lfs.getRoot(), DataLoaderPool.getFolderLoader ()); fail ("Constructor succeeded, it should not"); } catch (IllegalStateException ex) { // ok, we expect IllegalStateException } } // Test basic functionality of a DataFolder public void testBasicDataFolder() throws Exception { assertTrue("The DataObject.getFolder() method hasn't returned the same Folder as Folder which was created directly from the FileObject.",do1.equals(df1)); assertTrue("The DataObject.getClass() method hasn't returned class org.openide.loaders.DataFolder but "+do1.getClass().toString()+".",do1.getClass().toString().equalsIgnoreCase("class org.openide.loaders.DataFolder")); assertTrue("The DataObject.getNodeDelegate().getCookie(DataObject.getClass()) method hasn't returned the DataFolder itself.",df1.equals(do1.getNodeDelegate().getCookie(do1.getClass()))); assertTrue("The DataObject.getNodeDelegate().getCookie(DataObject.getClass()) method hasn't returned the DataObject itself.",do1.equals(do1.getNodeDelegate().getCookie(do1.getClass()))); assertTrue("The DataObject.getFolder().getPrimaryFile() hasn't returned the same value as the DataObject.getPrimaryFile().getParent() method.",do1.getFolder().getPrimaryFile().equals(do1.getPrimaryFile().getParent())); assertTrue("The DataObject.getName() hasn't returned the proper name but "+do1.getName()+".",do1.getName().equalsIgnoreCase("SubDir")); assertTrue("The DataObject.getLoader() hasn't returned the proper loader class but "+do1.getLoader().getClass().toString()+".",do1.getLoader().getClass().toString().equalsIgnoreCase("class org.openide.loaders.DataLoaderPool$FolderLoader")); assertTrue("Two different DataObjects created on folder have not the same loader.",do1.getLoader().equals(do2.getLoader())); assertTrue("DataObject created on folder has not the same loader as the DataFolder.",do2.getLoader().equals(df1.getLoader()) || df1.getLoader().equals(df2.getLoader())); DataObject[] arr = df1.getChildren(); assertTrue("The DataFolder.getChildren() hasn't returned proper value.",arr.length == 0); boolean hlpBool_1 = do1.isValid(); do1.setValid(!hlpBool_1); boolean hlpBool_2 = (do1.isValid() == !hlpBool_1); assertTrue("The DataObject.setValid() method has not changed the Valid state.", hlpBool_2); hlpBool_2 = (do1.isValid() == df1.isValid()); assertTrue("The DataObject.setValid() method has not changed the Valid state on a DataFolder object created directly from the Folder.", hlpBool_2); } // Test basic functionality of a DataInstance public void testBasicDataInstance() throws Exception { FileObject fo1 = do1.getPrimaryFile().createData("file.instance"); FileObject fo2 = do1.getPrimaryFile().createData("file.settings"); Object nc = do1.getCookie(DataFolder.class); if (nc == null) { fail("FAILED - can't recieave the DataFolder.class Coockie."); } DataFolder df1 = (DataFolder)nc; DataObject[] arr = df1.getChildren(); if (arr.length <= 0 && arr.length > 2) { fail("The DataFolder.getChildren() hasn't returned proper value."); } 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.