fix: localize hardware cost step four validation
parent
046bc1fe96
commit
48637ac804
@ -0,0 +1,66 @@
|
||||
package com.sztzjy.linkCommerce.service.impl;
|
||||
|
||||
import com.sztzjy.linkCommerce.config.security.JwtUser;
|
||||
import com.sztzjy.linkCommerce.entity.StudentTrainingAnswer;
|
||||
import com.sztzjy.linkCommerce.entity.TeachingClassStudent;
|
||||
import com.sztzjy.linkCommerce.entity.TrainingTask;
|
||||
import com.sztzjy.linkCommerce.entity.dto.HardwareCostStepFourValidationRequest;
|
||||
import com.sztzjy.linkCommerce.entity.dto.HardwareCostStepFourValidationResult;
|
||||
import com.sztzjy.linkCommerce.mapper.StudentTrainingAnswerMapper;
|
||||
import com.sztzjy.linkCommerce.mapper.TeachingClassStudentMapper;
|
||||
import com.sztzjy.linkCommerce.mapper.TrainingTaskMapper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
class HardwareCostStepFourServiceImplTest {
|
||||
@Test
|
||||
void reportsChineseValidationSuccessAfterChartsAndOptimizationPlanAreComplete() {
|
||||
HardwareCostStepFourValidationResult result = serviceWithCompletedPreviousSteps().validate(completedRequest(), student());
|
||||
|
||||
assertTrue(result.isValid());
|
||||
assertEquals("成本结构图与成本优化方案校验通过。", result.getMessage());
|
||||
}
|
||||
|
||||
private HardwareCostStepFourServiceImpl serviceWithCompletedPreviousSteps() {
|
||||
HardwareCostStepFourServiceImpl service = new HardwareCostStepFourServiceImpl();
|
||||
TeachingClassStudentMapper memberships = mock(TeachingClassStudentMapper.class);
|
||||
TrainingTaskMapper tasks = mock(TrainingTaskMapper.class);
|
||||
StudentTrainingAnswerMapper answers = mock(StudentTrainingAnswerMapper.class);
|
||||
TeachingClassStudent membership = new TeachingClassStudent();
|
||||
membership.setTeachingClassId("class-1");
|
||||
TrainingTask task = new TrainingTask();
|
||||
task.setId("task-16");
|
||||
StudentTrainingAnswer answer = new StudentTrainingAnswer();
|
||||
answer.setStep1Answer("{}");
|
||||
answer.setStep2Answer("{}");
|
||||
answer.setStep3Answer("{}");
|
||||
when(memberships.selectActiveByStudentUserId("student-1")).thenReturn(membership);
|
||||
when(tasks.selectByTaskKey("hardware-cost")).thenReturn(task);
|
||||
when(answers.selectByStudentClassAndTask(anyString(), anyString(), anyString())).thenReturn(answer);
|
||||
ReflectionTestUtils.setField(service, "teachingClassStudentMapper", memberships);
|
||||
ReflectionTestUtils.setField(service, "trainingTaskMapper", tasks);
|
||||
ReflectionTestUtils.setField(service, "studentTrainingAnswerMapper", answers);
|
||||
return service;
|
||||
}
|
||||
|
||||
private HardwareCostStepFourValidationRequest completedRequest() {
|
||||
HardwareCostStepFourValidationRequest request = new HardwareCostStepFourValidationRequest();
|
||||
request.setSmallBatchChartUrl("/file/small-batch.png");
|
||||
request.setLargeBatchChartUrl("/file/large-batch.png");
|
||||
request.setOptimizationPlan("优先优化高成本元器件,并保留关键性能冗余。");
|
||||
return request;
|
||||
}
|
||||
|
||||
private JwtUser student() {
|
||||
JwtUser user = new JwtUser();
|
||||
user.setUserId("student-1");
|
||||
user.setRoleId(4);
|
||||
return user;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue