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: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.apisupport.project.layers;
043:
044: import java.io.IOException;
045: import junit.framework.Assert;
046: import org.netbeans.api.xml.services.UserCatalog;
047: import org.netbeans.junit.NbTestCase;
048: import org.openide.util.Lookup;
049: import org.openide.util.lookup.Lookups;
050: import org.openide.util.lookup.ProxyLookup;
051: import org.xml.sax.EntityResolver;
052: import org.xml.sax.InputSource;
053: import org.xml.sax.SAXException;
054:
055: /**
056: * Superclass for tests that work with XML layers.
057: * Does some setup, since TAX requires some special infrastructure.
058: * @author Jesse Glick
059: * @see "#62363"
060: */
061: public abstract class LayerTestBase extends NbTestCase {
062:
063: public static final class Lkp extends ProxyLookup {
064: // Copied from org.netbeans.api.project.TestUtil:
065: static {
066: // XXX replace with MockServices
067: System.setProperty("org.openide.util.Lookup", Lkp.class
068: .getName());
069: Assert.assertEquals(Lkp.class, Lookup.getDefault()
070: .getClass());
071: }
072: private static Lkp DEFAULT;
073:
074: public Lkp() {
075: Assert.assertNull(DEFAULT);
076: DEFAULT = this ;
077: setLookup(new Object[0]);
078: }
079:
080: public static void setLookup(Object[] instances) {
081: ClassLoader l = Lkp.class.getClassLoader();
082: DEFAULT
083: .setLookups(new Lookup[] {
084: Lookups.fixed(instances),
085: Lookups.metaInfServices(l),
086: Lookups.singleton(l), });
087: }
088: }
089:
090: protected LayerTestBase(String name) {
091: super (name);
092: }
093:
094: protected void setUp() throws Exception {
095: super .setUp();
096: clearWorkDir();
097: Lkp.setLookup(new Object[] { new TestCatalog(), });
098: }
099:
100: /**
101: * In the actual IDE, the default NetBeans Catalog will already be "mounted", so just for testing:
102: */
103: private static final class TestCatalog extends UserCatalog
104: implements EntityResolver {
105:
106: public TestCatalog() {
107: }
108:
109: public EntityResolver getEntityResolver() {
110: return this ;
111: }
112:
113: public InputSource resolveEntity(String publicId,
114: String systemId) throws SAXException, IOException {
115: if ("-//NetBeans//DTD Filesystem 1.1//EN".equals(publicId)) {
116: return new InputSource(
117: LayerTestBase.class
118: .getClassLoader()
119: .getResource(
120: "org/openide/filesystems/filesystem1_1.dtd")
121: .toExternalForm());
122: } else if ("-//NetBeans//DTD Filesystem 1.0//EN"
123: .equals(publicId)) {
124: return new InputSource(
125: LayerTestBase.class
126: .getClassLoader()
127: .getResource(
128: "org/openide/filesystems/filesystem.dtd")
129: .toExternalForm());
130: } else {
131: return null;
132: }
133: }
134:
135: }
136:
137: }
|