KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > layoutengine > ResultCheck


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. 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 /* $Id: ResultCheck.java 426576 2006-07-28 15:44:37Z jeremias $ */
19
20 package org.apache.fop.layoutengine;
21
22 import org.apache.fop.apps.FormattingResults;
23 import org.w3c.dom.Node JavaDoc;
24
25 /**
26  * Simple check that requires a result property to evaluate to the expected value
27  */

28 public class ResultCheck implements LayoutEngineCheck {
29
30     private String JavaDoc expected;
31     private String JavaDoc property;
32     
33     /**
34      * Creates a new instance
35      * @param expected expected value
36      * @param property property of which the value needs to be evaluated
37      */

38     public ResultCheck(String JavaDoc expected, String JavaDoc property) {
39         this.expected = expected;
40         this.property = property;
41     }
42     
43     /**
44      * Creates a new instance from a DOM node.
45      * @param node DOM node that defines this check
46      */

47     public ResultCheck(Node JavaDoc node) {
48         this.expected = node.getAttributes().getNamedItem("expected").getNodeValue();
49         this.property = node.getAttributes().getNamedItem("property").getNodeValue();
50     }
51     
52     /* (non-Javadoc)
53      * @see LayoutEngineCheck#check(LayoutResult)
54      */

55     public void check(LayoutResult result) {
56         FormattingResults results = result.getResults();
57         String JavaDoc actual;
58         if (property.equals("pagecount")) {
59             actual = Integer.toString(results.getPageCount());
60         } else {
61             throw new RuntimeException JavaDoc("No such property test: " + property);
62         }
63         if (!expected.equals(actual)) {
64             throw new RuntimeException JavaDoc(
65                     "Expected property to evaluate to '" + expected + "', but got '"
66                     + actual + "' (" + this + ")");
67         }
68
69     }
70
71     /** @see java.lang.Object#toString() */
72     public String JavaDoc toString() {
73         return "Property: " + property;
74     }
75
76 }
77
Popular Tags