Skip to content

Commit

Permalink
Merge pull request #210 from Kernel360/lee
Browse files Browse the repository at this point in the history
[#169] 테스트 코드 수정, 미사용 코드 삭제
  • Loading branch information
km2535 authored Aug 29, 2024
2 parents c42b726 + a2b28a9 commit 40f42fb
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
2 changes: 0 additions & 2 deletions src/main/java/com/speech/up/api/etri/dto/AiRequest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.speech.up.api.etri.dto;

import org.springframework.web.multipart.MultipartFile;

import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import com.speech.up.api.etri.type.ApiType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.speech.up.auth.entity.CustomOAuth2User;
import com.speech.up.auth.provider.JwtProvider;

import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
Expand All @@ -19,14 +18,16 @@
@RequiredArgsConstructor
public class OAuth2SuccessHandler extends SimpleUrlAuthenticationSuccessHandler {
private final JwtProvider jwtProvider;

@Value("${google.cloud.url}")
private String allowUrl;

@Override
public void onAuthenticationSuccess(
HttpServletRequest request,
HttpServletResponse response,
Authentication authentication) throws IOException {
CustomOAuth2User oAuth2User = (CustomOAuth2User) authentication.getPrincipal();
CustomOAuth2User oAuth2User = (CustomOAuth2User)authentication.getPrincipal();
String socialId = oAuth2User.getName();
String token = jwtProvider.createToken(socialId);
response.sendRedirect(allowUrl + "?token=Bearer " + token);
Expand Down
45 changes: 45 additions & 0 deletions src/test/java/com/speech/up/common/aspect/LoggingAspectTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.speech.up.common.aspect;

import static org.junit.jupiter.api.Assertions.*;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.MockitoAnnotations;
import org.slf4j.LoggerFactory;

import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.core.read.ListAppender;

public class LoggingAspectTest {

private ListAppender<ch.qos.logback.classic.spi.ILoggingEvent> listAppender;

@InjectMocks
private LoggingAspect loggingAspect;

@BeforeEach
void setUp() {
MockitoAnnotations.openMocks(this);

LoggerContext loggerContext = (LoggerContext)LoggerFactory.getILoggerFactory();
listAppender = new ListAppender<>();
listAppender.setContext(loggerContext);
listAppender.start();
((ch.qos.logback.classic.Logger)LoggerFactory.getLogger(LoggingAspect.class)).addAppender(listAppender);
}

@Test
void testLogAfterThrowing() {
// Given
RuntimeException exception = new RuntimeException("Test Exception");

// When
loggingAspect.logAfterThrowing(exception);

// Then
var logs = listAppender.list;
assertTrue(logs.stream()
.anyMatch(event -> event.getFormattedMessage().contains("Exception in method: Test Exception")));
}
}

0 comments on commit 40f42fb

Please sign in to comment.