gpt4 book ai didi

java - Citrus Framework-SUT与其他服务进行通信时出现问题

转载 作者:行者123 更新时间:2023-12-01 18:34:07 26 4
gpt4 key购买 nike

我有一组通过Spring Boot实现的微服务,它们通过HTTP REST进行通信。我正在尝试使用Citrus框架设置集成测试。我已经为某些服务成功编写并执行了集成测试,但是正在为更复杂的用例而苦苦挣扎。

场景如下:

我有一个概念性的“任务计划”应用程序,涉及3个服务:任务计划器,路线生成器和路线评估器。任务计划者要求2条路线服务执行计划任务所需的一些工作。路由服务不进行REST调用。

我已经设置了我的maven POM文件,以便在执行Maven验证步骤时运行集成测试。故障安全和Spring Boot maven插件已配置为执行此操作。

路线服务的集成测试按预期工作,但任务计划程序的测试不起作用。我怀疑一个可能的原因是路由服务尚未启动。因此,在进行了一些研究之后,我在集成测试逻辑中插入了调用,以在进行测试工作之前启动这两个服务,并随后停止它们。

我不确定100%是否已采取正确的步骤正确启动服务。我也很好奇是否有办法知道他们是否真的成功启动了。我找不到解决此问题的任何文档。

无论如何,要么它们没有被启动,要么它们的配置有问题,或者还有其他引起问题的原因。当我运行测试时,它失败,并指示任务计划程序无法连接到路由生成器(首先称为路由生成器)。

以下是网络详细信息:


目前一切都在localhost上运行。
当前不涉及SSL / TLS。
路由生成器将在端口9110上侦听。
路由评估器将在端口9120上侦听。
任务计划程序配置为使用上述端口访问路线服务。


我的工作场所确实使用HTTP代理-这会影响本地主机通信吗?

任务计划者

EndpointConfig.java:

@Configuration
public class EndpointConfig {
@Bean
public HttpClient missionPlannerHTTPClient() {
return CitrusEndpoints.http().client().requestUrl("http://localhost:9100").build();
}
@Bean
public Server routeGeneratorServer() {
return CitrusEndpoints.http().server().port(9110).timeout(10000).build();
}
@Bean
public Server routeAssessorServer() {
return CitrusEndpoints.http().server().port(9120).timeout(10000).build();
}
}


我有限的理解是,这些bean应该提供在指定端口上运行的HTTP服务器。但是,对我来说,一个巨大的未知数是我实际上该如何运行相应的服务?如何将它们与这些端点关联?

我应该改为“模拟”路线服务吗?我假设我会做以下事情:

