(OracleContainer + MockServer)java.net.ConnectException:连接被拒绝:没有更多信息:localhost / 0:0:0:0:0:0:0:0:1:49561

时间:2019-01-28 10:57:00

标签: docker playframework docker-compose junit4 testcontainers

框架: Play 2.6.x
TestContianer:"org.testcontainers" % "oracle-xe" % "1.10.5"
通过模拟WSClient尝试为oracle-container编写测试用例
原因:当使用模拟服务器调用内部服务时,抛出异常。

我试图创建一个通用容器,但是存在问题。

@ClassRule     公共静态OracleContainer oracleContainer =新的OracleContainer(“ niteshsharma / oracle-xe:11”);

@BeforeClass
public static void setUp() {
    oracleContainer.withExtraHost("localhost","1522");
    oracleContainer.addExposedPort(1522);
    oracleContainer.setPortBindings(Collections.singletonList(1521));
    oracleContainer.start();

    app = new GuiceApplicationBuilder()
            .overrides(bind(WSClient.class).to(WSClientMock.class))
            .configure("db.default", ImmutableMap.of(
                    "driver",oracleContainer.getDriverClassName(),
                    "url", oracleContainer.getJdbcUrl(),
                    "username", oracleContainer.getUsername(),
                    "password", oracleContainer.getPassword()
            ))
            .configure("aws.sqs",ImmutableMap.of(
                    "url",sqsQueueUrl
            ))
            .configure("aws",ImmutableMap.of(
                    "accessKeyId","foo",
                    "secretKey","foo"
            ))
            .in(Mode.TEST).build();
    Helpers.start(app);
}

MockServer代码:

public WSClientMock() {
    server = Server.forRouter((components) -> RoutingDsl.fromComponents(components)
            .GET("/Auth/v1/rules")
            .routeTo(() -> ok().sendResource("mock-responses/apiAuthRule.json"))
            .build());
    ws = WSTestClient.newClient(server.httpPort());
}

模拟服务器应正常工作,不会引发异常。

0 个答案:

没有答案