Skip to main content
Filter by
Sorted by
Tagged with
0 votes
0 answers
22 views

MVC tests not working after updates in Java and SpringBoot

I performed some updates in an aplication: Java 11 -> 17, and the SpringBoot version is now 3.2.10. Because of this changes I had to stop using javax* imports and started using jakarta*. Another ...
User0212's user avatar
0 votes
2 answers
31 views

MockMVC test controller from other module

Given this maven modules: web = MVC Layer (Spring MVC Project with Controllers) client = WebClient (Spring Webflux WebClient) How can i integration test the client module to fetch information from a ...
Thomas Lang's user avatar
  • 1,465
0 votes
0 answers
43 views

JUnit test failing Status expected:<201> but was:<404> (SOLVED)

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 ...
dom's user avatar
  • 58
1 vote
0 answers
89 views

Is there a way to document multipart form data with id ‘com.epages.restdocs-api-spec’ version “0.18.2” library?

I’m currently working on a Spring Boot project and I’m using the com.epages.restdocs-api-spec library version “0.18.2” to generate API documentation. However, I am having trouble documenting endpoints ...
김도연's user avatar
0 votes
0 answers
79 views

Adding Custom Response Headers in a Spring Boot Application with Spring Security

I have a Spring Boot application (2.7.18) with Spring MVC and Spring Security. I have a a HandlerInterceptor that manages a token bucket with Bucket4j (most of the bucket handling is in a parent class)...
Jason's user avatar
  • 4,108
0 votes
1 answer
121 views

Spring MVC Error Handling using Junit 5 and MockMvc class