[摘自Citrus Framework用户指南 https://citrusframework.org/citrus/reference/2.8.0/html/index.html#http-rest-server]

http().server("helloHttpServer")
.receive()
.post("/test")
.payload("<testRequestMessage>" +
"<text<Hello HttpServer</text>" +
"</testRequestMessage>")
.contentType("application/xml")
.accept("application/xml, */*")
.header("X-CustomHeaderId", "${custom_header_id}")
.header("Authorization", "Basic c29tZVVzZXJuYW1lOnNvbWVQYXNzd29yZA==")
.extractFromHeader("X-MessageId", "message_id");
http().server("helloHttpServer")
.send()
.response(HttpStatus.OK)
.payload("<testResponseMessage>" +
"<text<Hello Citrus</text>" +
"</testResponseMessage>")
.version("HTTP/1.1")
.contentType("application/xml")
.header("X-CustomHeaderId", "${custom_header_id}")
.header("X-MessageId", "${message_id}");


完全不确定我实际需要显示多少内容。我不理解这两个电话的大部分最后部分。

模拟非SUT服务对于某些形式的测试很有意义,但是当给定使用链中的所有服务都是真实的时,我将如何进行端到端测试?

MissionPlannerIT.java:

public class MissionPlannerIT extends JUnit4CitrusTest {

@Qualifier("routeGeneratorServer")
private HttpServer routeGeneratorServer;
@Qualifier("routeAssessorServer")
private HttpServer routeAssessorServer;

@Autowired
private HttpClient missionPlannerHTTPClient;

@Test
@CitrusTest
// @formatter:off
public void testPlanMission(@CitrusResource TestRunner runner) {
runner.description("Test mission planning 'plan mission' REST endpoint");

// Start route generator and route assessor.
runner.start(routeGeneratorServer);
runner.start(routeAssessorServer);

// Call mission planner to plan a mission.
// Note: There is no request body (payload).
runner.http(builder -> builder
.client(missionPlannerHTTPClient)
.send()
.post("/v1/missionServices/missionPlanning/planMission"));

// Expect a success response.
runner.http(builder -> builder
.client(missionPlannerHTTPClient)
.receive()
.response(HttpStatus.OK)
.messageType(MessageType.JSON)
.payload(new ClassPathResource("templates/plan-mission-response.json")));

// Shut down route services.
runner.stop(routeGeneratorServer);
runner.stop(routeAssessorServer);
}
// @formatter:on

}


我不清楚为什么两个服务器都用 @Qualifier而不是 @Autowired进行注释。

pom.xml:

  <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<systemProperties>
<system.under.test.mode>${system.under.test.mode}</system.under.test.mode>
</systemProperties>
</configuration>
<executions>
<execution>
<id>integration-tests</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>edu.mit.ll.mission_services.service.mission_planner.ApplicationMain</mainClass>
<useTestClasspath>false</useTestClasspath>
</configuration>
<executions>
<execution>
<id>pre-integration-test</id>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>post-integration-test</id>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>


控制台日志:

$ mvn verify
...
[INFO] --- spring-boot-maven-plugin:2.1.6.RELEASE:start (pre-integration-test) @ mission-planner ---
...

. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.6.RELEASE)

