Skip to content

Commit 02b5f6b

Browse files
committed
Bump to hoverfly v1.8.0
1 parent dc7a30e commit 02b5f6b

File tree

3 files changed

+74
-15
lines changed

3 files changed

+74
-15
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
version=0.16.3-SNAPSHOT
22
title=Hoverfly Java
33
description=Hoverfly for Java. Capture and simulate HTTP(S) services in JUnit tests.
4-
hoverfly_binary_version=v1.7.0
4+
hoverfly_binary_version=v1.8.0

src/test/java/io/specto/hoverfly/ruletest/HoverflyDslTest.java

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
package io.specto.hoverfly.ruletest;
22

3+
import static io.specto.hoverfly.junit.core.SimulationSource.dsl;
4+
import static io.specto.hoverfly.junit.dsl.HoverflyDsl.service;
5+
import static io.specto.hoverfly.junit.dsl.HttpBodyConverter.jsonWithSingleQuotes;
6+
import static io.specto.hoverfly.junit.dsl.ResponseCreators.created;
7+
import static io.specto.hoverfly.junit.dsl.ResponseCreators.noContent;
8+
import static io.specto.hoverfly.junit.dsl.ResponseCreators.success;
9+
import static net.javacrumbs.jsonunit.fluent.JsonFluentAssert.assertThatJson;
10+
import static org.assertj.core.api.Assertions.assertThat;
11+
import static org.springframework.http.HttpStatus.OK;
12+
import static org.springframework.http.MediaType.APPLICATION_JSON;
13+
314
import io.specto.hoverfly.junit.rule.HoverflyRule;
15+
import java.net.URI;
16+
import java.net.URISyntaxException;
417
import org.junit.ClassRule;
518
import org.junit.Test;
619
import org.springframework.http.HttpStatus;
@@ -10,18 +23,6 @@
1023
import org.springframework.web.client.RestTemplate;
1124
import org.springframework.web.util.UriComponentsBuilder;
1225

13-
import java.net.URI;
14-
import java.net.URISyntaxException;
15-
16-
import static io.specto.hoverfly.junit.core.SimulationSource.dsl;
17-
import static io.specto.hoverfly.junit.dsl.HoverflyDsl.service;
18-
import static io.specto.hoverfly.junit.dsl.HttpBodyConverter.jsonWithSingleQuotes;
19-
import static io.specto.hoverfly.junit.dsl.ResponseCreators.*;
20-
import static net.javacrumbs.jsonunit.fluent.JsonFluentAssert.assertThatJson;
21-
import static org.assertj.core.api.Assertions.assertThat;
22-
import static org.springframework.http.HttpStatus.OK;
23-
import static org.springframework.http.MediaType.APPLICATION_JSON;
24-
2526
public class HoverflyDslTest {
2627

2728
@ClassRule
@@ -125,6 +126,4 @@ public void shouldBeAbleToPatchBookingsUsingHoverfly() throws Exception {
125126
assertThat(bookFlightResponse.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT);
126127
}
127128

128-
129-
130129
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package io.specto.hoverfly.ruletest;
2+
3+
import io.specto.hoverfly.junit.core.SimulationSource;
4+
import io.specto.hoverfly.junit.dsl.HoverflyDsl;
5+
import io.specto.hoverfly.junit.dsl.HttpBodyConverter;
6+
import io.specto.hoverfly.junit.dsl.ResponseCreators;
7+
import io.specto.hoverfly.junit.dsl.matchers.HoverflyMatchers;
8+
import io.specto.hoverfly.junit.rule.HoverflyRule;
9+
import org.assertj.core.api.Assertions;
10+
import org.junit.ClassRule;
11+
import org.junit.Test;
12+
import org.springframework.http.HttpEntity;
13+
import org.springframework.http.HttpMethod;
14+
import org.springframework.web.client.RestTemplate;
15+
16+
public class HoverflyMatchingPriorityTest {
17+
18+
@ClassRule
19+
public static HoverflyRule hoverflyRule = HoverflyRule.inSimulationMode();
20+
21+
@Test
22+
public void shouldPassWhenSpecificBodyMatcherDeclaredFirst() {
23+
hoverflyRule.simulate(SimulationSource.dsl(
24+
HoverflyDsl.service("https://test.com")
25+
.post("/sameUrl")
26+
.body(HoverflyMatchers.matchesPartialJson(HttpBodyConverter.jsonWithSingleQuotes("{'attr':'value'}")))
27+
.willReturn(ResponseCreators.success())
28+
.post("/sameUrl")
29+
.anyBody()
30+
.willReturn(ResponseCreators.badRequest())
31+
));
32+
Assertions.assertThat(new RestTemplate().exchange("https://test.com/sameUrl", HttpMethod.POST, new HttpEntity<>(" {\n"
33+
+ " \"test\": 1,\n"
34+
+ " \"attr\": \"value\",\n"
35+
+ " \"list\": [ \"A\", \"B\" ]\n"
36+
+ " }"), String.class))
37+
.isNotNull();
38+
}
39+
40+
@Test
41+
public void shouldPassWhenSpecificBodyMatcherDeclaredLast() {
42+
hoverflyRule.simulate(SimulationSource.dsl(
43+
HoverflyDsl.service("https://test.com")
44+
.post("/sameUrl")
45+
.anyBody()
46+
.willReturn(ResponseCreators.badRequest())
47+
.post("/sameUrl")
48+
.body(HoverflyMatchers.matchesPartialJson(HttpBodyConverter.jsonWithSingleQuotes("{'attr':'value'}")))
49+
.willReturn(ResponseCreators.success())
50+
51+
));
52+
Assertions.assertThat(new RestTemplate().exchange("https://test.com/sameUrl", HttpMethod.POST, new HttpEntity<>(" {\n"
53+
+ " \"test\": 1,\n"
54+
+ " \"attr\": \"value\",\n"
55+
+ " \"list\": [ \"A\", \"B\" ]\n"
56+
+ " }"), String.class))
57+
.isNotNull();
58+
}
59+
60+
}

0 commit comments

Comments
 (0)