Юнит 5 разыскивался, но не вызван: в сервисе, который использует AsynctaskexecutorJAVA

Программисты JAVA общаются здесь
Anonymous
Юнит 5 разыскивался, но не вызван: в сервисе, который использует Asynctaskexecutor

Сообщение Anonymous »

разыскивается, но не вызван:
kimsactrestclient.act(br /> kimSactExecutionRequest [idkey = 1, changeKeyName = keyName, censueBy = null, ops = {}]
); < /p>
**PlanKeyServiceImpl.java**

@Service
public class PlanKeyServiceImpl implements PlanKeyService {
private final PlanKeyFunctions planKeyFunctions;
private final ChangeKeyService changeKeyService;
private final KimsActService kimsActService;
private final PlanKeyRepository planKeyRepository;
private final PlanSetRepository planSetRepository;
private final KimsActRestClient kimsActRestClient;
private final DraftKeyRepository draftKeyRepository;
private final AsyncTaskExecutor delegatingSecurityContextAsyncTaskExecutor;
private final AssortmentCommonsClient assortmentCommonsClient;

public PlanKeyServiceImpl(
PlanKeyFunctions planKeyFunctions,
ChangeKeyService changeKeyService,
KimsActService kimsActService,
PlanKeyRepository planKeyRepository,
PlanSetRepository planSetRepository,
KimsActRestClient kimsActRestClient,
DraftKeyRepository draftKeyRepository,
AssortmentCommonsClient assortmentCommonsClient,
@Qualifier ("asyncTaskExecutorWithSecurityContext") AsyncTaskExecutor delegatingSecurityContextAsyncTaskExecutor
) {
this.planKeyFunctions = planKeyFunctions;
this.changeKeyService = changeKeyService;
this.kimsActService = kimsActService;
this.planKeyRepository = planKeyRepository;
this.planSetRepository = planSetRepository;
this.kimsActRestClient = kimsActRestClient;
this.draftKeyRepository = draftKeyRepository;
this.delegatingSecurityContextAsyncTaskExecutor = delegatingSecurityContextAsyncTaskExecutor;
this.assortmentCommonsClient = assortmentCommonsClient;
}
10 public void commit(
11 PlanKeyRecord pkR
12 ) {
13 PlanKey planKey = planKeyFunctions.fetchPlanKey.apply(pkR.idkey());
14 PlanKeyStatus status = PlanKeyStatus.getStatus(planKey.getState());
15
16 switch (status) {
17 case CMPL -> throw new IllegalStateException("Cannot publish a completed PlanKey");
18 case PUB -> throw new IllegalStateException("PlanKey is already being published.");
19 case ACTV -> { //Active planKey is eligible for publish
20 ChangeKeyRecord ckR = changeKeyService.fetch(pkR.idkey());
21 act(pkR.idkey(), ckR.changeKeyName(), planKey.getCreatedBy());
22 } default -> throw new IllegalStateException("Unexpected value: " + status);
23 }
24 }

26 public void act(
27 Long idkey,
28 String changeKeyName,
29 String createdBy
30 ) {
31 CompletableFuture.supplyAsync(() -> {
32 kimsActRestClient.act(new KimsActExecutionRequest(idkey, changeKeyName,createdBy,null));
33 planKeyRepository.updateStatus(idkey, PlanKeyStatus.PUB.name().toLowerCase());
34 return null;
35 }, delegatingSecurityContextAsyncTaskExecutor);
36 }

**Junit Test class**

@ExtendWith(MockitoExtension.class)
public class PlanKeyServiceImplTest {

@Mock
DraftKeyRepository draftKeyRepository;

@Mock
PlanKeyRepository planKeyRepository;

@Mock
AssortmentCommonsClient assortmentCommonsClient;

@InjectMocks
PlanKeyFunctions planKeyFunctions = mock(PlanKeyFunctions.class);

@Mock
ChangeKeyService changeKeyService;

@Mock
KimsActRestClient kimsActRestClient;

@Mock
AsyncTaskExecutor delegatingSecurityContextAsyncTaskExecutor;

@InjectMocks
PlanKeyServiceImpl planKeyService;
@Test
void commit_actsWhenPlanKeyIsActive() {
// Initialize test data
PlanKeyRecord record = new PlanKeyRecord(1L);
PlanKey planKey = new PlanKey();
planKey.setState("ACTV");
ChangeKeyRecord changeKeyRecord = new ChangeKeyRecord(1L, "keyName");

// Ensure planKeyFunctions is properly initialized before use
planKeyFunctions.fetchPlanKey = ( Function )Mockito.mock(Function.class);

planKeyFunctions.fetchPlanKeyItem = ( Function
)Mockito.mock(Function.class);

planKeyFunctions.fetchPlanKeyLocation = ( Function )Mockito.mock(Function.class);

planKeyFunctions.fetchPlanKeySets = ( Function )Mockito.mock(Function.class);
assertThat(planKeyFunctions.fetchPlanKey).isNotNull();

// Setup mock behaviors
when(planKeyRepository.findPlanKeyByIdkey(1L)).thenReturn(planKey);
when(planKeyRepository.findById(1L)).thenReturn(Optional.of(planKey));
when(planKeyRepository.getPendingChangeSummaryNoActions(1L, 0, 0)).thenReturn(List.of());
when(planKeyRepository.getPendingChangeSummaryActions(1L)).thenReturn(List.of());
when(planKeyRepository.getPendingChangeSummaryCounts(1L)).thenReturn(Optional.empty());

when(kimsActRestClient.act(new KimsActExecutionRequest(record.idkey(), changeKeyRecord.changeKeyName(), planKey.getCreatedBy(),null))).thenReturn(null);
doNothing().when(planKeyRepository).updateStatus(1L, PlanKeyStatus.PUB.name().toLowerCase());

// Execute the test
planKeyService.commit(record);

// Verify the expected behaviors
40 verify(kimsActRestClient, times(1))
.act(new KimsActExecutionRequest(record.idkey(), changeKeyRecord.changeKeyName(), planKey.getCreatedBy(),null));
41 verify(planKeyRepository, times(1)).updateStatus(record.idkey(), PlanKeyStatus.PUB.name().toLowerCase());

}
< /code>
plankeyRepository.java
@Repository
public interface PlanKeyRepository extends JpaRepository
{

PlanKey findPlanKeyByIdkey(long keyId);

@Query(name = "getPendingChangeSummaryCounts", nativeQuery = true)
Optional getPendingChangeSummaryCounts(@Param("idkey") Long idkey);

@Query(name = "getPendingChangeSummaryActions", nativeQuery = true)
List getPendingChangeSummaryActions(@Param("idkey") Long idkey);

@Query(name = "getPendingChangeSummaryNoActions", nativeQuery = true)
List getPendingChangeSummaryNoActions(@Param("idkey") Long idkey, @Param("iddepartment") Integer departmentId, @Param("idclass") Integer classId);
}
< /code>
Line 40 SND 41 броски разыскиваемых, но не вызывается. После запуска его в режиме отладчика я добавил точки останова в номерах строк 32 и 33 в PlankeyServiceImpl.java, но не ударил их.


Подробнее здесь: https://stackoverflow.com/questions/796 ... skexecutor

Вернуться в «JAVA»