15
15
import org .apache .commons .lang3 .tuple .Pair ;
16
16
import org .jetbrains .annotations .NotNull ;
17
17
import org .junit .Assert ;
18
+ import org .mockserver .closurecallback .websocketregistry .LocalCallbackRegistry ;
18
19
import org .mockserver .collections .CircularPriorityQueue ;
19
20
import org .mockserver .integration .ClientAndServer ;
20
21
import org .mockserver .matchers .*;
37
38
import java .util .regex .Pattern ;
38
39
39
40
import static com .decathlon .tzatziki .utils .Fields .getValue ;
40
- import static com .decathlon .tzatziki .utils .Mapper .toYaml ;
41
41
import static com .decathlon .tzatziki .utils .Unchecked .unchecked ;
42
42
import static java .util .function .Function .identity ;
43
43
import static java .util .stream .Collectors .*;
@@ -78,29 +78,6 @@ protected HttpState initialize() throws ConcurrentException {
78
78
public static synchronized void add_mock (HttpRequest httpRequest , ExpectationResponseCallback callback , Comparison comparison ) {
79
79
HttpState httpState = unchecked (HTTP_STATE ::get );
80
80
CircularPriorityQueue <String , HttpRequestMatcher , SortableExpectationId > expectationsQueue = Fields .getValue (httpState .getRequestMatchers (), "httpRequestMatchers" );
81
- httpState .getRequestMatchers ().retrieveActiveExpectations (httpRequest )
82
- // we are redefining an old mock with a matches, let's see if we have old callbacks still in 404
83
- .stream ()
84
- .filter (expectation -> {
85
- Pair <Expectation [], UpdatableExpectationResponseCallback > updatableExpectationResponseCallbackPair = MOCKS .get (expectation .getHttpRequest ().toString ());
86
- if (updatableExpectationResponseCallbackPair == null ) {
87
- log .error ("""
88
- couldn't find the httpRequest in the mocks, this shouldn't happen!
89
-
90
- httpRequest: {}
91
-
92
- MOCKS keys: {}
93
- """ , toYaml (httpRequest .toString ()), toYaml (MOCKS .keySet ()));
94
- return false ;
95
- }
96
- return updatableExpectationResponseCallbackPair .getValue ().callback .equals (NOT_FOUND );
97
- })
98
- .forEach (expectation -> {
99
- expectationsQueue .remove (expectationsQueue .getByKey (expectation .getId ()).orElseThrow (() ->
100
- new IllegalStateException ("couldn't find the old expectation in the queue for removal" )));
101
- MOCKS .remove (expectation .getHttpRequest ().toString ());
102
- log .debug ("removing expectation {}" , expectation .getHttpRequest ());
103
- });
104
81
105
82
AtomicBoolean isNew = new AtomicBoolean (false );
106
83
latestPriority ++;
@@ -127,7 +104,14 @@ public static synchronized void add_mock(HttpRequest httpRequest, ExpectationRes
127
104
// update the priority of the expectation
128
105
.map (expectation -> expectation .withPriority (latestPriority ))
129
106
// re-add the expectations, this will resort the CircularPriorityQueue
130
- .forEach (expectation -> httpState .getRequestMatchers ().add (expectation , MockServerMatcherNotifier .Cause .API ));
107
+ .forEach (expectation -> {
108
+ httpState .getRequestMatchers ().add (expectation , MockServerMatcherNotifier .Cause .API );
109
+
110
+ String clientId = expectation .getHttpResponseObjectCallback ().getClientId ();
111
+ Map <String , ExpectationResponseCallback > responseCallbackRegistry = LocalCallbackRegistry .responseCallbackRegistry ();
112
+ responseCallbackRegistry .remove (clientId );
113
+ responseCallbackRegistry .put (clientId , expectationWithCallback .getValue ());
114
+ });
131
115
}
132
116
133
117
if (httpRequest .getPath () instanceof NottableSchemaString uriSchema ) {
0 commit comments