You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by GitBox <gi...@apache.org> on 2020/11/04 09:07:07 UTC

[GitHub] [camel-quarkus] jamesnetherton commented on a change in pull request #1988: WireMockTestResourceLifecycleManager improvements

jamesnetherton commented on a change in pull request #1988:
URL: https://github.com/apache/camel-quarkus/pull/1988#discussion_r517192117



##########
File path: integration-tests-support/wiremock/src/main/java/org/apache/camel/quarkus/test/wiremock/WireMockTestResourceLifecycleManager.java
##########
@@ -78,30 +82,35 @@
      */
     @Override
     public void stop() {
-        if (server != null) {
-            LOG.info("Stopping WireMockServer");
-            if (server.getRecordingStatus().getStatus().equals(RecordingStatus.Recording)) {
-                LOG.info("Stopping recording");
-                SnapshotRecordResult recordResult = server.stopRecording();
-
-                List<StubMapping> stubMappings = recordResult.getStubMappings();
-                if (isDeleteRecordedMappingsOnError()) {
-                    for (StubMapping mapping : stubMappings) {
-                        int status = mapping.getResponse().getStatus();
-                        if (status >= 300 && mapping.shouldBePersisted()) {
-                            try {
-                                String fileName = mapping.getName() + "-" + mapping.getId() + ".json";
-                                Path mappingFilePath = Paths.get("./src/test/resources/mappings/", fileName);
-                                Files.deleteIfExists(mappingFilePath);
-                                LOG.infof("Deleted mapping file %s as status code was %d", fileName, status);
-                            } catch (IOException e) {
-                                LOG.errorf("Failed to delete mapping file %s", e, mapping.getName());
+        WireMockServer server = getServer();
+        try {
+            if (server != null) {
+                LOG.info("Stopping WireMockServer");
+                if (server.getRecordingStatus().getStatus().equals(RecordingStatus.Recording)) {
+                    LOG.info("Stopping recording");
+                    SnapshotRecordResult recordResult = server.stopRecording();
+
+                    List<StubMapping> stubMappings = recordResult.getStubMappings();
+                    if (isDeleteRecordedMappingsOnError()) {
+                        for (StubMapping mapping : stubMappings) {
+                            int status = mapping.getResponse().getStatus();
+                            if (status >= 300 && mapping.shouldBePersisted()) {
+                                try {
+                                    String fileName = mapping.getName() + "-" + mapping.getId() + ".json";
+                                    Path mappingFilePath = Paths.get("./src/test/resources/mappings/", fileName);
+                                    Files.deleteIfExists(mappingFilePath);
+                                    LOG.infof("Deleted mapping file %s as status code was %d", fileName, status);
+                                } catch (IOException e) {
+                                    LOG.errorf("Failed to delete mapping file %s", e, mapping.getName());
+                                }
                             }
                         }
                     }
                 }
+                server.stop();
             }
-            server.stop();
+        } finally {
+            servers.remove(getServerKey());

Review comment:
       If an integration test has multiple test classes annotated with `@TestResource(Foo.class)`. Then `start()` / `stop()` is only invoked once. I.e when the first test starts and the last test completes.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org