KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > project > ant > AntBasedProjectFactorySingletonTest


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.project.ant;
21
22 import java.lang.reflect.Method JavaDoc;
23 import org.netbeans.api.project.Project;
24 import org.netbeans.api.project.ProjectManager;
25 import org.netbeans.api.project.TestUtil;
26 import org.netbeans.junit.NbTestCase;
27 import org.netbeans.spi.project.support.ant.AntBasedProjectType;
28 import org.netbeans.spi.project.support.ant.AntBasedTestUtil;
29 import org.netbeans.spi.project.support.ant.AntProjectHelper;
30 import org.netbeans.spi.project.support.ant.AntProjectHelperTest;
31 import org.openide.filesystems.FileObject;
32 import org.openide.util.lookup.Lookups;
33
34 /**
35  *
36  * @author Jan Lahoda
37  */

38 public class AntBasedProjectFactorySingletonTest extends NbTestCase {
39     
40     public AntBasedProjectFactorySingletonTest(String JavaDoc testName) {
41         super(testName);
42     }
43
44     private FileObject scratch;
45     private FileObject projdir;
46     
47     protected void setUp() throws Exception JavaDoc {
48         scratch = TestUtil.makeScratchDir(this);
49         projdir = scratch.createFolder("proj");
50         TestUtil.createFileFromContent(AntProjectHelperTest.class.getResource("data/project.xml"), projdir, "nbproject/project.xml");
51         TestUtil.createFileFromContent(AntProjectHelperTest.class.getResource("data/private.xml"), projdir, "nbproject/private/private.xml");
52         TestUtil.createFileFromContent(AntProjectHelperTest.class.getResource("data/project.properties"), projdir, "nbproject/project.properties");
53         TestUtil.createFileFromContent(AntProjectHelperTest.class.getResource("data/private.properties"), projdir, "nbproject/private/private.properties");
54         TestUtil.createFileFromContent(AntProjectHelperTest.class.getResource("data/global.properties"), scratch, "userdir/build.properties");
55         TestUtil.setLookup(new Object JavaDoc[] {
56             AntBasedTestUtil.testAntBasedProjectType(),
57         });
58     }
59
60     /**Test for second part of #42738.
61      */

62     public void testAntBasedProjectTypesChanged() throws Exception JavaDoc {
63         AntBasedProjectFactorySingleton factory = new AntBasedProjectFactorySingleton();
64         AntBasedProjectType type1 = AntBasedTestUtil.testAntBasedProjectType();
65         AntBasedProjectType type2 = AntBasedTestUtil.testAntBasedProjectType();
66         
67         TestUtil.setLookup(Lookups.fixed(new Object JavaDoc[] {
68             factory,
69             type1,
70             type2,
71         }));
72         
73         Method JavaDoc getAntBasedProjectTypeMethod = AntProjectHelper.class.getDeclaredMethod("getType", new Class JavaDoc[0]);
74         
75         getAntBasedProjectTypeMethod.setAccessible(true);
76         
77         Project p = ProjectManager.getDefault().findProject(projdir);
78         AntProjectHelper helper = p.getLookup().lookup(AntProjectHelper.class);
79         
80         assertTrue(getAntBasedProjectTypeMethod.invoke(helper) == type2);
81         
82         TestUtil.setLookup(Lookups.fixed(new Object JavaDoc[] {
83             factory,
84             type1,
85         }));
86         
87         p = ProjectManager.getDefault().findProject(projdir);
88         helper = p.getLookup().lookup(AntProjectHelper.class);
89         
90         assertTrue(getAntBasedProjectTypeMethod.invoke(helper) == type1);
91         
92         TestUtil.setLookup(Lookups.fixed(new Object JavaDoc[] {
93             factory,
94             type2,
95         }));
96         
97         p = ProjectManager.getDefault().findProject(projdir);
98         helper = p.getLookup().lookup(AntProjectHelper.class);
99         
100         assertTrue(getAntBasedProjectTypeMethod.invoke(helper) == type2);
101         
102         TestUtil.setLookup(Lookups.fixed(new Object JavaDoc[] {
103             factory,
104         }));
105         
106         assertNull(ProjectManager.getDefault().findProject(projdir));
107
108         TestUtil.setLookup(Lookups.fixed(new Object JavaDoc[] {
109             factory,
110             type1,
111             type2,
112         }));
113         
114         assertTrue(getAntBasedProjectTypeMethod.invoke(helper) == type2);
115     }
116     
117 }
118
Popular Tags