This post is to perform error handling in Spring MVC 3. My Testcases were not testing error scenarios as mentioned below. My Controller class - @RestController public class CPCommonServiceController { ...
Nidhi257's user avatar
  • 967
1 vote
0 answers
101 views

WebMvcTest Spring Boot 3.2.4 and httpservletrequest

I have this exception in a thymeleaf template org.thymeleaf.exceptions.TemplateProcessingException: Exception evaluating SpringEL expression: "#httpServletRequest.getRequestURI().contains('admin')...
StefanoSKAL's user avatar
0 votes
0 answers
41 views

Error Spring after changing Eclipse Luna to Eclipse 2023-09 version 'Unable to build hbm.xml JAXBContext' due to 'Implementation of JAXB-API not found

Workspace works properly in LUNA but Eclipse 2023-12,2022-09 or any other it gives the above error.org.springframework.web.context.ContextLoaderListener org.springframework.beans.factory....
Anuj Sajwan's user avatar
1 vote
0 answers
63 views

WebMcvTest - no qualifying bean found

I've an issue while running unit tests for REST controllers using WebMvcTest annotation. It's important to mention that I don't want to bootstrap the whole context using the annotation @SpringBootTest....
Heril Muratovic's user avatar
0 votes
1 answer
523 views

Spring is not finding bean in an integration test using mock mvc

I am trying to test a spring boot controller using mockmvc, but it seems like spring boot is not finding the service: TranslatorService This is my controller: @RestController public class ...
rasilvap's user avatar
  • 2,129
0 votes
0 answers
659 views

what is the s Spring 6.0.11 module compatible not working on tomcat 10

I have migrated my Spring 4.2.4 version to Spring 6.0.11 version. I am trying to execute it on tomcat 10.But i am getting the follow exception. java.lang.ClassCastException: class org.springframework....
Ramesh Reddy's user avatar
0 votes
0 answers
1k views

Spring boot: Failed to perform cleanup of multipart items

When I want to transfer a file to spring mvc from browser using http, there will be a error.If I remove the filters, there will be accept.I infer the error occured in filters.And so on, If I delete ...
gold-three's user avatar
0 votes
1 answer
196 views

Mock mvc test with repository dependency

I'm trying to write mock mvc controler test in Spring boot. I'm not able to boot test because my service: StrategyService which I'm going to inject in controller via @MockBean annotation has ...
Krzysztof Michalski's user avatar
0 votes
0 answers
311 views

When trying to invoke a rest api to upload multipart file Getting error No serializer found for class java.io.ByteArrayInputStream?

I am trying to consume a rest api to upload a Multipart file. I have set MultipartFile in UploadFIleObject and I am sending the same to rest api. However when trying to invoke a rest API as below, I ...
Nishant's user avatar
3 votes
1 answer
2k views

Springboot 2.7 : Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required in @WebMvcTest for spring boot with mybatis

Below is my PaymentController Unittest @WebMvcTest(PaymentController.class) public class PaymentControllerTest { @MockBean PaymentService paymentService; @Autowired MockMvc mockMvc; ...
OTUser's user avatar
  • 3,848
3 votes
0 answers
327 views

MockMvc uses wrong ApplicationContext when it is used in a nested class

Apparently Spring creates another ApplicationContext when a @Nested class has custom configuration, e.g. @TestPropertySource. In that case two application contexts exist, one ...
Sirea's user avatar
  • 75
0 votes
1 answer
321 views

Mocked service class returns false instead of defined value

I'm currently trying to write Integration tests for a registration controller. When I run the test I get a different return value from the one I define using Mockito's when() method. Test method: @...
StruckCroissant's user avatar
0 votes
0 answers
262 views

unit test for REST-API @PutMapping controller - problem with JSON path

I have problem with unit test for controller that has to update an employee in REST-API. For testing I use mockito, JUnit, hamcrest. I am only posting the most important parts of these classes. ...
Dratewka's user avatar
  • 117
1 vote
1 answer
758 views

How can I test this springboot controller method with multipart and a object from a form submit?

I have the following controller method @PostMapping("/create") public ModelAndView createDocument(@ModelAttribute("user") @Valid User userToSave, BindingResult bindingResult,@...
SwisslogTest's user avatar
2 votes
0 answers
96 views

How to register a ContraintValidator with MockMvc?

I know this was asked before, but that was never really answered satisfactory. How do you add a ContstraintValidator with MockMvc? I expected to find something on the StandaloneMockMvcBuilder, as I ...
Sled's user avatar
  • 18.9k
2 votes
2 answers
3k views

Spring MockMvc second test fails when using StreamingResponseBody

I have a simple Spring Boot service that uses StreamingResponseBody to write the response. When testing this with MockMvc, the first test gives me the correct response, but the second one has an empty ...
Rob Gansevles's user avatar
0 votes
1 answer
293 views

Custom Meta atribute in hibernate xml?

What is the purpose of custom meta tags? I have seen them at class level and at property level. Example of Propery level level: </property> <property name="name" column="...
user124's user avatar
  • 483
0 votes
1 answer
454 views

Cannot load images in spring mvc

I cannot load static images. Did I miss anything here? Here is my servlet xml file servlet.xml Project structure And this is on my page
beginneronly's user avatar
0 votes
1 answer
268 views

Spring MVC - Binding results missing after manually overriding model

I've got some code which looks like this @Controller public class FooController { @RequestMapping(value = "/foos", method = POST) public String createFoo(@ModelAttribute("FooDto") ...
Theiaz's user avatar
  • 754
0 votes
2 answers
884 views

Mockito.when method doesn't manage my service call

i'm trying to make Unit Test testing a simple GET controller method apply MockMvc.perform method but when the controller receive a request the method Mockito.when seems to doesn't manage the method ...
gusmero's user avatar
0 votes
2 answers
931 views

Integer overflow attack mitigation in Spring Rest API

We are currently undertaking security vulnerability assessment of our webapps. For this we have been using the ZAP tool from OWASP for automated penetration testing. One of the alerts we received from ...
SargentD's user avatar
  • 323
1 vote
1 answer
332 views

Spring boot v2 No qualifying bean of type TestRestTemplate

I am getting an error when trying to get the TestRestTemplate. Is there any way to get the TestRestTemplate or test the ErrorController? error log: https://pastebin.com/XVPU9qrb Main test class: ...
dungsil's user avatar
  • 13
1 vote
1 answer
2k views

Why does @WebMvcTest not load Controller-Advices into the Application-Context?

Helloin my parameterized junit5-test i get a NestedServletException until i add the @ContextConfiguration-Annotation above my test class in which i reference my custom exception handler that is ...
Nico S.'s user avatar
  • 151
1 vote
2 answers
2k views

How to create a general MockMvc class for multiple test classes?

I am writing end to end tests for many different Spring Controllers. Right now, I am trying to write a general class for testing that contains MockMvc performing methods. I have endpoints that I need ...
M. Merim's user avatar
0 votes
1 answer
1k views

Why does environment.getProperty("spring.profiles.active") return null on activating a Profile in Tests with @ActiveProfiles

If I activate a Profile in Tests with @ActiveProfiles, say @ActiveProfiles("test"), and declare @Mock private ConfigurableEnvironment environment in test, will I be able to retrieve ...
sammy's user avatar
  • 31
0 votes
1 answer
1k views

Spring 5 MVC Test with MockMvc, test-context.xml, and annotation-based WebAppConfig (ie, in Java)

Versions (SpringBoot is not involved): Spring: 5.2.16 web-app / servlet API: 4.0 JUnit: 5.8 Spring MVC Testing is not working for controller endpoint that returns ResponseEntity<ReturnStatus>, ...
Kode Charlie's user avatar
  • 1,467
0 votes
1 answer
711 views

MockHttpServletResponse has empty in test, despite Controller working correctly

I'm testing a @RestController POST endpoint using MockMvc. In this test, the MockHttpServletResponse content is always empty & the content type is not set. I checked the controller method; it's ...
Nice Books's user avatar
  • 1,861
1 vote
1 answer
1k views

My controller code is not reachable from the MockMvc get request and i am always getting 404

I am trying to mock my controller and write testcases for it. But when I tried to debug the Test class the control is not getting into my Controller class. I am not sure what I am doing wrong here. ...
harish's user avatar
  • 23
0 votes
1 answer
339 views

Is there a way we can load properties from src/test/resources/application.properties in spring boot test?

@ExtendWith(SpringExtension.class) @WebMvcTest(MyClass.class) @TestPropertySource(locations="classpath:application-test.yml") //Something like this?
Murugan's user avatar
  • 51
0 votes
1 answer
110 views

Configuration for Mvc testing

guys. I have spring MVC project and I want to test CoursesController, but can not find out how to do it. Do I need to make separated configuration class for tests? Before springMvc I used separated ...
BM9's user avatar
  • 21
0 votes
1 answer
720 views

How to make Constructor for entityclass in springboot that extends mappedsuperclass

step1: I have mappedsuperclass that has constructor. @MappedSuperclass public abstract class CommonConfig{ @JsonFormat @Column(name ="LastModifiedTime") @Temporal(...
kavin G's user avatar
  • 15
0 votes
1 answer
1k views

Spring MVC Unit Testing - Mocked Service method is not called

I was working on a spring boot project where I have controller which calls a service method and process the output. I'am using spring MockMvc for testing the web layer. In my test class I have mocked ...
Venkat's user avatar
  • 149
1 vote
1 answer
958 views

Spring Boot Controller Test with Mock Service doesn't use the mock service

I have a simple RestController with a Service and want to test just the controller by providing a mock implementation for the Service. However, I'm getting an empty response in resultActions = mockMvc....
VishalM93's user avatar
0 votes
1 answer
2k views

Why is Spring Security CSRF check failing when using MockMVC MockMvc

Sorry for the information overload, I would think that a lot more information is here than needed. So I have this test code package com.myapp.ui.controller.user; import static com.myapp.ui.controller....
xenoterracide's user avatar
1 vote
1 answer
180 views

Spring mvc test case with string in request header and multipart file as a request parameter for a post request

@Controller @PostMapping("/hello/{studentName}") public ResponseEntity<Void> method1( @RequestMapping(value = "/upload/{studentName}", method = RequestMethod.POST) ...
Anu Shree's user avatar
3 votes
3 answers
22k views

java.lang.ExceptionInInitializerError when trying to mock

I'm running into this issue when trying to mock an object of the interface org.springframework.ui.Model. I'm using Mockito 3.5.15 w/Java 8 and JUnit Jupiter. I've tried using both @Mock and Mockito....
vnavs's user avatar
  • 51
0 votes
2 answers
1k views

Spring MVC controller test fails with empty body

I am writing a small REST API with spring boot and trying to write the MVC test. Unfortunately the MVC tests fails as I get the empty response from the controller. Controller class: @RestController @...
G.S's user avatar
  • 10.9k
2 votes
1 answer
5k views

Spring Boot @WebMvcTest with constructor injection not working

Constructor injection with @WebMvcTest is NOT working. The mocked bean SomeService is not initialized. Why? Doesn't Mockito create SomeService independently of Spring Boot? If I use @MockBean ...
enhancedJack's user avatar
1 vote
2 answers
10k views

Format specifiers should be used instead of string concatenation in java

I am writing code the below code Logger.error("Error in x file :",+ e.getMessage()); But for the above line of code I am getting the error to use format specifiers instead of string ...
ritu4's user avatar
  • 21
0 votes
0 answers
7k views

JUtit test Exception of java.lang.NoSuchMethodError: org.springframework.util.Assert.notNull

When I debug the File as Junit then it will throw exception couldn't figure it out ... package com.fort313.webexmd.test; import org.junit.Assert; import org.junit.Test; import org.junit.runner....
Asad Malik's user avatar
3 votes
2 answers
5k views

How to exclude @EnableJpaRepositories from test?

I have a main @SpringBootApplication which needs to scan a specific package in order to enable the JPA repositories, so I use @EnableJpaRepositories to specify that. Right now I'm implementing unit ...
Erick Siordia's user avatar
2 votes
0 answers
567 views

How to enable Async in springboot testing using webmvctest?

This my test case: @Test public void sampleTestCase(int parm1, int parm2, Integer expectedReturnedMessageCode, String expectedReturnedparm2, Integer expectedReturnedparm1) throws Exception { ...
Saed Manaf's user avatar
1 vote
1 answer
677 views

WebMvcTest of @Controller with @RequestParam and status is not 200, but 400

i try to write @WebMvcTest: @ExtendWith(SpringExtension.class) @WebMvcTest(AudienceController.class) class LectureControllerTest { @Autowired private MockMvc mockMvc; @MockBean ...
Jun K's user avatar
  • 37
0 votes
2 answers
97 views

Demystifying Spring framework

With multiple ways to configure using either XML, Annotations or Java Config and the need to remember 100's of annotations and super-lengthy class-names, the Spring framework appears an extremely ...
Ali's user avatar
  • 103
0 votes
1 answer
373 views

Spring Boot Test - Mockito - Service call return null

I'm testing a post method in my controller that only return a String and using Mockito to mock the service call. My problem is that when the service method is called on controller it return null. @...
Aldo Inácio da Silva's user avatar

1
2 3 4 5