-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[5기 최정은] Shorten-URL 과제 제출합니다. #68
Open
JeongeunChoi
wants to merge
15
commits into
prgrms-be-devcourse:JeongeunChoi
Choose a base branch
from
JeongeunChoi:JeongeunChoi
base: JeongeunChoi
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
d7def34
init: 프로젝트 초기 설정
JeongeunChoi 14f5576
feat: Url 엔터티 생성
JeongeunChoi bb9a605
feat: UrlRepository 생성
JeongeunChoi 37dc9c3
feat: Base62 인코딩 디코딩 알고리즘 구현
JeongeunChoi 06f74a8
feat: 단축 url 생성 서비스 로직 구현
JeongeunChoi a59b5e4
feat: 단축 url을 기존 url 반환하는 서비스 로직 구현
JeongeunChoi 6cf971e
feat: 요청 수 정보 저장 기능 추가
JeongeunChoi be2d0e5
feat: 단축 url 생성 및 반환 요청을 위한 컨트롤러 및 결과 출력 html 추가
JeongeunChoi 4e624a2
feat: url 관련 예외 코드 및 커스텀 예외 생성
JeongeunChoi fee5af2
feat: 유효하지 않은 기존 url 예외 처리 추가
JeongeunChoi 2f35454
feat: 존재하지 않는 단축 url 예외 처리 추가
JeongeunChoi bea61ca
feat: 단축 url 생성 요청 dto 추가
JeongeunChoi f510a9a
feat: 예외 처리 핸들러 추가 및 출력 html 추가
JeongeunChoi c95d11f
test: UrlController 테스트 코드 추가
JeongeunChoi 4f037a5
test: UrlService 테스트 코드 추가
JeongeunChoi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
src/test/java/com/springboot/springbooturlshortner/controller/UrlControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.springboot.springbooturlshortner.controller; | ||
|
||
import com.springboot.springbooturlshortner.service.ShortenUrlRequestDto; | ||
import com.springboot.springbooturlshortner.service.UrlService; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; | ||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.when; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; | ||
|
||
@WebMvcTest(UrlController.class) | ||
class UrlControllerTest { | ||
|
||
@Autowired | ||
private MockMvc mockMvc; | ||
@MockBean | ||
private UrlService urlService; | ||
@Value("${spring.start-url}") | ||
private String startUrl; | ||
|
||
@Test | ||
@DisplayName("url 단축 요청 성공") | ||
void Success_ShrotenUrl() throws Exception { | ||
// given | ||
String originUrl = "https://test-url"; | ||
String shortenUrl = startUrl + "/" + "testkey"; | ||
when(urlService.createShortenUrl(any(ShortenUrlRequestDto.class))).thenReturn(shortenUrl); | ||
|
||
// when, then | ||
mockMvc.perform(MockMvcRequestBuilders.post("/shorten-url") | ||
.param("originUrl", originUrl) // URL 인코딩이 필요한 경우에는 여기에서 수행 | ||
.contentType("application/x-www-form-urlencoded")) | ||
.andExpect(status().isOk()) | ||
.andDo(print()) | ||
.andExpect(view().name("shortenUrl")) | ||
.andExpect(model().attribute("shortenUrl", shortenUrl)); | ||
} | ||
|
||
@Test | ||
@DisplayName("기존 url로 리다이렉트 성공") | ||
void Success_RedirectToOriginUrl() throws Exception { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 메서드명이 대문자로 되어있어요. |
||
// given | ||
String originUrl = "https://test-url"; | ||
String uniqueKey = "testkey"; | ||
when(urlService.getOriginUrl(uniqueKey)).thenReturn(originUrl); | ||
|
||
// when | ||
mockMvc.perform(MockMvcRequestBuilders.get("/jeurl.com/{uniqueKey}", uniqueKey)) | ||
.andExpect(status().is3xxRedirection()) | ||
.andExpect(redirectedUrl(originUrl)); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
메서드명이 대문자로 시작되어있네요.