package com.arms.config; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.ApplicationContext; import org.springframework.test.context.ActiveProfiles; import com.arms.api.issue.almapi.model.entity.AlmIssueEntity; import com.arms.egovframework.javaservice.esframework.repository.공통저장소; @SpringBootTest @ActiveProfiles("dev") class ApplicationContextProviderTest { @Autowired private List<공통저장소> repositories; private 공통저장소 findRepositoryByClass(Class clazz) { return repositories.stream() .filter(repo -> { Type[] genericInterfaces = repo.getClass().getGenericInterfaces(); List collect = Arrays.stream(genericInterfaces) .flatMap(type -> { Type[] generics = ((Class)type).getGenericInterfaces(); return Arrays.stream(generics) .filter(generic -> generic instanceof ParameterizedType) .filter(generic -> ((ParameterizedType)generic).getActualTypeArguments()[0].equals(clazz)); }).collect(Collectors.toList()); return !collect.isEmpty(); }) .map(repo-> (공통저장소)repo) .findFirst() .orElseThrow(()->new IllegalArgumentException("타입이 존재 하지 않습니다.")); } @Test @DisplayName("엔티티로저장소찾기") void test(){ 공통저장소 entityRepository = findRepositoryByClass(AlmIssueEntity.class); List allDocs = entityRepository.findAllHits().toDocs(); System.out.println(allDocs); } }