[INFO]
[INFO] --- maven-failsafe-plugin:2.22.2:integration-test (default) @ mission-planner ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running edu.mit.ll.mission_services.service.mission_planner.MissionPlannerIT
[WARNING]
org.springframework.web.client.ResourceAccessException: I/O error on POST request for "http://localhost:9110/v1/missionServices/missionPlanning/generateRoute": Connect to localhost:9110 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect; nested exception is org.apache.http.conn.HttpHostConnectException: Connect to localhost:9110 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect
at org.springframework.web.client.RestTemplate.doExecute (RestTemplate.java:744)
at org.springframework.web.client.RestTemplate.execute (RestTemplate.java:670)
at org.springframework.web.client.RestTemplate.postForEntity (RestTemplate.java:445)
at edu.mit.ll.mission_services.service.mission_planner.service.MissionPlanner.postGenerateRoute (MissionPlanner.java:210)
at edu.mit.ll.mission_services.service.mission_planner.service.MissionPlanner.planMission (MissionPlanner.java:143)
at edu.mit.ll.mission_services.service.mission_planner.controller.MissionPlannerController$Runner.executeTask (MissionPlannerController.java:51)
at edu.mit.ll.mission_services.common.util.ITask.run (ITask.java:37)
at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:624)
at java.lang.Thread.run (Thread.java:748)
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to localhost:9110 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect (DefaultHttpClientConnectionOperator.java:156)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect (PoolingHttpClientConnectionManager.java:374)
at org.apache.http.impl.execchain.MainClientExec.establishRoute (MainClientExec.java:393)
at org.apache.http.impl.execchain.MainClientExec.execute (MainClientExec.java:236)
at org.apache.http.impl.execchain.ProtocolExec.execute (ProtocolExec.java:186)
at org.apache.http.impl.execchain.RetryExec.execute (RetryExec.java:89)
at org.apache.http.impl.execchain.RedirectExec.execute (RedirectExec.java:110)
at org.apache.http.impl.client.InternalHttpClient.doExecute (InternalHttpClient.java:185)
at org.apache.http.impl.client.CloseableHttpClient.execute (CloseableHttpClient.java:83)
at org.apache.http.impl.client.CloseableHttpClient.execute (CloseableHttpClient.java:56)
at org.springframework.http.client.HttpComponentsClientHttpRequest.executeInternal (HttpComponentsClientHttpRequest.java:87)
at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal (AbstractBufferingClientHttpRequest.java:48)
at org.springframework.http.client.AbstractClientHttpRequest.execute (AbstractClientHttpRequest.java:53)
at org.springframework.web.client.RestTemplate.doExecute (RestTemplate.java:735)
at org.springframework.web.client.RestTemplate.execute (RestTemplate.java:670)
at org.springframework.web.client.RestTemplate.postForEntity (RestTemplate.java:445)
at edu.mit.ll.mission_services.service.mission_planner.service.MissionPlanner.postGenerateRoute (MissionPlanner.java:210)
at edu.mit.ll.mission_services.service.mission_planner.service.MissionPlanner.planMission (MissionPlanner.java:143)
at edu.mit.ll.mission_services.service.mission_planner.controller.MissionPlannerController$Runner.executeTask (MissionPlannerController.java:51)
at edu.mit.ll.mission_services.common.util.ITask.run (ITask.java:37)
at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:624)
at java.lang.Thread.run (Thread.java:748)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.waitForConnect (Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect (DualStackPlainSocketImpl.java:85)
at java.net.AbstractPlainSocketImpl.doConnect (AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress (AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect (AbstractPlainSocketImpl.java:188)
at java.net.PlainSocketImpl.connect (PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect (SocksSocketImpl.java:392)
at java.net.Socket.connect (Socket.java:589)
at org.apache.http.conn.socket.PlainConnectionSocketFactory.connectSocket (PlainConnectionSocketFactory.java:75)
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect (DefaultHttpClientConnectionOperator.java:142)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect (PoolingHttpClientConnectionManager.java:374)
at org.apache.http.impl.execchain.MainClientExec.establishRoute (MainClientExec.java:393)
at org.apache.http.impl.execchain.MainClientExec.execute (MainClientExec.java:236)
at org.apache.http.impl.execchain.ProtocolExec.execute (ProtocolExec.java:186)
at org.apache.http.impl.execchain.RetryExec.execute (RetryExec.java:89)
at org.apache.http.impl.execchain.RedirectExec.execute (RedirectExec.java:110)
at org.apache.http.impl.client.InternalHttpClient.doExecute (InternalHttpClient.java:185)
at org.apache.http.impl.client.CloseableHttpClient.execute (CloseableHttpClient.java:83)
at org.apache.http.impl.client.CloseableHttpClient.execute (CloseableHttpClient.java:56)
at org.springframework.http.client.HttpComponentsClientHttpRequest.executeInternal (HttpComponentsClientHttpRequest.java:87)
at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal (AbstractBufferingClientHttpRequest.java:48)
at org.springframework.http.client.AbstractClientHttpRequest.execute (AbstractClientHttpRequest.java:53)
at org.springframework.web.client.RestTemplate.doExecute (RestTemplate.java:735)
at org.springframework.web.client.RestTemplate.execute (RestTemplate.java:670)
at org.springframework.web.client.RestTemplate.postForEntity (RestTemplate.java:445)
at edu.mit.ll.mission_services.service.mission_planner.service.MissionPlanner.postGenerateRoute (MissionPlanner.java:210)
at edu.mit.ll.mission_services.service.mission_planner.service.MissionPlanner.planMission (MissionPlanner.java:143)
at edu.mit.ll.mission_services.service.mission_planner.controller.MissionPlannerController$Runner.executeTask (MissionPlannerController.java:51)
at edu.mit.ll.mission_services.common.util.ITask.run (ITask.java:37)
at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:624)
at java.lang.Thread.run (Thread.java:748)
09:00:46.576 [main] ERROR com.consol.citrus.report.LoggingReporter - TEST FAILED MissionPlannerIT.testPlanMission <edu.mit.ll.mission_services.service.mission_planner> Nested exception is:
com.consol.citrus.exceptions.TestCaseFailedException: Failed to validate JSON text:
{"timestamp":"2020-02-06T14:00:46.436+0000","status":503,"error":"Service Unavailable","message":"Service Unavailable","path":"/v1/missionServices/missionPlanning/planMission"} Number of JSON entries not equal for element: '$.', expected '1' but was '5'
at com.consol.citrus.TestCase.executeAction(TestCase.java:227) [citrus-core-2.8.0.jar:?]
at com.consol.citrus.dsl.runner.DefaultTestRunner.run(DefaultTestRunner.java:188) ~[citrus-java-dsl-2.8.0.jar:?]
at com.consol.citrus.dsl.runner.DefaultTestRunner.http(DefaultTestRunner.java:540) [citrus-java-dsl-2.8.0.jar:?]
at edu.mit.ll.mission_services.service.mission_planner.MissionPlannerIT.testPlanMission(MissionPlannerIT.java:44) ~[test-classes/:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_191]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_191]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_191]
at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_191]
at org.springframework.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:282) ~[spring-core-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at com.consol.citrus.dsl.junit.JUnit4CitrusTest.invokeTestMethod(JUnit4CitrusTest.java:99) [citrus-java-dsl-2.8.0.jar:?]
at com.consol.citrus.dsl.junit.JUnit4CitrusTest.run(JUnit4CitrusTest.java:70) [citrus-java-dsl-2.8.0.jar:?]
at com.consol.citrus.junit.CitrusJUnit4Runner$InvokeRunMethod.evaluate(CitrusJUnit4Runner.java:217) [citrus-core-2.8.0.jar:?]
at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:74) [spring-test-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:84) [spring-test-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75) [spring-test-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86) [spring-test-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84) [spring-test-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) [junit-4.12.jar:4.12]
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251) [spring-test-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97) [spring-test-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) [junit-4.12.jar:4.12]
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) [junit-4.12.jar:4.12]
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) [junit-4.12.jar:4.12]
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) [junit-4.12.jar:4.12]
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) [junit-4.12.jar:4.12]
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) [spring-test-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70) [spring-test-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.junit.runners.ParentRunner.run(ParentRunner.java:363) [junit-4.12.jar:4.12]
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190) [spring-test-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:365) [surefire-junit4-2.22.2.jar:2.22.2]
at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:273) [surefire-junit4-2.22.2.jar:2.22.2]
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:238) [surefire-junit4-2.22.2.jar:2.22.2]
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:159) [surefire-junit4-2.22.2.jar:2.22.2]
at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:384) [surefire-booter-2.22.2.jar:2.22.2]
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:345) [surefire-booter-2.22.2.jar:2.22.2]
at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:126) [surefire-booter-2.22.2.jar:2.22.2]
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:418) [surefire-booter-2.22.2.jar:2.22.2]
Caused by: com.consol.citrus.exceptions.ValidationException: Failed to validate JSON text:
{"timestamp":"2020-02-06T14:00:46.436+0000","status":503,"error":"Service Unavailable","message":"Service Unavailable","path":"/v1/missionServices/missionPlanning/planMission"} Number of JSON entries not equal for element: '$.', expected '1' but was '5'
at com.consol.citrus.validation.json.JsonTextMessageValidator.validateMessage(JsonTextMessageValidator.java:127) ~[citrus-core-2.8.0.jar:?]
at com.consol.citrus.validation.json.JsonTextMessageValidator.validateMessage(JsonTextMessageValidator.java:62) ~[citrus-core-2.8.0.jar:?]
at com.consol.citrus.validation.AbstractMessageValidator.validateMessage(AbstractMessageValidator.java:46) ~[citrus-core-2.8.0.jar:?]
at com.consol.citrus.actions.ReceiveMessageAction.validateMessage(ReceiveMessageAction.java:231) ~[citrus-core-2.8.0.jar:?]
at com.consol.citrus.actions.ReceiveMessageAction.doExecute(ReceiveMessageAction.java:128) ~[citrus-core-2.8.0.jar:?]
at com.consol.citrus.actions.AbstractTestAction.execute(AbstractTestAction.java:42) ~[citrus-core-2.8.0.jar:?]
at com.consol.citrus.dsl.actions.DelegatingTestAction.doExecute(DelegatingTestAction.java:54) ~[citrus-java-dsl-2.8.0.jar:?]
at com.consol.citrus.actions.AbstractTestAction.execute(AbstractTestAction.java:42) ~[citrus-core-2.8.0.jar:?]
at com.consol.citrus.TestCase.executeAction(TestCase.java:220) ~[citrus-core-2.8.0.jar:?]
... 36 more
Caused by: java.lang.IllegalArgumentException: Number of JSON entries not equal for element: '$.', expected '1' but was '5'
at org.springframework.util.Assert.isTrue(Assert.java:118) ~[spring-core-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at com.consol.citrus.validation.json.JsonTextMessageValidator.validateJson(JsonTextMessageValidator.java:170) ~[citrus-core-2.8.0.jar:?]
at com.consol.citrus.validation.json.JsonTextMessageValidator.validateMessage(JsonTextMessageValidator.java:115) ~[citrus-core-2.8.0.jar:?]
at com.consol.citrus.validation.json.JsonTextMessageValidator.validateMessage(JsonTextMessageValidator.java:62) ~[citrus-core-2.8.0.jar:?]
at com.consol.citrus.validation.AbstractMessageValidator.validateMessage(AbstractMessageValidator.java:46) ~[citrus-core-2.8.0.jar:?]
at com.consol.citrus.actions.ReceiveMessageAction.validateMessage(ReceiveMessageAction.java:231) ~[citrus-core-2.8.0.jar:?]
at com.consol.citrus.actions.ReceiveMessageAction.doExecute(ReceiveMessageAction.java:128) ~[citrus-core-2.8.0.jar:?]
at com.consol.citrus.actions.AbstractTestAction.execute(AbstractTestAction.java:42) ~[citrus-core-2.8.0.jar:?]
at com.consol.citrus.dsl.actions.DelegatingTestAction.doExecute(DelegatingTestAction.java:54) ~[citrus-java-dsl-2.8.0.jar:?]
at com.consol.citrus.actions.AbstractTestAction.execute(AbstractTestAction.java:42) ~[citrus-core-2.8.0.jar:?]
at com.consol.citrus.TestCase.executeAction(TestCase.java:220) ~[citrus-core-2.8.0.jar:?]
... 36 more
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 13.907 s <<< FAILURE! - in edu.mit.ll.mission_services.service.mission_planner.MissionPlannerIT
[ERROR] testPlanMission(edu.mit.ll.mission_services.service.mission_planner.MissionPlannerIT) Time elapsed: 9.88 s <<< ERROR!
com.consol.citrus.exceptions.TestCaseFailedException:
Failed to validate JSON text:
{"timestamp":"2020-02-06T14:00:46.436+0000","status":503,"error":"Service Unavailable","message":"Service Unavailable","path":"/v1/missionServices/missionPlanning/planMission"} Number of JSON entries not equal for element: '$.', expected '1' but was '5'
at edu.mit.ll.mission_services.service.mission_planner.MissionPlannerIT.testPlanMission(MissionPlannerIT.java:44)
Caused by: com.consol.citrus.exceptions.ValidationException:
Failed to validate JSON text:
{"timestamp":"2020-02-06T14:00:46.436+0000","status":503,"error":"Service Unavailable","message":"Service Unavailable","path":"/v1/missionServices/missionPlanning/planMission"} Number of JSON entries not equal for element: '$.', expected '1' but was '5'
at edu.mit.ll.mission_services.service.mission_planner.MissionPlannerIT.testPlanMission(MissionPlannerIT.java:44)
Caused by: java.lang.IllegalArgumentException: Number of JSON entries not equal for element: '$.', expected '1' but was '5'
at edu.mit.ll.mission_services.service.mission_planner.MissionPlannerIT.testPlanMission(MissionPlannerIT.java:44)

[INFO]
[INFO] Results:
[INFO]
[ERROR] Errors:
[ERROR] MissionPlannerIT>JUnit4CitrusTest.run:70->JUnit4CitrusTest.invokeTestMethod:102 » TestCaseFailed
[INFO]
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0
[INFO]
[INFO]
[INFO] --- maven-failsafe-plugin:2.22.2:integration-test (integration-tests) @ mission-planner ---
[INFO] Skipping execution of surefire because it has already been run for this configuration
[INFO]
[INFO] --- spring-boot-maven-plugin:2.1.6.RELEASE:stop (post-integration-test) @ mission-planner ---
[INFO] Stopping application...
[INFO]
[INFO] --- maven-failsafe-plugin:2.22.2:verify (default) @ mission-planner ---
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for Mission Services - REST 0.0.1-SNAPSHOT:
[INFO]
[INFO] Mission Services - REST ............................ SUCCESS [ 2.475 s]
[INFO] Common Utilities ................................... SUCCESS [ 3.778 s]
[INFO] Mission Services Message Types ..................... SUCCESS [ 1.823 s]
[INFO] Security ........................................... SUCCESS [ 1.262 s]
[INFO] Mission Planner Client ............................. SUCCESS [ 4.679 s]
[INFO] Mission Planner Service ............................ FAILURE [ 48.212 s]
[INFO] Route Generator Service ............................ SKIPPED
[INFO] Route Assessor Service ............................. SKIPPED
[INFO] UAV Service ........................................ SKIPPED
[INFO] Correlator Service ................................. SKIPPED
[INFO] Correlator Client .................................. SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:03 min
[INFO] Finished at: 2020-02-06T09:00:50-05:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-failsafe-plugin:2.22.2:verify (default) on project mission-planner: There are test failures.
[ERROR]
[ERROR] Please refer to C:\Users\JO24447\workspace\REST_RST_Service\mission-services\mission-planner\target\failsafe-reports for the individual test results.
[ERROR] Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR] mvn <goals> -rf :mission-planner


