Grails - Apache Tika插件测试应用程序失败

时间:2016-02-18 21:38:29

标签: unit-testing grails apache-tika

我正在学习如何使用Apache Tika plugin。我刚刚从github复制了代码,我在单元测试时遇到了失败错误。

这是unit test

import grails.test.mixin.TestFor
import spock.lang.Specification

/**
 * Test for tikaService: try to parse test data.
 */
@TestFor(TikaService)
class TikaServiceSpec extends Specification {

    def 'Parse a word file to XML'() {
        given:
        def file = new File('parserTest.doc')

        when:
        def xml = service.parseFile(file)

        then:
        def doc = new XmlSlurper().parseText(xml)
        doc.body.p.find{
            it.text() == 'This is a simple test document'
        }
    }
}

这是我得到的错误。

Running 5 unit tests... 8 of 8
| Failure:  Parse a word file to XML(com.myApp.TikaServiceSpec)
|  Condition not satisfied:
doc.body.p.find{ it.text() == 'This is a simple test document' }
|   |    | |
|   |    | groovy.util.slurpersupport.NoChildren@4c2a4e84
|   |    Tika Parser Test
|   |    This is a simple test document
|   Tika Parser Test
|   This is a simple test document
Tika Parser Test
This is a simple test document
    at com.myApp.TikaServiceSpec.Parse a word file to XML(TikaServiceSpec.groovy:21)

我做错了什么?

dependencies {
    compile('org.apache.tika:tika-core:0.7')
    compile('org.apache.tika:tika-parsers:0.7') { excludes "xercesImpl", "xmlParserAPIs", "xml-apis", "log4j" }
}

1 个答案:

答案 0 :(得分:1)

感谢@Gagravarr,问题已经解决了。我使用的是版本1.12并且它有效。

回购是https://repo1.maven.org/maven2/org/apache/tika/