Search in sources :

Example 1 with Account

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"));
}
Also used : Account(com.apistudy.restapi.accounts.Account) BaseControllerTest(com.apistudy.restapi.common.BaseControllerTest) Test(org.junit.jupiter.api.Test) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 2 with Account

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
}
Also used : Account(com.apistudy.restapi.accounts.Account) BaseControllerTest(com.apistudy.restapi.common.BaseControllerTest) Test(org.junit.jupiter.api.Test) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 3 with Account

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);
        }
    };
}
Also used : Account(com.apistudy.restapi.accounts.Account) ApplicationRunner(org.springframework.boot.ApplicationRunner) AccountService(com.apistudy.restapi.accounts.AccountService) AppProperties(com.apistudy.restapi.common.AppProperties) ApplicationArguments(org.springframework.boot.ApplicationArguments) Bean(org.springframework.context.annotation.Bean)

Aggregations

Account (com.apistudy.restapi.accounts.Account)3 BaseControllerTest (com.apistudy.restapi.common.BaseControllerTest)2 DisplayName (org.junit.jupiter.api.DisplayName)2 Test (org.junit.jupiter.api.Test)2 WebMvcTest (org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 AccountService (com.apistudy.restapi.accounts.AccountService)1 AppProperties (com.apistudy.restapi.common.AppProperties)1 ApplicationArguments (org.springframework.boot.ApplicationArguments)1 ApplicationRunner (org.springframework.boot.ApplicationRunner)1 Bean (org.springframework.context.annotation.Bean)1