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.

AbstractRendererConfigParserTester.java 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. /* $Id$ */
  18. package org.apache.fop.apps;
  19. import static org.mockito.Mockito.mock;
  20. import static org.mockito.Mockito.when;
  21. import org.apache.fop.apps.FopConfBuilder.RendererConfBuilder;
  22. import org.apache.fop.configuration.Configuration;
  23. import org.apache.fop.configuration.DefaultConfigurationBuilder;
  24. import org.apache.fop.events.DefaultEventBroadcaster;
  25. import org.apache.fop.fonts.FontManager;
  26. import org.apache.fop.render.RendererConfig;
  27. import org.apache.fop.render.RendererConfig.RendererConfigParser;
  28. public abstract class AbstractRendererConfigParserTester<B extends RendererConfBuilder,
  29. C extends RendererConfig> {
  30. protected B builder;
  31. protected C conf;
  32. protected final RendererConfigParser configBuilder;
  33. private final Class<B> type;
  34. public AbstractRendererConfigParserTester(RendererConfigParser configBuilder, Class<B> type) {
  35. this.configBuilder = configBuilder;
  36. this.type = type;
  37. }
  38. protected void parseConfig() throws Exception {
  39. parseConfig(createRenderer());
  40. }
  41. protected void parseConfig(B rendererConfBuilder) throws Exception {
  42. DefaultConfigurationBuilder cfgBuilder = new DefaultConfigurationBuilder();
  43. Configuration cfg = cfgBuilder.build(rendererConfBuilder.endRendererConfig().build())
  44. .getChild("renderers")
  45. .getChild("renderer");
  46. FOUserAgent userAgent = mock(FOUserAgent.class);
  47. when(userAgent.validateStrictly()).thenReturn(true);
  48. FontManager fontManager = mock(FontManager.class);
  49. when(userAgent.getFontManager()).thenReturn(fontManager);
  50. when(userAgent.getEventBroadcaster()).thenReturn(new DefaultEventBroadcaster());
  51. conf = (C) configBuilder.build(userAgent, cfg);
  52. }
  53. protected B createRenderer() {
  54. return createRenderer(type);
  55. }
  56. protected B createRenderer(Class<B> type) {
  57. builder = new FopConfBuilder().setStrictValidation(true).startRendererConfig(type);
  58. return builder;
  59. }
  60. protected void dump() throws Exception {
  61. builder.dump();
  62. }
  63. }