Skip to content

Commit 6fc4e9a

Browse files
Oliver Meyertommysitu
authored andcommitted
Allow Java API access to the DiffView objects from HoverflyClient.getDiffs() #249
1 parent 46a5635 commit 6fc4e9a

File tree

2 files changed

+46
-30
lines changed

2 files changed

+46
-30
lines changed

src/main/java/io/specto/hoverfly/junit/core/Hoverfly.java

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,34 @@
1212
*/
1313
package io.specto.hoverfly.junit.core;
1414

15+
import static io.specto.hoverfly.junit.core.HoverflyConfig.localConfigs;
16+
import static io.specto.hoverfly.junit.core.HoverflyMode.CAPTURE;
17+
import static io.specto.hoverfly.junit.core.HoverflyMode.DIFF;
18+
import static io.specto.hoverfly.junit.core.HoverflyUtils.checkPortInUse;
19+
import static io.specto.hoverfly.junit.core.HoverflyUtils.readSimulationFromString;
20+
import static io.specto.hoverfly.junit.dsl.matchers.HoverflyMatchers.any;
21+
import static io.specto.hoverfly.junit.verification.HoverflyVerifications.atLeastOnce;
22+
import static io.specto.hoverfly.junit.verification.HoverflyVerifications.never;
23+
import static io.specto.hoverfly.junit.verification.HoverflyVerifications.times;
24+
25+
import com.fasterxml.jackson.databind.ObjectMapper;
26+
import com.fasterxml.jackson.databind.ObjectWriter;
27+
import io.specto.hoverfly.junit.api.HoverflyClient;
28+
import io.specto.hoverfly.junit.api.HoverflyClientException;
29+
import io.specto.hoverfly.junit.api.model.ModeArguments;
30+
import io.specto.hoverfly.junit.api.view.DiffView;
31+
import io.specto.hoverfly.junit.api.view.HoverflyInfoView;
32+
import io.specto.hoverfly.junit.api.view.StateView;
33+
import io.specto.hoverfly.junit.core.config.HoverflyConfiguration;
34+
import io.specto.hoverfly.junit.core.model.Journal;
35+
import io.specto.hoverfly.junit.core.model.Request;
36+
import io.specto.hoverfly.junit.core.model.RequestResponsePair;
37+
import io.specto.hoverfly.junit.core.model.Simulation;
38+
import io.specto.hoverfly.junit.dsl.RequestMatcherBuilder;
39+
import io.specto.hoverfly.junit.dsl.StubServiceBuilder;
40+
import io.specto.hoverfly.junit.verification.HoverflyComparisonFailure;
41+
import io.specto.hoverfly.junit.verification.VerificationCriteria;
42+
import io.specto.hoverfly.junit.verification.VerificationData;
1543
import java.io.File;
1644
import java.io.IOException;
1745
import java.io.OutputStream;
@@ -32,41 +60,12 @@
3260
import java.util.concurrent.TimeUnit;
3361
import java.util.concurrent.TimeoutException;
3462
import java.util.stream.Stream;
35-
36-
import com.fasterxml.jackson.databind.ObjectMapper;
37-
import com.fasterxml.jackson.databind.ObjectWriter;
38-
import io.specto.hoverfly.junit.api.HoverflyClient;
39-
import io.specto.hoverfly.junit.api.HoverflyClientException;
40-
import io.specto.hoverfly.junit.api.model.ModeArguments;
41-
import io.specto.hoverfly.junit.api.view.DiffView;
42-
import io.specto.hoverfly.junit.api.view.HoverflyInfoView;
43-
import io.specto.hoverfly.junit.api.view.StateView;
44-
import io.specto.hoverfly.junit.core.config.HoverflyConfiguration;
45-
import io.specto.hoverfly.junit.core.model.Journal;
46-
import io.specto.hoverfly.junit.core.model.Request;
47-
import io.specto.hoverfly.junit.core.model.RequestResponsePair;
48-
import io.specto.hoverfly.junit.core.model.Simulation;
49-
import io.specto.hoverfly.junit.dsl.RequestMatcherBuilder;
50-
import io.specto.hoverfly.junit.dsl.StubServiceBuilder;
51-
import io.specto.hoverfly.junit.verification.VerificationCriteria;
52-
import io.specto.hoverfly.junit.verification.VerificationData;
5363
import org.apache.commons.lang3.StringUtils;
54-
import org.junit.Assert;
5564
import org.slf4j.Logger;
5665
import org.slf4j.LoggerFactory;
5766
import org.zeroturnaround.exec.ProcessExecutor;
5867
import org.zeroturnaround.exec.StartedProcess;
5968

60-
import static io.specto.hoverfly.junit.core.HoverflyConfig.localConfigs;
61-
import static io.specto.hoverfly.junit.core.HoverflyMode.CAPTURE;
62-
import static io.specto.hoverfly.junit.core.HoverflyMode.DIFF;
63-
import static io.specto.hoverfly.junit.core.HoverflyUtils.checkPortInUse;
64-
import static io.specto.hoverfly.junit.core.HoverflyUtils.readSimulationFromString;
65-
import static io.specto.hoverfly.junit.dsl.matchers.HoverflyMatchers.any;
66-
import static io.specto.hoverfly.junit.verification.HoverflyVerifications.atLeastOnce;
67-
import static io.specto.hoverfly.junit.verification.HoverflyVerifications.never;
68-
import static io.specto.hoverfly.junit.verification.HoverflyVerifications.times;
69-
7069
/**
7170
* A wrapper class for the Hoverfly binary. Manage the lifecycle of the processes, and then manage Hoverfly itself by using it's API endpoints.
7271
*/
@@ -494,7 +493,7 @@ public void assertThatNoDiffIsReported(boolean shouldResetDiff) {
494493
if (shouldResetDiff) {
495494
hoverflyClient.cleanDiffs();
496495
}
497-
Assert.fail(message.toString());
496+
throw new HoverflyComparisonFailure(message.toString(), diffs);
498497
}
499498
}
500499

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package io.specto.hoverfly.junit.verification;
2+
3+
import io.specto.hoverfly.junit.api.view.DiffView;
4+
5+
public class HoverflyComparisonFailure extends AssertionError {
6+
7+
private final DiffView diffs;
8+
9+
public HoverflyComparisonFailure(String message, DiffView diffs) {
10+
super(message);
11+
this.diffs = diffs;
12+
}
13+
14+
public DiffView getDiffs() {
15+
return diffs;
16+
}
17+
}

0 commit comments

Comments
 (0)