我相信测试失败报告它正在等待指定的JSON消息,但是却收到了503消息JSON。这让我离开了很长时间,使我认为问题出在任务计划程序服务不可用。我认为这根本不是问题。

我在测试逻辑中定义/启动服务的方式有问题吗?代理会妨碍您吗?是否可以通过某种方法来评估路由服务的运行状况(假设它们甚至已经启动)?启动其他服务时是否缺少配置?

我很欣赏Citrus框架的大量文档和示例,它非常有帮助。但是,有许多情况和使用场景未进行讨论,这使得很难知道如何做才能成功。

更新:

陪审团仍未解决,但我可能偶然发现了解决方案。如果这确实解决了问题,那么当您找出问题后,它将像大多数典型的解决方案一样:极其简单。

我浏览了github上的Citrus示例,最后遇到了一个至少在某些方面与我的情况相似的示例。我发现的东西引起了我的注意,当我尝试一下时,似乎终于克服了这个问题。

这是一个片段:

@Autowired
@Qualifier("networkBackendHttpServer")
private HttpServer networkHttpServer;


请注意 @Autowired批注。那就是我的代码所缺少的。记住,我对上面的事情很感兴趣。如果只有我知道 @Qualifer注释做了什么和没有做什么。

最佳答案

解决方案很简单。我需要用@Autowired注释我的“服务器”对象。

public class MissionPlannerIT extends JUnit4CitrusTest {

@Autowired
@Qualifier("routeGeneratorServer")
private HttpServer rgServer;
@Autowired
@Qualifier("routeAssessorServer")
private HttpServer raServer;


我做出了一个错误的假设,即 @Qualifier注释也会自动连接这些对象。嘿,不。

关于java - Citrus Framework-SUT与其他服务进行通信时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60097222/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com