1

I'd like to use MockServer analysis in the dumpToLogAsJava mode to have it print java-formatted expectations of a HTTP service I have.

Moreover I'd like to use mockserver-maven-plugin for it.

So far I was able to get a json-formatted output like this:

2016-06-07 19:10:46,348 DEBUG [main] org.mockserver.cli.Main [?:?]

Using command line options: proxyPort=18080

2016-06-07 19:10:46,623 INFO [MockServer HttpProxy Thread] org.mockserver.proxy.http.HttpProxy [?:?] MockServer proxy started on port: 18080
2016-06-07 19:10:46,626 DEBUG [MockServer HttpProxy Thread] o.m.c.ConfigurationProperties [?:?] Property file not found on classpath using path [mockserver.properties]
2016-06-07 19:10:46,626 DEBUG [MockServer HttpProxy Thread] o.m.c.ConfigurationProperties [?:?] Property file not found using path [mockserver.properties]
2016-06-07 19:11:01,838 DEBUG [nioEventLoopGroup-3-1] o.m.client.netty.NettyHttpClient [?:?] Sending request: {
"method" : "GET",
"path" : "/sources",
 [...]
}
2016-06-07 19:11:02,180 DEBUG [nioEventLoopGroup-3-1] o.m.client.netty.NettyHttpClient [?:?] Received response: {
 [...]
}
2016-06-07 19:11:02,220 INFO [nioEventLoopGroup-3-1] o.m.proxy.http.HttpProxyHandler [?:?] returning response:
        {
          [...]
        }
 for request as json:    
        {
          [...]
        }

 as curl:    
        [...]

By adding the following to my pom.xml

                <plugin>
                    <groupId>org.mock-server</groupId>
                    <artifactId>mockserver-maven-plugin</artifactId>
                    <version>3.10.4</version>
                    <configuration>                       
                        <proxyPort>18080</proxyPort>
                        <logLevel>DEBUG</logLevel>
                    </configuration>
                    <executions>
                        <execution>
                            <id>start-mock</id>
                            <phase>pre-integration-test</phase>
                            <goals>
                                <goal>runForked</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>stop-mock</id>
                            <phase>post-integration-test</phase>
                            <goals>
                                <goal>stopForked</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>

I have no idea how to change the output format to Java without writing some additional Java code (and even then I'm not sure what exactly would I have to write).

PS. I can't seem to get a Java-formatted dump at all -- I've filled an issue on GH

Jakub Bochenski
  • 3,113
  • 4
  • 33
  • 61

1 Answers1

0

The missing part was that you need dump the expectations after the requests you are interested in have been executed. My impression was that it's a feature you enable and then Mockserver dumps the expectation on the go.

Anyhow, here is one ugly way to do it:

    ClientAndProxy client = ClientAndProxy.startClientAndProxy(18080);
    Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override
        public void run() {
            client.dumpToLogAsJava();
        }
    });
Jakub Bochenski
  • 3,113
  • 4
  • 33
  • 61