bump product version to 5.0.4.1
[LibreOffice.git] / qadevOOo / tests / java / mod / _sw / XMLMetaImporter.java
blob1c20d090d2460230a29f7451cb9f193d433091bc
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package mod._sw;
21 import java.io.PrintWriter;
23 import lib.StatusException;
24 import lib.TestCase;
25 import lib.TestEnvironment;
26 import lib.TestParameters;
27 import util.SOfficeFactory;
29 import com.sun.star.document.XDocumentPropertiesSupplier;
30 import com.sun.star.document.XDocumentProperties;
31 import com.sun.star.lang.XMultiServiceFactory;
32 import com.sun.star.text.XTextDocument;
33 import com.sun.star.uno.UnoRuntime;
34 import com.sun.star.uno.XInterface;
36 /**
37 * Test for object which is represented by service
38 * <code>com.sun.star.comp.Writer.XMLMetaImporter</code>. <p>
39 * Object implements the following interfaces :
40 * <ul>
41 * <li><code>com::sun::star::lang::XInitialization</code></li>
42 * <li><code>com::sun::star::document::XImporter</code></li>
43 * <li><code>com::sun::star::document::XFilter</code></li>
44 * <li><code>com::sun::star::document::ImportFilter</code></li>
45 * <li><code>com::sun::star::beans::XPropertySet</code></li>
46 * <li><code>com::sun::star::xml::sax::XDocumentHandler</code></li>
48 * </ul>
49 * @see com.sun.star.lang.XInitialization
50 * @see com.sun.star.document.XImporter
51 * @see com.sun.star.document.XFilter
52 * @see com.sun.star.document.ImportFilter
53 * @see com.sun.star.beans.XPropertySet
54 * @see com.sun.star.xml.sax.XDocumentHandler
55 * @see ifc.lang._XInitialization
56 * @see ifc.document._XImporter
57 * @see ifc.document._XFilter
58 * @see ifc.document._XExporter
59 * @see ifc.beans._XPropertySet
60 * @see ifc.xml.sax._XDocumentHandler
62 public class XMLMetaImporter extends TestCase {
63 XTextDocument xTextDoc;
65 /**
66 * New text document created.
68 @Override
69 protected void initialize( TestParameters tParam, PrintWriter log ) {
70 SOfficeFactory SOF = SOfficeFactory.getFactory( tParam.getMSF() );
72 try {
73 log.println( "creating a textdocument" );
74 xTextDoc = SOF.createTextDoc( null );
75 } catch ( com.sun.star.uno.Exception e ) {
76 // Some exception occurs.FAILED
77 e.printStackTrace( log );
78 throw new StatusException( "Couldn't create document", e );
82 /**
83 * Text document destroyed.
85 @Override
86 protected void cleanup( TestParameters tParam, PrintWriter log ) {
87 log.println( " disposing xTextDoc " );
88 util.DesktopTools.closeDoc(xTextDoc);
91 /**
92 * Creating a Testenvironment for the interfaces to be tested.
93 * Creates an instance of the service
94 * <code>com.sun.star.comp.Writer.XMLMetaImporter</code><p>
96 * The text document is set as a target document for importer.
97 * Imported XML-data contains only meta tags including
98 * title tag with test name.
99 * After import title name getting from target document is checked.
100 * Object relations created :
101 * <ul>
102 * <li> <code>'XDocumentHandler.XMLData'</code> for
103 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
104 * <li> <code>'XDocumentHandler.ImportChecker'</code> for
105 * {@link ifc.xml.sax._XDocumentHandler} interface </li>
106 * <li> <code>'TargetDocument'</code> for
107 * {@link ifc.document._XImporter} interface </li>
108 * </ul>
110 @Override
111 public synchronized TestEnvironment createTestEnvironment( TestParameters tParam,
112 PrintWriter log )
113 throws StatusException {
115 XInterface oObj = null;
116 Object oInt = null ;
117 final String impTitle = "XMLMetaImporter test." ;
119 // creation of testobject here
120 // first we write what we are intend to do to log file
121 log.println( "creating a test environment" );
123 XMultiServiceFactory xMSF = tParam.getMSF() ;
125 try {
126 oInt = xMSF.createInstance
127 ("com.sun.star.comp.Writer.XMLMetaImporter") ;
128 } catch (com.sun.star.uno.Exception e) {
129 e.printStackTrace(log) ;
130 throw new StatusException("Can't create component.", e) ;
133 oObj = (XInterface) oInt ;
135 // create testobject here
136 log.println( "creating a new environment for Paragraph object" );
137 TestEnvironment tEnv = new TestEnvironment( oObj );
139 // adding relation
140 tEnv.addObjRelation("TargetDocument", xTextDoc) ;
142 // adding relation for XDocumentHandler
143 String[][] xml = new String[][] {
144 {"start", "office:document-meta" ,
145 "xmlns:office", "CDATA", "http://openoffice.org/2000/office",
146 "xmlns:dc", "CDATA", "http://purl.org/dc/elements/1.1/"},
147 {"start", "office:meta"} ,
148 {"start", "dc:title"},
149 {"chars", impTitle},
150 {"end", "dc:title"},
151 {"end", "office:meta"},
152 {"end", "office:document-meta"}} ;
154 tEnv.addObjRelation("XDocumentHandler.XMLData", xml) ;
156 XDocumentPropertiesSupplier xPropSup = UnoRuntime.queryInterface
157 (XDocumentPropertiesSupplier.class, xTextDoc);
158 final XDocumentProperties xDocProps = xPropSup.getDocumentProperties();
159 final PrintWriter logF = log ;
161 tEnv.addObjRelation("XDocumentHandler.ImportChecker",
162 new ifc.xml.sax._XDocumentHandler.ImportChecker() {
163 public boolean checkImport() {
164 String title = xDocProps.getTitle();
165 logF.println("Title returned = '" + title + "'") ;
166 return impTitle.equals(title) ;
168 }) ;
170 return tEnv;
171 } // finish method getTestEnvironment