Skip to content

Commit

Permalink
deploy: d398ac4
Browse files Browse the repository at this point in the history
  • Loading branch information
osoykan committed Dec 11, 2024
1 parent 96d2e20 commit ebf6b72
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
49 changes: 49 additions & 0 deletions Components/04-wiremock/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,21 @@
</span>
</a>

<nav class="md-nav" aria-label="Mocking">
<ul class="md-nav__list">

<li class="md-nav__item">
<a href="#behavioural-mocking" class="md-nav__link">
<span class="md-ellipsis">
Behavioural Mocking
</span>
</a>

</li>

</ul>
</nav>

</li>

</ul>
Expand Down Expand Up @@ -747,6 +762,40 @@ <h2 id="mocking">Mocking<a class="headerlink" href="#mocking" title="Permanent l
</code></pre></div>
<p>Relative url is mocked. BaseUrl is known by Wiremock server since it hosts it, and your application because you passed
it as a command line argument.</p>
<h3 id="behavioural-mocking">Behavioural Mocking<a class="headerlink" href="#behavioural-mocking" title="Permanent link">&para;</a></h3>
<p>Sometimes, a service call returns a failure response before a success response. You can define this behaviour with
behavioural mocking.</p>
<div class="highlight"><pre><span></span><code><a id="__codelineno-5-1" name="__codelineno-5-1" href="#__codelineno-5-1"></a><span class="n">test</span><span class="p">(</span><span class="s">&quot;behavioural tests&quot;</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-5-2" name="__codelineno-5-2" href="#__codelineno-5-2"></a><span class="w"> </span><span class="kd">val</span><span class="w"> </span><span class="nv">expectedGetDtoName</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">UUID</span><span class="p">.</span><span class="na">randomUUID</span><span class="p">().</span><span class="na">toString</span><span class="p">()</span>
<a id="__codelineno-5-3" name="__codelineno-5-3" href="#__codelineno-5-3"></a><span class="w"> </span><span class="n">TestSystem</span><span class="p">.</span><span class="na">validate</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-5-4" name="__codelineno-5-4" href="#__codelineno-5-4"></a><span class="w"> </span><span class="n">wiremock</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-5-5" name="__codelineno-5-5" href="#__codelineno-5-5"></a><span class="w"> </span><span class="n">behaviourFor</span><span class="p">(</span><span class="s">&quot;/get-behaviour&quot;</span><span class="p">,</span><span class="w"> </span><span class="n">WireMock</span><span class="o">::</span><span class="k">get</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-5-6" name="__codelineno-5-6" href="#__codelineno-5-6"></a><span class="w"> </span><span class="n">initially</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-5-7" name="__codelineno-5-7" href="#__codelineno-5-7"></a><span class="w"> </span><span class="n">aResponse</span><span class="p">()</span>
<a id="__codelineno-5-8" name="__codelineno-5-8" href="#__codelineno-5-8"></a><span class="w"> </span><span class="p">.</span><span class="na">withStatus</span><span class="p">(</span><span class="m">503</span><span class="p">)</span>
<a id="__codelineno-5-9" name="__codelineno-5-9" href="#__codelineno-5-9"></a><span class="w"> </span><span class="p">.</span><span class="na">withBody</span><span class="p">(</span><span class="s">&quot;Service unavailable&quot;</span><span class="p">)</span>
<a id="__codelineno-5-10" name="__codelineno-5-10" href="#__codelineno-5-10"></a><span class="w"> </span><span class="p">}</span>
<a id="__codelineno-5-11" name="__codelineno-5-11" href="#__codelineno-5-11"></a><span class="w"> </span><span class="n">then</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-5-12" name="__codelineno-5-12" href="#__codelineno-5-12"></a><span class="w"> </span><span class="n">aResponse</span><span class="p">()</span>
<a id="__codelineno-5-13" name="__codelineno-5-13" href="#__codelineno-5-13"></a><span class="w"> </span><span class="p">.</span><span class="na">withHeader</span><span class="p">(</span><span class="s">&quot;Content-Type&quot;</span><span class="p">,</span><span class="w"> </span><span class="s">&quot;application/json&quot;</span><span class="p">)</span>
<a id="__codelineno-5-14" name="__codelineno-5-14" href="#__codelineno-5-14"></a><span class="w"> </span><span class="p">.</span><span class="na">withStatus</span><span class="p">(</span><span class="m">200</span><span class="p">)</span>
<a id="__codelineno-5-15" name="__codelineno-5-15" href="#__codelineno-5-15"></a><span class="w"> </span><span class="p">.</span><span class="na">withBody</span><span class="p">(</span><span class="nb">it</span><span class="p">.</span><span class="na">serialize</span><span class="p">(</span><span class="n">TestDto</span><span class="p">(</span><span class="n">expectedGetDtoName</span><span class="p">)))</span>
<a id="__codelineno-5-16" name="__codelineno-5-16" href="#__codelineno-5-16"></a><span class="w"> </span><span class="p">}</span>
<a id="__codelineno-5-17" name="__codelineno-5-17" href="#__codelineno-5-17"></a><span class="w"> </span><span class="p">}</span>
<a id="__codelineno-5-18" name="__codelineno-5-18" href="#__codelineno-5-18"></a><span class="w"> </span><span class="p">}</span>
<a id="__codelineno-5-19" name="__codelineno-5-19" href="#__codelineno-5-19"></a><span class="w"> </span><span class="n">http</span><span class="w"> </span><span class="p">{</span>
<a id="__codelineno-5-20" name="__codelineno-5-20" href="#__codelineno-5-20"></a><span class="w"> </span><span class="k">this</span><span class="p">.</span><span class="na">getResponse</span><span class="p">(</span><span class="s">&quot;/get-behaviour&quot;</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">actual</span><span class="w"> </span><span class="o">-&gt;</span>
<a id="__codelineno-5-21" name="__codelineno-5-21" href="#__codelineno-5-21"></a><span class="w"> </span><span class="n">actual</span><span class="p">.</span><span class="na">status</span><span class="w"> </span><span class="n">shouldBe</span><span class="w"> </span><span class="m">503</span>
<a id="__codelineno-5-22" name="__codelineno-5-22" href="#__codelineno-5-22"></a><span class="w"> </span><span class="p">}</span>
<a id="__codelineno-5-23" name="__codelineno-5-23" href="#__codelineno-5-23"></a><span class="w"> </span><span class="k">get</span><span class="o">&lt;</span><span class="n">TestDto</span><span class="o">&gt;</span><span class="p">(</span><span class="s">&quot;/get-behaviour&quot;</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">actual</span><span class="w"> </span><span class="o">-&gt;</span>
<a id="__codelineno-5-24" name="__codelineno-5-24" href="#__codelineno-5-24"></a><span class="w"> </span><span class="n">actual</span><span class="p">.</span><span class="na">name</span><span class="w"> </span><span class="n">shouldBe</span><span class="w"> </span><span class="n">expectedGetDtoName</span>
<a id="__codelineno-5-25" name="__codelineno-5-25" href="#__codelineno-5-25"></a><span class="w"> </span><span class="p">}</span>
<a id="__codelineno-5-26" name="__codelineno-5-26" href="#__codelineno-5-26"></a><span class="w"> </span><span class="p">}</span>
<a id="__codelineno-5-27" name="__codelineno-5-27" href="#__codelineno-5-27"></a><span class="w"> </span><span class="p">}</span>
<a id="__codelineno-5-28" name="__codelineno-5-28" href="#__codelineno-5-28"></a><span class="p">}</span>
</code></pre></div>
<p>Here we define a behaviour for the <code>/get-behaviour</code> endpoint. Initially, it returns a 503 status code with a message.
Then, it returns a 200 status code with a <code>TestDto</code> object.</p>



Expand Down
2 changes: 1 addition & 1 deletion search/search_index.json

Large diffs are not rendered by default.

Binary file modified sitemap.xml.gz
Binary file not shown.

0 comments on commit ebf6b72

Please sign in to comment.