Skip to content

Commit

Permalink
Test: 발자취 GetFootprintAdaptor 임시 데이터 객체 생성
Browse files Browse the repository at this point in the history
  • Loading branch information
JuwoongKim committed Feb 17, 2024
1 parent 51c64aa commit dbdcf59
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ public Footprint getFootprint(Long id) {
.orElseThrow(() -> AjajaException.withId(id, NOT_FOUND_FOOTPRINT));

TargetEntity targetEntity = queryFactory.select(
Projections.fields(TargetEntity.class, planEntity.id, planEntity.title))
Projections.constructor(TargetEntity.class, planEntity.id, planEntity.title))
.from(planEntity)
.where(planEntity.id.eq(footprintEntity.getTargetId()))
.fetchOne();

WriterEntity writerEntity = queryFactory.select(
Projections.fields(WriterEntity.class, userEntity.id, userEntity.nickname))
Projections.constructor(WriterEntity.class, userEntity.id, userEntity.nickname))
.from(userEntity)
.where(userEntity.id.eq(footprintEntity.getWriterId()))
.fetchOne();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ default Footprint createFootprint(FootprintEntity footprintEntity, TargetEntity
if (footprintEntity.getType().equals("FREE")) {
return new FreeFootprint(
footprintEntity.getId(),
new Target(targetEntity.getId(), targetEntity.getTitle()),
new Writer(writerEntity.getId(), writerEntity.getNickname()),
new Target(targetEntity.id(), targetEntity.title()),
new Writer(writerEntity.id(), writerEntity.nickname()),
new Title(footprintEntity.getTitle()),
footprintEntity.isVisible(),
footprintEntity.isDeleted(),
Expand All @@ -68,8 +68,8 @@ default Footprint createFootprint(FootprintEntity footprintEntity, TargetEntity
} else {
return new KptFootprint(
footprintEntity.getId(),
new Target(targetEntity.getId(), targetEntity.getTitle()),
new Writer(writerEntity.getId(), writerEntity.getNickname()),
new Target(targetEntity.id(), targetEntity.title()),
new Writer(writerEntity.id(), writerEntity.nickname()),
new Title(footprintEntity.getTitle()),
footprintEntity.isVisible(),
footprintEntity.isDeleted(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,70 @@

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

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.test.context.ContextConfiguration;

import me.ajaja.common.support.JpaTestSupport;
import me.ajaja.module.footprint.domain.Footprint;
import me.ajaja.module.footprint.domain.FootprintFactory;
import me.ajaja.module.footprint.domain.FreeFootprint;
import me.ajaja.module.footprint.domain.KptFootprint;
import me.ajaja.module.footprint.domain.Target;
import me.ajaja.module.footprint.domain.Writer;
import me.ajaja.module.footprint.dto.FootprintParam;
import me.ajaja.module.footprint.mapper.FootprintMapperImpl;

import com.navercorp.fixturemonkey.FixtureMonkey;
import com.navercorp.fixturemonkey.api.introspector.ConstructorPropertiesArbitraryIntrospector;
import com.navercorp.fixturemonkey.jakarta.validation.plugin.JakartaValidationPlugin;

@ContextConfiguration(classes = {
CreateFootprintAdaptor.class,
GetFootprintAdaptor.class,
FootprintMapperImpl.class
})
class GetFootprintAdaptorTest extends JpaTestSupport {
private final FixtureMonkey fixtureMonkey = FixtureMonkey.builder()
.objectIntrospector(ConstructorPropertiesArbitraryIntrospector.INSTANCE)
.plugin(new JakartaValidationPlugin())
.defaultNotNull(true)
.build();
private final String userCreateQuery = """
INSERT INTO users
(deleted, verified, created_at, oauth_id, updated_at, user_id, phone_number, nickname, remind_type, email,
remind_email, oauth_provider)
VALUES
(false, true, CURRENT_TIMESTAMP(6) AT TIME ZONE 'UTC', 1, CURRENT_TIMESTAMP(6) AT TIME ZONE 'UTC',
DEFAULT, '12345678901', 'example_nickname', 'example_remind_type', '[email protected]', '[email protected]', 'KAKAO');
""";
private final String planCreateQuery = """
INSERT INTO plans
(can_ajaja, can_remind, deleted, icon_number, is_public, remind_date, remind_term, remind_total_period,
created_at, plan_id, updated_at, user_id, title, description, remind_time)
VALUES
(true, true, false, 1, true, 1, 7, 30, CURRENT_TIMESTAMP(6) AT TIME ZONE 'UTC', DEFAULT,
CURRENT_TIMESTAMP(6) AT TIME ZONE 'UTC', 1, 'Example Plan', 'This is an example description.', '12:00 PM');
""";

@Autowired
private CreateFootprintAdaptor createFootprintAdaptor;

@Autowired
private GetFootprintAdaptor getFootprintAdaptor;

@Autowired
private JdbcTemplate jdbcTemplate;

@BeforeEach
void createTempDate() {
jdbcTemplate.update(userCreateQuery);
jdbcTemplate.update(planCreateQuery);
}

@Test
@DisplayName("자유 형식 발자취 조회 매핑 기능 구현 테스트")
void get_FreeFootprint_Success() {
// given
FootprintParam.Create param = fixtureMonkey.giveMeOne(FootprintParam.Create.class);
FootprintParam.Create param = sut.giveMeBuilder(FootprintParam.Create.class)
.set("writer", new Writer(1L, "nickName"))
.set("target", new Target(1L, "title"))
.sample();

String content = "content";
FreeFootprint freeFootprint = FootprintFactory.freeTemplate(param, content);

Expand All @@ -58,7 +82,11 @@ void get_FreeFootprint_Success() {
@DisplayName("Kpt 형식 발자취 조회 매핑 기능 구현 테스트")
void get_KptFootprint_Success() {
// given
FootprintParam.Create param = fixtureMonkey.giveMeOne(FootprintParam.Create.class);
FootprintParam.Create param = sut.giveMeBuilder(FootprintParam.Create.class)
.set("writer", new Writer(1L, "nickName"))
.set("target", new Target(1L, "title"))
.sample();

String keepContent = "keepContent";
String problemContent = "problemContent";
String tryContent = "tryContent";
Expand Down
20 changes: 5 additions & 15 deletions src/test/java/me/ajaja/module/footprint/domain/FootprintTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,26 @@
import me.ajaja.common.support.MonkeySupport;
import me.ajaja.module.footprint.dto.FootprintParam;

import com.navercorp.fixturemonkey.FixtureMonkey;
import com.navercorp.fixturemonkey.api.introspector.ConstructorPropertiesArbitraryIntrospector;
import com.navercorp.fixturemonkey.jakarta.validation.plugin.JakartaValidationPlugin;

class FootprintTest extends MonkeySupport {
private final FixtureMonkey fixtureMonkey = FixtureMonkey.builder()
.objectIntrospector(ConstructorPropertiesArbitraryIntrospector.INSTANCE)
.plugin(new JakartaValidationPlugin())
.defaultNotNull(true)
.build();

@Nested
@DisplayName("조건에 맞는 입력 값에 따라 유형별 발자취 도메인 생성에 성공 한다.")
class CreateFootprintTest {
@Test
@DisplayName("자유 형식 발자취 도메인 생성에 성공 한다.")
void create_FreeFootprint_Success_WithNoException() {
FootprintParam.Create param = fixtureMonkey.giveMeOne(FootprintParam.Create.class);
FootprintParam.Create param = sut.giveMeOne(FootprintParam.Create.class);
String content = "content";

assertThatNoException().isThrownBy(() -> {
FootprintFactory.freeTemplate(param, content);
FreeFootprint freeFootprint = FootprintFactory.freeTemplate(param, content);
});
}

@Test
@DisplayName("KPT 형식 발자취 도메인 생성에 성공 한다.")
void create_KptFootprint_Success_WithNoException() {
FootprintParam.Create param = fixtureMonkey.giveMeOne(FootprintParam.Create.class);
FootprintParam.Create param = sut.giveMeOne(FootprintParam.Create.class);
String keepContent = "keepContent";
String problemContent = "problemContent";
String tryContent = "tryContent";
Expand All @@ -52,11 +43,10 @@ void create_KptFootprint_Success_WithNoException() {
@Test
@DisplayName("발자취 항목에 대한 값이 null 일 때 예외가 발생 한다.")
void create_Fail_ByNoneContnets() {
FootprintParam.Create param = fixtureMonkey.giveMeOne(FootprintParam.Create.class);
FootprintParam.Create param = sut.giveMeOne(FootprintParam.Create.class);
String content = null;

assertThatExceptionOfType(ConstraintViolationException.class).isThrownBy(
() -> FootprintFactory.freeTemplate(param, content)
);
() -> FootprintFactory.freeTemplate(param, content));
}
}

0 comments on commit dbdcf59

Please sign in to comment.