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  * _XSingleLayerStratum.java
24  *
25  * Created on 23. March 2004, 16:37
26  */
27 package ifc.configuration.backend;
28 import com.sun.star.configuration.backend.XLayer;
29 import com.sun.star.configuration.backend.XSingleLayerStratum;
30 import com.sun.star.configuration.backend.XUpdatableLayer;
31 
32 import lib.MultiMethodTest;
33 
34 import util.XLayerHandlerImpl;
35 
36 
37 public class _XSingleLayerStratum extends MultiMethodTest {
38     public XSingleLayerStratum oObj;
39 
_getLayer()40     public void _getLayer() {
41         String aLayerID = "org.openoffice.Office.Common";
42         boolean res = true;
43 
44         try {
45             XLayer aLayer = oObj.getLayer("", "");
46             log.println("Exception expected -- FAILED");
47             res = false;
48         } catch (com.sun.star.configuration.backend.BackendAccessException e) {
49             log.println("unexpected Exception " + e + " -- FAILED");
50             res = false;
51         } catch (com.sun.star.lang.IllegalArgumentException e) {
52             log.println("expected Exception -- OK");
53         }
54 
55         try {
56             XLayer aLayer = oObj.getLayer(aLayerID, "");
57             res &= (aLayer != null);
58 
59             if (aLayer == null) {
60                 log.println("\treturned Layer is NULL -- FAILED");
61             }
62 
63             res &= checkLayer(aLayer);
64         } catch (com.sun.star.configuration.backend.BackendAccessException e) {
65             log.println("unexpected Exception -- FAILED");
66             res = false;
67         } catch (com.sun.star.lang.IllegalArgumentException e) {
68             log.println("unexpected Exception -- FAILED");
69             res = false;
70         }
71 
72         tRes.tested("getLayer()", res);
73     }
74 
_getUpdatableLayer()75     public void _getUpdatableLayer() {
76         String aLayerID = "org.openoffice.Office.Common";
77         boolean res = true;
78 
79         try {
80             XUpdatableLayer aLayer = oObj.getUpdatableLayer("");
81             log.println("Exception expected -- FAILED");
82             res = false;
83         } catch (com.sun.star.configuration.backend.BackendAccessException e) {
84             log.println("unexpected Exception " + e + " -- FAILED");
85             res = false;
86         } catch (com.sun.star.lang.IllegalArgumentException e) {
87             log.println("expected Exception -- OK");
88         } catch (com.sun.star.lang.NoSupportException e) {
89             log.println("unexpected Exception -- FAILED");
90             res = false;
91         }
92 
93         try {
94             XUpdatableLayer aLayer = oObj.getUpdatableLayer(aLayerID);
95             res &= (aLayer != null);
96 
97             if (aLayer == null) {
98                 log.println("\treturned Layer is NULL -- FAILED");
99             }
100 
101             res &= checkLayer(aLayer);
102         } catch (com.sun.star.configuration.backend.BackendAccessException e) {
103             log.println("unexpected Exception -- FAILED");
104             res = false;
105         } catch (com.sun.star.lang.IllegalArgumentException e) {
106             log.println("unexpected Exception -- FAILED");
107             res = false;
108         } catch (com.sun.star.lang.NoSupportException e) {
109             log.println("unexpected Exception -- FAILED");
110             res = false;
111         }
112 
113         tRes.tested("getUpdatableLayer()", res);
114     }
115 
checkLayer(XLayer aLayer)116     protected boolean checkLayer(XLayer aLayer) {
117         boolean res = false;
118 
119         log.println("Checking for Exception in case of null argument");
120 
121         try {
122             aLayer.readData(null);
123         } catch (com.sun.star.lang.NullPointerException e) {
124             log.println("Expected Exception -- OK");
125             res = true;
126         } catch (com.sun.star.lang.WrappedTargetException e) {
127             log.println("Unexpected Exception (" + e + ") -- FAILED");
128         } catch (com.sun.star.configuration.backend.MalformedDataException e) {
129             log.println("Unexpected Exception (" + e + ") -- FAILED");
130         }
131 
132         log.println("checking read data with own XLayerHandler implementation");
133 
134         try {
135             XLayerHandlerImpl xLayerHandler = new XLayerHandlerImpl();
136             aLayer.readData(xLayerHandler);
137 
138             String implCalled = xLayerHandler.getCalls();
139             log.println(implCalled);
140 
141             int sl = implCalled.indexOf("startLayer");
142 
143             if (sl < 0) {
144                 log.println("startLayer wasn't called -- FAILED");
145                 res &= false;
146             } else {
147                 log.println("startLayer was called -- OK");
148                 res &= true;
149             }
150 
151             int el = implCalled.indexOf("endLayer");
152 
153             if (el < 0) {
154                 log.println("endLayer wasn't called -- FAILED");
155                 res &= false;
156             } else {
157                 log.println("endLayer was called -- OK");
158                 res &= true;
159             }
160         } catch (com.sun.star.lang.NullPointerException e) {
161             log.println("Unexpected Exception (" + e + ") -- FAILED");
162             res &= false;
163         } catch (com.sun.star.lang.WrappedTargetException e) {
164             log.println("Unexpected Exception (" + e + ") -- FAILED");
165             res &= false;
166         } catch (com.sun.star.configuration.backend.MalformedDataException e) {
167             log.println("Unexpected Exception (" + e + ") -- FAILED");
168             res &= false;
169         }
170 
171         return res;
172     }
173 }
174