|
|
|
@ -14,6 +14,10 @@ import com.sztzjy.linkCommerce.config.exception.handler.ServiceException;
|
|
|
|
import com.sztzjy.linkCommerce.config.security.JwtUser;
|
|
|
|
import com.sztzjy.linkCommerce.config.security.JwtUser;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import org.mockito.ArgumentCaptor;
|
|
|
|
import org.mockito.ArgumentCaptor;
|
|
|
|
|
|
|
|
import org.springframework.transaction.PlatformTransactionManager;
|
|
|
|
|
|
|
|
import org.springframework.transaction.TransactionDefinition;
|
|
|
|
|
|
|
|
import org.springframework.transaction.TransactionStatus;
|
|
|
|
|
|
|
|
import org.springframework.transaction.support.SimpleTransactionStatus;
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
@ -72,6 +76,8 @@ class AiTrainingEvaluationServiceImplTest {
|
|
|
|
.thenReturn(null, evaluation);
|
|
|
|
.thenReturn(null, evaluation);
|
|
|
|
when(service.aiTrainingEvaluationMapper.claimAssessment(eq("evaluation-1"), any(Date.class))).thenReturn(1);
|
|
|
|
when(service.aiTrainingEvaluationMapper.claimAssessment(eq("evaluation-1"), any(Date.class))).thenReturn(1);
|
|
|
|
when(service.qwenChatClient.completeJson(any(), any())).thenReturn(assessmentJson());
|
|
|
|
when(service.qwenChatClient.completeJson(any(), any())).thenReturn(assessmentJson());
|
|
|
|
|
|
|
|
when(service.aiTrainingEvaluationMapper.completeAssessment(any(AiTrainingEvaluation.class))).thenReturn(1);
|
|
|
|
|
|
|
|
when(service.studentTrainingAnswerMapper.updateAiAssessmentScore(eq("answer-1"), eq(86), any(Date.class))).thenReturn(1);
|
|
|
|
|
|
|
|
|
|
|
|
AiTrainingEvaluationView view = service.generateAssessment("new-product-survey", student());
|
|
|
|
AiTrainingEvaluationView view = service.generateAssessment("new-product-survey", student());
|
|
|
|
|
|
|
|
|
|
|
|
@ -79,6 +85,43 @@ class AiTrainingEvaluationServiceImplTest {
|
|
|
|
verify(service.studentTrainingAnswerMapper).updateAiAssessmentScore(eq("answer-1"), eq(86), any(Date.class));
|
|
|
|
verify(service.studentTrainingAnswerMapper).updateAiAssessmentScore(eq("answer-1"), eq(86), any(Date.class));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
void assessmentScoreWriteFailureRollsBackCompletionAndLeavesEvaluationRetryable() throws Exception {
|
|
|
|
|
|
|
|
AiTrainingEvaluationServiceImpl service = serviceWithContext(answer("answer-1", "step one", null, null, null));
|
|
|
|
|
|
|
|
AiTrainingEvaluation evaluation = evaluation("NOT_STARTED", "NOT_STARTED");
|
|
|
|
|
|
|
|
RecordingTransactionManager transactionManager = new RecordingTransactionManager(evaluation);
|
|
|
|
|
|
|
|
service.assessmentCompletionTransactionManager = transactionManager;
|
|
|
|
|
|
|
|
when(service.aiTrainingEvaluationMapper.findByStudentClassAndTask("stu-1", "class-1", "task-1"))
|
|
|
|
|
|
|
|
.thenReturn(null, evaluation);
|
|
|
|
|
|
|
|
when(service.aiTrainingEvaluationMapper.claimAssessment(eq("evaluation-1"), any(Date.class))).thenAnswer(invocation -> {
|
|
|
|
|
|
|
|
evaluation.setAssessmentStatus("PROCESSING");
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
when(service.qwenChatClient.completeJson(any(), any())).thenAnswer(invocation -> {
|
|
|
|
|
|
|
|
assertTrue(!transactionManager.transactionActive);
|
|
|
|
|
|
|
|
return assessmentJson();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
when(service.aiTrainingEvaluationMapper.completeAssessment(any(AiTrainingEvaluation.class))).thenAnswer(invocation -> {
|
|
|
|
|
|
|
|
evaluation.setAssessmentStatus("SUCCEEDED");
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
when(service.studentTrainingAnswerMapper.updateAiAssessmentScore(eq("answer-1"), eq(86), any(Date.class)))
|
|
|
|
|
|
|
|
.thenThrow(new IllegalStateException("score write failed"));
|
|
|
|
|
|
|
|
when(service.aiTrainingEvaluationMapper.failAssessment(eq("evaluation-1"), any(), any(Date.class))).thenAnswer(invocation -> {
|
|
|
|
|
|
|
|
if ("PROCESSING".equals(evaluation.getAssessmentStatus())) {
|
|
|
|
|
|
|
|
evaluation.setAssessmentStatus("FAILED");
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertThrows(ServiceException.class, () -> service.generateAssessment("new-product-survey", student()));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertEquals("FAILED", evaluation.getAssessmentStatus());
|
|
|
|
|
|
|
|
assertTrue(!"SUCCEEDED".equals(evaluation.getAssessmentStatus()));
|
|
|
|
|
|
|
|
assertTrue(transactionManager.rollbackCalled);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void assessmentRejectsInvalidCriteriaTotal() {
|
|
|
|
void assessmentRejectsInvalidCriteriaTotal() {
|
|
|
|
AiTrainingEvaluationServiceImpl service = serviceWithContext(answer("answer-1", "step one", null, null, null));
|
|
|
|
AiTrainingEvaluationServiceImpl service = serviceWithContext(answer("answer-1", "step one", null, null, null));
|
|
|
|
@ -216,6 +259,9 @@ class AiTrainingEvaluationServiceImplTest {
|
|
|
|
service.studentTrainingAnswerMapper = mock(StudentTrainingAnswerMapper.class);
|
|
|
|
service.studentTrainingAnswerMapper = mock(StudentTrainingAnswerMapper.class);
|
|
|
|
service.teachingClassStudentMapper = mock(TeachingClassStudentMapper.class);
|
|
|
|
service.teachingClassStudentMapper = mock(TeachingClassStudentMapper.class);
|
|
|
|
service.qwenChatClient = mock(QwenChatClient.class);
|
|
|
|
service.qwenChatClient = mock(QwenChatClient.class);
|
|
|
|
|
|
|
|
service.assessmentCompletionTransactionManager = mock(PlatformTransactionManager.class);
|
|
|
|
|
|
|
|
when(service.assessmentCompletionTransactionManager.getTransaction(any(TransactionDefinition.class)))
|
|
|
|
|
|
|
|
.thenReturn(new SimpleTransactionStatus());
|
|
|
|
when(service.trainingTaskMapper.selectByTaskKey("new-product-survey")).thenReturn(task());
|
|
|
|
when(service.trainingTaskMapper.selectByTaskKey("new-product-survey")).thenReturn(task());
|
|
|
|
TeachingClassStudent member = new TeachingClassStudent();
|
|
|
|
TeachingClassStudent member = new TeachingClassStudent();
|
|
|
|
member.setTeachingClassId("class-1");
|
|
|
|
member.setTeachingClassId("class-1");
|
|
|
|
@ -224,6 +270,34 @@ class AiTrainingEvaluationServiceImplTest {
|
|
|
|
return service;
|
|
|
|
return service;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static class RecordingTransactionManager implements PlatformTransactionManager {
|
|
|
|
|
|
|
|
private final AiTrainingEvaluation evaluation;
|
|
|
|
|
|
|
|
private boolean transactionActive;
|
|
|
|
|
|
|
|
private boolean rollbackCalled;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private RecordingTransactionManager(AiTrainingEvaluation evaluation) {
|
|
|
|
|
|
|
|
this.evaluation = evaluation;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public TransactionStatus getTransaction(TransactionDefinition definition) {
|
|
|
|
|
|
|
|
transactionActive = true;
|
|
|
|
|
|
|
|
return new SimpleTransactionStatus();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void commit(TransactionStatus status) {
|
|
|
|
|
|
|
|
transactionActive = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void rollback(TransactionStatus status) {
|
|
|
|
|
|
|
|
transactionActive = false;
|
|
|
|
|
|
|
|
rollbackCalled = true;
|
|
|
|
|
|
|
|
evaluation.setAssessmentStatus("PROCESSING");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private TrainingTask task() {
|
|
|
|
private TrainingTask task() {
|
|
|
|
TrainingTask task = new TrainingTask();
|
|
|
|
TrainingTask task = new TrainingTask();
|
|
|
|
task.setId("task-1");
|
|
|
|
task.setId("task-1");
|
|
|
|
|