SHARE
TWEET

Untitled

a guest Aug 18th, 2018 142 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Failed to resolve parameter [org.springframework.test.web.servlet.MockMvc mockMvc] in executable [public demons.controllers.DemonsUserControllerTest(org.springframework.test.web.servlet.MockMvc)]
  2. org.junit.jupiter.api.extension.ParameterResolutionException: Failed to resolve parameter [org.springframework.test.web.servlet.MockMvc mockMvc] in executable [public demons.controllers.DemonsUserControllerTest(org.springframework.test.web.servlet.MockMvc)]
  3.     at org.junit.jupiter.engine.execution.ExecutableInvoker.resolveParameter(ExecutableInvoker.java:221)
  4.     at org.junit.jupiter.engine.execution.ExecutableInvoker.resolveParameters(ExecutableInvoker.java:174)
  5.     at org.junit.jupiter.engine.execution.ExecutableInvoker.resolveParameters(ExecutableInvoker.java:135)
  6.     at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:61)
  7.     at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.instantiateTestClass(ClassTestDescriptor.java:208)
  8.     at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.instantiateAndPostProcessTestInstance(ClassTestDescriptor.java:195)
  9.     at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.lambda$testInstanceProvider$0(ClassTestDescriptor.java:185)
  10.     at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.lambda$testInstanceProvider$1(ClassTestDescriptor.java:189)
  11.     at java.util.Optional.orElseGet(Optional.java:267)
  12.     at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.lambda$testInstanceProvider$2(ClassTestDescriptor.java:188)
  13.     at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.before(ClassTestDescriptor.java:156)
  14.     at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.before(ClassTestDescriptor.java:65)
  15.     at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.lambda$executeRecursively$3(HierarchicalTestExecutor.java:110)
  16.     at org.junit.platform.engine.support.hierarchical.SingleTestExecutor.executeSafely(SingleTestExecutor.java:66)
  17.     at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.executeRecursively(HierarchicalTestExecutor.java:108)
  18.     at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.execute(HierarchicalTestExecutor.java:79)
  19.     at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.lambda$executeRecursively$2(HierarchicalTestExecutor.java:120)
  20.     at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)
  21.     at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175)
  22.     at java.util.Iterator.forEachRemaining(Iterator.java:116)
  23.     at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
  24.     at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
  25.     at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
  26.     at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:151)
  27.     at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:174)
  28.     at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
  29.     at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418)
  30.     at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.lambda$executeRecursively$3(HierarchicalTestExecutor.java:120)
  31.     at org.junit.platform.engine.support.hierarchical.SingleTestExecutor.executeSafely(SingleTestExecutor.java:66)
  32.     at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.executeRecursively(HierarchicalTestExecutor.java:108)
  33.     at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.execute(HierarchicalTestExecutor.java:79)
  34.     at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:55)
  35.     at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:43)
  36.     at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:170)
  37.     at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:154)
  38.     at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:90)
  39.     at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.processAllTestClasses(JUnitPlatformTestClassProcessor.java:92)
  40.     at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.access$100(JUnitPlatformTestClassProcessor.java:77)
  41.     at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor.stop(JUnitPlatformTestClassProcessor.java:73)
  42.     at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:61)
  43.     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  44.     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  45.     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  46.     at java.lang.reflect.Method.invoke(Method.java:498)
  47.     at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
  48.     at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
  49.     at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32)
  50.     at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
  51.     at com.sun.proxy.$Proxy1.stop(Unknown Source)
  52.     at org.gradle.api.internal.tasks.testing.worker.TestWorker.stop(TestWorker.java:123)
  53.     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  54.     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  55.     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  56.     at java.lang.reflect.Method.invoke(Method.java:498)
  57.     at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35)
  58.     at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
  59.     at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:155)
  60.     at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:137)
  61.     at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:404)
  62.     at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
  63.     at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
  64.     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
  65.     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
  66.     at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
  67.     at java.lang.Thread.run(Thread.java:748)
  68. Caused by: java.lang.IllegalStateException: Failed to load ApplicationContext
  69.     at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:125)
  70.     at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108)
  71.     at org.springframework.test.context.junit.jupiter.SpringExtension.getApplicationContext(SpringExtension.java:191)
  72.     at org.springframework.test.context.junit.jupiter.SpringExtension.resolveParameter(SpringExtension.java:178)
  73.     at org.junit.jupiter.engine.execution.ExecutableInvoker.resolveParameter(ExecutableInvoker.java:207)
  74.     ... 64 more
  75. Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'jwtAuthorizationFilter': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.security.authentication.AuthenticationManager' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
  76.     at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:732)
  77.     at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:197)
  78.     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1267)
  79.     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1124)
  80.     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:535)
  81.     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495)
  82.     at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317)
  83.     at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
  84.     at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315)
  85.     at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
  86.     at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:759)
  87.     at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:869)
  88.     at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)
  89.     at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:762)
  90.     at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:398)
  91.     at org.springframework.boot.SpringApplication.run(SpringApplication.java:330)
  92.     at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:139)
  93.     at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99)
  94.     at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117)
  95.     ... 68 more
  96. Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.security.authentication.AuthenticationManager' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
  97.     at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1506)
  98.     at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1140)
  99.     at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1062)
  100.     at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:818)
  101.     at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:724)
  102.     ... 86 more
  103.    
  104. @EnableWebSecurity
  105. @EnableWebMvc
  106. class SecurityConfig (@Autowired val userDetailsService: DemonsUserService): WebSecurityConfigurerAdapter() {
  107.     override fun configure(httpSecurity: HttpSecurity) {
  108.         http
  109.                 .cors().and().csrf().disable()
  110.                 .authorizeRequests()
  111.                 .antMatchers(HttpMethod.POST, "/users").permitAll()
  112.                 .anyRequest().authenticated()
  113.                 .and()
  114.                 .addFilter(jwtAuthenticationFilter())
  115.                 .addFilter(jwtAuthorizationFilter())
  116.     }
  117.  
  118.     @Bean(name = [BeanIds.AUTHENTICATION_MANAGER])
  119.     override fun authenticationManagerBean(): AuthenticationManager {
  120.         return super.authenticationManager()
  121.     }
  122.  
  123.     companion object {
  124.         @Bean
  125.         fun passwordEncoder() : PasswordEncoder {
  126.             return PasswordEncoderFactories.createDelegatingPasswordEncoder()
  127.         }
  128.     }
  129.  
  130.     @Bean
  131.     fun jwtAuthenticationFilter() : JwtAuthenticationFilter {
  132.         return JwtAuthenticationFilter(authenticationManagerBean())
  133.     }
  134.  
  135.     @Bean
  136.     fun jwtAuthorizationFilter() : JwtAuthorizationFilter {
  137.         return JwtAuthorizationFilter(authenticationManagerBean(), userDetailsService)
  138.     }
  139. }
  140.    
  141. @ExtendWith(SpringExtension::class)
  142. @WebMvcTest(controllers = [DemonsUserController::class])
  143. @TestInstance(TestInstance.Lifecycle.PER_CLASS)
  144. @ContextConfiguration
  145. class DemonsUserControllerTest (@Autowired val mockMvc: MockMvc){
  146.     @MockBean
  147.     private lateinit var userService : DemonsUserService
  148.  
  149.     @MockBean
  150.     private lateinit var securityConfig: SecurityConfig
  151.  
  152.     val email = "test@test.test"
  153.     val password = "password"
  154.     val testUser = DemonsUser(email = email, password = password)
  155.  
  156.     @Test
  157.     fun `Sending POST to the users endpoint with a valid json creates a new user`() {
  158.         val payload = mapOf(
  159.                 "email" to email,
  160.                 "password" to password
  161.         )
  162.         Mockito.`when`(userService.addUser(testUser))
  163.                 .thenReturn(testUser)
  164.  
  165.  
  166.         mockMvc.perform(MockMvcRequestBuilders.post("/users")
  167.                 .with(csrf().asHeader())
  168.                 .with(user("user"))
  169.                 .contentType(MediaType.APPLICATION_JSON_UTF8)
  170.                 .content(JSONObject(payload).toString()))
  171.                 .andExpect(MockMvcResultMatchers.status().isCreated)
  172.                 .andExpect(MockMvcResultMatchers.content().contentType(MediaType.APPLICATION_JSON_UTF8))
  173.                 .andExpect(jsonPath("$.created").value("true"))
  174.                 .andExpect(jsonPath("$.email").value(testUser.email))
  175.     }
  176. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top