I have following test class for my spring-integration application.
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath*:/test-dao-rest.xml"})
public class TestEmployeeRestDao {
@Autowired
private EmployeeDao employeeRestDao;
@Autowired
private RestTemplate mockRestTemplate;
private MockRestServiceServer mockServer;
/**
* Sets up.
*/
@Before
public void setUp() {
mockServer = MockRestServiceServer.bindTo(mockRestTemplate).build();
}
@Test
public void testGetEmployeeById() {
when(mockRestTemplate.getForObject(url + 1, Employee.class)).thenReturn(emp2);
mockServer.expect(times(1), requestTo(url + 1))
.andExpect(method(HttpMethod.GET))
Employee employee = employeeRestDao.getEmployeeById(1L);
assertNotNull(employee);
mockServer.verify();
}
`}
My xml config
<bean class="com.nikolay.client.handler.CustomResponseErrorHandler"
id="customResponseErrorHandler"/>
<bean class="org.mockito.Mockito" factory-method="mock" id="mockRestTemplate">
<constructor-arg value="org.springframework.web.client.RestTemplate"/>
<property name="messageConverters">
<list>
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"/>
</list>
</property>
<property name="errorHandler" ref="customResponseErrorHandler"/>
</bean>
<bean class="com.nikolay.client.EmployeeRestDaoImpl" id="employeeRestDao">
<property name="restTemplate" ref="mockRestTemplate"/>
</bean>
</beans>
When I run a test, an error is thrown. Who can say what is wrong? I could not understand why this error occurs.
java.lang.AssertionError: Further request(s) expected leaving 1 unsatisfied expectation(s).
0 request(s) executed.
Can you please help me to find out how this issue can be resolved.
Aucun commentaire:
Enregistrer un commentaire