KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > activation > MailcapCommandMapTest


1 /**
2  *
3  * Copyright 2003-2004 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 //
19
// This source code implements specifications defined by the Java
20
// Community Process. In order to remain compliant with the specification
21
// DO NOT add / change / or delete method signatures!
22
//
23
package javax.activation;
24
25 import junit.framework.TestCase;
26
27 /**
28  * @version $Rev$ $Date$
29  */

30 public class MailcapCommandMapTest extends TestCase {
31     private MailcapCommandMap map;
32
33     public void testAdd() {
34         map.addMailcap("foo/bar ;; x-java-view=Foo; x-java-edit=Bar");
35         CommandInfo info = map.getCommand("foo/bar", "view");
36         assertEquals("view", info.getCommandName());
37         assertEquals("Foo", info.getCommandClass());
38         info = map.getCommand("foo/bar", "edit");
39         assertEquals("edit", info.getCommandName());
40         assertEquals("Bar", info.getCommandClass());
41     }
42
43     public void testExplicitWildcard() {
44         map.addMailcap("foo/bar ;; x-java-view=Bar");
45         map.addMailcap("foo/* ;; x-java-view=Star");
46         CommandInfo info = map.getCommand("foo/bar", "view");
47         assertEquals("view", info.getCommandName());
48         assertEquals("Bar", info.getCommandClass());
49         info = map.getCommand("foo/foo", "view");
50         assertEquals("view", info.getCommandName());
51         assertEquals("Star", info.getCommandClass());
52         info = map.getCommand("foo/*", "view");
53         assertEquals("view", info.getCommandName());
54         assertEquals("Star", info.getCommandClass());
55         info = map.getCommand("foo", "view");
56         assertEquals("view", info.getCommandName());
57         assertEquals("Star", info.getCommandClass());
58     }
59
60     public void testImplicitWildcard() {
61         map.addMailcap("foo/bar ;; x-java-view=Bar");
62         map.addMailcap("foo ;; x-java-view=Star");
63         CommandInfo info = map.getCommand("foo/bar", "view");
64         assertEquals("view", info.getCommandName());
65         assertEquals("Bar", info.getCommandClass());
66         info = map.getCommand("foo/foo", "view");
67         assertEquals("view", info.getCommandName());
68         assertEquals("Star", info.getCommandClass());
69         info = map.getCommand("foo", "view");
70         assertEquals("view", info.getCommandName());
71         assertEquals("Star", info.getCommandClass());
72     }
73
74     public void testParameterizedMimeType() {
75         map.addMailcap("foo/bar ;; x-java-view=Bar");
76         CommandInfo info = map.getCommand("foo/bar ; type=\"text/plain\"", "view");
77         assertEquals("view", info.getCommandName());
78         assertEquals("Bar", info.getCommandClass());
79     }
80
81     protected void setUp() throws Exception {
82         super.setUp();
83         map = new MailcapCommandMap();
84     }
85 }
86
Popular Tags