当前位置: 首页 > 知识库问答 >
问题:

在GAE上使用Hamcrest 1.3和Maven的NoSuchMethodError

秦凯定
2023-03-14

我已经找到了三个问题,它们应该与同一个问题有关,但不知何故,它们并没有完全解决我的问题。

在IntelliJ10.5中运行测试时获得“NosuchMethoderRor:org.hamcrest.matcher.DescripbeMismatch”

单元测试运行良好,但RestAssured测试失败时是在集成测试期间:

expect().
    statusCode(Status.CREATED.getStatusCode()).log().all().
when().
    post("/projects").
then().
    body("directory", Matchers.anything()).body("files", Matchers.empty()); 

正如前面提到的其他三个相关问题,在testng/jUnit和Hamcrest和/或Mockito的相互冲突的依赖关系中似乎存在一些问题,因此我尝试了所述工件的各种导出和其他包含,不幸的是,都没有成功。但是起作用的是没有使用RestAssured中的log().all(),这一定是问题的根源。因此,这将是可行的:

expect().
    statusCode(Status.CREATED.getStatusCode()).
when().
    post("/projects").
then().
    body("directory", Matchers.anything()).body("files", Matchers.empty()); 
     java.lang.NoSuchMethodError: org.hamcrest.core.IsInstanceOf.any(Ljava/lang/Class;)Lorg/hamcrest/Matcher;
        at org.hamcrest.Matchers.any(Matchers.java:371)
        at com.jayway.restassured.filter.log.ResponseLoggingFilter.<init>(ResponseLoggingFilter.java:94)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
        at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:77)
        at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:102)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:57)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:182)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:198)
        at com.jayway.restassured.internal.ResponseLogSpecificationImpl.logWith(ResponseLogSpecificationImpl.groovy:85)
        at com.jayway.restassured.internal.ResponseLogSpecificationImpl.this$3$logWith(ResponseLogSpecificationImpl.groovy)
        at com.jayway.restassured.internal.ResponseLogSpecificationImpl$this$3$logWith.callCurrent(Unknown Source)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:49)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:145)
        at com.jayway.restassured.internal.ResponseLogSpecificationImpl.all(ResponseLogSpecificationImpl.groovy:45)
        at com.jayway.restassured.internal.ResponseLogSpecificationImpl.all(ResponseLogSpecificationImpl.groovy)
        at com.jayway.restassured.specification.LogSpecification$all.callCurrent(Unknown Source)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:49)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:141)
        at com.jayway.restassured.internal.ResponseLogSpecificationImpl.all(ResponseLogSpecificationImpl.groovy:41)
        at com.jayway.restassured.internal.ResponseLogSpecificationImpl.all(ResponseLogSpecificationImpl.groovy)
        at de.uniluebeck.collaboratex.test.service.ProjectServiceTests.testDeleteNonExistingProject(ProjectServiceTests.java:84)
        <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <packaging>war</packaging>
    <version>1.0-SNAPSHOT</version>
    <groupId>de.uniluebeck.collaboratex</groupId>
    <artifactId>CollaboraTex</artifactId>

    <name>CollaboraTex</name>

    <pluginRepositories>
        <pluginRepository>
            <id>google-staging</id>
            <name>Google Staging</name>
            <url>https://oss.sonatype.org/content/repositories/comgoogleappengine-1004/</url>
        </pluginRepository>
    </pluginRepositories>

    <properties>
        <appengine.target.version>1.9.2</appengine.target.version>
        <datanucleus.version>3.1.3</datanucleus.version>
        <jersey.version>2.6</jersey.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <!-- Compile/runtime dependencies -->
        <dependency>
            <groupId>com.google.appengine</groupId>
            <artifactId>appengine-api-1.0-sdk</artifactId>
            <version>1.9.2</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.1</version>
        </dependency>

        <!-- Jersey WS-RS dependencies -->
        <dependency>
            <groupId>javax.ws.rs</groupId>
            <artifactId>javax.ws.rs-api</artifactId>
            <version>2.0</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.core</groupId>
            <artifactId>jersey-server</artifactId>
            <version>${jersey.version}</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.media</groupId>
            <artifactId>jersey-media-multipart</artifactId>
            <version>${jersey.version}</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.media</groupId>
            <artifactId>jersey-media-moxy</artifactId>
            <version>${jersey.version}</version>
            <scope>compile</scope>
        </dependency>

        <!-- JPA dependencies -->
        <dependency>
            <groupId>org.eclipse.persistence</groupId>
            <artifactId>javax.persistence</artifactId>
            <version>2.1.0</version>
        </dependency>
        <dependency>
            <groupId>org.eclipse.persistence</groupId>
            <artifactId>org.eclipse.persistence.core</artifactId>
            <version>2.5.0</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.eclipse.persistence</groupId>
            <artifactId>org.eclipse.persistence.moxy</artifactId>
            <version>2.5.0</version>
            <scope>compile</scope>
            <type>jar</type>
        </dependency>

        <!-- JPA Data Nucleus dependencies -->
        <dependency>
            <groupId>com.google.appengine.orm</groupId>
            <artifactId>datanucleus-appengine</artifactId>
            <version>2.1.2</version>
        </dependency>
        <dependency>
            <groupId>org.datanucleus</groupId>
            <artifactId>datanucleus-core</artifactId>
            <version>${datanucleus.version}</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.datanucleus</groupId>
            <artifactId>datanucleus-api-jpa</artifactId>
            <version>${datanucleus.version}</version>
        </dependency>
        <dependency>
            <groupId>javax.jdo</groupId>
            <artifactId>jdo-api</artifactId>
            <version>3.0.1</version>
            <scope>compile</scope>
        </dependency>

        <!-- needed to solve JPA Data Nucleus validation error -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>5.1.0.Final</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.5.6</version>
        </dependency>

        <!-- test dependencies -->
        <dependency>
            <groupId>com.jayway.restassured</groupId>
            <artifactId>rest-assured</artifactId>
            <version>2.3.1</version>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <artifactId>asm</artifactId>
                    <groupId>org.ow2.asm</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>com.jayway.restassured</groupId>
            <artifactId>json-path</artifactId>
            <version>2.3.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-library</artifactId>
            <version>1.3</version>
            <scope>test</scope>
            <type>jar</type>
        </dependency>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.8.7</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-all</artifactId>
            <version>1.9.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.google.appengine</groupId>
            <artifactId>appengine-testing</artifactId>
            <version>${appengine.target.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.google.appengine</groupId>
            <artifactId>appengine-api-stubs</artifactId>
            <version>${appengine.target.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.google.appengine</groupId>
            <artifactId>appengine-api-labs</artifactId>
            <version>${appengine.target.version}</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <version>2.5.1</version>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <archiveClasses>true</archiveClasses>
                    <webResources>
                        <!-- in order to interpolate version from pom into appengine-web.xml -->
                        <resource>
                            <directory>${basedir}/src/main/webapp/WEB-INF</directory>
                            <filtering>true</filtering>
                            <targetPath>WEB-INF</targetPath>
                        </resource>
                    </webResources>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>  
                <version>2.6</version>  
                <configuration>  
                    <includes>  
                        <include>**/*ServiceTests.java</include>  
                    </includes>  
                </configuration>  
                <executions>
                    <execution>  
                        <id>it</id>
                        <phase>integration-test</phase>
                        <goals>  
                            <goal>integration-test</goal>  
                        </goals>  
                    </execution>  
                </executions>  
            </plugin>

            <plugin>
                <groupId>com.google.appengine</groupId>
                <artifactId>appengine-maven-plugin</artifactId>
                <version>${appengine.target.version}</version>
                <!-- 
                <configuration>
                    <port>7378</port>
                    <offline>true</offline>
                </configuration>
                -->
                <executions>
                    <execution>
                        <id>start-gae</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>devserver_start</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>stop-gae</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>devserver_stop</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                <groupId>org.datanucleus</groupId>
                <artifactId>maven-datanucleus-plugin</artifactId>
                <version>${datanucleus.version}</version>
                <configuration>
                    <api>JPA</api>
                    <verbose>true</verbose>             
                    <mappingIncludes>**/entity/*.class</mappingIncludes>
                    <fork>false</fork>
                </configuration>
                <executions>
                    <execution>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>enhance</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

        </plugins>
    </build>
</project>

最后但并非最不重要的是,这里是mvn依赖项的输出:树

de.uniluebeck.collaboratex:CollaboraTex:war:1.0-SNAPSHOT
+- com.google.appengine:appengine-api-1.0-sdk:jar:1.9.2:compile
+- javax.servlet:servlet-api:jar:2.5:provided
+- org.apache.commons:commons-lang3:jar:3.1:compile
+- javax.ws.rs:javax.ws.rs-api:jar:2.0:compile
+- org.glassfish.jersey.core:jersey-server:jar:2.6:compile
|  +- org.glassfish.jersey.core:jersey-common:jar:2.6:compile
|  |  +- org.glassfish.jersey.bundles.repackaged:jersey-guava:jar:2.6:compile
|  |  \- org.glassfish.hk2:osgi-resource-locator:jar:1.0.1:compile
|  +- org.glassfish.jersey.core:jersey-client:jar:2.6:compile
|  +- javax.annotation:javax.annotation-api:jar:1.2:compile
|  +- org.glassfish.hk2:hk2-api:jar:2.2.0:compile
|  |  +- org.glassfish.hk2:hk2-utils:jar:2.2.0:compile
|  |  \- org.glassfish.hk2.external:aopalliance-repackaged:jar:2.2.0:compile
|  +- org.glassfish.hk2.external:javax.inject:jar:2.2.0:compile
|  +- org.glassfish.hk2:hk2-locator:jar:2.2.0:compile
|  |  \- org.javassist:javassist:jar:3.18.1-GA:compile
|  \- javax.validation:validation-api:jar:1.1.0.Final:compile
+- org.glassfish.jersey.media:jersey-media-multipart:jar:2.6:compile
|  \- org.jvnet.mimepull:mimepull:jar:1.9.3:compile
+- org.glassfish.jersey.media:jersey-media-moxy:jar:2.6:compile
|  +- org.glassfish.jersey.ext:jersey-entity-filtering:jar:2.6:compile
|  \- org.eclipse.persistence:org.eclipse.persistence.antlr:jar:2.5.0:compile
+- org.eclipse.persistence:javax.persistence:jar:2.1.0:compile
+- org.eclipse.persistence:org.eclipse.persistence.core:jar:2.5.0:compile
|  \- org.eclipse.persistence:org.eclipse.persistence.asm:jar:2.5.0:compile
+- org.eclipse.persistence:org.eclipse.persistence.moxy:jar:2.5.0:compile
+- com.google.appengine.orm:datanucleus-appengine:jar:2.1.2:compile
|  \- org.datanucleus:datanucleus-enhancer:jar:3.1.1:compile
|     \- org.ow2.asm:asm:jar:4.0:compile
+- org.datanucleus:datanucleus-core:jar:3.1.3:runtime
+- org.datanucleus:datanucleus-api-jpa:jar:3.1.3:compile
+- javax.jdo:jdo-api:jar:3.0.1:compile
|  \- javax.transaction:jta:jar:1.1:compile
+- org.hibernate:hibernate-validator:jar:5.1.0.Final:compile
|  +- org.jboss.logging:jboss-logging:jar:3.1.3.GA:compile
|  \- com.fasterxml:classmate:jar:1.0.0:compile
+- org.slf4j:slf4j-log4j12:jar:1.5.6:compile
|  +- org.slf4j:slf4j-api:jar:1.5.6:compile
|  \- log4j:log4j:jar:1.2.14:compile
+- com.jayway.restassured:rest-assured:jar:2.3.1:test
|  +- org.codehaus.groovy:groovy:jar:2.2.1:test
|  |  +- org.ow2.asm:asm-tree:jar:4.1:test
|  |  +- antlr:antlr:jar:2.7.7:test
|  |  +- org.ow2.asm:asm-util:jar:4.1:test
|  |  +- org.ow2.asm:asm-commons:jar:4.1:test
|  |  \- org.ow2.asm:asm-analysis:jar:4.1:test
|  +- org.codehaus.groovy:groovy-xml:jar:2.2.1:test
|  +- org.apache.httpcomponents:httpclient:jar:4.2.6:test
|  |  +- org.apache.httpcomponents:httpcore:jar:4.2.5:test
|  |  +- commons-logging:commons-logging:jar:1.1.1:test
|  |  \- commons-codec:commons-codec:jar:1.6:test
|  +- org.apache.httpcomponents:httpmime:jar:4.2.6:test
|  +- org.hamcrest:hamcrest-core:jar:1.3:test
|  +- org.ccil.cowan.tagsoup:tagsoup:jar:1.2.1:test
|  \- com.jayway.restassured:xml-path:jar:2.3.1:test
+- com.jayway.restassured:json-path:jar:2.3.1:test
|  +- org.codehaus.groovy:groovy-json:jar:2.2.1:test
|  \- com.jayway.restassured:rest-assured-common:jar:2.3.1:test
+- org.hamcrest:hamcrest-library:jar:1.3:test
+- org.testng:testng:jar:6.8.7:test
|  +- junit:junit:jar:4.10:test
|  +- org.beanshell:bsh:jar:2.0b4:test
|  +- com.beust:jcommander:jar:1.27:test
|  \- org.yaml:snakeyaml:jar:1.12:test
+- org.mockito:mockito-all:jar:1.9.0:test
+- com.google.appengine:appengine-testing:jar:1.9.2:test
+- com.google.appengine:appengine-api-stubs:jar:1.9.2:test
\- com.google.appengine:appengine-api-labs:jar:1.9.2:test

共有1个答案

文心思
2023-03-14

TestNG依赖于JUnit。因此,Junit-4.10.jar位于类路径中。这个Jar包括比Hamcrest 1.3更早的Hamcrest类,并且缺少一些方法。classloader从JUnit加载org.hamcrest.core.IsInstanceOf,因此会遇到问题。

将JUnit4.11的依赖项添加到POM中。这覆盖了TestNG对JUnit4.10的依赖,并解决了您的Hamcrest问题,因为JUnit4.11不再包括Hamcrest类。

<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>4.11</version>
</dependency>
 类似资料:
  • 我有一个java app engine程序,它将读取文件上载到Blob,然后使用文件API用于blobKey,并将其用于ImageAPI getServing URL。 所以目前的步骤是:1。文件上传使用Angular JS或其他客户端2。Servlet读取该文件并将其转换为BLOB3。文件API将Blob转换为blobkey4。然后Image API将返回调用客户端将获得的图像url。 null

  • 问题内容: 我正在尝试将Google App Engine与Maven一起用于基于Spring的简单应用程序。我发现有一种适用于这种Web应用程序的Maven原型(没有Spring,但是我可以自己添加):Maven GAE。 因此,我使用了以下命令: 但是,当我尝试使用“ mvn gae:run”时,它不起作用,而且我不知道如何解决此缺失的要求: 可以补充一点,我尝试使用不同版本的maven-ga

  • 问题内容: 我正在尝试使用websocket调整我的应用程序以使其在GAE上运行,但是在阅读文档时,我没有找到解决此问题的漂亮方法。 使用一个像这样的非常简单的应用程序:https : //github.com/marcosbergamo/gae-nodejs- websocket 这是我尝试使用的示例演示。但是,当我尝试连接到我的websocket时会收到此错误; 跟随有关请求的图像; 问题答案

  • 问题内容: 我试图弄清楚如何使用Go使用嵌套结构与GAE数据存储区一起使用。我知道数据存储区不专门支持嵌套结构。我需要找到一种简单的方法,使用户信息以JSON的形式发送给用户时,将其与帖子一起发送。 我想到的一件事是为用户放置两个字段。一个用于引用用户的ID /密钥,另一个用于用户类型struct,当从数据存储区加载帖子时,该结构将添加到其中。多余的字段似乎很愚蠢,所以我希望对此有更好的解决方案。

  • 我安装了一个新的并下载了最新的Maven。在中: :我选择了刚下载的Maven :我选择了 此外,当我打开该项目的时,它在带有的行中显示: 似乎有一个错误: 在此行找到多个批注:

  • 生成失败,错误如下: [ERROR]未能执行目标org.apache.maven.plugins:maven-compiler-plugin:3.1:编译(默认编译)上的项目r esPonderhub:编译失败[ERROR] /X:/工作区/响应器HubWorkspace/响应器Hub/src/main/java/uk/org/响应器Hub/MemberServlet.java:[23,110]找