All Questions
Tagged with junit spring-mvc
532
questions
0
votes
0
answers
9
views
JUnit test failing Status expected:<201> but was:<404>
I've spent a lot of time trying to figure out this issue, but when I'm running my tests on my UserControllerTest class I'm getting Status expected:<201> but was:<404>.
Here's my ...
1
vote
1
answer
36
views
I cant init my webclient in a test with mockito
I'm working on a project with java spring boot 2.x and java 1.8. In my pom i got the dependencies of junit 4.13.2 and mockito 3.12.4. When i try to run my test i got the problem that my setup function ...
0
votes
0
answers
40
views
Spring Boot test: Why is my response body empty when testing a POST request?
I'm trying to test a POST endpoint in my Spring Boot application that creates a ChallengeReport. However, the response body is always empty, even though the status code is correct. I need help ...
0
votes
1
answer
42
views
Getting java.lang.NoClassDefFoundError Exception while using MockMvcBuilders.standaloneSetup() method in Junit 5
Below is my Test class that I have created for Controller class.
My Testclass is in package src/test/java and my java classes are in folder src/main/java.
public class MyControllerTest {
@...
0
votes
2
answers
36
views
MockMultipartFile is not included in MockHttpServletRequest
I wanna test what happens when the oversized image file is sent to spring boot server using MockMultipartFile.
@SpringBootTest
@AutoConfigureMockMvc
class PostControllerTest {
@Autowired
...
1
vote
0
answers
77
views
Face an issue about HttpStatusCode when I upgrade spring 3.1
guys
I face a strange issue when I upgrade the sping 2.65 to 3.1.0.
This is the code:
import org.springframework.http.HttpStatus
import org.springframework.http.HttpStatus.OK
import org....
0
votes
1
answer
64
views
Mock testing a post method which returns the location of the newly added entity and a 201 status code, using ServletUriComponentsBuilder
@PostMapping(path= "/users/{username}/events")
public ResponseEntity<Object> createEventsForUser(@PathVariable String username, @RequestBody @Valid EventBean event){
event....
0
votes
1
answer
222
views
How to do an OR condition on result, when using Spring MockMVC?
Currently I have below -
.andExpect(org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath("$.message",
org.hamcrest.Matchers.equalTo("...
1
vote
1
answer
1k
views
How to simulate the downloading of a file during java unit testing?
I can't figure out how to simulate downloading from a file path in spring with Map<Long, String>
I've implemented this method:
@Test
void testDownloadFile() throws Exception {
...
0
votes
0
answers
34
views
how to mock RestTemplate to mock it's methods
I'm trying write unit tests for the class which has a
restTemplate.getForObject( Url, Response.class);
I've mocked the RestTemplate in the test class still when I run test case, request hit's server ...
1
vote
1
answer
289
views
Bean serialization issue while running test case
when hit the endpoint from the browser it is working fine but test case failing. please find the code below:
Controller class:
@RestController
public class EmployeeController {
@Autowired
...
0
votes
0
answers
186
views
Upgrading spring application from 4.3.2.RELEASE to 5.2.20.RELEASE
I'm upgrading my spring multi module project from 4.3.2.RELEASE to 5.2.20.RELEASE.
After changing version in the dependency application works fine.
but when I ran the application with test throwing an ...
0
votes
0
answers
137
views
ObjectMapper with and without mock
I have a controller ItemController.java in which I'm using objectmapper in logger.info
objectMapper.writeValueAsString("something");
In the controller unit test, I need to use the object ...
1
vote
1
answer
398
views
How to write unit test for Spring Boot Controller if it required user name which was got from Security Context Holder?
I want to write a unit to allow users to change their personal Information. However, I don't know how to include the Security Context Holder mock into Unit Test. Especially, it is required to extract ...
0
votes
1
answer
217
views
How to assert FlashAttributes in Spring WebTestClient?
I want to test FlashMap assignment of a spring @Controller:
@Controller
public class MyServlet {
@GetMapping("/test")
public String get() {
ServletRequestAttributes ...