使用Maven插件进行MockServer分析 - 输出为Java

时间:2016-06-07 17:32:29

标签: java maven mocking mockserver

我想在dumpToLogAsJava模式下使用MockServer analysis来打印我所拥有的HTTP服务的java格式期望。

此外,我还想使用mockserver-maven-plugin。

到目前为止,我能够得到像这样的json格式输出:

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:    
        [...]

将以下内容添加到我的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>

我不知道如何在不编写其他Java代码的情况下将输出格式更改为Java(即使那时我也不确定我究竟要写什么)。

PS。我根本无法获得Java格式的转储 - 我在GH上填写了一个问题

1 个答案:

答案 0 :(得分:0)

缺少的部分是你需要在你感兴趣的请求被执行后转储期望。 我的印象是,这是你启用的一项功能,然后Mockserver会在旅途中抛弃预期。

无论如何,这是一种丑陋的方式:

    ClientAndProxy client = ClientAndProxy.startClientAndProxy(18080);
    Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override
        public void run() {
            client.dumpToLogAsJava();
        }
    });