Advertisement
Guest User

Untitled

a guest
Mar 16th, 2018
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.64 KB | None | 0 0
  1.  
  2. @RunWith(SpringJUnit4ClassRunner.class)
  3. @WebAppConfiguration
  4. @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
  5. @ContextConfiguration
  6. @SpringBootTest
  7. @FixMethodOrder(MethodSorters.NAME_ASCENDING)
  8. public class UserControllerTest {
  9.     @Autowired
  10.     private WebApplicationContext wac;
  11.  
  12.     private MockMvc mockMvc;
  13.  
  14.     @Before
  15.     public void setup() {
  16.         this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).dispatchOptions(true).build();
  17.     }
  18.  
  19. //    @Test
  20. //    public void createUser()
  21. //    {
  22. //        // uzivatel uz existuje => 400
  23. //
  24. //        BakeryUser bakeryUser = new BakeryUser();
  25. //        bakeryUser.setName("Arya");
  26. //        bakeryUser.setPassword("shit");
  27. //        bakeryUser.setSurname("Stark");
  28. //        bakeryUser.setUsername("Stark");
  29. //        bakeryUser.setEmail("aS@manyFacedGods.com");
  30. //        bakeryUser.setPhoneNumber("");
  31. //
  32. //        String jsonContent;
  33. //        try {
  34. //            ObjectMapper mapper = new ObjectMapper();
  35. //            jsonContent = mapper.writeValueAsString(bakeryUser);
  36. //
  37. //            mockMvc.perform(post("/users/sing-up")
  38. //                    .contentType(MediaType.APPLICATION_JSON)
  39. //                    .content(jsonContent))
  40. //                    .andExpect(status().isOk());
  41. //
  42. //
  43. //        } catch (Exception e) {
  44. //            throw new RuntimeException(e);
  45. //        }
  46. //    }
  47.  
  48.     @Test
  49.     public void login() throws Exception
  50.     {
  51.         BakeryUser bakeryUser = new BakeryUser();
  52.         Auth auth = new Auth();
  53.         auth.username = "Kocka";
  54.         auth.password = "shit";
  55. //        bakeryUser.setPassword("shit");
  56. //        bakeryUser.setUsername("Kocka");
  57.  
  58.         String jsonContent;
  59.         try {
  60.             ObjectMapper mapper = new ObjectMapper();
  61.             jsonContent = mapper.writeValueAsString(auth);
  62.  
  63.             mockMvc.perform(post("/login")
  64.                     .content(jsonContent))
  65.                     .andExpect(status().isOk());
  66.  
  67.  
  68.         } catch (Exception e) {
  69.             throw new RuntimeException(e);
  70.         }
  71.  
  72.  
  73.     }
  74.  
  75. //    @Test
  76. //    public void getUser() throws Exception
  77. //    {
  78. //        String authKey = "Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJLb2NrYSIsInJvbGVzIjpbXSwiZXhwIjoxNTIxMzkxNTk3fQ.IrmljbZvGhEGGrlFeAbrLqskfBxlrCpTtCgkOJ1AzA9ZnuqQktgcsuFjHxh6oygMrZekeIOxZ754m9-eIX9v_g";
  79. //        mockMvc.perform(get("/users/" + "Stark")
  80. //                .contentType(MediaType.APPLICATION_JSON))
  81. //                .andExpect(status().isOk());
  82. //
  83. //    }
  84. //
  85.     public class Auth
  86.     {
  87.         public String username;
  88.         public String password;
  89.  
  90.     }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement