org.springframework.web.util.NestedServletException: Request processing failed
Get this exception error when try to execute Junit Test for restApi method to DeleteById
the problem that in Controller implements when i change return type of method from DeviceTO to device it works but i need to be returned as DeviceTO (DTO) so i faced this issue :
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.NullPointerException
Please help me
this is the code for test class:
@RunWith(MockitoJUnitRunner.class)
@EnableWebMvc
public class DeviceControllerFacadeTest {
@Mock
DeviceServiceImpl deviceServiceMock;
@MockBean
DeviceControllerFacadeImpl deviceControllerFacade = new DeviceControllerFacadeImpl();
MockMvc mockMvc;
/**
*
*/
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mockMvc = MockMvcBuilders.standaloneSetup(deviceControllerFacade)
.build();
}
/**
* @throws java.lang.Exception
*/
@After
public void tearDown()
throws Exception
{
}
/**
* @throws Exception
*/
@Test
public void DeleteDeviceById()
throws Exception
{
mockMvc.perform(MockMvcRequestBuilders
.delete("/device/delete?id=336").accept(MediaType.APPLICATION_JSON)
.contentType(MediaType.APPLICATION_JSON))
.andDo(MockMvcResultHandlers.print());
}
and this is the controller interface :
@DeleteMapping("/delete")
DeviceTO deleteDevice(@RequestParam("id") long id);
and this is for Controller implements class:
@Override
public DeviceTO deleteDevice(long id)
{
try {
begin();
Device device = deviceService.getEntity(id);
//deviceService.delete(device);
DeviceTO deviceTO = new DeviceTO();
deviceTO.mergeEntityToTransferObject(device);
commit();
return deviceTO;
} catch (
final Exception exception) {
LOG.error(exception.getMessage(), exception);
throw exception;
} finally {
cleanupTransaction();
}
}
Thank you for helping
I need this issue of exception will never appear again and the Test of method deleteById worked and return the device are deleted and the return type is DeviceTO not Device.
Thank you for helping.