Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @RunWith(SpringJUnit4ClassRunner.class)
- @WebAppConfiguration
- @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
- @ContextConfiguration
- @SpringBootTest
- @FixMethodOrder(MethodSorters.NAME_ASCENDING)
- public class UserControllerTest {
- @Autowired
- private WebApplicationContext wac;
- private MockMvc mockMvc;
- @Before
- public void setup() {
- this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).dispatchOptions(true).build();
- }
- // @Test
- // public void createUser()
- // {
- // // uzivatel uz existuje => 400
- //
- // BakeryUser bakeryUser = new BakeryUser();
- // bakeryUser.setName("Arya");
- // bakeryUser.setPassword("shit");
- // bakeryUser.setSurname("Stark");
- // bakeryUser.setUsername("Stark");
- // bakeryUser.setEmail("aS@manyFacedGods.com");
- // bakeryUser.setPhoneNumber("");
- //
- // String jsonContent;
- // try {
- // ObjectMapper mapper = new ObjectMapper();
- // jsonContent = mapper.writeValueAsString(bakeryUser);
- //
- // mockMvc.perform(post("/users/sing-up")
- // .contentType(MediaType.APPLICATION_JSON)
- // .content(jsonContent))
- // .andExpect(status().isOk());
- //
- //
- // } catch (Exception e) {
- // throw new RuntimeException(e);
- // }
- // }
- @Test
- public void login() throws Exception
- {
- BakeryUser bakeryUser = new BakeryUser();
- Auth auth = new Auth();
- auth.username = "Kocka";
- auth.password = "shit";
- // bakeryUser.setPassword("shit");
- // bakeryUser.setUsername("Kocka");
- String jsonContent;
- try {
- ObjectMapper mapper = new ObjectMapper();
- jsonContent = mapper.writeValueAsString(auth);
- mockMvc.perform(post("/login")
- .content(jsonContent))
- .andExpect(status().isOk());
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
- // @Test
- // public void getUser() throws Exception
- // {
- // String authKey = "Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJLb2NrYSIsInJvbGVzIjpbXSwiZXhwIjoxNTIxMzkxNTk3fQ.IrmljbZvGhEGGrlFeAbrLqskfBxlrCpTtCgkOJ1AzA9ZnuqQktgcsuFjHxh6oygMrZekeIOxZ754m9-eIX9v_g";
- // mockMvc.perform(get("/users/" + "Stark")
- // .contentType(MediaType.APPLICATION_JSON))
- // .andExpect(status().isOk());
- //
- // }
- //
- public class Auth
- {
- public String username;
- public String password;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement