mock-server / mockserver

MockServer enables easy mocking of any system you integrate with via HTTP or HTTPS with clients written in Java, JavaScript and Ruby. MockServer also includes a proxy that introspects all proxied traffic including encrypted SSL traffic and supports Port Forwarding, Web Proxying (i.e. HTTP proxy), HTTPS Tunneling Proxying (using HTTP CONNECT) and SOCKS Proxying (i.e. dynamic port forwarding).
http://mock-server.com
Apache License 2.0
4.59k stars 1.07k forks source link

Updating from 5.2.3 -> 5.3.0 Introduces java.lang.NoSuchMethodError #404

Closed brcolow closed 6 years ago

brcolow commented 6 years ago

Hello,

Upgrading from 5.2.3 to 5.3.0 I go from no errors to getting an exception. Here is a simple example:

import static org.mockserver.integration.ClientAndServer.startClientAndServer;

public abstract class MockserverTest {
    protected static ClientAndServer mockServer;
    protected static final int MOCKSERVER_PORT = 54335;
    protected static final Delay RESPONSE_DELAY = new Delay(TimeUnit.MILLISECONDS, 10);

    @BeforeClass
    public static void setUp() {
        if (mockServer == null) {
            mockServer = startClientAndServer(MOCKSERVER_PORT);
        }
    }

    @After
    public void clearExpectations() {
        mockServer.reset();
    }
}
import static org.mockserver.model.HttpRequest.request;
import static org.mockserver.model.HttpResponse.response;

import org.junit.Test;

public class IntegrationTest extends MockserverTest {
    @Test
    public void test() {
       mockServer.when(request()
            .withMethod("POST")
            .withBody("{ \"method\" : \"test\" }"), Times.exactly(1))
            .respond(response()
                    .withBody("{ \"hello\": \"goodbye\" })
                    .withStatusCode(200)
                    .withDelay(new Delay(TimeUnit.SECONDS, 1)));
    }
}

Gives:

java.lang.NoSuchMethodError: org.mockserver.integration.ClientAndServer.when(Lorg/mockserver/model/HttpRequest;Lorg/mockserver/matchers/Times;)Lorg/mockserver/client/server/ForwardChainExpectation;

My POM looks like so:

<properties>
  <mockserver.version>5.3.0</mockserver.version>
</properties>
<dependency>
    <groupId>org.mock-server</groupId>
    <artifactId>mockserver-core</artifactId>
    <version>${mockserver.version}</version>
    <scope>test</scope>
    <exclusions>
        <exclusion>
            <groupId>com.google.code.findbugs</groupId>
            <artifactId>jsr305</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.mock-server</groupId>
    <artifactId>mockserver-client-java</artifactId>
    <version>${mockserver.version}</version>
    <scope>test</scope>
    <exclusions>
        <exclusion>
            <groupId>javax.inject</groupId>
            <artifactId>javax.inject</artifactId>
        </exclusion>
        <exclusion>
            <groupId>com.google.code.findbugs</groupId>
            <artifactId>jsr305</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.mock-server</groupId>
    <artifactId>mockserver-netty</artifactId>
    <version>${mockserver.version}</version>
    <scope>test</scope>
</dependency

And the IntegrationTest is being run with maven-failsafe-plugin. I have been using Mockserver for a couple years, and code like this hasn't broken before. As I said, upgrading from 5.2.3 to 5.3.0 is exactly when the error happens. I wish I had an easy way to git bisect the exact commit, but alas, I am not setup to do that (because I am not sure how to use a git-local dependency with Maven).

Thanks very much.

jamesdbloom commented 6 years ago

I’ll take a look in the next week or so, currently I’m working on some high priority issues.

brcolow commented 6 years ago

I found the problem. I had some lingering, stray imports, namely:

import org.mockserver.client.AbstractClient;
import org.mockserver.client.server.MockServerClient;

in the MockserverTest class. For some reason my IDE was not fully working and didn't show they were unnecessary. Why that caused the no method exceptions, I'm not sure.

Thanks for your work on Mockserver, James.