use of com.apistudy.restapi.accounts.Account in project spring-study by backtony.
the class EventControllerTest method updateEvent.
// 첫 테스트 이후 doc을 생략하고 있는데
// 오류테스트 말고 정상적인 테스트에 대해서는 doc를 link 다 걸어서 작성해줘야한다
@DisplayName("이벤트를 정상적으로 수정하기")
@Test
void updateEvent() throws Exception {
// given
Account account = createAccount();
Event event = generateEvent(200, account);
String eventName = "Updated Event";
EventDto eventDto = modelMapper.map(event, EventDto.class);
eventDto.setName(eventName);
mockMvc.perform(put("/api/events/{id}", event.getId()).header(HttpHeaders.AUTHORIZATION, getBearerToken(false)).contentType(MediaType.APPLICATION_JSON_VALUE).content(objectMapper.writeValueAsString(eventDto))).andDo(print()).andExpect(status().isOk()).andExpect(jsonPath("name").value(eventName)).andExpect(jsonPath("_links.self").exists()).andDo(document("update-event"));
}
use of com.apistudy.restapi.accounts.Account in project spring-study by backtony.
the class EventControllerTest method getEvent.
@DisplayName("기존의 이벤트를 하나 조회하기")
@Test
void getEvent() throws Exception {
// given
Account account = createAccount();
Event event = generateEvent(100, account);
// when
// 쉼표찍고 뒤에 값주면 pathvaraible 값 줄 수 있음
mockMvc.perform(get("/api/events/{id}", event.getId())).andExpect(status().isOk()).andExpect(jsonPath("name").exists()).andExpect(jsonPath("id").exists()).andExpect(jsonPath("_links.self").exists()).andExpect(jsonPath("_links.profile").exists()).andDo(document("get-an-event"));
// then
}
use of com.apistudy.restapi.accounts.Account in project spring-study by backtony.
the class AppConfig method applicationRunner.
// 그냥 스프링 뜰때 유저 하나 넣어준 거임
@Bean
public ApplicationRunner applicationRunner() {
return new ApplicationRunner() {
@Autowired
AccountService accountService;
@Autowired
AppProperties appProperties;
@Override
public void run(ApplicationArguments args) throws Exception {
Account admin = Account.builder().email(appProperties.getAdminUsername()).password(appProperties.getAdminPassword()).roles(Set.of(AccountRole.ADMIN, AccountRole.USER)).build();
accountService.saveAccount(admin);
Account user = Account.builder().email(appProperties.getUserUsername()).password(appProperties.getUserPassword()).roles(Set.of(AccountRole.USER)).build();
accountService.saveAccount(user);
}
};
}
Aggregations