Line 0
Link Here
|
|
|
1 |
/* |
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
3 |
* |
4 |
* Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved. |
5 |
* |
6 |
* Oracle and Java are registered trademarks of Oracle and/or its affiliates. |
7 |
* Other names may be trademarks of their respective owners. |
8 |
* |
9 |
* The contents of this file are subject to the terms of either the GNU |
10 |
* General Public License Version 2 only ("GPL") or the Common |
11 |
* Development and Distribution License("CDDL") (collectively, the |
12 |
* "License"). You may not use this file except in compliance with the |
13 |
* License. You can obtain a copy of the License at |
14 |
* http://www.netbeans.org/cddl-gplv2.html |
15 |
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the |
16 |
* specific language governing permissions and limitations under the |
17 |
* License. When distributing the software, include this License Header |
18 |
* Notice in each file and include the License file at |
19 |
* nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this |
20 |
* particular file as subject to the "Classpath" exception as provided |
21 |
* by Oracle in the GPL Version 2 section of the License file that |
22 |
* accompanied this code. If applicable, add the following below the |
23 |
* License Header, with the fields enclosed by brackets [] replaced by |
24 |
* your own identifying information: |
25 |
* "Portions Copyrighted [year] [name of copyright owner]" |
26 |
* |
27 |
* Contributor(s): |
28 |
* |
29 |
* The Original Software is NetBeans. The Initial Developer of the Original |
30 |
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun |
31 |
* Microsystems, Inc. All Rights Reserved. |
32 |
* |
33 |
* If you wish your version of this file to be governed by only the CDDL |
34 |
* or only the GPL Version 2, indicate your decision by adding |
35 |
* "[Contributor] elects to include this software in this distribution |
36 |
* under the [CDDL or GPL Version 2] license." If you do not indicate a |
37 |
* single choice of license, a recipient has the option to distribute |
38 |
* your version of this file under either the CDDL, the GPL Version 2 or |
39 |
* to extend the choice of license to its licensees as provided above. |
40 |
* However, if you add GPL Version 2 code and therefore, elected the GPL |
41 |
* Version 2 license, then the option applies only if the new code is |
42 |
* made subject to such option by the copyright holder. |
43 |
*/ |
44 |
package org.netbeans.modules.versioning.core.spi; |
45 |
|
46 |
import java.io.IOException; |
47 |
import org.openide.filesystems.FileStateInvalidException; |
48 |
|
49 |
import java.io.File; |
50 |
import org.netbeans.api.queries.CollocationQuery; |
51 |
import org.netbeans.junit.NbTestCase; |
52 |
import org.netbeans.modules.versioning.spi.testvcs.TestVCS; |
53 |
import org.netbeans.modules.versioning.spi.testvcs.TestVCSCollocationQuery; |
54 |
import org.openide.util.test.MockLookup; |
55 |
|
56 |
/** |
57 |
* Versioning SPI unit tests of VCSVisibilityQuery. |
58 |
* |
59 |
* @author Tomas Stupka |
60 |
*/ |
61 |
public class VCSCollocationQueryTest extends NbTestCase { |
62 |
|
63 |
|
64 |
public VCSCollocationQueryTest(String testName) { |
65 |
super(testName); |
66 |
MockLookup.setLayersAndInstances(); |
67 |
} |
68 |
|
69 |
protected void setUp() throws Exception { |
70 |
MockLookup.setLayersAndInstances(); |
71 |
File userdir = new File(getWorkDir() + "userdir"); |
72 |
userdir.mkdirs(); |
73 |
System.setProperty("netbeans.user", userdir.getAbsolutePath()); |
74 |
super.setUp(); |
75 |
} |
76 |
|
77 |
public void testFindRootExisting() throws FileStateInvalidException, IOException, Exception { |
78 |
File folder = createVersionedFolder(); |
79 |
folder.mkdirs(); |
80 |
File file = new File(folder, "somefile"); |
81 |
file.createNewFile(); |
82 |
|
83 |
assertRoot(folder, file); |
84 |
} |
85 |
|
86 |
public void testFindRootNotExisting() throws FileStateInvalidException, IOException, Exception { |
87 |
File folder = createVersionedFolder(); |
88 |
File file = new File(folder, "dontexist"); |
89 |
assertRoot(folder, file); |
90 |
} |
91 |
|
92 |
public void testFindRootBogusFile() throws FileStateInvalidException, IOException, Exception { |
93 |
assertNull(CollocationQuery.findRoot(new File("/a/b/c").toURI())); |
94 |
} |
95 |
|
96 |
private void assertRoot(File root, File file) { |
97 |
assertEquals(root.toURI(), CollocationQuery.findRoot(file.toURI())); |
98 |
} |
99 |
|
100 |
public void testAreCollocatedExisting() throws FileStateInvalidException, IOException, Exception { |
101 |
File folder = createVersionedFolder(); |
102 |
|
103 |
File file1 = new File(folder, "file2" + TestVCSCollocationQuery.COLLOCATED_FILENAME_SUFFIX); |
104 |
file1.createNewFile(); |
105 |
File file2 = new File(folder, "file1" + TestVCSCollocationQuery.COLLOCATED_FILENAME_SUFFIX); |
106 |
file2.createNewFile(); |
107 |
|
108 |
assertCollocated(true, file1, file2); |
109 |
} |
110 |
|
111 |
public void testAreCollocatedNotExisting() throws FileStateInvalidException, IOException, Exception { |
112 |
File folder = createVersionedFolder(); |
113 |
|
114 |
File file1 = new File(folder, "file2" + TestVCSCollocationQuery.COLLOCATED_FILENAME_SUFFIX); |
115 |
file1.createNewFile(); |
116 |
File file2 = new File(folder, "file1" + TestVCSCollocationQuery.COLLOCATED_FILENAME_SUFFIX); |
117 |
file2.createNewFile(); |
118 |
|
119 |
assertCollocated(true, file1, file2); |
120 |
} |
121 |
|
122 |
|
123 |
public void testNotCollocatedExisting() throws FileStateInvalidException, IOException, Exception { |
124 |
File folder = createVersionedFolder(); |
125 |
|
126 |
File file1 = new File(folder, "file1"); |
127 |
file1.createNewFile(); |
128 |
File file2 = new File(folder, "file2"); |
129 |
file2.createNewFile(); |
130 |
|
131 |
assertCollocated(false, file1, file2); |
132 |
} |
133 |
|
134 |
public void testNotCollocatedNotExisting() throws FileStateInvalidException, IOException, Exception { |
135 |
File folder = createVersionedFolder(); |
136 |
|
137 |
File file1 = new File(folder, "file1"); |
138 |
file1.createNewFile(); |
139 |
File file2 = new File(folder, "file2"); |
140 |
file2.createNewFile(); |
141 |
|
142 |
assertCollocated(false, file1, file2); |
143 |
} |
144 |
|
145 |
void assertCollocated(boolean expected, File file1, File file2) { |
146 |
if(expected) { |
147 |
assertTrue(CollocationQuery.areCollocated(file1.toURI(), file2.toURI())); |
148 |
} else { |
149 |
assertFalse(CollocationQuery.areCollocated(file1.toURI(), file2.toURI())); |
150 |
} |
151 |
} |
152 |
|
153 |
private File createVersionedFolder() throws IOException { |
154 |
File folder = new File(getWorkDir(), TestVCS.VERSIONED_FOLDER_SUFFIX); |
155 |
new File(folder, TestVCS.TEST_VCS_METADATA).mkdirs(); |
156 |
return folder; |
157 |
} |
158 |
|
159 |
} |