qwerasdfzxc
165
2020-10-06 14:18:39 작성 2020-10-06 14:20:00 수정됨
0
165

jUnit테스트와 서비스환경에서 쿼리문 차이


테스트 코드 작성중 이해가 안가는 부분이 있어서 질문드립니다.


우선 제 코드는

@Test
void findUserAssetTest() {
AssetReturnDto assetReturnDto = Assertions.assertDoesNotThrow(() -> userService.findUserAsset("ktj7916"));
Assertions.assertAll(
() -> Assertions.assertNotNull(assetReturnDto),
() -> Assertions.assertNotEquals(0, assetReturnDto.getInventory().getInterior().size())
);
}
@Transactional(readOnly = true)
public AssetReturnDto findUserAsset(String userName) {
User user = userRepository.findByUserName(userName).orElseThrow(UserNotExistException::new);
AssetObjectListDto field = new AssetObjectListDto();
AssetObjectListDto inventory = new AssetObjectListDto();

findAssetFunction.findInterior(user, field, inventory);
findAssetFunction.findFurniture(user, field, inventory);
findAssetFunction.findRoom(user, field, inventory);

return new AssetReturnDto(user.getWallet(), field, inventory);
}
@Transactional
public void findInterior(User user, AssetObjectListDto field, AssetObjectListDto inventory) {
System.out.println("interior start");
user.getInteriorWrapperList()
.forEach(it -> {
if (it.getInventory())
inventory.getInterior().add(new InteriorWrapperDto(it));
else
field.getInterior().add(new InteriorWrapperDto(it));
});
}

이런식으로 되어있습니다.

postMan을 사용해서 테스트 할시에는 user와 Wrapper들의 OneToMany로 연결이 된 관계에대해서

쿼리 조인을 해오는데 테스트에서 실행 할 시에는 다른 쿼리가 실행되지않고, User만을 가지고 옵니다.


분명 같은 메소드를 이용하였는데 왜 환경에 따라서 쿼리문의 차이가 나는건지 잘 모르겠습니다.

혹시 알려주실 분 계신가요 ㅠㅠ


테스트코드 쿼리문

Hibernate: 

    select

        user0_.id as id1_6_,

        user0_.nick_name as nick_nam2_6_,

        user0_.password as password3_6_,

        user0_.user_name as user_nam4_6_,

        user0_.wallet as wallet5_6_ 

    from

        user user0_ 

    where

        user0_.user_name=?

postMan 이용시

Hibernate: 

    select

        interiorwr0_.user_id as user_id6_3_0_,

        interiorwr0_.id as id1_3_0_,

        interiorwr0_.id as id1_3_1_,

        interiorwr0_.created_at as created_2_3_1_,

        interiorwr0_.inventory as inventor3_3_1_,

        interiorwr0_.user_id as user_id6_3_1_,

        interiorwr0_.x as x4_3_1_,

        interiorwr0_.z as z5_3_1_,

        interiorwr0_.interior_id as interior7_3_1_,

        interior1_.id as id1_2_2_,

        interior1_.cost as cost2_2_2_,

        interior1_.name as name3_2_2_,

        interior1_.type as type4_2_2_ 

    from

        interior_wrapper interiorwr0_ 

    inner join

        interior interior1_ 

            on interiorwr0_.interior_id=interior1_.id 

    where

        interiorwr0_.user_id=?

Hibernate: 

    select

        furniturew0_.user_id as user_id6_1_0_,

        furniturew0_.id as id1_1_0_,

        furniturew0_.id as id1_1_1_,

        furniturew0_.created_at as created_2_1_1_,

        furniturew0_.inventory as inventor3_1_1_,

        furniturew0_.user_id as user_id6_1_1_,

        furniturew0_.x as x4_1_1_,

        furniturew0_.z as z5_1_1_,

        furniturew0_.furniture_id as furnitur7_1_1_,

        furniture1_.id as id1_0_2_,

        furniture1_.cost as cost2_0_2_,

        furniture1_.name as name3_0_2_,

        furniture1_.type as type4_0_2_ 

    from

        furniture_wrapper furniturew0_ 

    inner join

        furniture furniture1_ 

            on furniturew0_.furniture_id=furniture1_.id 

    where

        furniturew0_.user_id=?

Hibernate: 

    select

        roomwrappe0_.user_id as user_id4_5_0_,

        roomwrappe0_.id as id1_5_0_,

        roomwrappe0_.id as id1_5_1_,

        roomwrappe0_.created_at as created_2_5_1_,

        roomwrappe0_.inventory as inventor3_5_1_,

        roomwrappe0_.user_id as user_id4_5_1_,

        roomwrappe0_.room_id as room_id5_5_1_,

        room1_.id as id1_4_2_,

        room1_.cost as cost2_4_2_,

        room1_.name as name3_4_2_ 

    from

        room_wrapper roomwrappe0_ 

    inner join

        room room1_ 

            on roomwrappe0_.room_id=room1_.id 

    where

        roomwrappe0_.user_id=?



0
  • 답변 0

  • 로그인을 하시면 답변을 등록할 수 있습니다.