f-lopes / spring-mvc-test-utils Goto Github PK
View Code? Open in Web Editor NEWTest library aimed to ease Spring MVC form validation tests. Easily post an entire form to a given url.
License: MIT License
Test library aimed to ease Spring MVC form validation tests. Easily post an entire form to a given url.
License: MIT License
for some reason it seems this isn't working with Spring Boot 2.6 and Java 17. Perhaps worth updating spring dependencies
Hi @f-lopes ,
it is very common to send files together with a form. It would be nice to add full support for multipart requests or at least set some methods to public so that the main functionality can be accessed.
Kind regards,
Stefan
When I run the tests on our CI, the maven runs them and jacoco probably injects some garbage to the objects. The builder then picks it up and adds it to the request, which causes the validations to stop form processing and ultimately, the test fails.
20:09:22.477 [main ] DEBUG i.f.s.t.w.s.r.MockMvcRequestBuilderUtils: Adding form field ($jacocoData=[Z@212beaa6) to HTTP request parameters
I'm not completely sure where to report this, but the first time I've seen this is with your lib.
output from maven effective pom:
<dependency>
<groupId>io.florianlopes</groupId>
<artifactId>spring-mvc-test-utils</artifactId>
<version>2.2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
<version>2.2.0.M1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<executions>
<execution>
<id>default-test</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<systemPropertyVariables>
<java.util.logging.config.class>com.cogvio.configuration.JavaUtilLoggingConfig</java.util.logging.config.class>
</systemPropertyVariables>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit4</artifactId>
<version>2.22.1</version>
<scope>compile</scope>
</dependency>
</dependencies>
<configuration>
<systemPropertyVariables>
<java.util.logging.config.class>com.cogvio.configuration.JavaUtilLoggingConfig</java.util.logging.config.class>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.1</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>generate-code-coverage-report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
Dear @f-lopes,
the addition of support for Map
types in #3 is great! In future forms, I will need to test with multidimensional arrays and maps (Array of Arrays, Map of Maps or even more dimensions).
Would you agree that adding support for them would respond to a common pattern of data usage? (At least I know this concept is heavily used within the PHP/Python/Perl world...)
Cheers,
Poikilotherm
I've tried using spring-mvc-test-utils v3.1.0 and found that both:
MockMvcRequestBuilderUtils.postForm("/myapp/path", formObject)
and
MockMvcRequestBuilders.post("/myapp/path").with(MockMvcRequestBuilderUtils.form(formObject))
fail to map to the handler that deals with "/myapp/path". Not sure if it's related but my controller has @RequestMapping("/myapp")
on the class and @PostMapping({"/path"})
on the method. Also, the pojo in question uses lombok a bit like this:
@Data
@Builder(setterPrefix = "with")
@NoArgsConstructor
@AllArgsConstructor
public class User {
@NonNull
private String emailAddress;
@Nullable
private String name;
private Long level;
}
Hello,
after introducing a Comparator constant to a model class, we're running into issues with certain fields in that comparator not being accessible to reflection. After some digging I found out that this library includes both static and transient fields in the generated form data.
Since most libraries with similar functionality (e.g. JSON Libraries) don't include such fields, I would like to suggest to exclude static and transient fields either alltogether or as a default, but configurable behaviour.
The code change would probably fit into getAllNonSyntheticFields to also exclude aforementioned fields. I would be happy to provide a pull request if there's any interest.
Greetings,
schosins
Dear @f-lopes,
I just posted a question at StackOverflow, while experiencing a tricky bug in my tests.
https://stackoverflow.com/q/49782283/9457141
Maybe you have a clue if this could be related to using your little helper and hitting some hidden bug?
Your help would be very much appreciated!
Cheers
Oliver
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.