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: package org.netbeans.modules.editor.settings.storage.fontscolors;
042:
043: import java.net.URL;
044: import java.util.Collection;
045: import org.netbeans.api.editor.mimelookup.MimeLookup;
046: import org.netbeans.api.editor.mimelookup.MimePath;
047: import org.netbeans.api.editor.settings.FontColorSettings;
048: import org.netbeans.core.startup.Main;
049: import org.netbeans.junit.NbTestCase;
050: import org.netbeans.modules.editor.settings.storage.EditorSettingsImpl;
051: import org.netbeans.modules.editor.settings.storage.EditorTestLookup;
052: import org.openide.util.Lookup;
053:
054: /**
055: *
056: * @author vita
057: */
058: public class CompositeFCSTest extends NbTestCase {
059:
060: public CompositeFCSTest(String name) {
061: super (name);
062: }
063:
064: protected @Override
065: void setUp() throws Exception {
066: super .setUp();
067:
068: EditorTestLookup
069: .setLookup(
070: new URL[] {
071: getClass()
072: .getClassLoader()
073: .getResource(
074: "org/netbeans/modules/editor/settings/storage/test-layer.xml"),
075: getClass()
076: .getClassLoader()
077: .getResource(
078: "org/netbeans/modules/editor/settings/storage/layer.xml"),
079: getClass()
080: .getClassLoader()
081: .getResource(
082: "org/netbeans/core/resources/mf-layer.xml"), // for MIMEResolverImpl to work
083: }, getWorkDir(), new Object[] {}, getClass()
084: .getClassLoader());
085:
086: // This is here to initialize Nb URL factory (org.netbeans.core.startup),
087: // which is needed by Nb EntityCatalog (org.netbeans.core).
088: // Also see the test dependencies in project.xml
089: Main.initializeURLFactory();
090: }
091:
092: public void testColoringsForMimeType() throws Exception {
093: final String mimeType = "text/x-orig";
094:
095: Lookup lookup = MimeLookup.getLookup(MimePath.parse(mimeType));
096:
097: // Check the API class
098: Collection<? extends FontColorSettings> c = lookup
099: .lookupAll(FontColorSettings.class);
100: assertEquals("Wrong number of fcs", 1, c.size());
101:
102: FontColorSettings fcs = c.iterator().next();
103: assertNotNull("FCS should not be null", fcs);
104: assertTrue("Wrong fcs impl", fcs instanceof CompositeFCS);
105:
106: CompositeFCS compositeFcs = (CompositeFCS) fcs;
107: assertEquals("CompositeFCS using wrong profile",
108: EditorSettingsImpl.DEFAULT_PROFILE,
109: compositeFcs.profile);
110: }
111:
112: public void testColoringsForSpecialTestMimeType() throws Exception {
113: final String origMimeType = "text/x-orig";
114: final String specialTestMimeType = "test123456_" + origMimeType;
115:
116: Lookup lookup = MimeLookup.getLookup(MimePath
117: .parse(specialTestMimeType));
118:
119: // Check the API class
120: Collection<? extends FontColorSettings> c = lookup
121: .lookupAll(FontColorSettings.class);
122: assertEquals("Wrong number of fcs", 1, c.size());
123:
124: FontColorSettings fcs = c.iterator().next();
125: assertNotNull("FCS should not be null", fcs);
126: assertTrue("Wrong fcs impl", fcs instanceof CompositeFCS);
127:
128: CompositeFCS compositeFcs = (CompositeFCS) fcs;
129: assertEquals(
130: "CompositeFCS should be using special test profile",
131: "test123456", compositeFcs.profile);
132: }
133:
134: }
|