Advertisement
Guest User

Untitled

a guest
Jan 30th, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.63 KB | None | 0 0
  1. @RunWith(SpringRunner.class)
  2. @SpringBootTest
  3. @DataJpaTest
  4. @AutoConfigureMockMvc
  5. public class AuthenticationTest {
  6.  
  7. @Autowired
  8. private MockMvc mockMvc;
  9.  
  10. @Test
  11. public void loginWithCorrectCredentials() throws Exception {
  12. RequestBuilder request = post("/api/login")
  13. .contentType(MediaType.APPLICATION_FORM_URLENCODED)
  14. .param("username", "user")
  15. .param("password", "password");
  16. mockMvc.perform(request)
  17. .andExpect(status().isOk())
  18. .andExpect(cookie().exists("JSESSIONID"));
  19. }
  20.  
  21. MockHttpServletRequest:
  22. HTTP Method = POST
  23. Request URI = /api/login
  24. Parameters = {username=[user], password=[password]}
  25. Headers = {Content-Type=[application/x-www-form-urlencoded]}
  26.  
  27. Handler:
  28. Type = null
  29.  
  30. Async:
  31. Async started = false
  32. Async result = null
  33.  
  34. Resolved Exception:
  35. Type = null
  36.  
  37. ModelAndView:
  38. View name = null
  39. View = null
  40. Model = null
  41.  
  42. FlashMap:
  43. Attributes = null
  44.  
  45. MockHttpServletResponse:
  46. Status = 401
  47. Error message = Full authentication is required to access this resource
  48. Headers = {X-Content-Type-Options=[nosniff], X-XSS-Protection=[1; mode=block], Cache-Control=[no-cache, no-store, max-age=0, must-revalidate], Pragma=[no-cache], Expires=[0], X-Frame-Options=[DENY], Strict-Transport-Security=[max-age=31536000 ; includeSubDomains], WWW-Authenticate=[Basic realm="Spring"]}
  49. Content type = null
  50. Body =
  51. Forwarded URL = null
  52. Redirected URL = null
  53. Cookies = []
  54. 2018-01-30 13:28:17.471 INFO 3988 --- [ main] o.s.t.c.transaction.TransactionContext : Rolled back transaction for test context [DefaultTestContext@6ac13091 testClass = AuthenticationTest, testInstance = ua.com.kidspace.controller.AuthenticationTest@752b69e3, testMethod = loginWithCorrectCredentials@AuthenticationTest, testException = java.lang.AssertionError: Status expected:<200> but was:<401>, mergedContextConfiguration = [WebMergedContextConfiguration@5e316c74 testClass = AuthenticationTest, locations = '{}', classes = '{class ua.com.kidspace.Application}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}', contextCustomizers = set[[ImportsContextCustomizer@6d2a209c key = [org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration, org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration, org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration, org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration, org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration, org.springframework.boot.autoconfigure.jdbc.JdbcTemplateAutoConfiguration, org.springframework.boot.autoconfigure.liquibase.LiquibaseAutoConfiguration, org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration, org.springframework.boot.autoconfigure.transaction.TransactionAutoConfiguration, org.springframework.boot.test.autoconfigure.jdbc.TestDatabaseAutoConfiguration, org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManagerAutoConfiguration, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcAutoConfiguration, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcSecurityAutoConfiguration, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcWebClientAutoConfiguration, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcWebDriverAutoConfiguration]], org.springframework.boot.test.context.SpringBootTestContextCustomizer@42607a4f, org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@64485a47, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@7276c8cd, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.autoconfigure.OverrideAutoConfigurationContextCustomizerFactory$DisableAutoConfigurationContextCustomizer@306279ee, org.springframework.boot.test.autoconfigure.filter.TypeExcludeFiltersContextCustomizer@351584c0, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@178398d7, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@24b1d79b], resourceBasePath = 'src/main/webapp', contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]]].
  55.  
  56. java.lang.AssertionError: Status
  57. Expected :200
  58. Actual :401
  59.  
  60. security.user.password=password
  61. security.user.name=username
  62. management.security.enabled=false
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement