#WithMockUser and kotlin test - spring-boot

I'm a big fan of Kotlintest syntax and I'd like to know if it's possible to make it work with WebMvcTest. More particularly, I don't manage to annotate the test methods with #WithMockUser.
Does somebody know if it's feasible?
Thanks beforehand.

It's not something that is currently built into KotlinTest but there is a Spring module, so it should be fairly easy to create another extension that provides this.
This is the source for the spring module.
https://github.com/kotlintest/kotlintest/tree/master/kotlintest-samples/kotlintest-samples-spring

Related

Implementing functions like #LocalPort in Spring Boot

I am contributing some framework and I am integrating it with Spring Boot. I want to create an annotation like #LocalPort that I made to use in testing. 😎
I found #LocalPort to be #Value in the end, but I don't think I can't use it because the annotation I'm making needs to be passed another value. In the end I think I should inherit ContextAnnotationAutowireCandidateResolver and either reimplement the getSuggestedValue(...) method or find another way. But I don't think this is the right way.
Is there another way to implement this? 🤔
For example,
#LocalSomePort(Protocol.HTTP) // Protocol.HTTPS
It was late, but I solved it by adding a custom BeanPostProcessor.

Spring-Boot Custom Repository

I have been reading about Spring Boot custom repository. I have dozens of blogs explaining how to implement those but none of them explained scenario when we actually need it?
I mean one example where we cannot live without custom repo. I mean if there is case of complex query, we can anyhow achieve it using #Query.
Please explain.
Lets say I want strongly typed query instead of #Query. I would create a custom repo, autowire EntityManager and use QueryDSL with it so I can use strongly typed references.
You can use it to extend the repository with other libraries that aren't part of Spring.
I find them useful when working with a program generator like jHipster. They keep your code separate from the generated code.
The xxxRepositoryCustom.java xxxRepositoryImpl will not be overwritten when the entities are re-generated by a dumb programmer (me.) The queries themselves have some complex logic that can not be expressed in a simple #Query

I`m looking for a equivalent in Spring of JavaAsync from Play Framework

I wondering is there an equivalent of this feature from play framework
http://www.playframework.org/documentation/2.0/JavaAsync
Basicly it helps to create more efective applications. Doesn anyone knows something like that for Spring Framework ?
Sure, Spring provides asynchronous processing via the #Async annotation. See http://static.springsource.org/spring/docs/current/spring-framework-reference/html/scheduling.html#scheduling-annotation-support
Not from Spring, but if you don't want/can't use Play, check Akka, it provides similar tools.

Unit-testing Spring applications using Scala's Specs

We have a large infrastructure that's highly dependent on Spring Framework. Recently I began writing code in Scala and test it using Specs. This is all great but at some point I need to use Spring-dependent features (Such as a HibernateDaoSupport-based DAO).
Has anyone managed to use the SpringJUnit4ClassRunner class to run Specs tests? Does anyone have a different direction as to how to achieve this goal?
Thanks
I've struggled with the class runner in a similarly awkward scenario once and then I created a MethodRule implementation called TemporarySpringContext that could also solve your problem I think.

Spring-managed Clojure beans

I'm just wondering if it's possible to create Spring managed beans backed by Clojure code (Clojure namespace I guess, would implement regular Java interface)? If so, the example would be appreciated.
Thanks,
Dmitriy.
I haven't tried that yet, but section 3.3 of Programming Clojure explains how to create class files with the :gen-class form. Use it with :implements and :extends, build a JAR from your classes and import them into your Spring project. That should - theoretically - do the trick.
I'd be very interested in any example code, too, by the way.
See this as an example of clojure, spring, junit and swt integration.

Resources