001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Michael Danilov
019: * @version $Revision$
020: */package java.awt.datatransfer;
021:
022: import java.util.*;
023:
024: import junit.framework.TestCase;
025:
026: public class SystemFlavorMapTest extends TestCase {
027:
028: public final void testIsJavaMIMEType() {
029: assertTrue(SystemFlavorMap
030: .isJavaMIMEType("org.apache.harmony.awt.datatransfer:"));
031: assertFalse(SystemFlavorMap.isJavaMIMEType("JAVA"));
032: assertFalse(SystemFlavorMap.isJavaMIMEType(null));
033: }
034:
035: public final void testEncodeJavaMIMEType() {
036: assertEquals(SystemFlavorMap.encodeJavaMIMEType("z"),
037: "org.apache.harmony.awt.datatransfer:z");
038: assertNull(SystemFlavorMap.encodeJavaMIMEType(null));
039: }
040:
041: public final void testDecodeJavaMIMEType() {
042: }
043:
044: public final void testEncodeDataFlavor() {
045: assertEquals(SystemFlavorMap
046: .encodeDataFlavor(DataFlavor.stringFlavor),
047: "org.apache.harmony.awt.datatransfer:"
048: + "application/x-java-serialized-object;"
049: + " class=\"java.lang.String\"");
050: assertNull(SystemFlavorMap.encodeDataFlavor(null));
051: }
052:
053: public final void testDecodeDataFlavor() {
054: try {
055: assertEquals(
056: SystemFlavorMap
057: .decodeDataFlavor("org.apache.harmony.awt.datatransfer:"
058: + "application/x-java-serialized-object;"
059: + " class=\"java.lang.String\""),
060: DataFlavor.stringFlavor);
061: assertNull(SystemFlavorMap.decodeDataFlavor(null));
062: assertNull(SystemFlavorMap.decodeDataFlavor("z"));
063: } catch (ClassNotFoundException e) {
064: fail();
065: }
066:
067: try {
068: assertEquals(
069: SystemFlavorMap
070: .decodeDataFlavor("org.apache.harmony.awt.datatransfer"
071: + ":application/x-java-serialized-object; class=Ing"),
072: DataFlavor.stringFlavor);
073: fail();
074: } catch (ClassNotFoundException e) {
075: assertTrue(true);
076: }
077: }
078:
079: public final void testGetDefaultFlavorMap() {
080: FlavorMap map = SystemFlavorMap.getDefaultFlavorMap();
081:
082: assertTrue(map.getFlavorsForNatives(null).size() > 0);
083: assertTrue(map.getNativesForFlavors(null).size() > 0);
084: }
085:
086: public final void testGetFlavorsForNative() {
087: SystemFlavorMap map = (SystemFlavorMap) SystemFlavorMap
088: .getDefaultFlavorMap();
089: List<DataFlavor> list;
090:
091: map.addFlavorForUnencodedNative("1nat1", new DataFlavor(
092: "1data1/flavor", "flav1"));
093: map.addFlavorForUnencodedNative("1nat1", new DataFlavor(
094: "1data2/flavor", "flav2"));
095: map.addFlavorForUnencodedNative("1nat2", new DataFlavor(
096: "1data3/flavor", "flav3"));
097: map.addFlavorForUnencodedNative("1nat2", new DataFlavor(
098: "1data4/flavor", "flav4"));
099:
100: list = map.getFlavorsForNative("1nat1");
101: assertTrue(list.size() == 2);
102: assertTrue(list.contains(new DataFlavor("1data1/flavor",
103: "flav1")));
104: assertTrue(list.contains(new DataFlavor("1data2/flavor",
105: "flav2")));
106:
107: list = map.getFlavorsForNative(null);
108: assertTrue(list.size() >= 4);
109: assertTrue(list.contains(new DataFlavor("1data1/flavor",
110: "flav1")));
111: assertTrue(list.contains(new DataFlavor("1data2/flavor",
112: "flav2")));
113: assertTrue(list.contains(new DataFlavor("1data3/flavor",
114: "flav3")));
115: assertTrue(list.contains(new DataFlavor("1data4/flavor",
116: "flav4")));
117: }
118:
119: public final void testGetNativesForFlavor() {
120: SystemFlavorMap map = (SystemFlavorMap) SystemFlavorMap
121: .getDefaultFlavorMap();
122: List<String> list;
123:
124: map.addUnencodedNativeForFlavor(new DataFlavor("2data1/flavor",
125: "flav1"), "2nat1");
126: map.addUnencodedNativeForFlavor(new DataFlavor("2data1/flavor",
127: "flav1"), "2nat2");
128: map.addUnencodedNativeForFlavor(new DataFlavor("2data2/flavor",
129: "flav2"), "2nat3");
130: map.addUnencodedNativeForFlavor(new DataFlavor("2data2/flavor",
131: "flav2"), "2nat4");
132:
133: list = map.getNativesForFlavor(new DataFlavor("2data1/flavor",
134: "flav1"));
135: assertTrue(list.size() == 2);
136: assertTrue(list.contains("2nat1"));
137: assertTrue(list.contains("2nat2"));
138:
139: list = map.getNativesForFlavor(null);
140: assertTrue(list.size() >= 4);
141: assertTrue(list.contains("2nat1"));
142: assertTrue(list.contains("2nat2"));
143: assertTrue(list.contains("2nat3"));
144: assertTrue(list.contains("2nat4"));
145: }
146:
147: public final void testGetFlavorsForNatives() {
148: SystemFlavorMap map = (SystemFlavorMap) SystemFlavorMap
149: .getDefaultFlavorMap();
150: Map<String, DataFlavor> submap;
151:
152: map.addFlavorForUnencodedNative("3nat1", new DataFlavor(
153: "3data1/flavor", "flav1"));
154: map.addFlavorForUnencodedNative("3nat1", new DataFlavor(
155: "3data2/flavor", "flav2"));
156: map.addFlavorForUnencodedNative("3nat2", new DataFlavor(
157: "3data3/flavor", "flav3"));
158: map.addFlavorForUnencodedNative("3nat2", new DataFlavor(
159: "3data4/flavor", "flav4"));
160:
161: submap = map.getFlavorsForNatives(new String[] { "3nat1" });
162: assertTrue(submap.keySet().size() == 1);
163: assertEquals(submap.get("3nat1"), new DataFlavor(
164: "3data1/flavor", "flav1"));
165:
166: submap = map.getFlavorsForNatives(null);
167: assertTrue(submap.keySet().size() >= 2);
168: assertEquals(submap.get("3nat1"), new DataFlavor(
169: "3data1/flavor", "flav1"));
170: assertEquals(submap.get("3nat2"), new DataFlavor(
171: "3data3/flavor", "flav3"));
172: }
173:
174: public final void testGetNativesForFlavors() {
175: SystemFlavorMap map = (SystemFlavorMap) SystemFlavorMap
176: .getDefaultFlavorMap();
177: Map<DataFlavor, String> submap;
178:
179: map.addUnencodedNativeForFlavor(new DataFlavor("4data1/flavor",
180: "flav1"), "4nat1");
181: map.addUnencodedNativeForFlavor(new DataFlavor("4data1/flavor",
182: "flav1"), "4nat2");
183: map.addUnencodedNativeForFlavor(new DataFlavor("4data2/flavor",
184: "flav2"), "4nat3");
185: map.addUnencodedNativeForFlavor(new DataFlavor("4data2/flavor",
186: "flav2"), "4nat4");
187:
188: submap = map
189: .getNativesForFlavors(new DataFlavor[] { new DataFlavor(
190: "4data1/flavor", "flav1") });
191: assertTrue(submap.keySet().size() == 1);
192: assertEquals(submap.get(new DataFlavor("4data1/flavor",
193: "4flav1")), "4nat1");
194:
195: submap = map.getNativesForFlavors(null);
196: assertTrue(submap.keySet().size() >= 2);
197: assertEquals(submap
198: .get(new DataFlavor("4data1/flavor", "flav1")), "4nat1");
199: assertEquals(submap
200: .get(new DataFlavor("4data2/flavor", "flav2")), "4nat3");
201: }
202:
203: public final void testAddUnencodedNativeForFlavor() {
204: SystemFlavorMap map = (SystemFlavorMap) SystemFlavorMap
205: .getDefaultFlavorMap();
206: List<String> list;
207:
208: map.addUnencodedNativeForFlavor(new DataFlavor("5data1/flavor",
209: "flav1"), "5nat1");
210: map.addUnencodedNativeForFlavor(new DataFlavor("5data1/flavor",
211: "flav1"), "5nat2");
212: map.addUnencodedNativeForFlavor(new DataFlavor("5data1/flavor",
213: "flav1"), "5nat2");
214:
215: list = map.getNativesForFlavor(new DataFlavor("5data1/flavor",
216: "flav1"));
217: assertTrue(list.size() == 2);
218: assertTrue(list.contains("5nat1"));
219: assertTrue(list.contains("5nat2"));
220: }
221:
222: public final void testAddFlavorForUnencodedNative() {
223: SystemFlavorMap map = (SystemFlavorMap) SystemFlavorMap
224: .getDefaultFlavorMap();
225: List<DataFlavor> list;
226:
227: map.addFlavorForUnencodedNative("6nat1", new DataFlavor(
228: "6data1/flavor", "flav1"));
229: map.addFlavorForUnencodedNative("6nat1", new DataFlavor(
230: "6data2/flavor", "flav2"));
231: map.addFlavorForUnencodedNative("6nat1", new DataFlavor(
232: "6data2/flavor", "flav2"));
233:
234: list = map.getFlavorsForNative("6nat1");
235: assertTrue(list.size() == 2);
236: assertTrue(list.contains(new DataFlavor("6data1/flavor",
237: "flav1")));
238: assertTrue(list.contains(new DataFlavor("6data2/flavor",
239: "flav2")));
240: }
241:
242: public final void testSetNativesForFlavor() {
243: SystemFlavorMap map = (SystemFlavorMap) SystemFlavorMap
244: .getDefaultFlavorMap();
245: List<String> list;
246:
247: map.addUnencodedNativeForFlavor(new DataFlavor("7data1/flavor",
248: "flav1"), "77nat1");
249: map.setNativesForFlavor(
250: new DataFlavor("7data1/flavor", "flav1"), new String[] {
251: "7nat10", "7nat11" });
252:
253: list = map.getNativesForFlavor(new DataFlavor("7data1/flavor",
254: "flav1"));
255: assertTrue(list.size() == 2);
256: assertTrue(list.contains("7nat10"));
257: assertTrue(list.contains("7nat11"));
258: }
259:
260: public final void testSetFlavorsForNative() {
261: SystemFlavorMap map = (SystemFlavorMap) SystemFlavorMap
262: .getDefaultFlavorMap();
263: List<DataFlavor> list;
264:
265: map.addFlavorForUnencodedNative("8nat1", new DataFlavor(
266: "88data1/flavor", "flav1"));
267: map.setFlavorsForNative("8nat1", new DataFlavor[] {
268: new DataFlavor("8data10/flavor", "flav1"),
269: new DataFlavor("8data11/flavor", "flav1") });
270:
271: list = map.getFlavorsForNative("8nat1");
272: assertTrue(list.size() == 2);
273: assertTrue(list.contains(new DataFlavor("8data10/flavor",
274: "flav1")));
275: assertTrue(list.contains(new DataFlavor("8data11/flavor",
276: "flav1")));
277: }
278:
279: }
|