You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AssertElement.java 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Copyright 2005 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /* $Id$ */
  17. package org.apache.fop.fotreetest.ext;
  18. import org.apache.fop.apps.FOPException;
  19. import org.apache.fop.fo.FONode;
  20. import org.apache.fop.fo.FOPropertyMapping;
  21. import org.apache.fop.fo.PropertyList;
  22. import org.apache.fop.fo.properties.Property;
  23. import org.apache.fop.fotreetest.ResultCollector;
  24. import org.xml.sax.Attributes;
  25. import org.xml.sax.Locator;
  26. /**
  27. * Defines the assert element for the FOP Test extension.
  28. */
  29. public class AssertElement extends TestObj {
  30. /**
  31. * @see org.apache.fop.fo.FONode#FONode(FONode)
  32. */
  33. public AssertElement(FONode parent) {
  34. super(parent);
  35. }
  36. /**
  37. * @see org.apache.fop.fo.FONode#processNode
  38. */
  39. public void processNode(String elementName,
  40. Locator locator,
  41. Attributes attlist,
  42. PropertyList propertyList) throws FOPException {
  43. //super.processNode(elementName, locator, attlist, propertyList);
  44. ResultCollector collector = ResultCollector.getInstance();
  45. String propName = attlist.getValue("property");
  46. int propID = FOPropertyMapping.getPropertyId(propName);
  47. if (propID < 0) {
  48. collector.notifyException(new IllegalArgumentException(
  49. "Property not found: " + propName));
  50. } else {
  51. Property prop = propertyList.get(propID);
  52. String s = String.valueOf(prop);
  53. String expected = attlist.getValue("expected");
  54. if (!expected.equals(s)) {
  55. collector.notifyException(new IllegalStateException("Property '" + propName
  56. + "' expected to evaluate to '" + expected + "' but got: " + s));
  57. }
  58. }
  59. }
  60. }