<@U3ZLPSCAC> yeah man, I dont really understand to...
# spring
a
@leodeng yeah man, I dont really understand too, do you mind to have a look at my code? https://ander_dev@bitbucket.org/ander_dev/kotlin-jee.git
c
I looked at it. I've seen this before, for some reason Spring doesn't care in some cases for the
@ComponentScan
annotation. If you move
Application.kt
out of
thinksoft.application
to
thinksoft
package your code should start working.
a
I will try and let you know
l
and also the
UserControllerUnitTest
class needs to be moved to the
thinksoft.controller
package
a
really.
trying your solution without userControllerUnitTest in the controller package, did not work, still asking for configuration
even tough Application.kt and Config.kt are on thinksoft package
l
your original @ContextConfiguration(classes = arrayOf(Application::class)) is needed when your package organization is weird ..
a
OK, so, test class has been moved back to controller package....application.kt is not required anymore
l
now you can add
@MockBean
a
but using your solution @leodeng I am still facing Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'entityManagerFactory' available
@leodeng how do I use @MockBean
?
l
Copy code
@MockBean
    lateinit var userRepository: UserRepository

    @MockBean
    lateinit var userService: UserService

    @Test
    fun testGetUsers() {

        given(userService.findByEmail("<mailto:ander.dev@gmail.com|ander.dev@gmail.com>")).willReturn(UserDTO(
                name = "",
                username = "",
                password = "",
                enabled = true,
                credentialExpired = false,
                email = ""
        ))

        this.mvc.perform(get("/rest/user/ander.dev@gmail.com")
                .accept(MediaType.APPLICATION_JSON))
                .andDo(print())
                .andExpect(status().isOk)
    }
but your gradle script has some problem
you need to use spring boot 1.5.9.RELEASE and kotlin 1.1.61
a
thanks Bro, I will test right now and post results.
@leodeng I have changed as per your suggestion, but now I have a new error... Caused by: java.lang.IllegalArgumentException: At least one JPA metamodel must be present!
seems like I have made a mess
just pushed this change, thanks very much for your help
l
you can try changing the Application.kt to:
Copy code
@SpringBootApplication
class Application

fun main(args: Array<String>) {
    SpringApplication.run(Application::class.java, *args)
}
i think SpringBootServletInitializer is probably not needed. and also why not use spring boot’s default behavior - using embedded container?
a
ah, I need that
because I am running on JEE container
wildfly
my whole point of this test is use it in a JEE container....have more than one app running in the same server, without the need to have to change ports of access the application
like, if I use the normal behavior of spring boot, every app will be using a port when deployed....this is what I dont want
l
you can still try to remove that SpringBootServletInitializer and see if it still work. i think it is causing the exception
a
I will do that
Hey @leodeng, I removed the SpringBootServletInitializer() from my application
and still same error
Caused by: java.lang.IllegalArgumentException: At least one JPA metamodel must be present!
you have helped me a lot mate, thanks...I will google it...and see I what got
thanks a lot
hey @leodeng my issue was the annotation @EnableJpaRepositories
with this annotation I am skipping spring boot to handle jpa and doing it myself....
took it from here
thanks bro.
I need a better reading about the annotations that I am using...lol
l
yah, i would still suggest changing your Application.kt to
Copy code
@SpringBootApplication
class Application

fun main(args: Array<String>) {
    SpringApplication.run(Application::class.java, *args)
}
and now you may get a 401 instead of 200