01: /*
02: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
03: *
04: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
05: *
06: * The contents of this file are subject to the terms of either the GNU
07: * General Public License Version 2 only ("GPL") or the Common
08: * Development and Distribution License("CDDL") (collectively, the
09: * "License"). You may not use this file except in compliance with the
10: * License. You can obtain a copy of the License at
11: * http://www.netbeans.org/cddl-gplv2.html
12: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13: * specific language governing permissions and limitations under the
14: * License. When distributing the software, include this License Header
15: * Notice in each file and include the License file at
16: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17: * particular file as subject to the "Classpath" exception as provided
18: * by Sun in the GPL Version 2 section of the License file that
19: * accompanied this code. If applicable, add the following below the
20: * License Header, with the fields enclosed by brackets [] replaced by
21: * your own identifying information:
22: * "Portions Copyrighted [year] [name of copyright owner]"
23: *
24: * Contributor(s):
25: *
26: * The Original Software is NetBeans. The Initial Developer of the Original
27: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28: * Microsystems, Inc. All Rights Reserved.
29: *
30: * If you wish your version of this file to be governed by only the CDDL
31: * or only the GPL Version 2, indicate your decision by adding
32: * "[Contributor] elects to include this software in this distribution
33: * under the [CDDL or GPL Version 2] license." If you do not indicate a
34: * single choice of license, a recipient has the option to distribute
35: * your version of this file under either the CDDL, the GPL Version 2 or
36: * to extend the choice of license to its licensees as provided above.
37: * However, if you add GPL Version 2 code and therefore, elected the GPL
38: * Version 2 license, then the option applies only if the new code is
39: * made subject to such option by the copyright holder.
40: */
41:
42: package org.netbeans.api.project;
43:
44: import java.net.URL;
45: import java.util.Date;
46: import org.netbeans.junit.NbTestCase;
47: import org.openide.filesystems.FileObject;
48: import org.openide.filesystems.FileUtil;
49: import org.openide.util.Lookup;
50: import org.openide.util.lookup.Lookups;
51:
52: /**
53: * Test functionality of TestUtil.
54: * @author Jesse Glick
55: */
56: public class TestUtilTest extends NbTestCase {
57:
58: public TestUtilTest(String name) {
59: super (name);
60: }
61:
62: public void testCreateFileFromContent() throws Exception {
63: URL content = TestUtilTest.class
64: .getResource("TestUtilTest.class");
65: assertNotNull("have TestUtilTest.class", content);
66: int length = content.openConnection().getContentLength();
67: assertTrue("have some length", length > 0);
68: FileObject scratch = TestUtil.makeScratchDir(this );
69: assertTrue("scratch is a dir", scratch.isFolder());
70: assertEquals("scratch is empty", 0,
71: scratch.getChildren().length);
72: FileObject a = TestUtil.createFileFromContent(content, scratch,
73: "d/a");
74: assertTrue("a is a file", a.isData());
75: assertEquals("right path", "d/a", FileUtil.getRelativePath(
76: scratch, a));
77: assertEquals("right length", length, (int) a.getSize());
78: FileObject b = TestUtil.createFileFromContent(null, scratch,
79: "d2/b");
80: assertTrue("b is a file", b.isData());
81: assertEquals("right path", "d2/b", FileUtil.getRelativePath(
82: scratch, b));
83: assertEquals("b is empty", 0, (int) b.getSize());
84: Date created = b.lastModified();
85: Thread.sleep(1500); // Unix has coarse timestamp marking
86: assertEquals("got same b back", b, TestUtil
87: .createFileFromContent(null, scratch, "d2/b"));
88: Date modified = b.lastModified();
89: assertTrue("touched and changed timestamp", modified
90: .after(created));
91: }
92:
93: }
|