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.project.ant;
041:
042: import org.netbeans.modules.project.ant.*;
043: import org.netbeans.modules.project.ant.FileOwnerCollocationQueryImpl;
044: import java.io.File;
045: import java.io.IOException;
046: import org.netbeans.api.project.TestUtil;
047: import org.netbeans.junit.NbTestCase;
048: import org.openide.filesystems.FileObject;
049: import org.openide.filesystems.FileUtil;
050: import org.openide.util.test.MockLookup;
051:
052: /**
053: *
054: * @author mkleint
055: */
056: public class FileOwnerCollocationQueryImplTest extends NbTestCase {
057:
058: public FileOwnerCollocationQueryImplTest(String testName) {
059: super (testName);
060: }
061:
062: private FileObject scratch;
063:
064: @Override
065: protected void setUp() throws Exception {
066: super .setUp();
067: MockLookup.setInstances(TestUtil.testProjectFactory());
068: scratch = TestUtil.makeScratchDir(this );
069: }
070:
071: @Override
072: protected void tearDown() throws Exception {
073: super .tearDown();
074: }
075:
076: /**
077: * Test of findRoot method, of class FileOwnerCollocationQueryImpl.
078: */
079: public void testFindRoot() throws IOException {
080: FileObject root = scratch.createFolder("root");
081: FileObject projdir = root.createFolder("prj1");
082: projdir.createFolder("testproject");
083:
084: //root/prj1/foo
085: FileOwnerCollocationQueryImpl instance = new FileOwnerCollocationQueryImpl();
086: assertEquals(instance.findRoot(FileUtil.toFile(projdir
087: .createData("foo"))), FileUtil.toFile(projdir));
088:
089: //root/prj2/foo/prj3/bar
090: projdir = root.createFolder("prj2");
091: FileObject expected = projdir;
092: projdir.createFolder("testproject");
093: projdir = projdir.createFolder("foo").createFolder("prj3");
094: projdir.createFolder("testproject");
095: assertEquals(instance.findRoot(FileUtil.toFile(projdir
096: .createData("bar"))), FileUtil.toFile(expected));
097:
098: //root
099: assertEquals(instance.findRoot(FileUtil.toFile(root)), null);
100: }
101:
102: /**
103: * Test of areCollocated method, of class FileOwnerCollocationQueryImpl.
104: */
105: public void testAreCollocated() throws IOException {
106: FileObject root = scratch.createFolder("root");
107: FileObject projdir = scratch.createFolder("prj1");
108: projdir.createFolder("testproject");
109: FileObject lib = root.createFolder("libs");
110:
111: File file1 = FileUtil.toFile(lib.createData("pron"));
112: File file2 = FileUtil.toFile(projdir.createData("xxx"));
113: FileOwnerCollocationQueryImpl instance = new FileOwnerCollocationQueryImpl();
114: assertFalse(instance.areCollocated(file1, file2));
115: file1 = FileUtil.toFile(projdir.createData("pron"));
116: assertTrue(instance.areCollocated(file1, file2));
117:
118: file1 = FileUtil.toFile(projdir);
119: file2 = FileUtil.toFile(lib);
120: assertFalse(instance.areCollocated(file1, file2));
121:
122: projdir = root.createFolder("noproj").createFolder("proj1");
123: projdir.createFolder("testproject");
124: FileObject projdir2 = root.createFolder("noproj2")
125: .createFolder("proj2");
126: projdir2.createFolder("testproject");
127: file1 = FileUtil.toFile(projdir.createData("foo"));
128: file2 = FileUtil.toFile(projdir2.createData("bar"));
129: // System.out.println("root1=" + instance.findRoot(file1));
130: // System.out.println("root2=" + instance.findRoot(file2));
131: assertFalse(instance.areCollocated(file1, file2));
132:
133: }
134:
135: }
|