aboutsummaryrefslogtreecommitdiffstats
path: root/test/java/org/apache/fop/events/EventProcessingTestCase.java
blob: 9660e5b799c12b45b70975294b5ba1c2e6311c4c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/* $Id$ */

package org.apache.fop.events;

import java.io.File;

import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.sax.SAXResult;
import javax.xml.transform.stream.StreamSource;

import org.apache.commons.io.output.NullOutputStream;
import org.apache.fop.ResourceEventProducer;
import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.Fop;
import org.apache.fop.apps.FopFactory;
import org.apache.fop.area.AreaEventProducer;
import org.apache.fop.fo.FOValidationEventProducer;
import org.apache.fop.fo.flow.table.TableEventProducer;
import org.apache.fop.fonts.FontEventProducer;
import org.apache.fop.layoutmgr.BlockLevelEventProducer;
import org.apache.fop.layoutmgr.inline.InlineLevelEventProducer;
import org.apache.xmlgraphics.util.MimeConstants;
import org.junit.Test;

/**
 * Tests that the event notification system runs smoothly.
 */
public class EventProcessingTestCase {

    private final FopFactory fopFactory = FopFactory.newInstance();

    private final TransformerFactory tFactory = TransformerFactory.newInstance();

    private final File basedir;

    public EventProcessingTestCase() {
        String base = System.getProperty("basedir");
        if (base != null) {
            basedir = new File(base);
        } else {
            basedir = new File(".");
        }
    }

    private void doTest(String filename, String expectedEventID)
            throws FOPException, TransformerException {
        Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, new NullOutputStream());
        EventChecker eventChecker = new EventChecker(expectedEventID);
        fop.getUserAgent().getEventBroadcaster().addEventListener(eventChecker);
        Transformer transformer = tFactory.newTransformer();
        Source src = new StreamSource(new File(basedir, filename));
        Result res = new SAXResult(fop.getDefaultHandler());
        transformer.transform(src, res);
        eventChecker.end();
    }

    @Test
    public void testArea() throws FOPException, TransformerException {
        doTest("area.fo",
                AreaEventProducer.class.getName() + ".unresolvedIDReferenceOnPage");
    }

    @Test
    public void testResource() throws FOPException, TransformerException {
        doTest("resource.fo",
                ResourceEventProducer.class.getName() + ".imageNotFound");
    }

    @Test
    public void testValidation() throws FOPException, TransformerException {
        doTest("validation.fo",
                FOValidationEventProducer.class.getName() + ".invalidPropertyValue");
    }

    @Test
    public void testTable() throws FOPException, TransformerException {
        doTest("table.fo",
                TableEventProducer.class.getName() + ".noTablePaddingWithCollapsingBorderModel");
    }

    @Test
    public void testBlockLevel() throws FOPException, TransformerException {
        doTest("block-level.fo",
                BlockLevelEventProducer.class.getName() + ".overconstrainedAdjustEndIndent");
    }

    @Test
    public void testInlineLevel() throws FOPException, TransformerException {
        doTest("inline-level.fo",
                InlineLevelEventProducer.class.getName() + ".lineOverflows");
    }

    @Test
    public void testFont() throws FOPException, TransformerException {
        doTest("font.fo",
                FontEventProducer.class.getName() + ".fontSubstituted");
    }
}