Questions tagged [spring-mvc-test]

241 questions
0
votes
1 answer

How to order Tests while building Spring Boot application

I am building spring boot application with unit testing. I have entities those are dependent on each other, Eg: I have User and Roles. To create User i should need Roles. I am testing roles and user object resources with MockMvc. I created Test…
user_27
  • 201
  • 7
  • 19
0
votes
1 answer

Spring Controller not being called for expected URL

I am trying to build a SpringMVC application and try to invoke a controller. it is giving me an error of java.io.FileNotFound Exception. Application is built with a RootContext value 'springmvc' and installed on Websphere 9 URL being invoked to hit…
0
votes
0 answers

failed to load application context in junit with spring 4 annotations

I'm using the following POM versions: ${project.build.directory}/endorsed UTF-8
Tarek
  • 1,904
  • 2
  • 18
  • 36
0
votes
1 answer

Spring MVC Test missing imports from MockMvc example

I'm trying to test using Spring MVC, but even when using example from MockMvc: .andExpect(status().isOk()) .andExpect(content().mimeType("text/html")) Using MockHttpServletRequestBuilder: MockHttpServletRequestBuilder…
Ori Marko
  • 56,308
  • 23
  • 131
  • 233
0
votes
0 answers

CSS is loading only for the main page but not for the next pages

I have used spring boot with Thymeleaf (thymeleaf starter dependency is added). The css files are places under src/main/resources/static and the html files are placed under src/main/resources/templates The spring main class is annotated with…
0
votes
2 answers

How to remove duplicate names of routes when testing

I have a simple controller REST: @RestController @RequestMapping("/employees") public class EmployeeController { @Autowired private EmployeeRepository repository; @GetMapping("") List all() { return…
FreeOnGoo
  • 868
  • 1
  • 8
  • 26
0
votes
1 answer

Test Request body of restTemplate.postforEntity(url, request,ResponseObj.class)

How can I test the request json passed in restTemplate.postForEntity. Lets say for the below method: void doAsyncCall(Int id){ MyObject obj= mydao.getObject(id); ///do something MyRequstObject myrequet =…
Stin
  • 141
  • 1
  • 2
  • 12
0
votes
1 answer

Method invocation exception when using spring mvc test

I have a @RestController defined for updating Person class as: @RestController @RequestMapping("/api/person") class PersonRestController { @Autowired private IPersonService mPersonService; @PostMapping("/update") public Person…
Prashant
  • 4,775
  • 3
  • 28
  • 47
0
votes
1 answer

AssertJ to Hamcrest equivalency (only for Spring MVC Test): How test each POJO item of a collection (with dates)

For a Spring Framework App, about Testing: The business layer is working with AssertJ and JUnit. The web layer is working with JUnit and Spring MVC Test, where the latter works mandatorily with Hamcrest. See Is there a way to use AssertJ…
Manuel Jordan
  • 15,253
  • 21
  • 95
  • 158
0
votes
1 answer

When to use Spring Framework while unit testing

I am new to Junit and Mockito and Spring. I am trying to understand when to use Spring when Unit Testing. I am able to unit test below code without using Spring. I read many articles saying one of the benefits of Spring is when unit testing. I am…
Neha
  • 745
  • 4
  • 10
  • 18
0
votes
1 answer

A lot of hibernate tests done when try I try to Run simple Junit test in spring

I have a project that uses the following tools and frameworks: Spring mvc 5, hibernate 5, junit 5 and maven. I wrote a simple test class as the following: @ExtendWith(SpringExtension.class) @ContextConfiguration(classes=DBConfig.class) public class…
M.R.M
  • 540
  • 1
  • 13
  • 30
0
votes
1 answer

How to change a field in controller for test?

I have the next controller: @EnableWebMvc @RequestMapping("experiences") @RestController("experience_controller") public class ExperienceController { @Autowired private ExperienceManager mExperienceManager; protected boolean mIsTest…
Denis Sologub
  • 7,277
  • 11
  • 56
  • 123
0
votes
1 answer

Spring Test DB Unit: Failed to load Application Context

Below is the error I encountered while running Spring-Test-DBUnit. Have you encountered the same issue when doing integration test. Do you have any idea on how can this be resolved? Thanks. testCreatePerson(some project file): Failed to load…
James
  • 211
  • 3
  • 4
  • 12
0
votes
1 answer

jUnit with Spring MVC returns a 400 instead a 200

I am trying to do testing for my mvc controllers so I know they are working properly. I will post all the code first and then explain what is happening: My Controller @RequestMapping(value ="Residents/create", method=RequestMethod.POST) public…
SkiiNet
  • 67
  • 1
  • 8
0
votes
1 answer

spring mvc how to test that my service persists entities in post request

So I'm writing this web app with Spring Boot using Spring Data with JPA and Spring MVC and I would like to make mock controller tests. I figured out how to test the get method, but in my controllers post method a new JPA entity is being either…
Johan
  • 231
  • 4
  • 14