I am new at this. please help me. I am using Mockito. I am looking for how to mock a service used in method property of transform tag. My beans-test.xml
is
<spring:route id="jobRoute" startupOrder="2">
<spring:from uri="direct:start"/>
<spring:transform>
<spring:method ref="camelJobService" method="findByStatus"/>
</spring:transform>
<spring:to uri="mock:result"/>
</spring:route>
Service bean above always hits database. So test case fails. I have looked and fond that adviceWith can be used but I am unable to use it.
However in my test the service is mocked properly.
My test looks like this
@RunWith(CamelSpringJUnit4ClassRunner.class)
@BootstrapWith(CamelTestContextBootstrapper.class)
@ContextConfiguration(locations = "/beans-test.xml")
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
public class CamelRouteTest extends AbstractJUnit4SpringContextTests {
@EndpointInject(uri = "mock:result")
protected MockEndpoint resultEndpoint;
@Produce(uri = "direct:start")
protected ProducerTemplate producerTemplate;
@Produce(uri = "direct:startA")
protected ProducerTemplate producerTemplate1;
@Autowired
QuartzComponent quartzComponent;
CamelJob camelJob;
@Mock
CamelJobRepository camelJobRepository;
@InjectMocks
CamelJobService camelJobService;
@Before
public void setup(){
MockitoAnnotations.initMocks(this);
returnCamelJob();
}
@Test
public void testJobWithStatus() throws Exception{
when(camelJobService.findByStatus()).thenReturn(camelJob);
resultEndpoint.expectedBodiesReceived(camelJobService.findByStatus());
verify(camelJobService.findByStatus());
producerTemplate.sendBody(resultEndpoint);
resultEndpoint.assertIsSatisfied();
}
Aucun commentaire:
Enregistrer un commentaire