1*ef39d40dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*ef39d40dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ef39d40dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ef39d40dSAndrew Rist  * distributed with this work for additional information
6*ef39d40dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ef39d40dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ef39d40dSAndrew Rist  * "License"); you may not use this file except in compliance
9*ef39d40dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*ef39d40dSAndrew Rist  *
11*ef39d40dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*ef39d40dSAndrew Rist  *
13*ef39d40dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ef39d40dSAndrew Rist  * software distributed under the License is distributed on an
15*ef39d40dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ef39d40dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*ef39d40dSAndrew Rist  * specific language governing permissions and limitations
18*ef39d40dSAndrew Rist  * under the License.
19*ef39d40dSAndrew Rist  *
20*ef39d40dSAndrew Rist  *************************************************************/
21*ef39d40dSAndrew Rist 
22*ef39d40dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir package ifc.document;
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import lib.MultiMethodTest;
27cdf0e10cSrcweir import lib.Status;
28cdf0e10cSrcweir import lib.StatusException;
29cdf0e10cSrcweir 
30cdf0e10cSrcweir import com.sun.star.beans.XPropertySet;
31cdf0e10cSrcweir import com.sun.star.document.XStandaloneDocumentInfo;
32cdf0e10cSrcweir import com.sun.star.io.IOException;
33cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
34cdf0e10cSrcweir 
35cdf0e10cSrcweir /**
36cdf0e10cSrcweir * Testing <code>com.sun.star.document.XStandaloneDocumentInfo</code>
37cdf0e10cSrcweir * interface methods. <p>
38cdf0e10cSrcweir * This test needs the following object relations :
39cdf0e10cSrcweir * <ul>
40cdf0e10cSrcweir *  <li> <code>'DOCURL'</code> (of type <code>String</code>):
41cdf0e10cSrcweir *   URL of document which info is loaded.</li>
42cdf0e10cSrcweir * <ul> <p>
43cdf0e10cSrcweir * Test is <b> NOT </b> multithread compilant. <p>
44cdf0e10cSrcweir * @see com.sun.star.document.XStandaloneDocumentInfo
45cdf0e10cSrcweir */
46cdf0e10cSrcweir public class _XStandaloneDocumentInfo extends MultiMethodTest {
47cdf0e10cSrcweir 
48cdf0e10cSrcweir     public XStandaloneDocumentInfo oObj = null;
49cdf0e10cSrcweir     String url = null;
50cdf0e10cSrcweir 
before()51cdf0e10cSrcweir     protected void before() {
52cdf0e10cSrcweir         url = (String)tEnv.getObjRelation("DOCURL");
53cdf0e10cSrcweir         if (url == null) {
54cdf0e10cSrcweir             throw new StatusException
55cdf0e10cSrcweir                 (Status.failed("Relation 'DOCURL' not found"));
56cdf0e10cSrcweir         }
57cdf0e10cSrcweir     }
58cdf0e10cSrcweir 
59cdf0e10cSrcweir     String oldProp = null;
60cdf0e10cSrcweir     String newProp = null;
61cdf0e10cSrcweir     /**
62cdf0e10cSrcweir     * Sets new value of the property 'Author' and calls the method. <p>
63cdf0e10cSrcweir     * Has <b> OK </b> status if no exception occured.
64cdf0e10cSrcweir     */
_storeIntoURL()65cdf0e10cSrcweir     public void _storeIntoURL() {
66cdf0e10cSrcweir         try {
67cdf0e10cSrcweir             oObj.loadFromURL(url);
68cdf0e10cSrcweir             XPropertySet propSet = (XPropertySet)
69cdf0e10cSrcweir                 UnoRuntime.queryInterface(XPropertySet.class, oObj);
70cdf0e10cSrcweir             oldProp = (String)propSet.getPropertyValue("Author");
71cdf0e10cSrcweir             newProp = oldProp + "_";
72cdf0e10cSrcweir             propSet.setPropertyValue("Author", newProp);
73cdf0e10cSrcweir 
74cdf0e10cSrcweir             oObj.storeIntoURL(url);
75cdf0e10cSrcweir             tRes.tested("storeIntoURL()", true);
76cdf0e10cSrcweir         } catch (IOException e) {
77cdf0e10cSrcweir             log.println("Couldn't store to " + url
78cdf0e10cSrcweir                     + " : " + e.getMessage());
79cdf0e10cSrcweir             e.printStackTrace(log);
80cdf0e10cSrcweir             tRes.tested("storeIntoURL()", false);
81cdf0e10cSrcweir         } catch(com.sun.star.lang.WrappedTargetException e) {
82cdf0e10cSrcweir             log.println("Couldn't get/set property 'Author':" + e);
83cdf0e10cSrcweir             tRes.tested("storeIntoURL()", false);
84cdf0e10cSrcweir         } catch(com.sun.star.beans.UnknownPropertyException e) {
85cdf0e10cSrcweir             log.println("Couldn't get/set property 'Author':" + e);
86cdf0e10cSrcweir             tRes.tested("storeIntoURL()", false);
87cdf0e10cSrcweir         } catch(com.sun.star.lang.IllegalArgumentException e) {
88cdf0e10cSrcweir             log.println("Couldn't get/set property 'Author':" + e);
89cdf0e10cSrcweir             tRes.tested("storeIntoURL()", false);
90cdf0e10cSrcweir         } catch(com.sun.star.beans.PropertyVetoException e) {
91cdf0e10cSrcweir             log.println("Couldn't get/set property 'Author':" + e);
92cdf0e10cSrcweir             tRes.tested("storeIntoURL()", false);
93cdf0e10cSrcweir         }
94cdf0e10cSrcweir     }
95cdf0e10cSrcweir 
96cdf0e10cSrcweir     /**
97cdf0e10cSrcweir     * Calls the method and checks value of the property 'Author'. <p>
98cdf0e10cSrcweir     * Has <b> OK </b> status if no exception occured and value of the property
99cdf0e10cSrcweir     * 'Author' is equal to value that was set in the method
100cdf0e10cSrcweir     * <code>storeIntoURL</code>.
101cdf0e10cSrcweir     */
_loadFromURL()102cdf0e10cSrcweir     public void _loadFromURL() {
103cdf0e10cSrcweir         requiredMethod("storeIntoURL()");
104cdf0e10cSrcweir         try {
105cdf0e10cSrcweir             oObj.loadFromURL(url);
106cdf0e10cSrcweir             XPropertySet propSet = (XPropertySet)
107cdf0e10cSrcweir                 UnoRuntime.queryInterface(XPropertySet.class, oObj);
108cdf0e10cSrcweir             String resProp = (String)propSet.getPropertyValue("Author");
109cdf0e10cSrcweir             log.println("Was: '" + oldProp + "',Set: '" + newProp +
110cdf0e10cSrcweir                         "', New: " + resProp + "'");
111cdf0e10cSrcweir             tRes.tested("loadFromURL()", resProp.equals(newProp) );
112cdf0e10cSrcweir         } catch (IOException e) {
113cdf0e10cSrcweir             log.println("Couldn't load from " + url
114cdf0e10cSrcweir                     + " : " + e.getMessage());
115cdf0e10cSrcweir             e.printStackTrace(log);
116cdf0e10cSrcweir             tRes.tested("loadFromURL()", false);
117cdf0e10cSrcweir         } catch(com.sun.star.lang.WrappedTargetException e) {
118cdf0e10cSrcweir             log.println("Couldn't get/set property 'Author':" + e);
119cdf0e10cSrcweir             tRes.tested("loadFromURL()", false);
120cdf0e10cSrcweir         } catch(com.sun.star.beans.UnknownPropertyException e) {
121cdf0e10cSrcweir             log.println("Couldn't get/set property 'Author':" + e);
122cdf0e10cSrcweir             tRes.tested("loadFromURL()", false);
123cdf0e10cSrcweir         }
124cdf0e10cSrcweir     }
125cdf0e10cSrcweir 
126cdf0e10cSrcweir }  // finish class _XStandaloneDocumentInfo
127cdf0e10cSrcweir 
128