@@ -15,6 +15,7 @@ import org.junit.Test
1515import static com.github.tomakehurst.wiremock.client.WireMock.*
1616import static org.junit.Assert.assertNotNull
1717import static org.junit.Assert.assertNull
18+ import static org.junit.Assert.assertTrue
1819
1920class ValidateHarRestTest extends BaseRestTest {
2021
@@ -23,6 +24,90 @@ class ValidateHarRestTest extends BaseRestTest {
2324 return ' har'
2425 }
2526
27+ @Test
28+ void cleanHarFalseTest () {
29+ def urlToCatch = ' test'
30+ def responseBody = ' '
31+
32+ mockTargetServerResponse(urlToCatch, responseBody)
33+
34+ proxyManager. get()[0 ]. newHar()
35+
36+ requestToTargetServer(urlToCatch, responseBody)
37+
38+ proxyRestServerClient. request(Method . GET , ContentType . WILDCARD ) { req ->
39+ uri. path = " /proxy/${ proxy.port} /${ urlPath} "
40+ response. success = { HttpResponseDecorator resp ->
41+ Har har = new ObjectMapper (). readValue(resp. entity. content, Har ) as Har
42+
43+ assertTrue (" Expected captured queries in har" , har. getLog(). getEntries(). size() > 0 )
44+ }
45+ }
46+
47+ proxyRestServerClient. request(Method . GET , ContentType . WILDCARD ) { req ->
48+ uri. path = " /proxy/${ proxy.port} /${ urlPath} "
49+ uri. query = [' cleanHar' : false ]
50+ response. success = { HttpResponseDecorator resp ->
51+ Har har = new ObjectMapper (). readValue(resp. entity. content, Har ) as Har
52+
53+ assertTrue (" Expected captured queries in har" , har. getLog(). getEntries(). size() > 0 )
54+ }
55+ }
56+
57+ proxyRestServerClient. request(Method . GET , ContentType . WILDCARD ) { req ->
58+ uri. path = " /proxy/${ proxy.port} /${ urlPath} "
59+ response. success = { HttpResponseDecorator resp ->
60+ Har har = new ObjectMapper (). readValue(resp. entity. content, Har ) as Har
61+
62+ assertTrue (" Expected captured queries in har" , har. getLog(). getEntries(). size() > 0 )
63+ }
64+ }
65+
66+ verify(1 , getRequestedFor(urlEqualTo(" /${ urlToCatch} " )))
67+ }
68+
69+ @Test
70+ void cleanHarTest () {
71+ def urlToCatch = ' test'
72+ def responseBody = ' '
73+
74+ mockTargetServerResponse(urlToCatch, responseBody)
75+
76+ proxyManager. get()[0 ]. newHar()
77+
78+ requestToTargetServer(urlToCatch, responseBody)
79+
80+ proxyRestServerClient. request(Method . GET , ContentType . WILDCARD ) { req ->
81+ uri. path = " /proxy/${ proxy.port} /${ urlPath} "
82+ response. success = { HttpResponseDecorator resp ->
83+ Har har = new ObjectMapper (). readValue(resp. entity. content, Har ) as Har
84+
85+ assertTrue (" Expected captured queries in har" , har. getLog(). getEntries(). size() > 0 )
86+ }
87+ }
88+
89+ proxyRestServerClient. request(Method . GET , ContentType . WILDCARD ) { req ->
90+ uri. path = " /proxy/${ proxy.port} /${ urlPath} "
91+ uri. query = [' cleanHar' : true ]
92+ response. success = { HttpResponseDecorator resp ->
93+ Har har = new ObjectMapper (). readValue(resp. entity. content, Har ) as Har
94+
95+ assertTrue (" Expected captured queries in old har" , har. getLog(). getEntries(). size() > 0 )
96+ }
97+ }
98+
99+ proxyRestServerClient. request(Method . GET , ContentType . WILDCARD ) { req ->
100+ uri. path = " /proxy/${ proxy.port} /${ urlPath} "
101+ response. success = { HttpResponseDecorator resp ->
102+ Har har = new ObjectMapper (). readValue(resp. entity. content, Har ) as Har
103+
104+ assertTrue (" Expected to get Har without entries" , har. getLog(). getEntries(). size() == 0 )
105+ }
106+ }
107+
108+ verify(1 , getRequestedFor(urlEqualTo(" /${ urlToCatch} " )))
109+ }
110+
26111 @Test
27112 void validateHarForRequestWithEmptyContentAndMimeType () {
28113 def urlToCatch = ' test'
0 commit comments