KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > ui > wizard > librarydescriptor > DataModelTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.apisupport.project.ui.wizard.librarydescriptor;
21
22 import org.netbeans.api.project.libraries.LibraryManager;
23 import org.netbeans.modules.apisupport.project.NbModuleProject;
24 import org.netbeans.modules.apisupport.project.TestBase;
25 import org.netbeans.modules.apisupport.project.layers.LayerTestBase;
26 import org.netbeans.modules.apisupport.project.layers.LayerUtils;
27 import org.netbeans.modules.project.uiapi.ProjectChooserFactory;
28 import org.openide.WizardDescriptor;
29 import org.openide.WizardDescriptor.Panel;
30 import org.openide.filesystems.FileObject;
31 import org.openide.filesystems.FileSystem;
32 import org.openide.filesystems.FileUtil;
33
34 /**
35  * Tests {@link DataModel}.
36  *
37  * @author Radek Matous
38  */

39 public class DataModelTest extends LayerTestBase {
40     public DataModelTest(String JavaDoc name) {
41         super(name);
42     }
43     
44     protected void setUp() throws Exception JavaDoc {
45         super.setUp();
46         TestBase.initializeBuildProperties(getWorkDir(), getDataDir());
47         LibraryManager lbm = LibraryManager.getDefault();
48     }
49     
50     public void testValidityOfDataModel() throws Exception JavaDoc {
51         NbModuleProject project = TestBase.generateStandaloneModule(getWorkDir(), "module1");
52         WizardDescriptor wd = new WizardDescriptor(new Panel[] {});
53         wd.putProperty(ProjectChooserFactory.WIZARD_KEY_PROJECT, project);
54         NewLibraryDescriptor.DataModel data = new NewLibraryDescriptor.DataModel(wd);
55         
56         assertEquals(project, data.getProject());
57         
58         assertFalse(data.isValidLibraryDisplayName());
59         assertFalse(data.isValidLibraryName());
60         
61         data.setLibraryName("");
62         assertFalse(data.isValidLibraryName());
63
64         data.setLibraryDisplayName("");
65         assertFalse(data.isValidLibraryDisplayName());
66         
67         data.setLibraryName("mylibrary");
68         assertTrue(data.isValidLibraryName());
69
70         data.setLibraryDisplayName("mylibrary is great");
71         assertTrue(data.isValidLibraryDisplayName());
72         
73         
74         assertFalse(data.libraryAlreadyExists());
75         LayerUtils.LayerHandle h = LayerUtils.layerForProject(data.getProject());
76         FileSystem fs = h.layer(true);
77         FileObject fo = FileUtil.createData(fs.getRoot(),CreatedModifiedFilesProvider.getLibraryDescriptorEntryPath(data.getLibraryName()));
78         assertNotNull(fo);
79         assertTrue(data.libraryAlreadyExists());
80     }
81 }
82
83
Popular Tags