1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package ifc.datatransfer;
25 
26 import lib.MultiMethodTest;
27 
28 import com.sun.star.datatransfer.XMimeContentType;
29 import com.sun.star.datatransfer.XMimeContentTypeFactory;
30 
31 /**
32 * Testing <code>com.sun.star.datatransfer.XMimeContentTypeFactory</code>
33 * interface methods :
34 * <ul>
35 *  <li><code> createMimeContentType()</code></li>
36 * </ul> <p>
37 * Test is multithread compilant. <p>
38 * @see com.sun.star.datatransfer.XMimeContentTypeFactory
39 */
40 public class _XMimeContentTypeFactory extends MultiMethodTest {
41 
42     public XMimeContentTypeFactory oObj = null;
43 
44     /**
45     * First tries to create 'image/jpeg' MIME type and checks that
46     * valid <code>XMimeContentType</code> object was created.
47     * Second tries to create type with wrong argument and exception
48     * throwing is checked. <p>
49     * Has <b>OK</b> status if in the first case valid object is
50     * returned and in the second case <code>IllegalArgumentException</code>
51     * was thrown.
52     */
_createMimeContentType()53     public void _createMimeContentType() {
54         boolean result = true ;
55 		XMimeContentType type = null;
56 
57         try {
58             type = oObj.createMimeContentType("image/jpeg") ;
59 
60             if (type != null) {
61                 String typeS = type.getFullMediaType() ;
62 
63                 log.println("MediaType = '" + type.getMediaType() + "'") ;
64                 log.println("MediaSubType = '" + type.getMediaSubtype() + "'") ;
65                 log.println("FullMediaType = '" + typeS + "'") ;
66 
67                 result = "image/jpeg".equals(typeS) ;
68             } else {
69                 log.println("!!! Null was returned !!!") ;
70                 result = false ;
71             }
72         } catch (com.sun.star.lang.IllegalArgumentException e) {
73             log.println("Exception occured : " ) ;
74             e.printStackTrace(log) ;
75             result = false ;
76         }
77 
78         try {
79             type = oObj.createMimeContentType("nosuchtype") ;
80 
81             log.println("!!! No exception was thrown on wrong MIME type !!!") ;
82             result = false ;
83         } catch (com.sun.star.lang.IllegalArgumentException e) {
84             log.println("Right exception was thrown." ) ;
85         }
86 
87         tRes.tested("createMimeContentType()", result) ;
88     }
89 }
90 
91 
92