<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Overriding beans in Integration tests in Integration and Testing</title>
    <link>https://community.developer.cybersource.com/t5/Integration-and-Testing/Overriding-beans-in-Integration-tests/m-p/82548#M52007</link>
    <description>&lt;P&gt;Thus, bean overriding is a default behavior that happens when we define a bean within an ApplicationContext which has the same name as another bean. It works by simply replacing the former bean in case of a name conflict.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 23 May 2022 20:08:18 GMT</pubDate>
    <dc:creator>Robertt023</dc:creator>
    <dc:date>2022-05-23T20:08:18Z</dc:date>
    <item>
      <title>Overriding beans in Integration tests</title>
      <link>https://community.developer.cybersource.com/t5/Integration-and-Testing/Overriding-beans-in-Integration-tests/m-p/82541#M52003</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;For my Spring-Boot app I provide a RestTemplate though a @Configuration file so I can add sensible defaults(ex Timeouts). For my integration tests I would like to mock the RestTemplate as I dont want to connect to external services - I know what responses to expect. I tried providing a different implementation in the integration-test package in the hope that the latter will override the real implementation , but checking the logs it`s the other way around : the real implementation overrides the test one.&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;How can I make sure the one from the TestConfig is the one used?&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;This is my config file :&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;@Configuration&lt;/SPAN&gt;
&lt;SPAN class=""&gt;public&lt;/SPAN&gt; &lt;SPAN class=""&gt;class&lt;/SPAN&gt; &lt;SPAN class=""&gt;RestTemplateProvider&lt;/SPAN&gt; {

    &lt;SPAN class=""&gt;private&lt;/SPAN&gt; &lt;SPAN class=""&gt;static&lt;/SPAN&gt; &lt;SPAN class=""&gt;final&lt;/SPAN&gt; &lt;SPAN class=""&gt;int&lt;/SPAN&gt; &lt;SPAN class=""&gt;DEFAULT_SERVICE_TIMEOUT&lt;/SPAN&gt; &lt;SPAN class=""&gt;=&lt;/SPAN&gt; &lt;SPAN class=""&gt;5_000&lt;/SPAN&gt;;

    &lt;SPAN class=""&gt;@Bean&lt;/SPAN&gt;
    &lt;SPAN class=""&gt;public&lt;/SPAN&gt; RestTemplate &lt;SPAN class=""&gt;restTemplate&lt;/SPAN&gt;&lt;SPAN class=""&gt;()&lt;/SPAN&gt;{
        &lt;SPAN class=""&gt;return&lt;/SPAN&gt; &lt;SPAN class=""&gt;new&lt;/SPAN&gt; &lt;SPAN class=""&gt;RestTemplate&lt;/SPAN&gt;(buildClientConfigurationFactory());
    }

    &lt;SPAN class=""&gt;private&lt;/SPAN&gt; ClientHttpRequestFactory &lt;SPAN class=""&gt;buildClientConfigurationFactory&lt;/SPAN&gt;&lt;SPAN class=""&gt;()&lt;/SPAN&gt; {
        &lt;SPAN class=""&gt;HttpComponentsClientHttpRequestFactory&lt;/SPAN&gt; &lt;SPAN class=""&gt;factory&lt;/SPAN&gt; &lt;SPAN class=""&gt;=&lt;/SPAN&gt; &lt;SPAN class=""&gt;new&lt;/SPAN&gt; &lt;SPAN class=""&gt;HttpComponentsClientHttpRequestFactory&lt;/SPAN&gt;();
        factory.setReadTimeout(DEFAULT_SERVICE_TIMEOUT);
        factory.setConnectTimeout(DEFAULT_SERVICE_TIMEOUT);
        &lt;SPAN class=""&gt;return&lt;/SPAN&gt; factory;
    }
}&lt;/PRE&gt;&lt;P&gt;Integration test:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;@RunWith(SpringJUnit4ClassRunner.class)&lt;/SPAN&gt;
&lt;SPAN class=""&gt;@SpringApplicationConfiguration(classes = TestConfiguration.class)&lt;/SPAN&gt;
&lt;SPAN class=""&gt;@WebAppConfiguration&lt;/SPAN&gt;
&lt;SPAN class=""&gt;@ActiveProfiles("it")&lt;/SPAN&gt;
&lt;SPAN class=""&gt;public&lt;/SPAN&gt; &lt;SPAN class=""&gt;abstract&lt;/SPAN&gt; &lt;SPAN class=""&gt;class&lt;/SPAN&gt; &lt;SPAN class=""&gt;IntegrationTest&lt;/SPAN&gt; {}&lt;/PRE&gt;&lt;P&gt;TestConfiguration class:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;@Configuration&lt;/SPAN&gt;
&lt;SPAN class=""&gt;@Import({Application.class, MockRestTemplateConfiguration.class})&lt;/SPAN&gt;
&lt;SPAN class=""&gt;public&lt;/SPAN&gt; &lt;SPAN class=""&gt;class&lt;/SPAN&gt; &lt;SPAN class=""&gt;TestConfiguration&lt;/SPAN&gt; {}&lt;/PRE&gt;&lt;P&gt;And finally MockRestTemplateConfiguration&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;@Configuration&lt;/SPAN&gt;
&lt;SPAN class=""&gt;public&lt;/SPAN&gt; &lt;SPAN class=""&gt;class&lt;/SPAN&gt; &lt;SPAN class=""&gt;MockRestTemplateConfiguration&lt;/SPAN&gt; {

    &lt;SPAN class=""&gt;@Bean&lt;/SPAN&gt;
    &lt;SPAN class=""&gt;public&lt;/SPAN&gt; RestTemplate &lt;SPAN class=""&gt;restTemplate&lt;/SPAN&gt;&lt;SPAN class=""&gt;()&lt;/SPAN&gt; {
        &lt;SPAN class=""&gt;return&lt;/SPAN&gt; Mockito.mock(RestTemplate.class)
    }
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 May 2022 04:11:36 GMT</pubDate>
      <guid>https://community.developer.cybersource.com/t5/Integration-and-Testing/Overriding-beans-in-Integration-tests/m-p/82541#M52003</guid>
      <dc:creator>BettyVeronicasi</dc:creator>
      <dc:date>2022-05-09T04:11:36Z</dc:date>
    </item>
    <item>
      <title>Re: Overriding beans in Integration tests</title>
      <link>https://community.developer.cybersource.com/t5/Integration-and-Testing/Overriding-beans-in-Integration-tests/m-p/82548#M52007</link>
      <description>&lt;P&gt;Thus, bean overriding is a default behavior that happens when we define a bean within an ApplicationContext which has the same name as another bean. It works by simply replacing the former bean in case of a name conflict.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 May 2022 20:08:18 GMT</pubDate>
      <guid>https://community.developer.cybersource.com/t5/Integration-and-Testing/Overriding-beans-in-Integration-tests/m-p/82548#M52007</guid>
      <dc:creator>Robertt023</dc:creator>
      <dc:date>2022-05-23T20:08:18Z</dc:date>
    </item>
  </channel>
</rss>

