inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

스프링 기반 REST API 개발

비즈니스 로직 적용

테스트시 enum 값 불일치

654

백엔드개발

작성한 질문수 3

0

public enum EventStatus {
DRAFT, PUBLISHED, BEGAN_ENROLLMENT;
}

@Enumerated(EnumType.STRING)
private EventStatus eventStatus = EventStatus.DRAFT; // 기본값 설정

@Test
@TestDescription("정상적으로 이벤트를 생성하는 테스트")
public void createEvent() throws Exception {
EventDto event = EventDto.builder()
.name("Spring")
.description("REST API Development with Spring")
.beginEnrollmentDateTime(LocalDateTime.of(2018, 11, 23, 14, 21))
.closeEnrollmentDateTime(LocalDateTime.of(2018, 11, 24, 14, 21))
.beginEventDateTime(LocalDateTime.of(2018, 11, 25, 14, 21))
.endEventDateTime(LocalDateTime.of(2018, 11, 26 , 14, 21))
.basePrice(100)
.maxPrice(200)
.limitOfEnrollment(100)
.location("강남역 D2 스타텁 팩토리")
.build();
//Mockito.when(eventRepository.save(event)).thenReturn(event);

mockMvc.perform(post("/api/events")
.contentType(MediaType.APPLICATION_JSON_VALUE)
.accept(MediaTypes.HAL_JSON_VALUE)
.content(objectMapper.writeValueAsString(event)))
.andDo(print())
.andExpect(status().isCreated())
.andExpect(jsonPath("id").exists())
.andExpect(header().exists(HttpHeaders.LOCATION))
.andExpect(header().string(HttpHeaders.CONTENT_TYPE, MediaTypes.HAL_JSON_VALUE))
.andExpect(jsonPath("id").value(Matchers.not(100)))
.andExpect(jsonPath("free").value(false))
.andExpect(jsonPath("offline").value(true))
.andExpect(jsonPath("eventStatus").value(EventStatus.DRAFT));

java.lang.AssertionError: JSON path "eventStatus" 

Expected :DRAFT

Actual   :DRAFT

위와 같은 오류가 발생합니다.

아래와 같이 String 값을 직접 입력해주면 통과하구요...

.andExpect(jsonPath("eventStatus").value("DRAFT"));

어떻게 해결해야 할 지 알고싶습니다.

java spring rest-api

답변 1

0

백기선

JSON에 들어있는 값은 문자열이지 enum 타입이 아니니까 타입이 맞지 않으니 다른게 맞지 않을까요? 문자열을 Enum하고 비교하지 마시고 문자열끼리 비교하거나 Enum끼리 비교해야겠죠.

Spring 시큐리티 관련해서 WebSecurityConfigurationAdapter

0

73

1

junit5 사용하시는 분들

0

87

1

자바 빈 스펙을 준수하는지 체크하는 테스트

0

234

2

REST API 개발 중 비즈니스 로직 적용 부분의 JSON 에러

0

241

1

스프링 부트 3버전에서의 실습

0

190

1

java.lang.AssertionError: Status

0

530

2

spring doc 관련 파일 생성 관련 배포 관련 질문 드립니다.

0

286

1

섹션2 201응답받기 부분 테스트 404에러 질문입니다

0

738

1

강의 자료가 404입니다 확인 부탁 드려요!

0

475

1

연동 DB문의

0

358

1

이벤트 Repository강의 중 Event 클래스에 private Integer Id; 위치 질문

0

503

1

(Mac) postgressql 관련하여 port kill 해도 다시 살아나는 경우

0

379

0

maven으로 생성한 docs파일(index.html)에서의 not found 오류 질문

0

621

1

테스트 오류 질문드립니다.

0

511

1

docs 요청값이 반영이 안되네요... (해결)

-1

392

1

psql 적용 후 에러

0

818

2

mvn package 시 다음과 같은 에러가 나시면

0

761

2

Event에 Account manager를 추가했으면 문서화 필요

0

273

1

2년 훨씬 전 부터 Restlet-> Talend API 로 바뀌었습니다~

1

473

1

asciidoc 추가 스니펫 에러 해결법

0

398

1

_links 는 현재 fieldWithPath 를 해주지 않아도 됩니다.

0

420

3

깃랩 처음 사용자를 위한 index.adoc raw 보는 법

0

330

1

eclipse 쓰시는 분을 위한 maven-resources-plugin 팁

0

331

1

부트 + jupiter 인 경우 설정법

0

340

1