<?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 JavaDelegate - Unit Test in Alfresco Forum</title>
    <link>https://connect.hyland.com/t5/alfresco-forum/javadelegate-unit-test/m-p/41537#M17420</link>
    <description>&lt;P&gt;I have created service task and I am using JavaDelegate for backend process.&lt;/P&gt;&lt;P&gt;Process working fine.&lt;/P&gt;&lt;P&gt;I have created test case using&amp;nbsp;&lt;A href="https://hub.alfresco.com/t5/alfresco-process-services/alfresco-process-services-unit-testing-ii/ba-p/292894" target="_self" rel="nofollow noopener noreferrer"&gt;alfresco-process-services-unit-testing.&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Normal Way it is working fine but when I Autowire any service,It is giving error.&lt;/P&gt;&lt;P&gt;First it was giving error of no bean type found of EndPointService. After that I have injected that class in&amp;nbsp;@Configuration, now it is giving error of no bean found&amp;nbsp; which is used inside EndPointService.&lt;/P&gt;&lt;P&gt;Anyone have idea how can I Mock all the required dependency?&lt;/P&gt;&lt;P&gt;Code :&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;@Component("searchRecord")
public class SearchRecord implements JavaDelegate {

	@Autowired
	private EndpointService endPointService;
}

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
public class SearchRecordTest {

	@Configuration
	static class ContextConfiguration {
		@Bean
		public SearchRecord searchRecord() {
			return new SearchRecord();
		}&lt;BR /&gt;@Bean &lt;BR /&gt;public EndPointService endPointServiceImpl() &lt;BR /&gt;{ return new EndPointServiceImpl(); &lt;BR /&gt;}
	}

	@InjectMocks
	@Spy
	private static SearchRecord searchRecord;

	@Mock
	private DelegateExecution execution;

	@Before
	public void initMocks() {
		MockitoAnnotations.initMocks(this);
	}
	@Test
	public void test() throws Exception {	
	}
}&lt;/PRE&gt;&lt;P&gt;&lt;A href="https://migration33.stage.lithium.com/t5/user/viewprofilepage/user-id/72575"&gt;@cjose&lt;/A&gt;&amp;nbsp;&lt;A href="https://migration33.stage.lithium.com/t5/user/viewprofilepage/user-id/43097"&gt;@openpj&lt;/A&gt;&amp;nbsp; Help would be appreciated.&lt;/P&gt;</description>
    <pubDate>Thu, 23 Jul 2020 08:37:13 GMT</pubDate>
    <dc:creator>sp2</dc:creator>
    <dc:date>2020-07-23T08:37:13Z</dc:date>
    <item>
      <title>JavaDelegate - Unit Test</title>
      <link>https://connect.hyland.com/t5/alfresco-forum/javadelegate-unit-test/m-p/41537#M17420</link>
      <description>&lt;P&gt;I have created service task and I am using JavaDelegate for backend process.&lt;/P&gt;&lt;P&gt;Process working fine.&lt;/P&gt;&lt;P&gt;I have created test case using&amp;nbsp;&lt;A href="https://hub.alfresco.com/t5/alfresco-process-services/alfresco-process-services-unit-testing-ii/ba-p/292894" target="_self" rel="nofollow noopener noreferrer"&gt;alfresco-process-services-unit-testing.&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Normal Way it is working fine but when I Autowire any service,It is giving error.&lt;/P&gt;&lt;P&gt;First it was giving error of no bean type found of EndPointService. After that I have injected that class in&amp;nbsp;@Configuration, now it is giving error of no bean found&amp;nbsp; which is used inside EndPointService.&lt;/P&gt;&lt;P&gt;Anyone have idea how can I Mock all the required dependency?&lt;/P&gt;&lt;P&gt;Code :&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;@Component("searchRecord")
public class SearchRecord implements JavaDelegate {

	@Autowired
	private EndpointService endPointService;
}

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
public class SearchRecordTest {

	@Configuration
	static class ContextConfiguration {
		@Bean
		public SearchRecord searchRecord() {
			return new SearchRecord();
		}&lt;BR /&gt;@Bean &lt;BR /&gt;public EndPointService endPointServiceImpl() &lt;BR /&gt;{ return new EndPointServiceImpl(); &lt;BR /&gt;}
	}

	@InjectMocks
	@Spy
	private static SearchRecord searchRecord;

	@Mock
	private DelegateExecution execution;

	@Before
	public void initMocks() {
		MockitoAnnotations.initMocks(this);
	}
	@Test
	public void test() throws Exception {	
	}
}&lt;/PRE&gt;&lt;P&gt;&lt;A href="https://migration33.stage.lithium.com/t5/user/viewprofilepage/user-id/72575"&gt;@cjose&lt;/A&gt;&amp;nbsp;&lt;A href="https://migration33.stage.lithium.com/t5/user/viewprofilepage/user-id/43097"&gt;@openpj&lt;/A&gt;&amp;nbsp; Help would be appreciated.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jul 2020 08:37:13 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-forum/javadelegate-unit-test/m-p/41537#M17420</guid>
      <dc:creator>sp2</dc:creator>
      <dc:date>2020-07-23T08:37:13Z</dc:date>
    </item>
  </channel>
</rss>

