Skip to content

Commit

Permalink
Merge pull request #247 from Genti2024/feat/241-service-unit-test
Browse files Browse the repository at this point in the history
Feat/241 service unit test
  • Loading branch information
LeeJae-H authored Dec 12, 2024
2 parents d8d5087 + 4a81bb6 commit ec3d5df
Show file tree
Hide file tree
Showing 19 changed files with 560 additions and 199 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,12 @@
import java.util.stream.Collectors;

import com.gt.genti.responseexample.dto.response.ExampleWithSquarePicture;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.gt.genti.error.ExpectedException;
import com.gt.genti.error.ResponseCode;
import com.gt.genti.picture.PictureRatio;
import com.gt.genti.picture.responseexample.model.ResponseExample;
import com.gt.genti.picture.responseexample.repository.ResponseExampleRepository;
import com.gt.genti.responseexample.command.ExampleSaveCommand;
import com.gt.genti.responseexample.dto.response.ExampleWithPictureFindResponseDto;
import com.gt.genti.user.model.User;
import com.gt.genti.user.repository.UserRepository;

import lombok.RequiredArgsConstructor;

Expand All @@ -28,12 +20,6 @@
@RequiredArgsConstructor
public class ResponseExampleService {
private final ResponseExampleRepository responseExampleRepository;
private final UserRepository userRepository;

public Page<ExampleWithPictureFindResponseDto> getAllResponseExamplesPagination(Pageable pageable) {
return responseExampleRepository.findAllByPromptOnlyIsFalse(pageable)
.map(ExampleWithPictureFindResponseDto::new);
}

public List<ExampleWithPictureFindResponseDto> getAllResponseExamples() {
List<ExampleWithPictureFindResponseDto> examples = responseExampleRepository.findAllByPromptOnlyIsFalse()
Expand All @@ -55,19 +41,6 @@ public List<ExampleWithPictureFindResponseDto> getAllResponseExamples() {
return examples;
}

public void addResponseExamples(List<ExampleSaveCommand> commandList,
Long userId) {
User foundUploader = userRepository.findById(userId).orElseThrow(() -> ExpectedException.withLogging(
ResponseCode.UserNotFound, userId));
responseExampleRepository.saveAll(
commandList.stream().map(command -> ResponseExample.builder()
.key(command.getKey())
.uploadedBy(foundUploader)
.pictureRatio(command.getPictureRatio())
.prompt(command.getPrompt())
.build()).toList());
}

public List<ExampleWithSquarePicture> getAllResponseExamplesInGenerateView() {
final String type = "FREE_ONE";
List<ExampleWithSquarePicture> examples = responseExampleRepository.findAllByType(type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ public class UserVerificationRequestDto {
@Schema(description = "s3 key", example = "USER_VERIFICATION_IMAGE/image.jpg")
String key;

public UserVerificationRequestDto(String key) {
this.key = key;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,26 @@ public Boolean checkUserVerification(Long userId){
}

public Boolean savePictureUserVerification(Long userId, UserVerificationRequestDto userVerificationRequestDto){
Boolean isSaved = false;

User foundUser = getUserByUserId(userId);
PictureUserVerification pictureUserVerification = new PictureUserVerification(userVerificationRequestDto.getKey(), foundUser);
pictureUserVerificationRepository.save(pictureUserVerification);
foundUser.verifyUser();
return true;
PictureUserVerification pictureUserVerification = PictureUserVerification.builder()
.key(userVerificationRequestDto.getKey())
.user(foundUser)
.build();
PictureUserVerification savePictureUserVerification = pictureUserVerificationRepository.save(pictureUserVerification);

if (savePictureUserVerification != null && savePictureUserVerification.getId() > 0){
foundUser.verifyUser();
User savedUser = userRepository.save(foundUser);
if (savedUser != null && savedUser.getId() > 0) {
isSaved = true;
}
}

return isSaved;
}


private User getUserByUserId(Long userId) {
return userRepository.findById(userId)
.orElseThrow(() -> ExpectedException.withLogging(ResponseCode.UserNotFound, userId));
Expand Down
26 changes: 13 additions & 13 deletions genti-api/src/test/java/com/gt/genti/GentiApiApplicationTests.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// package com.gt.genti;
//
// import org.junit.jupiter.api.Test;
// import org.springframework.boot.test.context.SpringBootTest;
//
// @SpringBootTest
// class GentiApiApplicationTests {
//
// @Test
// void contextLoads() {
// }
//
// }
package com.gt.genti;

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
class GentiApiApplicationTests {

@Test
void contextLoads() {
}

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.gt.genti;
package com.gt.genti.config;

import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.FilterType;
import org.springframework.test.context.ActiveProfiles;

import com.gt.genti.config.ScheduleConfig;
import com.gt.genti.discord.DiscordAppender;

@SpringBootTest
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.gt.genti;
package com.gt.genti.config;

import static org.assertj.core.api.Assertions.*;

Expand All @@ -7,9 +7,8 @@
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;

import com.gt.genti.TestUtils.Domain;
import com.gt.genti.TestUtils.Dto;
import com.gt.genti.config.TestConfig;
import com.gt.genti.config.TestUtils.Domain;
import com.gt.genti.config.TestUtils.Dto;
import com.gt.genti.matchingstrategy.model.RequestMatchStrategy;
import com.gt.genti.picturegeneraterequest.controller.UserPGREQController;
import com.gt.genti.picturegeneraterequest.dto.request.PGREQSaveRequestDto;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.gt.genti;
package com.gt.genti.config;

import static com.gt.genti.TestUtils.*;
import static com.gt.genti.config.TestUtils.*;
import static org.assertj.core.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.*;

Expand All @@ -12,7 +12,6 @@
import org.springframework.test.context.ActiveProfiles;

import com.gt.genti.common.AdminService;
import com.gt.genti.config.TestConfig;
import com.gt.genti.creator.model.Creator;
import com.gt.genti.picture.PictureRatio;
import com.gt.genti.picture.command.CreatePicturePoseCommand;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//package com.gt.genti;
//package com.gt.genti.config;
//
//import static com.gt.genti.TestUtils.*;
//import static com.gt.genti.TestUtils.Dto.*;
//import static com.gt.genti.config.TestUtils.*;
//import static com.gt.genti.config.TestUtils.Dto.*;
//import static com.gt.genti.picturegeneraterequest.service.mapper.PictureGenerateRequestStatusForUser.*;
//import static org.assertj.core.api.Assertions.*;
//
Expand All @@ -17,7 +17,6 @@
//import org.springframework.transaction.annotation.Transactional;
//
//import com.gt.genti.aws.FileType;
//import com.gt.genti.config.TestConfig;
//import com.gt.genti.matchingstrategy.model.RequestMatchStrategy;
//import com.gt.genti.picturegeneraterequest.controller.UserPGREQController;
//import com.gt.genti.picturegeneraterequest.dto.request.PGREQSaveRequestDto;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.gt.genti;
package com.gt.genti.config;

import static com.gt.genti.TestUtils.Domain.*;
import static com.gt.genti.config.TestUtils.Domain.*;

import java.time.LocalDateTime;
import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.gt.genti.picturegeneraterequest.service;
package com.gt.genti.config.picturegeneraterequest.service;

import static org.assertj.core.api.Assertions.*;

Expand All @@ -7,14 +7,15 @@
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.IntStream;

import com.gt.genti.picturegeneraterequest.service.PictureGenerateRequestService;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.gt.genti.BaseTest;
import com.gt.genti.TestUtils;
import com.gt.genti.config.BaseTest;
import com.gt.genti.config.TestUtils;
import com.gt.genti.creator.model.Creator;
import com.gt.genti.creator.repository.CreatorRepository;
import com.gt.genti.error.ExpectedException;
Expand Down
Loading

0 comments on commit ec3d5df

Please sign in to comment.