... import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; ... @ExtendWith(SpringExtension.class) public class TestTest { @Mock EntityRepository entityRepository; @AutoSource @ParameterizedTest public void create_test(Req..
import static org.mockito.Mockito.mock; public class TestClass { @ParameterizedTest public void test() { DummyRepository repository = mock(DummyRepository.class); DummyService service = new DummyService(repository); DummyClass dummy = new DummyClass(); Param param = new Param(); given(repository.getById(dummy.getId())).willReturn(dummy); service.update(dummy.getId(), param, "username"); assertTh..
list형 json custom converter 사용 import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import javax.persistence.AttributeConverter; import java.io.IOException; import java.util.List; public class StringListConverter implements AttributeConverter { private static final ObjectMapper..
entity에 enum list를 정의하고 싶을 때 사용! 1. enum 생성 public enum IndicatorReportType { ROE, TOTAL_REVENUE, TOTAL_EQUITY } 2. Converter를 만들고 public class ReportListConverter implements AttributeConverter { private static final ObjectMapper mapper = new ObjectMapper() .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) .configure(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, false); ..
@DataJpaTest @ActiveProfiles(value = "test") @AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE) @Import({DataBaseConfig.class, QuerydslConfig.class, SpringJpaProperties.class}) @ContextConfiguration(classes = { EnableConfigurationProperties.class, ConfigurationPropertiesScan.class }) @ComponentScan("my.project.domain.repository") 위 소스에 있는 annotation들을 붙이면 전체 spring cont..
@Entity @Table(name = "tb_item") @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) public class Item extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.AUTO) Long id; @Column(columnDefinition = "VARCHAR", length = 10) private String str; }
querydsl 사용할 경우 public Page findItemBy(SearchItemClause clause, Pageable pageable) { QueryResults results = jpaQueryFactory.select(QItem.item) .from(item) .where(clause.whereClause()) .distinct() .offset(pageable.getOffset()) .limit(pageable.getPageSize()) .fetchResults(); results.getResults().stream().map(Item::getSubItem).forEach(Hibernate::initialize); return new PageImpl(results.getResults()..
- Total
- Today
- Yesterday